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

前言
我们在之前章节介绍过ESL自定义事件订阅《【FreeSwitch开发实践】 ESL简介》,本篇介绍下在FreeSwitch中编写自定义模块,并定义自定义事件,然后发送事件、和用fs_cli中进行事件订阅。
自定义事件,是在FreeSwitch标准事件如Answer、Hangup事件之外,用于扩展事件,在实际业务中,可通过自定义事件将一些重要的结果,如ASR的识别结果、空号识别检测结果,通过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_event函数定义自定义事件、并设置事件参数、发送事件。switch_event_create_subclass定义事件,SWITCH_EVENT_CUSTOM为自定义事件, 事件名称my_event_name.- ‘switch_event_add_header_string’ 添加
事件参数, 为键值对,会出现在订阅事件体中。switch_event_fire发送事件。
2、配置拨号计划
本次示例,模块名称:
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>
10099是拨号计划的名称。
3、fs_cli事件订阅
/event plain CUSTOM my_event_name
my_event_name就是事件名称。
4、拨打软电话测试及结果输出
拨打软电话测试:
originate user/1000 10099
- 首先,需要注册
1000软电话,参考《【FreeSwitch开发实践】使用SIP客户端Yate连接FreeSwitch进行VoIP通话》。10099就是前面定义的拨号计划名称。
输出:
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
从自定义事件体中可以看到事件定义的变量
Custom-Variable、Unique-ID。
总结
以上就本篇的内容,主要介绍如下:
- 自定义事件的定义
- 自定义事件变量设置
- 拨号计划配置
- fs_cli自定义事件订阅
- 拨打软电话测试和订阅自定义事件结果
本文代码完整例子下载地址
(代码下载需要积分,如果没有积分可以私信博主即可以免费获取)
如果觉得有些帮助或觉得文章还不错,请关注一下博主,你的关注是我持续写作的动力。另外,如果有什么问题,可以在评论区留言,或者私信博主,博主看到后会第一时间回复。
想对未来的自己说的话: 间歇性的努力和蒙混过日子,都是对之前努力的清零
欢迎转载,转载请注明出处:https://xiao2macf.blog.csdn.net/article/details/126211171
边栏推荐
- 【Win10】若干睡眠问题及对策
- leetcode-isomorphic string judgment
- Open3D 基于颜色的ICP配准
- Leetcode78. Subset
- Open3D ICP精配准(使用鲁棒性核函数)
- Machine Learning Notes: Learning Rate Warmup
- C语言-函数
- 亚马逊云科技Build On学习心得
- [Code Analysis] Graph small sample anomaly detection method: GDN: Few-shot Network Anomaly Detection via Cross-network Meta-learning
- MindFusion.WPF Pack 2022.R1
猜你喜欢

【多任务CTR】阿里ESMM:Entire Space Multi-Task Model: An Effective Approach for Estimating Post-Click Conve

awk语法-03-awk表达式(if语句、while循环、for循环)、awk中执行shell命令

分类、目标检测、语义分割、实例分割的区别

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

走进音视频的世界——RGB与YUV格式

由联合体union引出的大小端问题

vulnhub-DC-3 drone penetration record

Amazon Cloud Technology Build On Learning Experience

leetcode-同构字符串判断

10款自媒体人必备的免费工具,快速高效运营
随机推荐
Strong Net Cup 2019 - Casual Bet (Stacked Injection)
C language - function
The use of mmedicting get_flops. Py
Risk control strategy must be learned | This method of mining rules with decision trees
手把手教你手撕SPF生成树(OSPF区域内防环)
The research project of the Institute of Metal Research of the Chinese Academy of Sciences has been certified by Huawei, helping to develop a new paradigm in materials science!
类似Bugfree的9大在线缺陷管理软件
BMS 产品功能和详细设计规格
由联合体union引出的大小端问题
Implementing Express middleware principles
Lecture 84 Biweekly t4 6144 and Lecture 305 t4 6138
Building a High-Performance Platform on AWS Using Presto and Alluxio to Support Real-Time Gaming Services
2022-08-07 mysql/stonedb慢SQL-子查询-半连接
6G-Oriented Communication Perception Integrated Architecture and Key Technologies
MYSQL export data dictionary
leetcode 70. Stair Climbing Dynamic Programming
MySQL从入门到入土【20W字收藏篇】
shell原地更新终端输出信息
基于扰动观察法的光伏mppt最大功率控制matlab仿真
【着色器实现Tricolor三原色型变效果_Shader效果第十八篇】