当前位置:网站首页>C language framework FreeSwitch custom event introduction and usage example
C language framework FreeSwitch custom event introduction and usage example
2022-08-08 04:54:00 【Small coachman】
博客主页:小小马车夫的主页
所属专栏:FreeSwitch开发实践
专栏介绍:主要介绍博主在实际项目中使用FreeSwitch开发外呼类项目的一些经验心得,主要涉及FreeSwitch的基本安装编译、基本配置、ESL、WSS、录音、自定义模块、media bug、语音播放、MRCP及对接AI机器人等内容.内容在持续更新中,如果感兴趣可以对专栏进行订阅~

文章目录
前言
We in the chapters beforeESLThe custom event subscription《【FreeSwitch开发实践】 ESL简介》,This paper introduced inFreeSwitchWriting a custom module,And define a custom event,然后发送事件、和用fs_cliIn the event subscription.
自定义事件,是在FreeSwitchStandard events such asAnswer、Hangup事件之外,Used to extend the event,在实际业务中,Can pass the custom events to some important results,如ASR的识别结果、Space to identify test results,通过ESL传输出来.
1、FreeSwitch自定义事件
先看代码:
switch_bool_t fire_my_event(switch_core_session_t* session)
{
switch_event_t *event = NULL;
const char* var = "my custom event";
switch_channel_t *channel = switch_core_session_get_channel(session);
if (switch_event_create_subclass(&event, SWITCH_EVENT_CUSTOM, "my_event_name") == SWITCH_STATUS_SUCCESS) {
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Custom-Variable", var);
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Unique-ID", switch_core_session_get_uuid(session));
switch_channel_event_set_data(channel, event);
switch_event_fire(&event);
}
return SWITCH_TRUE;
}
fire_my_eventFunction definitions custom events、并设置事件参数、发送事件.switch_event_create_subclass定义事件,SWITCH_EVENT_CUSTOM为自定义事件, 事件名称my_event_name.- ‘switch_event_add_header_string’ 添加
事件参数, 为键值对,Appear in the subscribe to events in the body.switch_event_fire发送事件.
2、Configure dialup plan
本次示例,模块名称:
myevent, 自定义事件名称:my_event_name·.
<extension name="myevent-diaplan">
<condition field="destination_number" expression="^10099$">
<action application="answer"/>
<action application="myevent"/>
<action application="echo" data=""/>
<action application="hangup" data=""/>
</condition>
</extension>
10099Is the name of the dial plan.
3、fs_cli事件订阅
/event plain CUSTOM my_event_name
my_event_name就是事件名称.
4、By calling the soft test and result output
By calling the soft test:
originate user/1000 10099
- 首先,需要注册
1000软电话,参考《【FreeSwitch开发实践】使用SIP客户端Yate连接FreeSwitch进行VoIP通话》.10099就是前面The dial plan defined names.
输出:
Event-Subclass: my_event_name
Event-Name: CUSTOM
Core-UUID: 25e79748-6092-4221-bf08-0ff2ff57baca
FreeSWITCH-Hostname: VM-8-10-centos
FreeSWITCH-Switchname: VM-8-10-centos
FreeSWITCH-IPv4: 10.0.8.10
FreeSWITCH-IPv6: fe80::5054:ff:fe58:28ea
Event-Date-Local: 2022-08-07 14:35:19
Event-Date-GMT: Sun, 07 Aug 2022 06:35:19 GMT
Event-Date-Timestamp: 1659854119135626
Event-Calling-File: mod_myevent.c
Event-Calling-Function: fire_my_event
Event-Calling-Line-Number: 58
Event-Sequence: 7236
Custom-Variable: my custom event
Unique-ID: 38ce44cd-d85d-46e2-a48e-be497e139f8a
Channel-State: CS_EXECUTE
Channel-Call-State: ACTIVE
Channel-State-Number: 4
Channel-Name: sofia/internal/[email protected]:33493
Unique-ID: 38ce44cd-d85d-46e2-a48e-be497e139f8a
Call-Direction: outbound
Presence-Call-Direction: outbound
Channel-HIT-Dialplan: true
Channel-Presence-ID: 1000@10.0.8.10
Channel-Call-UUID: 38ce44cd-d85d-46e2-a48e-be497e139f8a
Answer-State: answered
Channel-Read-Codec-Name: PCMU
Channel-Read-Codec-Rate: 8000
Channel-Read-Codec-Bit-Rate: 64000
Channel-Write-Codec-Name: PCMU
Channel-Write-Codec-Rate: 8000
Channel-Write-Codec-Bit-Rate: 64000
Caller-Direction: outbound
Caller-Logical-Direction: outbound
Caller-Dialplan: XML
Caller-Caller-ID-Name: Outbound Call
Caller-Caller-ID-Number: 1000
Caller-Orig-Caller-ID-Number: 0000000000
Caller-Callee-ID-Number: 0000000000
Caller-Network-Addr: 221.216.208.120
Caller-ANI: 0000000000
Caller-Destination-Number: 10099
Caller-Unique-ID: 38ce44cd-d85d-46e2-a48e-be497e139f8a
Caller-Source: src/switch_ivr_originate.c
Caller-Transfer-Source: 1659854119:38061f99-7fe0-4b03-9bdd-f0ca758622d3:bl_xfer:10099/default/XML
Caller-Context: default
Caller-RDNIS: 1000
Caller-Channel-Name: sofia/internal/[email protected]:33493
Caller-Profile-Index: 2
Caller-Profile-Created-Time: 1659854119135626
Caller-Channel-Created-Time: 1659854083475630
Caller-Channel-Answered-Time: 1659854119115643
Caller-Channel-Progress-Time: 1659854083535627
Caller-Channel-Progress-Media-Time: 0
Caller-Channel-Hangup-Time: 0
Caller-Channel-Transfer-Time: 0
Caller-Channel-Resurrect-Time: 0
Caller-Channel-Bridged-Time: 0
Caller-Channel-Last-Hold: 0
Caller-Channel-Hold-Accum: 0
Caller-Screen-Bit: true
Caller-Privacy-Hide-Name: false
Caller-Privacy-Hide-Number: false
variable_direction: outbound
variable_is_outbound: true
variable_uuid: 38ce44cd-d85d-46e2-a48e-be497e139f8a
variable_session_id: 16
variable_sip_profile_name: internal
variable_text_media_flow: disabled
variable_channel_name: sofia/internal/[email protected]:33493
variable_sip_destination_url: sip:[email protected]:33493
variable_dialed_user: 1000
variable_dialed_domain: 10.0.8.10
variable_sip_invite_domain: 10.0.8.10
variable_presence_id: 1000@10.0.8.10
variable_audio_media_flow: sendrecv
variable_local_video_ip: 10.0.8.10
variable_local_video_port: 21828
variable_video_media_flow: sendrecv
variable_rtp_local_sdp_str: v=0
o=FreeSWITCH 1659822373 1659822374 IN IP4 10.0.8.10
s=FreeSWITCH
c=IN IP4 10.0.8.10
t=0 0
m=audio 31710 RTP/AVP 9 0 8 101
a=rtpmap:9 G722/8000
a=rtpmap:0 PCMU/8000
a=rtpmap:8 PCMA/8000
a=rtpmap:101 telephone-event/8000
a=fmtp:101 0-15
a=ptime:20
a=sendrecv
m=video 21828 RTP/AVP 102
b=AS:3072
a=rtpmap:102 VP8/90000
a=sendrecv
a=rtcp-fb:102 ccm fir
a=rtcp-fb:102 ccm tmmbr
a=rtcp-fb:102 nack
a=rtcp-fb:102 nack pli
Can be seen in the custom event body event definitions of variables
Custom-Variable、Unique-ID.
总结
Above is the content of this,主要介绍如下:
- 自定义事件的定义
- The custom event variable Settings
- 拨号计划配置
- fs_cliThe custom event subscription
- By calling the soft test and subscribe to the custom event results
In this paper, code complete example download address
(The code download need integral,如果没有积分可以私信博主即可以免费获取)
如果觉得有些帮助或觉得文章还不错,请关注一下博主,你的关注是我持续写作的动力.另外,如果有什么问题,可以在评论区留言,或者私信博主,博主看到后会第一时间回复.
想对未来的自己说的话: 间歇性的努力和蒙混过日子,都是对之前努力的清零
欢迎转载,转载请注明出处:https://xiao2macf.blog.csdn.net/article/details/126211171
边栏推荐
- Lecture 84 Biweekly t4 6144 and Lecture 305 t4 6138
- 全网唯一OpenCyphal/UAVCAN教程(11)用candump和gawk工具写一个Cyphal协议解析小工具
- leetcode-同构字符串判断
- L3-007 天梯地图(测试点2卡住了可以看下)
- Error: [Intervention] Unable to preventDefault inside passive event listener due to target ...
- 【冷启动】快手《POSO: Personalized Cold Start Modules for Large-scale Recommender Systems》
- C language - function
- 76. 最小覆盖子串
- leetcode 112.路经总和 递归
- MindFusion.WPF Pack 2022.R1
猜你喜欢
![Talk about the principle and implementation of Redis distributed lock [Ant Financial Services Three Sides]](/img/ed/dbaeab544066b5dbf19e71bee0f8c9.png)
Talk about the principle and implementation of Redis distributed lock [Ant Financial Services Three Sides]

