需求:语音会议中,会议参与的任何一人挂断电话时候,如果会议中只剩下一人,则自动挂断电话。
实现,使用bgapi的方式,参考https://github.com/lusongcn/freeswitch-esl-php 提供的php bgapi接口实现。
//demo.php
<?php require_once 'lib/freeSwitchEsl.php'; $freeswitch = new Freeswitchesl(); $connect = $freeswitch->connect("127.0.0.1","8021","ClueCon"); if ($connect) { $version = $freeswitch->api("version"); var_dump($version); $status = $freeswitch->events("plain","ALL"); while (true) { $received_parameters = $freeswitch->recvEvent(); if (!empty($received_parameters)) { $info = $freeswitch->serialize($received_parameters,"json"); //var_dump($info); $Event_Name = $freeswitch->getHeader($received_parameters,"Event-Name"); //echo $Event_Name; $Action = $freeswitch->getHeader($received_parameters,"Action"); //echo $Action; if ($Action == "del-member"){ var_dump($info); $Conference_Size = $freeswitch->getHeader($received_parameters,"Conference-Size"); echo $Conference_Size; $Conference_Id = $freeswitch->getHeader($received_parameters,"Conference-Name"); echo $Conference_Id; if ($Conference_Size <= 1) { //判断是会议离开,并且会议只剩下一个人,则挂断会议 $hangupall = $freeswitch->bgapi("conference ".$Conference_Id." hup all"); } } } } } $freeswitch->disconnect();
运行demp.php
> php demo.php FreeSWITCH Version 1.9.0+git~20180619T173242Z~25e9376b29~64bit (git 25e9376 2018-06-19 17:32:42Z 64bit)
就可以监听到freeswitch中会议消息的变化,然后根据会议中的人数,判断是否自动结束这个会议。
远程连接event socket,需要修改配置文件/auto_configs/acl.config.xml ,增加如下的allow节点,否则只能本机连接。
<list name="loopback.auto" default="allow"> <node type="allow" cidr="10.95.38.0/24"/> </list>
-----更新-------------- freeeswitch会议室剩一人时不播报提示音,修改配置文件autoload_configs/conference.conf.xml: 注释掉,<alone-sound>的wav文件配置
-------------------广告线---------------
项目、合作,欢迎勾搭,邮箱:promall@qq.com
本文为呱牛笔记原创文章,转载无需和我联系,但请注明来自呱牛笔记 ,it3q.com