Skip to content
项目
群组
代码片段
帮助
正在加载...
登录
切换导航
F
freeswitch
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
张华
freeswitch
Commits
7e6ba429
提交
7e6ba429
authored
1月 06, 2017
作者:
Andrey Volk
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
FS-9928 [mod_v8] Implement Event Hooks in JavaScript
上级
c0423c58
隐藏空白字符变更
内嵌
并排
正在显示
6 个修改的文件
包含
78 行增加
和
5 行删除
+78
-5
v8.conf.xml
conf/curl/autoload_configs/v8.conf.xml
+2
-0
v8.conf.xml
conf/insideout/autoload_configs/v8.conf.xml
+2
-0
v8.conf.xml
conf/vanilla/autoload_configs/v8.conf.xml
+2
-0
v8.conf.xml
src/mod/languages/mod_v8/conf/autoload_configs/v8.conf.xml
+2
-0
mod_v8.cpp
src/mod/languages/mod_v8/mod_v8.cpp
+61
-5
mod_v8.h
src/mod/languages/mod_v8/mod_v8.h
+9
-0
没有找到文件。
conf/curl/autoload_configs/v8.conf.xml
浏览文件 @
7e6ba429
...
...
@@ -2,6 +2,8 @@
<settings>
<!-- <param name="xml-handler-script" value="directory.js"/> -->
<!-- <param name="xml-handler-bindings" value="directory"/> -->
<!-- <hook event="CUSTOM" subclass="sofia::register" script="catch-event.js"/> -->
<!-- <hook event="CHANNEL_HANGUP" script="hangup-event.js"/> -->
</settings>
<modules>
<!-- <load module="mod_v8_skel"/> -->
...
...
conf/insideout/autoload_configs/v8.conf.xml
浏览文件 @
7e6ba429
...
...
@@ -2,6 +2,8 @@
<settings>
<!-- <param name="xml-handler-script" value="directory.js"/> -->
<!-- <param name="xml-handler-bindings" value="directory"/> -->
<!-- <hook event="CUSTOM" subclass="sofia::register" script="catch-event.js"/> -->
<!-- <hook event="CHANNEL_HANGUP" script="hangup-event.js"/> -->
</settings>
<modules>
<!-- <load module="mod_v8_skel"/> -->
...
...
conf/vanilla/autoload_configs/v8.conf.xml
浏览文件 @
7e6ba429
...
...
@@ -2,6 +2,8 @@
<settings>
<!-- <param name="xml-handler-script" value="directory.js"/> -->
<!-- <param name="xml-handler-bindings" value="directory"/> -->
<!-- <hook event="CUSTOM" subclass="sofia::register" script="catch-event.js"/> -->
<!-- <hook event="CHANNEL_HANGUP" script="hangup-event.js"/> -->
</settings>
<modules>
<!-- <load module="mod_v8_skel"/> -->
...
...
src/mod/languages/mod_v8/conf/autoload_configs/v8.conf.xml
浏览文件 @
7e6ba429
...
...
@@ -2,6 +2,8 @@
<settings>
<!-- <param name="xml-handler-script" value="directory.js"/> -->
<!-- <param name="xml-handler-bindings" value="directory"/> -->
<!-- <hook event="CUSTOM" subclass="sofia::register" script="catch-event.js"/> -->
<!-- <hook event="CHANNEL_HANGUP" script="hangup-event.js"/> -->
</settings>
<modules>
<!-- <load module="mod_v8_skel"/> -->
...
...
src/mod/languages/mod_v8/mod_v8.cpp
浏览文件 @
7e6ba429
...
...
@@ -276,7 +276,7 @@ static switch_status_t load_modules(void)
switch_core_hash_init
(
&
module_manager
.
load_hash
);
if
((
xml
=
switch_xml_open_cfg
(
cf
,
&
cfg
,
NULL
)))
{
switch_xml_t
mods
,
ld
,
settings
,
param
;
switch_xml_t
mods
,
ld
,
settings
,
param
,
hook
;
if
((
settings
=
switch_xml_child
(
cfg
,
"settings"
)))
{
for
(
param
=
switch_xml_child
(
settings
,
"param"
);
param
;
param
=
param
->
next
)
{
...
...
@@ -293,6 +293,37 @@ static switch_status_t load_modules(void)
}
}
}
for
(
hook
=
switch_xml_child
(
settings
,
"hook"
);
hook
;
hook
=
hook
->
next
)
{
char
*
event
=
(
char
*
)
switch_xml_attr_soft
(
hook
,
"event"
);
char
*
subclass
=
(
char
*
)
switch_xml_attr_soft
(
hook
,
"subclass"
);
char
*
script
=
(
char
*
)
switch_xml_attr_soft
(
hook
,
"script"
);
switch_event_types_t
evtype
;
if
(
!
zstr
(
script
))
{
script
=
switch_core_strdup
(
globals
.
pool
,
script
);
}
switch_log_printf
(
SWITCH_CHANNEL_LOG
,
SWITCH_LOG_INFO
,
"hook params: '%s' | '%s' | '%s'
\n
"
,
event
,
subclass
,
script
);
if
(
switch_name_event
(
event
,
&
evtype
)
==
SWITCH_STATUS_SUCCESS
)
{
if
(
!
zstr
(
script
))
{
if
(
switch_event_bind
(
modname
,
evtype
,
!
zstr
(
subclass
)
?
subclass
:
SWITCH_EVENT_SUBCLASS_ANY
,
v8_event_handler
,
script
)
==
SWITCH_STATUS_SUCCESS
)
{
switch_log_printf
(
SWITCH_CHANNEL_LOG
,
SWITCH_LOG_INFO
,
"event handler for '%s' set to '%s'
\n
"
,
switch_event_name
(
evtype
),
script
);
}
else
{
switch_log_printf
(
SWITCH_CHANNEL_LOG
,
SWITCH_LOG_ERROR
,
"cannot set event handler: unsuccessful bind
\n
"
);
}
}
else
{
switch_log_printf
(
SWITCH_CHANNEL_LOG
,
SWITCH_LOG_ERROR
,
"cannot set event handler: no script name for event type '%s'
\n
"
,
event
);
}
}
else
{
switch_log_printf
(
SWITCH_CHANNEL_LOG
,
SWITCH_LOG_ERROR
,
"cannot set event handler: unknown event type '%s'
\n
"
,
event
);
}
}
}
if
((
mods
=
switch_xml_child
(
cfg
,
"modules"
)))
{
...
...
@@ -403,7 +434,7 @@ static char *v8_get_script_path(const char *script_file)
}
}
static
int
v8_parse_and_execute
(
switch_core_session_t
*
session
,
const
char
*
input_code
,
switch_stream_handle_t
*
api_stream
,
switch_event_t
*
message
,
v8_xml_handler_t
*
xml_handler
)
static
int
v8_parse_and_execute
(
switch_core_session_t
*
session
,
const
char
*
input_code
,
switch_stream_handle_t
*
api_stream
,
v8_event_t
*
v8_event
,
v8_xml_handler_t
*
xml_handler
)
{
string
res
;
JSMain
*
js
;
...
...
@@ -509,8 +540,9 @@ static int v8_parse_and_execute(switch_core_session_t *session, const char *inpu
context
->
Global
()
->
Set
(
String
::
NewFromUtf8
(
isolate
,
"session"
),
Boolean
::
New
(
isolate
,
false
));
}
if
(
message
)
{
FSEvent
::
New
(
message
,
"message"
,
js
);
if
(
v8_event
)
{
if
(
v8_event
->
event
&&
v8_event
->
var_name
)
FSEvent
::
New
(
v8_event
->
event
,
v8_event
->
var_name
,
js
);
}
if
(
api_stream
)
{
...
...
@@ -724,6 +756,25 @@ static switch_xml_t v8_fetch(const char *section,
return
xml
;
}
static
void
v8_event_handler
(
switch_event_t
*
event
)
{
char
*
script
=
NULL
;
if
(
event
->
bind_user_data
)
{
script
=
strdup
((
char
*
)
event
->
bind_user_data
);
}
v8_event_t
v8_event
;
v8_event
.
event
=
event
;
v8_event
.
var_name
=
"event"
;
switch_log_printf
(
SWITCH_CHANNEL_LOG
,
SWITCH_LOG_DEBUG
,
"v8 event hook: execute '%s'
\n
"
,
(
char
*
)
script
);
v8_parse_and_execute
(
NULL
,
script
,
NULL
,
&
v8_event
,
NULL
);
switch_safe_free
(
script
);
}
SWITCH_BEGIN_EXTERN_C
SWITCH_STANDARD_APP
(
v8_dp_function
)
...
...
@@ -733,7 +784,12 @@ SWITCH_STANDARD_APP(v8_dp_function)
SWITCH_STANDARD_CHAT_APP
(
v8_chat_function
)
{
v8_parse_and_execute
(
NULL
,
data
,
NULL
,
message
,
NULL
);
v8_event_t
v8_event
;
v8_event
.
event
=
message
;
v8_event
.
var_name
=
"message"
;
v8_parse_and_execute
(
NULL
,
data
,
NULL
,
&
v8_event
,
NULL
);
return
SWITCH_STATUS_SUCCESS
;
}
...
...
src/mod/languages/mod_v8/mod_v8.h
浏览文件 @
7e6ba429
...
...
@@ -24,6 +24,7 @@
* Contributor(s):
* Peter Olsson <peter@olssononline.se>
* Anthony Minessale II <anthm@freeswitch.org>
* Andrey Volk <andywolk@gmail.com>
*
* mod_v8.h -- JavaScript FreeSWITCH module header file
*
...
...
@@ -71,12 +72,20 @@ typedef struct {
char
*
XML_STRING
;
}
v8_xml_handler_t
;
/* Struct that stores a javascript variable's name for an event */
typedef
struct
{
const
char
*
var_name
;
switch_event_t
*
event
;
}
v8_event_t
;
SWITCH_END_EXTERN_C
void
v8_add_event_handler
(
void
*
event_handler
);
void
v8_remove_event_handler
(
void
*
event_handler
);
static
switch_xml_t
v8_fetch
(
const
char
*
section
,
const
char
*
tag_name
,
const
char
*
key_name
,
const
char
*
key_value
,
switch_event_t
*
params
,
void
*
user_data
);
static
void
v8_event_handler
(
switch_event_t
*
event
);
#endif
/* MOD_V8_H */
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论