Skip to content
项目
群组
代码片段
帮助
正在加载...
登录
切换导航
F
freeswitch
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
张华
freeswitch
Commits
ff555aa5
提交
ff555aa5
authored
3月 14, 2014
作者:
Chris Rienzo
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
mod_rayo: some bugfixes to pause-when-offline
上级
25db7bd7
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
82 行增加
和
46 行删除
+82
-46
mod_rayo.c
src/mod/event_handlers/mod_rayo/mod_rayo.c
+82
-46
没有找到文件。
src/mod/event_handlers/mod_rayo/mod_rayo.c
浏览文件 @
ff555aa5
...
...
@@ -36,7 +36,8 @@
SWITCH_MODULE_SHUTDOWN_FUNCTION
(
mod_rayo_shutdown
);
SWITCH_MODULE_LOAD_FUNCTION
(
mod_rayo_load
);
SWITCH_MODULE_DEFINITION
(
mod_rayo
,
mod_rayo_load
,
mod_rayo_shutdown
,
NULL
);
SWITCH_MODULE_RUNTIME_FUNCTION
(
mod_rayo_runtime
);
SWITCH_MODULE_DEFINITION
(
mod_rayo
,
mod_rayo_load
,
mod_rayo_shutdown
,
mod_rayo_runtime
);
#define RAYO_CAUSE_HANGUP SWITCH_CAUSE_NORMAL_CLEARING
#define RAYO_CAUSE_DECLINE SWITCH_CAUSE_CALL_REJECTED
...
...
@@ -224,6 +225,8 @@ static struct {
int
offer_uri
;
/** if true, pause inbound calling if all clients are offline */
int
pause_when_offline
;
/** flag to reduce log noise */
int
offline_logged
;
}
globals
;
/**
...
...
@@ -458,6 +461,62 @@ static void add_header(iks *node, const char *name, const char *value)
}
}
static
void
pause_inbound_calling
(
void
)
{
int32_t
arg
=
1
;
switch_mutex_lock
(
globals
.
clients_mutex
);
switch_core_session_ctl
(
SCSC_PAUSE_INBOUND
,
&
arg
);
if
(
!
globals
.
offline_logged
)
{
switch_log_printf
(
SWITCH_CHANNEL_LOG
,
SWITCH_LOG_INFO
,
"Pausing inbound calling
\n
"
);
globals
.
offline_logged
=
1
;
}
switch_mutex_unlock
(
globals
.
clients_mutex
);
}
static
void
resume_inbound_calling
(
void
)
{
int32_t
arg
=
0
;
switch_mutex_lock
(
globals
.
clients_mutex
);
switch_core_session_ctl
(
SCSC_PAUSE_INBOUND
,
&
arg
);
if
(
globals
.
offline_logged
)
{
switch_log_printf
(
SWITCH_CHANNEL_LOG
,
SWITCH_LOG_INFO
,
"Resuming inbound calling
\n
"
);
globals
.
offline_logged
=
0
;
}
switch_mutex_unlock
(
globals
.
clients_mutex
);
}
/**
* Check online status of rayo client(s) and pause/resume the server
*/
static
void
pause_when_offline
(
void
)
{
if
(
globals
.
pause_when_offline
)
{
int
is_online
=
0
;
switch_hash_index_t
*
hi
;
switch_mutex_lock
(
globals
.
clients_mutex
);
for
(
hi
=
switch_core_hash_first
(
globals
.
clients_roster
);
hi
;
hi
=
switch_core_hash_next
(
hi
))
{
const
void
*
key
;
void
*
client
;
switch_core_hash_this
(
hi
,
&
key
,
NULL
,
&
client
);
switch_assert
(
client
);
if
(
RAYO_CLIENT
(
client
)
->
availability
==
PS_ONLINE
)
{
is_online
=
1
;
break
;
}
}
if
(
is_online
)
{
resume_inbound_calling
();
}
else
{
pause_inbound_calling
();
}
switch_mutex_unlock
(
globals
.
clients_mutex
);
}
}
/**
* Send event to clients
* @param from event sender
...
...
@@ -1369,30 +1428,6 @@ struct rayo_component *_rayo_component_init(struct rayo_component *component, sw
return
component
;
}
/**
* @return true if at least one rayo client is online
*/
static
int
is_rayo_client_online
(
void
)
{
int
is_online
=
0
;
switch_hash_index_t
*
hi
;
switch_mutex_lock
(
globals
.
clients_mutex
);
for
(
hi
=
switch_core_hash_first
(
globals
.
clients_roster
);
hi
;
hi
=
switch_core_hash_next
(
hi
))
{
const
void
*
key
;
void
*
client
;
switch_core_hash_this
(
hi
,
&
key
,
NULL
,
&
client
);
switch_assert
(
client
);
if
(
RAYO_CLIENT
(
client
)
->
availability
==
PS_ONLINE
)
{
is_online
=
1
;
break
;
}
}
switch_mutex_unlock
(
globals
.
clients_mutex
);
return
is_online
;
}
/**
* Send XMPP message to client
*/
...
...
@@ -1417,11 +1452,7 @@ static void rayo_client_cleanup(struct rayo_actor *actor)
}
switch_mutex_unlock
(
globals
.
clients_mutex
);
if
(
globals
.
pause_when_offline
&&
!
is_rayo_client_online
())
{
/* pause inbound calling */
int32_t
arg
=
1
;
switch_core_session_ctl
(
SCSC_PAUSE_INBOUND
,
&
arg
);
}
pause_when_offline
();
}
/**
...
...
@@ -1455,11 +1486,7 @@ static struct rayo_client *rayo_client_init(struct rayo_client *client, switch_m
switch_mutex_unlock
(
globals
.
clients_mutex
);
}
if
(
globals
.
pause_when_offline
&&
is_rayo_client_online
())
{
/* resume inbound calling */
int32_t
arg
=
0
;
switch_core_session_ctl
(
SCSC_PAUSE_INBOUND
,
&
arg
);
}
pause_when_offline
();
return
client
;
}
...
...
@@ -2822,17 +2849,7 @@ static void on_client_presence(struct rayo_client *rclient, iks *node)
RAYO_UNLOCK
(
rclient
);
}
if
(
globals
.
pause_when_offline
)
{
if
(
is_rayo_client_online
())
{
/* resume inbound calling */
int32_t
arg
=
0
;
switch_core_session_ctl
(
SCSC_PAUSE_INBOUND
,
&
arg
);
}
else
{
/* pause inbound calling */
int32_t
arg
=
1
;
switch_core_session_ctl
(
SCSC_PAUSE_INBOUND
,
&
arg
);
}
}
pause_when_offline
();
}
/**
...
...
@@ -3613,6 +3630,7 @@ SWITCH_STANDARD_APP(rayo_app)
/* nobody to offer to */
if
(
!
ok
)
{
pause_when_offline
();
switch_log_printf
(
SWITCH_CHANNEL_SESSION_LOG
(
session
),
SWITCH_LOG_NOTICE
,
"Rejecting rayo call - there are no online rayo clients to offer call to
\n
"
);
switch_channel_hangup
(
channel
,
SWITCH_CAUSE_NORMAL_TEMPORARY_FAILURE
);
}
...
...
@@ -4534,6 +4552,7 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_rayo_load)
switch_core_hash_init
(
&
globals
.
cmd_aliases
);
switch_thread_rwlock_create
(
&
globals
.
shutdown_rwlock
,
pool
);
switch_queue_create
(
&
globals
.
msg_queue
,
25000
,
pool
);
globals
.
offline_logged
=
1
;
/* server commands */
rayo_actor_command_handler_add
(
RAT_SERVER
,
""
,
"get:"
IKS_NS_XMPP_PING
":ping"
,
on_iq_xmpp_ping
);
...
...
@@ -4668,6 +4687,23 @@ SWITCH_MODULE_SHUTDOWN_FUNCTION(mod_rayo_shutdown)
return
SWITCH_STATUS_SUCCESS
;
}
/**
* Checks status of connected clients
*/
SWITCH_MODULE_RUNTIME_FUNCTION
(
mod_rayo_runtime
)
{
if
(
globals
.
pause_when_offline
)
{
switch_thread_rwlock_rdlock
(
globals
.
shutdown_rwlock
);
while
(
!
globals
.
shutdown
)
{
switch_sleep
(
1000
*
1000
);
/* 1 second */
pause_when_offline
();
}
switch_thread_rwlock_unlock
(
globals
.
shutdown_rwlock
);
switch_log_printf
(
SWITCH_CHANNEL_LOG
,
SWITCH_LOG_DEBUG
,
"Runtime thread is done
\n
"
);
}
return
SWITCH_STATUS_TERM
;
}
/* For Emacs:
* Local Variables:
* mode:c
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论