NTP-26125 | processing events in ajaxClient

This commit is contained in:
Mayank Singh
2025-01-13 02:24:45 +05:30
parent 746651c301
commit 1259a3e468
2 changed files with 26 additions and 25 deletions

View File

@@ -1,7 +1,8 @@
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
//@ts-nocheck
import {extractAndProcessEvents} from "../../callStateManager.ts";
import {callStateManager} from "../../callStateManager.ts";
import {EventData} from "../../types.ts";
export enum MessagingType {
ON_AMEYO_CALL_INCOMING = 'onAmeyoCallIncoming',
@@ -107,6 +108,28 @@ function processResponse() {
// response
}
function extractAndProcessEvents(rawResponse: any) {
const parts = rawResponse
.replaceAll(`Content-type: application/json ; charset: utf-8\r\n\r\n`, '')
.split("--DON'T_PANIC!_more_will_follow\r\n")
.map((part: string) => {
try {
return JSON.parse(part.trim());
} catch {
return null;
}
})
.filter(Boolean);
parts.forEach((event : EventData) => {
try {
callStateManager.handleEvent(event);
} catch (error) {
console.error('Error processing event:', event, error);
}
});
}
function processPush(pushResponse) {
extractAndProcessEvents(pushResponse);
}

View File

@@ -1,5 +1,5 @@
import {MessagingType} from "./assets/js/ajaxClient.ts";
import {CallStatus, PushType, CallState, EventData} from "./types.ts";
import {CallStatus, PushType, CallState} from "./types.ts";
import {parseQuerystring} from "@universal-call-sdk/common/lib/utils/parsingUtils.ts";
class CallStateManager {
@@ -112,7 +112,7 @@ class CallStateManager {
this.state.customerCallStatus = data?.status;
this.state.crtObjectId = data?.crtObjectId;
// Keep disconnect handling
// handle for transfer call
if (data?.isDisposing && data?.status === 'hungup') {
this.handleCallDisconnect();
}
@@ -194,25 +194,3 @@ class CallStateManager {
}
export const callStateManager = new CallStateManager();
export function extractAndProcessEvents(rawResponse: any) {
const parts = rawResponse
.replaceAll(`Content-type: application/json ; charset: utf-8\r\n\r\n`, '')
.split("--DON'T_PANIC!_more_will_follow\r\n")
.map((part: string) => {
try {
return JSON.parse(part.trim());
} catch {
return null;
}
})
.filter(Boolean);
parts.forEach((event : EventData) => {
try {
callStateManager.handleEvent(event);
} catch (error) {
console.error('Error processing event:', event, error);
}
});
}