Building a High-Performance Platform on AWS Using Presto and Alluxio to Support Real-Time Gaming Services

Eighteen, OIDC OAuth2 】 【 the understanding of the application
![[opencv] Introduction to opencv development kit](/img/1a/7b60426d109c9f7231c67e4a4dad46.png)
[opencv] Introduction to opencv development kit

76. 最小覆盖子串

Awk syntax-03-awk expressions (if statements, while loops, for loops), execute shell commands in awk

Young freshmen who yearn for open source | The guide to avoiding pits from open source to employment is here!

【着色器实现Tricolor三原色型变效果_Shader效果第十八篇】

NetCore uses Dapper to query data

中国科学院金属研究所科研课题获华为技术认证,助力材料学发展新范式!
随机推荐
【OAuth2】十八、OIDC的认识应用
Personalized use of Qt log module
Shell 脚本 — 多行注释、开启子/不开启子进程执行、转义带颜色输出、读取键盘输入、输入输出重定向、单双引号、命令替换、读取变量、系统变量、正则过滤、算术运算、一行多条命令、字符串比较
The only OpenCyphal/UAVCAN tutorial in the whole network (11) Write a Cyphal protocol parsing tool with candump and gawk tools
关于如何做选择
C语言力扣第58题之最后一个单词的长度。从后往前遍历
leetcode 112.路经总和 递归
Let your text be seen by more people: Come and contribute, the payment is reliable!
The big and small end problem caused by union union
【着色器实现Tricolor三原色型变效果_Shader效果第十八篇】
bpftrace:简便输出调试信息
0字典树/字符串中等 LeetCode676. 实现一个魔法字典
《动机与人格》笔记(一)——人类似乎从来就没有长久地感到过心满意足
ToDesk企业版上新 | 十大新功能,让企业远控更安全、更便捷、更流畅
vulnhub-DC-3 drone penetration record
[Code Analysis] Graph small sample anomaly detection method: GDN: Few-shot Network Anomaly Detection via Cross-network Meta-learning
说说Redis分布式锁的原理和实现蚂【蚁金服三面】
顺序表(下)
postman---postman参数化
硬盘基础知识