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
+12 -15
View File
@@ -43,8 +43,8 @@
$text = $language->get();
//create event socket
$fp = event_socket_create();
if (!$fp) {
$esl = event_socket::create();
if (!$esl->is_connected()) {
message::add($text['error-event-socket'], 'negative', 5000);
}
@@ -57,8 +57,8 @@
unset($sql);
//get the sip profiles
if ($fp) {
$hostname = trim(event_socket_request($fp, 'api switchname'));
if ($esl->is_connected()) {
$hostname = trim(event_socket::api('switchname'));
}
$sql = "select sip_profile_uuid, sip_profile_name from v_sip_profiles ";
$sql .= "where sip_profile_enabled = 'true' ";
@@ -80,8 +80,8 @@
//get status
try {
$cmd = "api sofia xmlstatus";
$xml_response = trim(event_socket_request($fp, $cmd));
$cmd = "sofia xmlstatus";
$xml_response = trim(event_socket::api($cmd));
if ($xml_response) {
$xml = new SimpleXMLElement($xml_response);
}
@@ -91,8 +91,8 @@
message::add($message, 'negative', 5000);
}
try {
$cmd = "api sofia xmlstatus gateway";
$xml_response = trim(event_socket_request($fp, $cmd));
$cmd = "sofia xmlstatus gateway";
$xml_response = trim(event_socket::api($cmd));
if ($xml_response) {
$xml_gateways = new SimpleXMLElement($xml_response);
}
@@ -221,10 +221,9 @@
}
//sofia status profile
if ($fp && permission_exists('system_status_sofia_status_profile')) {
if ($esl && permission_exists('system_status_sofia_status_profile')) {
foreach ($sip_profiles as $sip_profile_name => $sip_profile_uuid) {
$cmd = "api sofia xmlstatus profile ".$sip_profile_name."";
$xml_response = trim(event_socket_request($fp, $cmd));
$xml_response = trim(event_socket::api("sofia xmlstatus profile $sip_profile_name"));
if ($xml_response == "Invalid Profile!") {
$xml_response = "<error_msg>Invalid Profile!</error_msg>";
$profile_state = 'stopped';
@@ -309,16 +308,14 @@
}
//status
if ($fp && permission_exists('sip_status_switch_status')) {
$cmd = "api status";
$response = event_socket_request($fp, $cmd);
if ($esl->is_connected() && permission_exists('sip_status_switch_status')) {
$response = event_socket::api("status");
echo "<b><a href='javascript:void(0);' onclick=\"$('#status').slideToggle();\">".$text['title-status']."</a></b>\n";
echo "<div id='status' style='margin-top: 20px; font-size: 9pt;'>";
echo "<pre>";
echo trim(escape($response));
echo "</pre>\n";
echo "</div>";
fclose($fp);
}
//include the footer