Event socket bug fix and more docs (#6823)

* Add documentation to methods. Use is_resource for added type detection

* Allow connect to specify timeout in microseconds with default 30,000

* Update calling mechanism for event sockets

* Update project for new singleton event sockets

* remove unused variable

* catch errors on closing the socket
This commit is contained in:
frytimo
2023-12-02 17:16:18 -07:00
committed by GitHub
parent 44567f7a05
commit 3a4c2f72e2
74 changed files with 1620 additions and 1533 deletions
+22 -22
View File
@@ -147,9 +147,9 @@
}
//define an alternative kick all
function conference_end($fp, $name) {
function conference_end($name) {
$switch_cmd = "conference '".$name."' xml_list";
$xml_str = trim(event_socket_request($fp, 'api '.$switch_cmd));
$xml_str = trim(event_socket::api($switch_cmd));
try {
$xml = new SimpleXMLElement($xml_str);
}
@@ -161,7 +161,7 @@
foreach ($xml->conference->members->member as $row) {
$uuid = (string)$row->uuid;
if (is_uuid($uuid)) {
$switch_result = event_socket_request($fp, 'api uuid_kill '.$uuid);
$switch_result = event_socket::api("uuid_kill $uuid");
}
if ($x < 1) {
usleep(500000); //500000 = 0.5 seconds
@@ -188,66 +188,66 @@
}
//connect to event socket
$fp = event_socket_create();
if ($fp) {
$esl = event_socket::create();
if ($esl->is_connected()) {
if ($data == "energy") {
//conference 3001-example-domain.org energy 103
$switch_result = event_socket_request($fp, 'api '.$switch_cmd);
$switch_result = event_socket::api($switch_cmd);
$result_array = explode("=",$switch_result);
$tmp_value = $result_array[1];
if ($direction == "up") { $tmp_value = $tmp_value + 100; }
if ($direction == "down") { $tmp_value = $tmp_value - 100; }
//echo "energy $tmp_value<br />\n";
$switch_result = event_socket_request($fp, 'api '.$switch_cmd.' '.$tmp_value);
$switch_result = event_socket::api("$switch_cmd $tmp_value");
}
elseif ($data == "volume_in") {
$switch_result = event_socket_request($fp, 'api '.$switch_cmd);
$switch_result = event_socket::api($switch_cmd);
$result_array = explode("=",$switch_result);
$tmp_value = $result_array[1];
if ($direction == "up") { $tmp_value = $tmp_value + 1; }
if ($direction == "down") { $tmp_value = $tmp_value - 1; }
//echo "volume $tmp_value<br />\n";
$switch_result = event_socket_request($fp, 'api '.$switch_cmd.' '.$tmp_value);
$switch_result = event_socket::api($switch_cmd.' '.$tmp_value);
}
elseif ($data == "volume_out") {
$switch_result = event_socket_request($fp, 'api '.$switch_cmd);
$switch_result = event_socket::api($switch_cmd);
$result_array = explode("=",$switch_result);
$tmp_value = $result_array[1];
if ($direction == "up") { $tmp_value = $tmp_value + 1; }
if ($direction == "down") { $tmp_value = $tmp_value - 1; }
//echo "volume $tmp_value<br />\n";
$switch_result = event_socket_request($fp, 'api '.$switch_cmd.' '.$tmp_value);
$switch_result = event_socket::api($switch_cmd.' '.$tmp_value);
}
elseif ($data == "record") {
$recording_dir = $_SESSION['switch']['recordings']['dir'].'/'.$_SESSION['domain_name'].'/archive/'.date("Y").'/'.date("M").'/'.date("d");
$switch_cmd .= $recording_dir."/".$uuid.".wav";
if (!file_exists($recording_dir."/".$uuid.".wav")) {
$switch_result = event_socket_request($fp, "api ".$switch_cmd);
$switch_cmd .= $recording_dir."/{$uuid}.wav";
if (!file_exists($switch_cmd)) {
$switch_result = event_socket::api($switch_cmd);
}
}
elseif ($data == "norecord") {
//stop recording and rename the file
$recording_dir = $_SESSION['switch']['recordings']['dir'].'/'.$_SESSION['domain_name'].'/archive/'.date("Y").'/'.date("M").'/'.date("d");
$switch_cmd .= $recording_dir."/".$uuid.".wav";
$switch_result = event_socket_request($fp, 'api '.$switch_cmd);
$switch_result = event_socket::api($switch_cmd);
}
elseif ($data == "kick") {
$switch_result = event_socket_request($fp, 'api uuid_kill '.$uuid);
$switch_result = event_socket::api("uuid_kill $uuid");
}
elseif ($data == "kick all") {
//$switch_result = event_socket_request($fp, 'api '.$switch_cmd);
conference_end($fp, $name);
//$switch_result = event_socket::api($switch_cmd);
conference_end($name);
}
elseif ($data == "mute" || $data == "unmute" || $data == "mute non_moderator" || $data == "unmute non_moderator") {
$switch_result = event_socket_request($fp, 'api '.$switch_cmd);
$switch_result = event_socket::api($switch_cmd);
$switch_cmd = "uuid_setvar ".$uuid. " hand_raised false";
event_socket_request($fp, 'api '.$switch_cmd);
event_socket::api($switch_cmd);
}
elseif ($data == "deaf" || $data == "undeaf" ) {
$switch_result = event_socket_request($fp, 'api '.$switch_cmd);
$switch_result = event_socket::api($switch_cmd);
}
elseif ($data == "lock" || $data == "unlock" ) {
$switch_result = event_socket_request($fp, 'api '.$switch_cmd);
$switch_result = event_socket::api($switch_cmd);
}
//echo "command: ".$switch_cmd." result: ".$switch_result."<br\n>";
}