根据上篇所述功能需求,esl需要处理以下几类事件:
- ESL_EVENT_CHANNEL_* #channel相关事件,用户判断参会者是否应答、计费
- DTMF事件 #识别参会者按键,根据按键进行操作(静音相关)
- CUSTOM conference::maintenance #mod_conference 相关事件
这里主要介绍会议相关事件以及如何关联进行控制。
- esl订阅事件并过滤关心事件
esl_events(pHandle, ESL_EVENT_TYPE_PLAIN, "CHANNEL_CREATE CHANNEL_ANSWER CHANNEL_HANGUP_COMPLETE DTMF CUSTOM conference::maintenance");
conference::maintenance事件
会议相关事件有以下几类(其他事件不关心,如需其他事件自行检测格式并封装)
- conference-create #会议创建,第一参会者应答后产生该事件
- add-member#加人
- floor-change#会议室状态改变
- del-member#参会者离开
- mute-member#参会者静音
- unmute-member#参会者恢复静音
- conference-destroy#会议结束
事件格式
Event-Subclass: conference%3A%3Amaintenance
Event-Name: CUSTOM
Core-UUID: 5560a1b8-a852-11e4-af5f-4d12ec2e8e2f
FreeSWITCH-Hostname: ds2
FreeSWITCH-Switchname: ds2
FreeSWITCH-IPv4: 115.29.227.76
FreeSWITCH-IPv6: %3A%3A1
Event-Date-Local: 2015-02-05%2014%3A33%3A00
Event-Date-GMT: Thu,%2005%20Feb%202015%2006%3A33%3A00%20GMT
Event-Date-Timestamp: 1423117980169214
Event-Calling-File: mod_conference.c
Event-Calling-Function: conference_thread_run
Event-Calling-Line-Number: 3049
Event-Sequence: 68603
Conference-Name: 3013-115.29.227.76
Conference-Size: 0
Conference-Ghosts: 0
Conference-Profile-Name: default
Conference-Unique-ID: d45300f8-ad00-11e4-b446-4d12ec2e8e2f
Action: conference-create
Event-Subclass: conference%3A%3Amaintenance
Event-Name: CUSTOM
Conference-Name: 3013-115.29.227.76
Conference-Size: 1
Conference-Ghosts: 0
Conference-Profile-Name: default
Conference-Unique-ID: d45300f8-ad00-11e4-b446-4d12ec2e8e2f
Floor: false
Video: false
Hear: true
Speak: true
Talking: false
Mute-Detect: false
Member-ID: 22
Member-Type: member
Member-Ghost: false
Energy-Level: 300
Current-Energy: 0
Action: add-member
Conference-Name: 3013-115.29.227.76
Conference-Size: 1
Conference-Ghosts: 0
Conference-Profile-Name: default
Conference-Unique-ID: d45300f8-ad00-11e4-b446-4d12ec2e8e2f
Action: floor-change
Old-ID: none
New-ID: 22
Conference-Name: 3000
Conference-Size: 2
Conference-Ghosts: 0
Conference-Profile-Name: default
Conference-Unique-ID: a28bcb66-ad02-11e4-b463-4d12ec2e8e2f
Floor: true
Video: false
Hear: true
Speak: false
Talking: false
Mute-Detect: false
Member-ID: 25
Member-Type: moderator
Member-Ghost: false
Energy-Level: 300
Current-Energy: 1
Action: mute-member
Conference-Name: 3000
Conference-Size: 2
Conference-Ghosts: 0
Conference-Profile-Name: default
Conference-Unique-ID: a28bcb66-ad02-11e4-b463-4d12ec2e8e2f
Floor: true
Video: false
Hear: true
Speak: true
Talking: false
Mute-Detect: false
Member-ID: 25
Member-Type: moderator
Member-Ghost: false
Energy-Level: 300
Current-Energy: 1
Action: unmute-member
Video: false
Hear: true
Speak: true
Talking: true
Mute-Detect: false
Member-ID: 27
Member-Type: member
Member-Ghost: false
Energy-Level: 300
Current-Energy: 8
Conference-Name: 3000
Conference-Size: 1
Conference-Ghosts: 0
Conference-Profile-Name: default
Conference-Unique-ID: a28bcb66-ad02-11e4-b463-4d12ec2e8e2f
Action: del-member
Conference-Name: 3000
Conference-Size: 0
Conference-Ghosts: 0
Conference-Profile-Name: default
Conference-Unique-ID: a28bcb66-ad02-11e4-b463-4d12ec2e8e2f
Action: conference-destroy
如上,隐藏了channel相关、event相关的键值,只保留了会议相关的属性。根据以上几个action,可以将不同的action进行封装,提取自己关心的参数。其中如果你的每一个会议都使用不同的Conference-Name,那Conference-Name可以作为关联会议的KEY值,或者使用Conference-Unique-ID。
在add-member和del-member中有Member-ID,是mod_conference命令操作参会者的参数,另外member相关的action中还携带该member的channel-uuid,与加人时指定的UUID相同,可以关联起来。
Member-Type参数显示了参会者的属性,是主持人还是普通参会者,创建会议时可以指定,如下:
conference 3000+flags{moderator} bgdial {bridge_early_media=false,ignore_early_media=true,effective_caller_id_number=02362909001}sofia/gateway/vos1/13800138000 #指定为主持人
DTMF事件
Event-Name: DTMF
Channel-Call-UUID: de747af8-ad00-11e4-b448-4d12ec2e8e2f
DTMF-Digit: 2
DTMF-Duration: 880
根据channel uuid可以识别是哪个参会者的按键,然后根据不同按键做不同操作即可。
以上,还缺少channel事件,这里不做介绍,一般情况下只关心CHANNEL_CREATE CHANNEL_ANSWER CHANNEL_HANGUP_COMPLETE三个事件即可满足基本需求。