Fix first line and app data of already in progress calls (#7931)
Also fixed application data not being read correctly from already in progress calls.
This commit is contained in:
@@ -74,6 +74,7 @@ class active_calls_service extends service implements websocket_service_interfac
|
||||
'secure',
|
||||
// Application
|
||||
'application',
|
||||
'application_name',
|
||||
'application_data',
|
||||
'variable_current_application',
|
||||
'playback_file_path',
|
||||
@@ -104,6 +105,7 @@ class active_calls_service extends service implements websocket_service_interfac
|
||||
'caller_channel_name' => 'call_active_profile',
|
||||
'secure' => 'call_active_secure',
|
||||
'application' => 'call_active_application',
|
||||
'application_name' => 'call_active_application',
|
||||
'application_data' => 'call_active_application',
|
||||
'playback_file_path' => 'call_active_application',
|
||||
'variable_current_application' => 'call_active_application',
|
||||
@@ -750,7 +752,19 @@ class active_calls_service extends service implements websocket_service_interfac
|
||||
$message->caller_caller_id_name = $call['initial_cid_name'];
|
||||
$message->caller_caller_id_number = $call['initial_cid_num'];
|
||||
$message->caller_destination_number = $call['initial_dest'];
|
||||
$message->application = $call['application'] ?? '';
|
||||
$application = $call['application'] ?? '';
|
||||
$application_data = $call['application_data'] ?? '';
|
||||
$message->application = $application;
|
||||
$message->application_data = $application_data;
|
||||
$application_name = '';
|
||||
if (!empty($application_data)) {
|
||||
$application_name = (!empty($application) && strpos($application_data, $application . ':') !== 0)
|
||||
? $application . ':' . $application_data
|
||||
: $application_data;
|
||||
} elseif (!empty($application)) {
|
||||
$application_name = $application;
|
||||
}
|
||||
$message->application_name = $application_name;
|
||||
$message->secure = $call['secure'] ?? '';
|
||||
|
||||
if (true) {
|
||||
|
||||
@@ -173,7 +173,7 @@ class event_message implements filterable_payload {
|
||||
}
|
||||
foreach ($json_array["rows"] as $call) {
|
||||
$message = new event_message($call);
|
||||
// adjust basic info to match an event setting the callstate to ringing
|
||||
// Adjust basic info to match an event setting the callstate to ringing
|
||||
// so that a row can be created for it
|
||||
$message['event_name'] = 'CHANNEL_CALLSTATE';
|
||||
$message['answer_state'] = 'ringing';
|
||||
@@ -181,23 +181,39 @@ class event_message implements filterable_payload {
|
||||
$message['unique_id'] = $call['uuid'];
|
||||
$message['call_direction'] = $call['direction'];
|
||||
|
||||
//set the codecs
|
||||
// Set the codecs
|
||||
$message['caller_channel_created_time'] = intval($call['created_epoch']) * 1000000;
|
||||
$message['channel_read_codec_name'] = $call['read_codec'];
|
||||
$message['channel_read_codec_rate'] = $call['read_rate'];
|
||||
$message['channel_write_codec_name'] = $call['write_codec'];
|
||||
$message['channel_write_codec_rate'] = $call['write_rate'];
|
||||
|
||||
//get the profile name
|
||||
// Get the profile name
|
||||
$message['caller_channel_name'] = $call['name'];
|
||||
|
||||
//domain or context
|
||||
// Domain or context
|
||||
$message['caller_context'] = $call['context'];
|
||||
$message['caller_caller_id_name'] = $call['initial_cid_name'];
|
||||
$message['caller_caller_id_number'] = $call['initial_cid_num'];
|
||||
$message['caller_destination_number'] = $call['initial_dest'];
|
||||
$message['application'] = $call['application'] ?? '';
|
||||
$message['secure'] = $call['secure'] ?? '';
|
||||
|
||||
// Application may or may not have data
|
||||
$application = $call['application'] ?? '';
|
||||
$application_data = $call['application_data'] ?? '';
|
||||
$message['application'] = $application;
|
||||
$message['application_data'] = $application_data;
|
||||
$application_name = '';
|
||||
if (!empty($application_data)) {
|
||||
$application_name = (!empty($application) && strpos($application_data, $application . ':') !== 0)
|
||||
? $application . ':' . $application_data
|
||||
: $application_data;
|
||||
} elseif (!empty($application)) {
|
||||
$application_name = $application;
|
||||
}
|
||||
$message['application_name'] = $application_name;
|
||||
|
||||
// Add the message to the list of calls
|
||||
$calls[] = $message;
|
||||
}
|
||||
return $calls;
|
||||
|
||||
@@ -34,22 +34,29 @@ class ws_client {
|
||||
|
||||
// If this is the response to a pending request
|
||||
if (rid && this._pending.has(rid)) {
|
||||
// Destructure with defaults in case they're missing
|
||||
const {
|
||||
service,
|
||||
topic = '',
|
||||
status = 'ok',
|
||||
code = 200,
|
||||
payload = {}
|
||||
} = message;
|
||||
const service = message.service_name ?? message.service;
|
||||
const topic = message.topic ?? '';
|
||||
const status = message.status_string ?? message.status ?? 'ok';
|
||||
const status_normalized = String(status).toLowerCase();
|
||||
const code_raw = message.status_code ?? message.code ?? 200;
|
||||
const code = Number.isFinite(Number(code_raw)) ? Number(code_raw) : parseInt(String(code_raw), 10);
|
||||
const payload = message.payload ?? {};
|
||||
|
||||
// active.calls can return multiple rows for one request_id; the first row
|
||||
// reaches this branch and would otherwise be dropped from UI rendering.
|
||||
if (service === 'active.calls' && payload && typeof payload === 'object' && payload.event_name) {
|
||||
this._dispatchEvent(service, payload);
|
||||
}
|
||||
|
||||
const {resolve, reject} = this._pending.get(rid);
|
||||
this._pending.delete(rid);
|
||||
|
||||
if (status === 'ok' && code >= 200 && code < 300) {
|
||||
const ok_by_status = status_normalized === 'ok' || status_normalized.startsWith('ok') || status_normalized.includes('success');
|
||||
const ok_by_code = !Number.isNaN(code) && code >= 200 && code < 300;
|
||||
if (ok_by_status || ok_by_code) {
|
||||
resolve({service, topic, payload, code, message});
|
||||
} else {
|
||||
const err = new Error(message || `Error ${code}`);
|
||||
const err = new Error(message.message || `Error ${code}`);
|
||||
err.code = code;
|
||||
reject(err);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user