NTP-15943 | retry for call connected
This commit is contained in:
@@ -137,29 +137,61 @@ function extractUserCallModelUpdatedPush(rawResponse) {
|
||||
} )
|
||||
}
|
||||
|
||||
const sendCallStatusMessage = res => {
|
||||
let message = null;
|
||||
const data = JSON.parse(
|
||||
localStorage.getItem('revEngCustomerInfo') || '{}'
|
||||
);
|
||||
if (res?.data?.status === 'ringing') {
|
||||
message = {
|
||||
type: MessagingType.ON_AMEYO_CALL_INCOMING,
|
||||
data
|
||||
const sendCallStatusMessage = (res) => {
|
||||
try {
|
||||
const status = res?.data?.status;
|
||||
|
||||
const getCustomerInfo = () =>
|
||||
JSON.parse(localStorage.getItem('revEngCustomerInfo') || '{}');
|
||||
|
||||
const sendConnectedMessage = (retryCount = 3) => {
|
||||
/* The callId is received after the call is connected.
|
||||
* Since callId is essential and cannot be null,
|
||||
* this retry mechanism ensures we wait until it becomes available. */
|
||||
const data = getCustomerInfo();
|
||||
if (data?.callId) {
|
||||
const message = {
|
||||
type: MessagingType.ON_AMEYO_CALL_ACCEPTED,
|
||||
data,
|
||||
};
|
||||
window.postMessage(message);
|
||||
} else if (retryCount > 0) {
|
||||
setTimeout(() => sendConnectedMessage(retryCount - 1), 100);
|
||||
} else {
|
||||
console.warn('Unable to send ON_AMEYO_CALL_ACCEPTED: callId not found.');
|
||||
}
|
||||
};
|
||||
} else if (res?.data?.status === 'connected') {
|
||||
message = {
|
||||
type: MessagingType.ON_AMEYO_CALL_ACCEPTED,
|
||||
data
|
||||
};
|
||||
} else if (res?.data?.status === 'hungup') {
|
||||
message = {
|
||||
type: MessagingType.ON_AMEYO_CALL_DISCONNECTED,
|
||||
data
|
||||
};
|
||||
localStorage.removeItem('revEngCustomerInfo');
|
||||
|
||||
switch (status) {
|
||||
case 'ringing': {
|
||||
const data = getCustomerInfo();
|
||||
const message = {
|
||||
type: MessagingType.ON_AMEYO_CALL_INCOMING,
|
||||
data,
|
||||
};
|
||||
window.postMessage(message);
|
||||
break;
|
||||
}
|
||||
case 'connected': {
|
||||
sendConnectedMessage();
|
||||
break;
|
||||
}
|
||||
case 'hungup': {
|
||||
const data = getCustomerInfo();
|
||||
const message = {
|
||||
type: MessagingType.ON_AMEYO_CALL_DISCONNECTED,
|
||||
data,
|
||||
};
|
||||
window.postMessage(message);
|
||||
localStorage.removeItem('revEngCustomerInfo');
|
||||
break;
|
||||
}
|
||||
default:
|
||||
console.warn(`Unhandled call status: ${status}`);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Error in sendCallStatusMessage:', error);
|
||||
}
|
||||
if (message) window.postMessage(message);
|
||||
};
|
||||
|
||||
function createRequestObject() {
|
||||
|
||||
@@ -310,6 +310,7 @@ class AmeyoAdapter implements IAdapter {
|
||||
|
||||
rejectCall() {
|
||||
sipHangUp();
|
||||
localStorage.removeItem('revEngCustomerInfo');
|
||||
}
|
||||
|
||||
disposeCall() {
|
||||
|
||||
Reference in New Issue
Block a user