需求:语音会议中,会议参与的任何一人挂断电话时候,如果会议中只剩下一人,则自动挂断电话。
实现,使用bgapi的方式,参考https://github.com/lusongcn/freeswitch-esl-php 提供的php bgapi接口实现。
//demo.php
代码语言:javascript复制<?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
代码语言:javascript复制> php demo.php
FreeSWITCH Version 1.9.0 git~20180619T173242Z~25e9376b29~64bit (git 25e9376 2018-06-19 17:32:42Z 64bit)
就可以监听到freeswitch中会议消息的变化,然后根据会议中的人数,判断是否自动结束这个会议。
本文为呱牛笔记原创文章,转载无需和我联系,但请注明来自呱牛笔记 ,it3q.com