From 8b1b7560a55aea59a3c160e60e76349e905799ac Mon Sep 17 00:00:00 2001 From: karthik raji <51771000+karthikraji2020@users.noreply.github.com> Date: Wed, 8 Nov 2023 14:15:14 +0530 Subject: [PATCH] fix(calling): detectNetwork change (#3142) Co-authored-by: Priya Kesari Co-authored-by: Kesari3008 <65543166+Kesari3008@users.noreply.github.com> --- .../src/CallingClient/CallingClient.test.ts | 75 +++++++++---------- .../src/CallingClient/CallingClient.ts | 11 ++- .../src/CallingClient/calling/call.test.ts | 1 + .../calling/src/CallingClient/line/index.ts | 17 ++--- .../src/CallingClient/line/line.test.ts | 21 +++--- .../calling/src/CallingClient/line/types.ts | 14 +--- .../registration/register.test.ts | 60 +++++++-------- .../CallingClient/registration/register.ts | 55 +++++++------- .../src/CallingClient/registration/types.ts | 6 +- .../src/Errors/catalog/CallingDeviceError.ts | 13 +++- .../calling/src/Errors/catalog/LineError.ts | 13 +++- packages/calling/src/Errors/types.ts | 5 +- packages/calling/src/Metrics/index.test.ts | 9 ++- packages/calling/src/common/Utils.test.ts | 4 +- packages/calling/src/common/Utils.ts | 33 ++++---- packages/calling/src/common/types.ts | 5 +- 16 files changed, 174 insertions(+), 168 deletions(-) diff --git a/packages/calling/src/CallingClient/CallingClient.test.ts b/packages/calling/src/CallingClient/CallingClient.test.ts index ad3e507ea7d..4a48d7fc350 100644 --- a/packages/calling/src/CallingClient/CallingClient.test.ts +++ b/packages/calling/src/CallingClient/CallingClient.test.ts @@ -6,7 +6,7 @@ import { getMockDeviceInfo, getMobiusDiscoveryResponse, } from '../common/testUtil'; -import {CallType, MobiusStatus, ServiceIndicator, WebexRequestPayload} from '../common/types'; +import {CallType, RegistrationStatus, ServiceIndicator, WebexRequestPayload} from '../common/types'; /* eslint-disable dot-notation */ import {CALLING_CLIENT_EVENT_KEYS, CallSessionEvent, MOBIUS_EVENT_KEYS} from '../Events/types'; import log from '../Logger'; @@ -23,7 +23,7 @@ import { SPARK_USER_AGENT, } from './constants'; import {MOCK_MULTIPLE_SESSIONS_EVENT, MOCK_SESSION_EVENT} from './callRecordFixtures'; -import {ILine, LineStatus} from './line/types'; +import {ILine} from './line/types'; import { ipPayload, regionBody, @@ -370,8 +370,6 @@ describe('CallingClient Tests', () => { callingClient = await createClient(webex, {logger: {level: LOGGER.INFO}}); line = Object.values(callingClient.lineDict)[0] as ILine; reg = line.registration; - - expect(line.getRegistrationStatus()).toEqual(MobiusStatus.DEFAULT); await line.register(); deRegSpy = jest.spyOn(line.registration, 'deregister'); @@ -390,7 +388,7 @@ describe('CallingClient Tests', () => { }); it('detect a network flap in mercury connection', async () => { - expect(line.getRegistrationStatus()).toEqual(MobiusStatus.ACTIVE); + expect(line.getStatus()).toEqual(RegistrationStatus.ACTIVE); /* Set mercury connection to be down and execute a delay of 2.5 seconds */ webex.internal.mercury.connected = false; @@ -398,7 +396,7 @@ describe('CallingClient Tests', () => { jest.advanceTimersByTime(NETWORK_FLAP_TIMEOUT + 500); /* We should be detecting the network flap */ - expect(warnSpy).toBeCalledWith( + expect(warnSpy).toBeCalledOnceWith( 'Network has flapped, waiting for mercury connection to be up', {file: CALLING_CLIENT_FILE, method: NETWORK_CHANGE_DETECTION_UTIL} ); @@ -411,13 +409,14 @@ describe('CallingClient Tests', () => { await flushPromises(); /* We should be detecting the network recovery */ - expect(logSpy).nthCalledWith( - 7, - 'Mercury connection is up again, Re-registering with Mobius', - {file: REGISTRATION_FILE, method: 'handleConnectionRestoration'} + expect(logSpy).toBeCalledWith( + 'Mercury connection is up again, re-registering with Webex Calling if needed', + { + file: REGISTRATION_FILE, + method: 'handleConnectionRestoration', + } ); - expect(deRegSpy).toBeCalledWith(); expect(restoreSpy).toBeCalledWith('handleConnectionRestoration'); expect(restartRegisterSpy).toBeCalledWith('handleConnectionRestoration'); expect(webex.request).toBeCalledTimes(6); @@ -426,7 +425,7 @@ describe('CallingClient Tests', () => { }); it('Simulate a network flap with no active calls and re-verify registration: Restore Failure', async () => { - expect(line.getRegistrationStatus()).toEqual(MobiusStatus.ACTIVE); + expect(line.getStatus()).toEqual(RegistrationStatus.ACTIVE); const failurePayload = ({ statusCode: 500, @@ -453,37 +452,37 @@ describe('CallingClient Tests', () => { /* Set mercury connection to be up and execute a delay of 2.5 seconds */ webex.internal.mercury.connected = true; + jest.advanceTimersByTime(NETWORK_FLAP_TIMEOUT + 500); await flushPromises(); + /* We should be detecting the network recovery */ - expect(logSpy).toBeCalledWith('Mercury connection is up again, Re-registering with Mobius', { - file: REGISTRATION_FILE, - method: 'handleConnectionRestoration', - }); + expect(logSpy).toBeCalledWith( + 'Mercury connection is up again, re-registering with Webex Calling if needed', + { + file: REGISTRATION_FILE, + method: 'handleConnectionRestoration', + } + ); - expect(deRegSpy).toBeCalledWith(); - expect(restoreSpy).toBeCalledWith('handleConnectionRestoration'); - expect(restartRegisterSpy).toBeCalledWith('handleConnectionRestoration'); + expect(restoreSpy).toBeCalledOnceWith('handleConnectionRestoration'); + expect(restartRegisterSpy).toBeCalledOnceWith('handleConnectionRestoration'); expect(webex.request).toBeCalledTimes(6); expect(registerSpy).toBeCalledWith('handleConnectionRestoration', [reg.getActiveMobiusUrl()]); expect(registerSpy).lastCalledWith('handleConnectionRestoration', [primaryUrl]); }); it('Simulate a network flap before initial registration is done', async () => { - expect(line.getRegistrationStatus()).toEqual(MobiusStatus.ACTIVE); - - reg.deregister(); - reg.setActiveMobiusUrl(undefined); - - jest.clearAllMocks(); + const handleConnectionRestoreSpy = jest.spyOn(reg, 'handleConnectionRestoration'); + reg.setStatus(RegistrationStatus.IDLE); /* Set mercury connection to be down and execute a delay of 2.5 seconds */ webex.internal.mercury.connected = false; jest.advanceTimersByTime(NETWORK_FLAP_TIMEOUT + 500); /* We should be detecting the network flap */ - expect(warnSpy).toBeCalledWith( + expect(warnSpy).toBeCalledOnceWith( 'Network has flapped, waiting for mercury connection to be up', {file: CALLING_CLIENT_FILE, method: NETWORK_CHANGE_DETECTION_UTIL} ); @@ -495,22 +494,23 @@ describe('CallingClient Tests', () => { await flushPromises(); /* We should be detecting the network recovery */ - expect(logSpy).toBeCalledWith('Mercury connection is up again, Re-registering with Mobius', { - file: REGISTRATION_FILE, - method: 'handleConnectionRestoration', - }); + expect(logSpy).not.toBeCalledWith( + 'Mercury connection is up again, re-registering with Webex Calling if needed', + { + file: REGISTRATION_FILE, + method: 'handleConnectionRestoration', + } + ); /* * When initial registration is not done, network flap * will not trigger de-registration/registration */ - expect(webex.request).not.toBeCalled(); - expect(restoreSpy).not.toBeCalled(); - expect(registerSpy).not.toBeCalled(); + expect(handleConnectionRestoreSpy).not.toBeCalledOnceWith(); }); it('Simulate a network flap with 1 active call', async () => { - expect(line.getRegistrationStatus()).toEqual(MobiusStatus.ACTIVE); + expect(line.getStatus()).toEqual(RegistrationStatus.ACTIVE); /** create a new call */ reg.callManager.createCall(); @@ -522,7 +522,7 @@ describe('CallingClient Tests', () => { await flushPromises(); /* We should be detecting the network flap */ - expect(warnSpy).not.toBeCalledWith( + expect(warnSpy).not.toBeCalledOnceWith( 'Network has flapped, waiting for mercury connection to be up', {file: CALLING_CLIENT_FILE, method: 'handleConnectionRestoration'} ); @@ -534,8 +534,8 @@ describe('CallingClient Tests', () => { await flushPromises(); /* We should be detecting the network recovery */ - expect(logSpy).not.toBeCalledWith( - 'Mercury connection is up again, Re-registering with Mobius', + expect(logSpy).not.toBeCalledOnceWith( + 'Mercury connection is up again, re-registering with Webex Calling if needed', {file: REGISTRATION_FILE, method: 'handleConnectionRestoration'} ); @@ -590,7 +590,6 @@ describe('CallingClient Tests', () => { line = new Line( userId, clientDeviceUri, - LineStatus.ACTIVE, mutex, primaryMobiusUris(), backupMobiusUris(), diff --git a/packages/calling/src/CallingClient/CallingClient.ts b/packages/calling/src/CallingClient/CallingClient.ts index eb9d04078f8..6c943640074 100644 --- a/packages/calling/src/CallingClient/CallingClient.ts +++ b/packages/calling/src/CallingClient/CallingClient.ts @@ -23,6 +23,7 @@ import { IpInfo, MobiusServers, WebexRequestPayload, + RegistrationStatus, } from '../common/types'; import {ICallingClient, CallingClientConfig} from './types'; import {ICall, ICallManager} from './calling/types'; @@ -41,7 +42,7 @@ import { NETWORK_FLAP_TIMEOUT, } from './constants'; import Line from './line'; -import {ILine, LINE_EVENTS, LineStatus} from './line/types'; +import {ILine, LINE_EVENTS} from './line/types'; import {METRIC_EVENT, REG_ACTION, METRIC_TYPE, IMetricManager} from '../Metrics/types'; import {getMetricManager} from '../Metrics'; @@ -156,14 +157,17 @@ export class CallingClient extends Eventing implements method: this.detectNetworkChange.name, }); - line.lineEmitter(LINE_EVENTS.UNREGISTERED); line.registration.clearKeepaliveTimer(); retry = true; } if (retry && this.webex.internal.mercury.connected) { - retry = await line.registration.handleConnectionRestoration(retry); + if (line.getStatus() !== RegistrationStatus.IDLE) { + retry = await line.registration.handleConnectionRestoration(retry); + } else { + retry = false; + } } }, NETWORK_FLAP_TIMEOUT); } @@ -411,7 +415,6 @@ export class CallingClient extends Eventing implements const line = new Line( this.webex.internal.device.userId, this.webex.internal.device.url, - LineStatus.INACTIVE, this.mutex, this.primaryMobiusUris, this.backupMobiusUris, diff --git a/packages/calling/src/CallingClient/calling/call.test.ts b/packages/calling/src/CallingClient/calling/call.test.ts index 174d0e0e3c9..0ce776afe42 100644 --- a/packages/calling/src/CallingClient/calling/call.test.ts +++ b/packages/calling/src/CallingClient/calling/call.test.ts @@ -183,6 +183,7 @@ describe('Call Tests', () => { outputStream: { getAudioTracks: jest.fn().mockReturnValue([mockTrack]), }, + on: jest.fn(), }; const localAudioStream = mockStream as unknown as MediaSDK.LocalMicrophoneStream; diff --git a/packages/calling/src/CallingClient/line/index.ts b/packages/calling/src/CallingClient/line/index.ts index 34de294e2d5..4a1a3599e58 100644 --- a/packages/calling/src/CallingClient/line/index.ts +++ b/packages/calling/src/CallingClient/line/index.ts @@ -6,10 +6,10 @@ import { CorrelationId, IDeviceInfo, MobiusDeviceId, - MobiusStatus, + RegistrationStatus, ServiceIndicator, } from '../../common/types'; -import {ILine, LINE_EVENTS, LineEventTypes, LineStatus} from './types'; +import {ILine, LINE_EVENTS, LineEventTypes} from './types'; import {LINE_FILE, VALID_PHONE} from '../constants'; import log from '../../Logger'; import {IRegistration} from '../registration/types'; @@ -49,8 +49,6 @@ export default class Line extends Eventing implements ILine { public extension?: string; - public status: LineStatus; - public sipAddresses?: string[]; public voicemail?: string; @@ -78,7 +76,6 @@ export default class Line extends Eventing implements ILine { constructor( userId: string, clientDeviceUri: string, - status: LineStatus, mutex: Mutex, primaryMobiusUris: string[], backupMobiusUris: string[], @@ -92,7 +89,6 @@ export default class Line extends Eventing implements ILine { this.lineId = uuid(); this.userId = userId; this.clientDeviceUri = clientDeviceUri; - this.status = status; this.phoneNumber = phoneNumber; this.extension = extension; this.voicemail = voicemail; @@ -118,7 +114,6 @@ export default class Line extends Eventing implements ILine { logLevel ); - this.registration.setStatus(MobiusStatus.DEFAULT); log.setLogger(logLevel, LINE_FILE); this.callManager = getCallManager(this.#webex, serviceData.indicator); @@ -131,7 +126,6 @@ export default class Line extends Eventing implements ILine { */ public async register() { await this.#mutex.runExclusive(async () => { - this.registration.setStatus(MobiusStatus.DEFAULT); this.emit(LINE_EVENTS.CONNECTING); this.registration.setMobiusServers(this.#primaryMobiusUris, this.#backupMobiusUris); @@ -146,7 +140,8 @@ export default class Line extends Eventing implements ILine { * Wrapper to for device deregister. */ public async deregister() { - this.registration.deregister(); + await this.registration.deregister(); + this.registration.setStatus(RegistrationStatus.IDLE); } /** @@ -218,7 +213,7 @@ export default class Line extends Eventing implements ILine { /** * Gets registration status */ - public getRegistrationStatus = (): MobiusStatus => this.registration.getStatus(); + public getStatus = (): RegistrationStatus => this.registration.getStatus(); /** * Gets device id @@ -260,7 +255,7 @@ export default class Line extends Eventing implements ILine { 'An invalid phone number was detected. Check the number and try again.', {}, ERROR_TYPE.CALL_ERROR, - LineStatus.ACTIVE + RegistrationStatus.ACTIVE ); this.emit(LINE_EVENTS.ERROR, err); diff --git a/packages/calling/src/CallingClient/line/line.test.ts b/packages/calling/src/CallingClient/line/line.test.ts index e450feeffa5..b49aee75411 100644 --- a/packages/calling/src/CallingClient/line/line.test.ts +++ b/packages/calling/src/CallingClient/line/line.test.ts @@ -11,11 +11,11 @@ import { CallDirection, CallType, MobiusServers, - MobiusStatus, + RegistrationStatus, ServiceIndicator, WebexRequestPayload, } from '../../common/types'; -import {LINE_EVENTS, LineStatus} from './types'; +import {LINE_EVENTS} from './types'; import Line from '.'; import * as utils from '../../common/Utils'; import SDKConnector from '../../SDKConnector'; @@ -57,7 +57,6 @@ describe('Line Tests', () => { line = new Line( userId, clientDeviceUri, - LineStatus.ACTIVE, mutex, primaryMobiusUris(), backupMobiusUris(), @@ -83,7 +82,7 @@ describe('Line Tests', () => { expect.anything(), LOGGER.INFO ); - expect(line.getRegistrationStatus()).toEqual(MobiusStatus.DEFAULT); + expect(line.getStatus()).toEqual(RegistrationStatus.IDLE); await line.register(); expect(webex.request).toBeCalledOnceWith({ @@ -98,7 +97,7 @@ describe('Line Tests', () => { }); expect(handleErrorSpy).not.toBeCalled(); - expect(line.getRegistrationStatus()).toEqual(MobiusStatus.ACTIVE); + expect(line.getStatus()).toEqual(RegistrationStatus.ACTIVE); expect(line.getActiveMobiusUrl()).toEqual(primaryUrl); expect(line.getLoggingLevel()).toEqual(LOGGER.INFO); expect(line.getDeviceId()).toEqual(mockRegistrationBody.device.deviceId); @@ -129,11 +128,11 @@ describe('Line Tests', () => { ); }); - expect(line.getRegistrationStatus()).toBe(MobiusStatus.DEFAULT); + expect(line.getStatus()).toBe(RegistrationStatus.IDLE); line.register(); await utils.waitForMsecs(20); - expect(line.getRegistrationStatus()).toBe(MobiusStatus.DEFAULT); + expect(line.getStatus()).toBe(RegistrationStatus.INACTIVE); expect(handleErrorSpy).toBeCalledOnceWith( expect.anything(), expect.anything(), @@ -148,14 +147,15 @@ describe('Line Tests', () => { it('verify successful de-registration cases', async () => { webex.request.mockReturnValueOnce(registrationPayload); - expect(line.getRegistrationStatus()).toEqual(MobiusStatus.DEFAULT); + expect(line.getStatus()).toEqual(RegistrationStatus.IDLE); await line.register(); - expect(line.getRegistrationStatus()).toEqual(MobiusStatus.ACTIVE); + expect(line.getStatus()).toEqual(RegistrationStatus.ACTIVE); await line.deregister(); - expect(line.getRegistrationStatus()).toEqual(MobiusStatus.DEFAULT); + expect(line.getStatus()).toEqual(RegistrationStatus.IDLE); }); }); + describe('Line calling tests', () => { let line; @@ -163,7 +163,6 @@ describe('Line Tests', () => { line = new Line( userId, clientDeviceUri, - LineStatus.ACTIVE, mutex, primaryMobiusUris(), backupMobiusUris(), diff --git a/packages/calling/src/CallingClient/line/types.ts b/packages/calling/src/CallingClient/line/types.ts index 283085b3dca..14a836cb93d 100644 --- a/packages/calling/src/CallingClient/line/types.ts +++ b/packages/calling/src/CallingClient/line/types.ts @@ -5,15 +5,10 @@ import { CorrelationId, IDeviceInfo, MobiusDeviceId, - MobiusStatus, + RegistrationStatus, } from '../../common/types'; import {ICall} from '../calling/types'; -export enum LineStatus { - INACTIVE = 'inactive', - ACTIVE = 'active', -} - export enum LINE_EVENTS { CONNECTING = 'connecting', ERROR = 'error', @@ -43,11 +38,6 @@ export interface ILine { */ lineId: string; - /** - * The current status of the line as {@link LineStatus}. - */ - status: LineStatus; - /** * The optional Mobius device identifier associated with the line. */ @@ -133,7 +123,7 @@ export interface ILine { * Retrieves the registration status of the line as {@link MobiusStatus}. * */ - getRegistrationStatus(): MobiusStatus; + getStatus(): RegistrationStatus; /** * Retrieves the device identifier associated with the line as {@link MobiusDeviceId}, diff --git a/packages/calling/src/CallingClient/registration/register.test.ts b/packages/calling/src/CallingClient/registration/register.test.ts index bc459eccc4f..dcaa1eea862 100644 --- a/packages/calling/src/CallingClient/registration/register.test.ts +++ b/packages/calling/src/CallingClient/registration/register.test.ts @@ -6,7 +6,7 @@ import { getMockRequestTemplate, getTestUtilsWebex, } from '../../common/testUtil'; -import {MobiusStatus, ServiceIndicator, WebexRequestPayload} from '../../common/types'; +import {RegistrationStatus, ServiceIndicator, WebexRequestPayload} from '../../common/types'; import * as utils from '../../common/Utils'; import log from '../../Logger'; import {LOGGER} from '../../Logger/types'; @@ -26,7 +26,7 @@ import { SEC_TO_MSEC_MFACTOR, } from '../constants'; import {ICall} from '../calling/types'; -import {LINE_EVENTS, LineStatus} from '../line/types'; +import {LINE_EVENTS} from '../line/types'; import {createLineError} from '../../Errors/catalog/LineError'; import {IRegistration} from './types'; @@ -115,7 +115,7 @@ describe('Registration Tests', () => { method: 'POST', }); - expect(reg.getStatus()).toEqual(MobiusStatus.ACTIVE); + expect(reg.getStatus()).toEqual(RegistrationStatus.ACTIVE); expect(lineEmitter).toBeCalledTimes(2); expect(lineEmitter).toBeCalledWith(LINE_EVENTS.CONNECTING); expect(lineEmitter).toBeCalledWith(LINE_EVENTS.REGISTERED, mockPostResponse); @@ -138,10 +138,10 @@ describe('Registration Tests', () => { 'User is unauthorized due to an expired token. Sign out, then sign back in.', {}, ERROR_TYPE.TOKEN_ERROR, - LineStatus.INACTIVE + RegistrationStatus.INACTIVE ); - expect(reg.getStatus()).toEqual(MobiusStatus.DEFAULT); + expect(reg.getStatus()).toEqual(RegistrationStatus.INACTIVE); expect(lineEmitter).toBeCalledTimes(2); expect(lineEmitter).nthCalledWith(1, LINE_EVENTS.CONNECTING); expect(lineEmitter).nthCalledWith(2, LINE_EVENTS.ERROR, undefined, error); @@ -164,7 +164,7 @@ describe('Registration Tests', () => { global.fetch = jest.fn(() => Promise.resolve({json: () => mockDeleteResponse})) as jest.Mock; - expect(reg.getStatus()).toEqual(MobiusStatus.DEFAULT); + expect(reg.getStatus()).toEqual(RegistrationStatus.IDLE); await reg.triggerRegistration(); expect(webex.request).toBeCalledTimes(2); expect(webex.request).toBeCalledWith({ @@ -180,7 +180,7 @@ describe('Registration Tests', () => { expect(logSpy).toBeCalledWith('Registration restoration in progress.', expect.anything()); expect(logSpy).toBeCalledWith('Registration restored successfully.', expect.anything()); - expect(reg.getStatus()).toEqual(MobiusStatus.ACTIVE); + expect(reg.getStatus()).toEqual(RegistrationStatus.ACTIVE); expect(lineEmitter).toBeCalledTimes(4); expect(lineEmitter).nthCalledWith(1, LINE_EVENTS.CONNECTING); expect(lineEmitter).nthCalledWith(2, LINE_EVENTS.UNREGISTERED); @@ -197,7 +197,7 @@ describe('Registration Tests', () => { .mockRejectedValueOnce(failurePayload) .mockResolvedValueOnce(successPayload); - expect(reg.getStatus()).toEqual(MobiusStatus.DEFAULT); + expect(reg.getStatus()).toEqual(RegistrationStatus.IDLE); await reg.triggerRegistration(); jest.advanceTimersByTime(REG_TRY_BACKUP_TIMER_VAL_IN_SEC * SEC_TO_MSEC_MFACTOR); await flushPromises(); @@ -213,7 +213,7 @@ describe('Registration Tests', () => { method: 'POST', uri: `${mobiusUris.backup[0]}device`, }); - expect(reg.getStatus()).toEqual(MobiusStatus.ACTIVE); + expect(reg.getStatus()).toEqual(RegistrationStatus.ACTIVE); /* Active Url must match with the backup url as per the test */ expect(reg.getActiveMobiusUrl()).toEqual(mobiusUris.backup[0]); }); @@ -223,7 +223,7 @@ describe('Registration Tests', () => { // try the primary twice and register successfully with backup servers webex.request.mockRejectedValue(failurePayload); - expect(reg.getStatus()).toEqual(MobiusStatus.DEFAULT); + expect(reg.getStatus()).toEqual(RegistrationStatus.IDLE); await reg.triggerRegistration(); jest.advanceTimersByTime(REG_TRY_BACKUP_TIMER_VAL_IN_SEC * SEC_TO_MSEC_MFACTOR); await flushPromises(); @@ -252,7 +252,7 @@ describe('Registration Tests', () => { method: 'POST', uri: `${mobiusUris.backup[1]}device`, }); - expect(reg.getStatus()).toEqual(MobiusStatus.DEFAULT); + expect(reg.getStatus()).toEqual(RegistrationStatus.INACTIVE); }); }); @@ -278,7 +278,7 @@ describe('Registration Tests', () => { /* Active Url must match with the backup url as per the test */ expect(reg.getActiveMobiusUrl()).toStrictEqual(mobiusUris.backup[0]); - expect(reg.getStatus()).toEqual(MobiusStatus.ACTIVE); + expect(reg.getStatus()).toEqual(RegistrationStatus.ACTIVE); }); afterEach(() => { @@ -305,7 +305,7 @@ describe('Registration Tests', () => { expect(failbackRetry429Spy).toBeCalledOnceWith(); expect(reg.failback429RetryAttempts).toBe(0); - expect(reg.getStatus()).toBe(MobiusStatus.DEFAULT); + expect(reg.getStatus()).toBe(RegistrationStatus.INACTIVE); expect(restoreSpy).toBeCalledOnceWith(FAILBACK_429_RETRY_UTIL); expect(restartSpy).toBeCalledOnceWith(FAILBACK_429_RETRY_UTIL); expect(reg.failbackTimer).toBe(undefined); @@ -326,7 +326,7 @@ describe('Registration Tests', () => { method: 'executeFailback', file: REGISTRATION_FILE, }); - expect(reg.getStatus()).toBe(MobiusStatus.DEFAULT); + expect(reg.getStatus()).toBe(RegistrationStatus.INACTIVE); expect(restoreSpy).toBeCalledOnceWith(FAILBACK_UTIL); expect(restartSpy).toBeCalledOnceWith(FAILBACK_UTIL); expect(reg.rehomingIntervalMin).toBe(DEFAULT_REHOMING_INTERVAL_MIN); @@ -352,7 +352,7 @@ describe('Registration Tests', () => { method: 'executeFailback', file: REGISTRATION_FILE, }); - expect(reg.getStatus()).toBe(MobiusStatus.DEFAULT); + expect(reg.getStatus()).toBe(RegistrationStatus.INACTIVE); expect(restoreSpy).toBeCalledOnceWith(FAILBACK_UTIL); expect(restartSpy).not.toBeCalled(); expect(reg.failbackTimer).toBe(undefined); @@ -375,7 +375,7 @@ describe('Registration Tests', () => { }); /* Active Url should still match backup url */ expect(reg.getActiveMobiusUrl()).toStrictEqual(mobiusUris.backup[0]); - expect(reg.getStatus()).toBe(MobiusStatus.ACTIVE); + expect(reg.getStatus()).toBe(RegistrationStatus.ACTIVE); expect(restoreSpy).toBeCalledOnceWith(FAILBACK_UTIL); expect(restartSpy).not.toBeCalled(); expect(reg.rehomingIntervalMin).toBe(DEFAULT_REHOMING_INTERVAL_MIN); @@ -398,7 +398,7 @@ describe('Registration Tests', () => { /* Active Url must now match with the primary url */ expect(reg.getActiveMobiusUrl()).toStrictEqual(mobiusUris.primary[0]); - expect(reg.getStatus()).toBe(MobiusStatus.ACTIVE); + expect(reg.getStatus()).toBe(RegistrationStatus.ACTIVE); expect(reg.failbackTimer).toBe(undefined); expect(restoreSpy).not.toBeCalled(); expect(reg.rehomingIntervalMin).toBe(mockPostResponse.rehomingIntervalMin); @@ -425,7 +425,7 @@ describe('Registration Tests', () => { /* Active Url should still match backup url */ expect(reg.getActiveMobiusUrl()).toStrictEqual(mobiusUris.backup[0]); - expect(reg.getStatus()).toBe(MobiusStatus.ACTIVE); + expect(reg.getStatus()).toBe(RegistrationStatus.ACTIVE); expect(restoreSpy).not.toBeCalled(); expect(restartSpy).not.toBeCalled(); @@ -451,7 +451,7 @@ describe('Registration Tests', () => { postRegistrationSpy.mockResolvedValueOnce(successPayload); jest.useFakeTimers(); await reg.triggerRegistration(); - expect(reg.getStatus()).toBe(MobiusStatus.ACTIVE); + expect(reg.getStatus()).toBe(RegistrationStatus.ACTIVE); }); afterEach(() => { @@ -509,7 +509,7 @@ describe('Registration Tests', () => { file: REGISTRATION_FILE, }); - expect(reg.getStatus()).toBe(MobiusStatus.ACTIVE); + expect(reg.getStatus()).toBe(RegistrationStatus.ACTIVE); expect(reg.keepaliveTimer).toBe(timer); expect(lineEmitter).nthCalledWith(1, LINE_EVENTS.RECONNECTING); expect(lineEmitter).nthCalledWith(2, LINE_EVENTS.RECONNECTED); @@ -532,7 +532,7 @@ describe('Registration Tests', () => { webex.request.mockRejectedValue(failurePayload); - expect(reg.getStatus()).toEqual(MobiusStatus.ACTIVE); + expect(reg.getStatus()).toEqual(RegistrationStatus.ACTIVE); const timer = reg.keepaliveTimer; @@ -544,7 +544,7 @@ describe('Registration Tests', () => { // sendKeepAlive tries to retry 5 times before accepting failure // later 2 attempts to register with primary server expect(handleErrorSpy).toBeCalledTimes(7); - expect(reg.getStatus()).toEqual(MobiusStatus.DEFAULT); + expect(reg.getStatus()).toEqual(RegistrationStatus.INACTIVE); expect(reg.reconnectPending).toStrictEqual(false); expect(reconnectSpy).toBeCalledOnceWith(KEEPALIVE_UTIL); expect(restoreSpy).toBeCalledOnceWith(KEEPALIVE_UTIL); @@ -591,7 +591,7 @@ describe('Registration Tests', () => { /* successful registration */ // webex.request.mockResolvedValue(successPayload); - expect(reg.getStatus()).toEqual(MobiusStatus.ACTIVE); + expect(reg.getStatus()).toEqual(RegistrationStatus.ACTIVE); const url = 'https://mobius.asydm-m-1.prod.infra.webex.com/api/v1'; @@ -605,7 +605,7 @@ describe('Registration Tests', () => { expect(clearIntervalSpy).toBeCalledOnceWith(timer); expect(handleErrorSpy).toBeCalledTimes(5); - expect(reg.getStatus()).toEqual(MobiusStatus.ACTIVE); + expect(reg.getStatus()).toEqual(RegistrationStatus.ACTIVE); expect(reconnectSpy).toBeCalledOnceWith(KEEPALIVE_UTIL); expect(restoreSpy).toBeCalledOnceWith(KEEPALIVE_UTIL); expect(restartRegSpy).not.toBeCalled(); @@ -632,7 +632,7 @@ describe('Registration Tests', () => { .mockRejectedValueOnce(failurePayload) .mockResolvedValue(successPayload); - expect(reg.getStatus()).toBe(MobiusStatus.ACTIVE); + expect(reg.getStatus()).toBe(RegistrationStatus.ACTIVE); const timer = reg.keepaliveTimer; @@ -641,7 +641,7 @@ describe('Registration Tests', () => { await flushPromises(); expect(webex.request).toBeCalledTimes(3); - expect(reg.getStatus()).toBe(MobiusStatus.ACTIVE); + expect(reg.getStatus()).toBe(RegistrationStatus.ACTIVE); expect(handleErrorSpy).toBeCalledTimes(2); expect(clearIntervalSpy).not.toBeCalled(); expect(reg.keepaliveTimer).toBe(timer); @@ -660,14 +660,14 @@ describe('Registration Tests', () => { webex.request.mockRejectedValue(failurePayload); - expect(reg.getStatus()).toBe(MobiusStatus.ACTIVE); + expect(reg.getStatus()).toBe(RegistrationStatus.ACTIVE); /* send one keepalive */ jest.advanceTimersByTime(mockPostResponse.keepaliveInterval * SEC_TO_MSEC_MFACTOR); await flushPromises(); expect(clearIntervalSpy).toBeCalledTimes(1); - expect(reg.getStatus()).toBe(MobiusStatus.DEFAULT); + expect(reg.getStatus()).toBe(RegistrationStatus.INACTIVE); expect(reconnectSpy).not.toBeCalled(); expect(restoreSpy).not.toBeCalled(); expect(restartRegSpy).not.toBeCalled(); @@ -731,7 +731,7 @@ describe('Registration Tests', () => { expect(handleErrorSpy).toBeCalledTimes(5); expect(reg.keepaliveTimer).toStrictEqual(undefined); expect(reg.failbackTimer).toStrictEqual(undefined); - expect(reg.getStatus()).toBe(MobiusStatus.DEFAULT); + expect(reg.getStatus()).toBe(RegistrationStatus.INACTIVE); expect(lineEmitter).lastCalledWith(LINE_EVENTS.UNREGISTERED); expect(reconnectSpy).toBeCalledOnceWith(KEEPALIVE_UTIL); expect(restoreSpy).not.toBeCalled(); @@ -749,7 +749,7 @@ describe('Registration Tests', () => { await reg.reconnectOnFailure(CALLS_CLEARED_HANDLER_UTIL); expect(Object.keys(reg.callManager.getActiveCalls()).length).toBe(0); - expect(reg.getStatus()).toBe(MobiusStatus.ACTIVE); + expect(reg.getStatus()).toBe(RegistrationStatus.ACTIVE); expect(reconnectSpy).toBeCalledOnceWith(CALLS_CLEARED_HANDLER_UTIL); expect(restoreSpy).toBeCalledOnceWith(CALLS_CLEARED_HANDLER_UTIL); expect(restartRegSpy).not.toBeCalled(); diff --git a/packages/calling/src/CallingClient/registration/register.ts b/packages/calling/src/CallingClient/registration/register.ts index 6c43b610b5c..1121a49407d 100644 --- a/packages/calling/src/CallingClient/registration/register.ts +++ b/packages/calling/src/CallingClient/registration/register.ts @@ -1,4 +1,3 @@ -/* eslint-disable valid-jsdoc */ import {v4 as uuid} from 'uuid'; import {Mutex} from 'async-mutex'; import {ERROR_CODE} from '../../Errors/types'; @@ -16,7 +15,7 @@ import { ALLOWED_SERVICES, HTTP_METHODS, IDeviceInfo, - MobiusStatus, + RegistrationStatus, ServiceData, WebexRequestPayload, } from '../../common/types'; @@ -57,7 +56,7 @@ export class Registration implements IRegistration { private serviceData: ServiceData; private failback429RetryAttempts: number; - private registrationStatus: MobiusStatus; + private registrationStatus: RegistrationStatus; private failbackTimer?: NodeJS.Timer; private activeMobiusUrl!: string; @@ -91,7 +90,7 @@ export class Registration implements IRegistration { } this.webex = this.sdkConnector.getWebex(); this.userId = this.webex.internal.device.userId; - this.registrationStatus = MobiusStatus.DEFAULT; + this.registrationStatus = RegistrationStatus.IDLE; this.failback429RetryAttempts = 0; log.setLogger(logLevel, REGISTRATION_FILE); this.rehomingIntervalMin = DEFAULT_REHOMING_INTERVAL_MIN; @@ -141,19 +140,25 @@ export class Registration implements IRegistration { * */ private async deleteRegistration(url: string, deviceId: string, deviceUrl: string) { - const response = await fetch(`${url}${DEVICES_ENDPOINT_RESOURCE}/${deviceId}`, { - method: HTTP_METHODS.DELETE, - headers: { - [CISCO_DEVICE_URL]: deviceUrl, - Authorization: await this.webex.credentials.getUserToken(), - trackingId: `${WEBEX_WEB_CLIENT}_${uuid()}`, - [SPARK_USER_AGENT]: CALLING_USER_AGENT, - }, - }); + let response; + try { + response = await fetch(`${url}${DEVICES_ENDPOINT_RESOURCE}/${deviceId}`, { + method: HTTP_METHODS.DELETE, + headers: { + [CISCO_DEVICE_URL]: deviceUrl, + Authorization: await this.webex.credentials.getUserToken(), + trackingId: `${WEBEX_WEB_CLIENT}_${uuid()}`, + [SPARK_USER_AGENT]: CALLING_USER_AGENT, + }, + }); + } catch (error) { + log.warn(`Delete failed with Mobius`, {}); + } + this.setStatus(RegistrationStatus.INACTIVE); this.lineEmitter(LINE_EVENTS.UNREGISTERED); - return response.json(); + return response?.json(); } /** @@ -442,14 +447,14 @@ export class Registration implements IRegistration { * ACTIVE, else false. */ public isDeviceRegistered(): boolean { - return this.registrationStatus === MobiusStatus.ACTIVE; + return this.registrationStatus === RegistrationStatus.ACTIVE; } - public getStatus(): MobiusStatus { + public getStatus(): RegistrationStatus { return this.registrationStatus; } - public setStatus(value: MobiusStatus) { + public setStatus(value: RegistrationStatus) { this.registrationStatus = value; } @@ -481,7 +486,7 @@ export class Registration implements IRegistration { await this.mutex.runExclusive(async () => { /* Check retry once again to see if another timer thread has not finished the job already. */ if (retry) { - log.info('Mercury connection is up again, Re-registering with Mobius', { + log.info('Mercury connection is up again, re-registering with Webex Calling if needed', { file: REGISTRATION_FILE, method: this.handleConnectionRestoration.name, }); @@ -592,7 +597,7 @@ export class Registration implements IRegistration { for (const url of servers) { try { abort = false; - this.registrationStatus = MobiusStatus.DEFAULT; + this.registrationStatus = RegistrationStatus.INACTIVE; this.lineEmitter(LINE_EVENTS.CONNECTING); log.log(`[${caller}] : Mobius url to contact: ${url}`, { file: REGISTRATION_FILE, @@ -600,10 +605,9 @@ export class Registration implements IRegistration { }); // eslint-disable-next-line no-await-in-loop const resp = await this.postRegistration(url); - this.deviceInfo = resp.body as IDeviceInfo; this.lineEmitter(LINE_EVENTS.REGISTERED, resp.body as IDeviceInfo); - this.registrationStatus = MobiusStatus.ACTIVE; + this.registrationStatus = RegistrationStatus.ACTIVE; this.setActiveMobiusUrl(url); this.setIntervalValues(this.deviceInfo); this.metricManager.setDeviceInfo(this.deviceInfo); @@ -641,7 +645,7 @@ export class Registration implements IRegistration { {method: this.attemptRegistrationWithServers.name, file: REGISTRATION_FILE}, this.restoreRegistrationCallBack() ); - if (this.registrationStatus === MobiusStatus.ACTIVE) { + if (this.registrationStatus === RegistrationStatus.ACTIVE) { log.info( `[${caller}] : Device is already restored, active mobius url: ${this.activeMobiusUrl}`, { @@ -652,6 +656,7 @@ export class Registration implements IRegistration { break; } if (abort) { + this.setStatus(RegistrationStatus.INACTIVE); break; } else if (caller === this.executeFailback.name) { const error = body.statusCode; @@ -716,7 +721,7 @@ export class Registration implements IRegistration { ); if (abort || keepAliveRetryCount >= 5) { - this.setStatus(MobiusStatus.DEFAULT); + this.setStatus(RegistrationStatus.INACTIVE); this.clearKeepaliveTimer(); this.clearFailbackTimer(); this.lineEmitter(LINE_EVENTS.UNREGISTERED); @@ -760,7 +765,7 @@ export class Registration implements IRegistration { } this.clearKeepaliveTimer(); - this.setStatus(MobiusStatus.DEFAULT); + this.setStatus(RegistrationStatus.INACTIVE); } /** @@ -798,7 +803,7 @@ export class Registration implements IRegistration { const uri = restoreData.devices[0].uri.replace(stringToReplace, ''); this.setActiveMobiusUrl(uri); - this.registrationStatus = MobiusStatus.ACTIVE; + this.registrationStatus = RegistrationStatus.ACTIVE; return true; } diff --git a/packages/calling/src/CallingClient/registration/types.ts b/packages/calling/src/CallingClient/registration/types.ts index bd11a26183b..5791ec33631 100644 --- a/packages/calling/src/CallingClient/registration/types.ts +++ b/packages/calling/src/CallingClient/registration/types.ts @@ -1,4 +1,4 @@ -import {IDeviceInfo, MobiusStatus} from '../../common/types'; +import {IDeviceInfo, RegistrationStatus} from '../../common/types'; export type Header = { [key: string]: string; @@ -38,13 +38,13 @@ export interface IRegistration { * * @param value - The registration status to set. */ - setStatus(value: MobiusStatus): void; + setStatus(value: RegistrationStatus): void; /** * Retrieves the current registration status. * */ - getStatus(): MobiusStatus; + getStatus(): RegistrationStatus; /** * Retrieves information about the device as {@link IDeviceInfo}. diff --git a/packages/calling/src/Errors/catalog/CallingDeviceError.ts b/packages/calling/src/Errors/catalog/CallingDeviceError.ts index c6a7e0b8b21..9eb92e85ee1 100644 --- a/packages/calling/src/Errors/catalog/CallingDeviceError.ts +++ b/packages/calling/src/Errors/catalog/CallingDeviceError.ts @@ -1,5 +1,5 @@ /* eslint-disable valid-jsdoc */ -import {MobiusStatus} from '../../common/types'; +import {RegistrationStatus} from '../../common/types'; import {ErrorContext, ErrorMessage, ErrorObject, ERROR_TYPE} from '../types'; import ExtendedError from './ExtendedError'; @@ -8,7 +8,7 @@ import ExtendedError from './ExtendedError'; * Any error reported from Calling client should be stored here. */ export class CallingClientError extends ExtendedError { - public status: MobiusStatus = MobiusStatus.DEFAULT; + public status: RegistrationStatus = RegistrationStatus.INACTIVE; /** * Instantiate the Error class with these parameters. @@ -18,7 +18,12 @@ export class CallingClientError extends ExtendedError { * @param type - Error Type. * @param status - Mobius Status, should be default. */ - constructor(msg: ErrorMessage, context: ErrorContext, type: ERROR_TYPE, status: MobiusStatus) { + constructor( + msg: ErrorMessage, + context: ErrorContext, + type: ERROR_TYPE, + status: RegistrationStatus + ) { super(msg, context, type); this.status = status; } @@ -57,5 +62,5 @@ export const createClientError = ( msg: ErrorMessage, context: ErrorContext, type: ERROR_TYPE, - status: MobiusStatus + status: RegistrationStatus ) => new CallingClientError(msg, context, type, status); diff --git a/packages/calling/src/Errors/catalog/LineError.ts b/packages/calling/src/Errors/catalog/LineError.ts index 2e309e88999..19d9c5bdda6 100644 --- a/packages/calling/src/Errors/catalog/LineError.ts +++ b/packages/calling/src/Errors/catalog/LineError.ts @@ -1,5 +1,5 @@ /* eslint-disable valid-jsdoc */ -import {LineStatus} from '../../CallingClient/line/types'; +import {RegistrationStatus} from '../../common/types'; import {ErrorMessage, ERROR_TYPE, LineErrorObject, ErrorContext} from '../types'; import ExtendedError from './ExtendedError'; @@ -7,7 +7,7 @@ import ExtendedError from './ExtendedError'; * Any error reported from Line class should be stored here. */ export class LineError extends ExtendedError { - public status: LineStatus = LineStatus.INACTIVE; + public status: RegistrationStatus = RegistrationStatus.INACTIVE; /** * Instantiate the Error class with these parameters. @@ -17,7 +17,12 @@ export class LineError extends ExtendedError { * @param type - Error Type. * @param status - Line Status, should be inactive. */ - constructor(msg: ErrorMessage, context: ErrorContext, type: ERROR_TYPE, status: LineStatus) { + constructor( + msg: ErrorMessage, + context: ErrorContext, + type: ERROR_TYPE, + status: RegistrationStatus + ) { super(msg, context, type); this.status = status; } @@ -62,5 +67,5 @@ export const createLineError = ( msg: ErrorMessage, context: ErrorContext, type: ERROR_TYPE, - status: LineStatus + status: RegistrationStatus ) => new LineError(msg, context, type, status); diff --git a/packages/calling/src/Errors/types.ts b/packages/calling/src/Errors/types.ts index fbdf7a517cd..c7c8fb3a7b4 100644 --- a/packages/calling/src/Errors/types.ts +++ b/packages/calling/src/Errors/types.ts @@ -1,6 +1,5 @@ /* eslint-disable @typescript-eslint/no-empty-interface */ -import {LineStatus} from '../CallingClient/line/types'; -import {CorrelationId, IMetaContext} from '../common/types'; +import {CorrelationId, IMetaContext, RegistrationStatus} from '../common/types'; export type ErrorMessage = string; @@ -61,7 +60,7 @@ export type ErrorObject = { }; export interface LineErrorObject extends ErrorObject { - status: LineStatus; + status: RegistrationStatus; } export interface CallErrorObject extends ErrorObject { diff --git a/packages/calling/src/Metrics/index.test.ts b/packages/calling/src/Metrics/index.test.ts index 733859d703d..a251d90f429 100644 --- a/packages/calling/src/Metrics/index.test.ts +++ b/packages/calling/src/Metrics/index.test.ts @@ -5,7 +5,7 @@ import {METRIC_TYPE, METRIC_EVENT, REG_ACTION, VOICEMAIL_ACTION} from './types'; import {VERSION} from '../CallingClient/constants'; import {createClientError} from '../Errors/catalog/CallingDeviceError'; import {CallErrorObject, ErrorObject, ERROR_LAYER, ERROR_TYPE} from '../Errors/types'; -import {MobiusStatus, ServiceIndicator} from '../common/types'; +import {RegistrationStatus, ServiceIndicator} from '../common/types'; import log from '../Logger'; import {createCallError} from '../Errors/catalog/CallError'; @@ -67,7 +67,12 @@ describe('CALLING: Metric tests', () => { it('submit registration failure metric', () => { metricManager.setDeviceInfo(mockDeviceInfo); - const clientError = createClientError('', {}, ERROR_TYPE.DEFAULT, MobiusStatus.DEFAULT); + const clientError = createClientError( + '', + {}, + ERROR_TYPE.DEFAULT, + RegistrationStatus.INACTIVE + ); const err = {}; err.context = {}; diff --git a/packages/calling/src/common/Utils.test.ts b/packages/calling/src/common/Utils.test.ts index 78d990d9225..e480b3497b9 100644 --- a/packages/calling/src/common/Utils.test.ts +++ b/packages/calling/src/common/Utils.test.ts @@ -13,11 +13,11 @@ import { CallDirection, CallType, DecodeType, - MobiusStatus, ServiceIndicator, SORT, WebexRequestPayload, CALLING_BACKEND, + RegistrationStatus, } from './types'; import log from '../Logger'; import { @@ -300,7 +300,7 @@ describe('Registration Tests', () => { mockErrorEvent.message, mockErrorEvent.context, mockErrorEvent.type, - MobiusStatus.ACTIVE + RegistrationStatus.ACTIVE ); handleRegistrationErrors(webexPayload, mockEmitterCb, logObj, mockRestoreCb); diff --git a/packages/calling/src/common/Utils.ts b/packages/calling/src/common/Utils.ts index e8973656a8f..a1254af13a0 100644 --- a/packages/calling/src/common/Utils.ts +++ b/packages/calling/src/common/Utils.ts @@ -1,6 +1,5 @@ /* eslint-disable no-fallthrough */ /* eslint-disable no-underscore-dangle */ -/* eslint-disable valid-jsdoc */ /* eslint-disable @typescript-eslint/no-shadow */ import * as platform from 'platform'; import {restoreRegistrationCallBack} from '../CallingClient/registration/types'; @@ -36,7 +35,7 @@ import { HTTP_METHODS, IDeviceInfo, MobiusServers, - MobiusStatus, + RegistrationStatus, SORT, ServiceData, ServiceIndicator, @@ -120,7 +119,7 @@ import {scimResponseBody} from '../CallingClient/calling/CallerId/types'; import SDKConnector from '../SDKConnector'; import {CallSettingResponse} from '../CallSettings/types'; import {ContactResponse} from '../Contacts/types'; -import {LineErrorEmitterCallback, LineStatus} from '../CallingClient/line/types'; +import {LineErrorEmitterCallback} from '../CallingClient/line/types'; import {LineError, createLineError} from '../Errors/catalog/LineError'; export function filterMobiusUris(mobiusServers: MobiusServers, defaultMobiusUrl: string) { @@ -215,7 +214,7 @@ function updateLineErrorContext( errContext: ErrorContext, type: ERROR_TYPE, message: string, - status: LineStatus, + status: RegistrationStatus, lineError: LineError ) { const errObj = {}; @@ -258,13 +257,13 @@ function updateErrorContext( * @param file - File name from where error got reported. */ export function emitFinalFailure(emitterCb: LineErrorEmitterCallback, loggerContext: LogContext) { - const clientError = createLineError('', {}, ERROR_TYPE.DEFAULT, LineStatus.INACTIVE); + const clientError = createLineError('', {}, ERROR_TYPE.DEFAULT, RegistrationStatus.INACTIVE); updateLineErrorContext( loggerContext, ERROR_TYPE.SERVICE_UNAVAILABLE, 'An unknown error occurred. Wait a moment and try again. Please contact the administrator if the problem persists.', - LineStatus.INACTIVE, + RegistrationStatus.INACTIVE, clientError ); emitterCb(clientError); @@ -292,7 +291,7 @@ export async function handleRegistrationErrors( loggerContext: LogContext, restoreRegCb?: restoreRegistrationCallBack ): Promise { - const lineError = createLineError('', {}, ERROR_TYPE.DEFAULT, LineStatus.INACTIVE); + const lineError = createLineError('', {}, ERROR_TYPE.DEFAULT, RegistrationStatus.INACTIVE); const errorCode = Number(err.statusCode); let finalError = false; @@ -307,7 +306,7 @@ export async function handleRegistrationErrors( loggerContext, ERROR_TYPE.TOKEN_ERROR, 'User is unauthorized due to an expired token. Sign out, then sign back in.', - LineStatus.INACTIVE, + RegistrationStatus.INACTIVE, lineError ); @@ -321,7 +320,7 @@ export async function handleRegistrationErrors( loggerContext, ERROR_TYPE.SERVER_ERROR, 'An unknown error occurred while placing the request. Wait a moment and try again.', - LineStatus.INACTIVE, + RegistrationStatus.INACTIVE, lineError ); @@ -335,7 +334,7 @@ export async function handleRegistrationErrors( loggerContext, ERROR_TYPE.SERVICE_UNAVAILABLE, 'An error occurred on the server while processing the request. Wait a moment and try again.', - LineStatus.INACTIVE, + RegistrationStatus.INACTIVE, lineError ); @@ -352,7 +351,7 @@ export async function handleRegistrationErrors( loggerContext, ERROR_TYPE.FORBIDDEN_ERROR, 'An unauthorized action has been received. This action has been blocked. Please contact the administrator if this persists.', - LineStatus.INACTIVE, + RegistrationStatus.INACTIVE, lineError ); @@ -381,7 +380,7 @@ export async function handleRegistrationErrors( loggerContext, ERROR_TYPE.FORBIDDEN_ERROR, errorMessage, - LineStatus.INACTIVE, + RegistrationStatus.INACTIVE, lineError ); log.warn(errorMessage, loggerContext); @@ -395,7 +394,7 @@ export async function handleRegistrationErrors( loggerContext, ERROR_TYPE.FORBIDDEN_ERROR, errorMessage, - LineStatus.INACTIVE, + RegistrationStatus.INACTIVE, lineError ); log.warn(errorMessage, loggerContext); @@ -409,7 +408,7 @@ export async function handleRegistrationErrors( loggerContext, ERROR_TYPE.FORBIDDEN_ERROR, errorMessage, - LineStatus.INACTIVE, + RegistrationStatus.INACTIVE, lineError ); log.warn(errorMessage, loggerContext); @@ -426,7 +425,7 @@ export async function handleRegistrationErrors( loggerContext, ERROR_TYPE.NOT_FOUND, 'The client has unregistered. Please wait for the client to register before attempting the call. If error persists, sign out, sign back in and attempt the call.', - LineStatus.INACTIVE, + RegistrationStatus.INACTIVE, lineError ); emitterCb(lineError, finalError); @@ -438,7 +437,7 @@ export async function handleRegistrationErrors( loggerContext, ERROR_TYPE.DEFAULT, 'Unknown error', - LineStatus.INACTIVE, + RegistrationStatus.INACTIVE, lineError ); log.warn(`Unknown Error`, loggerContext); @@ -461,7 +460,7 @@ export async function handleCallingClientErrors( emitterCb: CallingClientErrorEmitterCallback, loggerContext: LogContext ): Promise { - const clientError = createClientError('', {}, ERROR_TYPE.DEFAULT, MobiusStatus.DEFAULT); + const clientError = createClientError('', {}, ERROR_TYPE.DEFAULT, RegistrationStatus.INACTIVE); const errorCode = Number(err.statusCode); const finalError = false; diff --git a/packages/calling/src/common/types.ts b/packages/calling/src/common/types.ts index bf13432cd38..a5ef4d22b84 100644 --- a/packages/calling/src/common/types.ts +++ b/packages/calling/src/common/types.ts @@ -14,9 +14,10 @@ export enum HTTP_METHODS { DELETE = 'DELETE', } -export enum MobiusStatus { +export enum RegistrationStatus { + IDLE = 'IDLE', ACTIVE = 'active', - DEFAULT = 'default', + INACTIVE = 'inactive', } export enum CALLING_BACKEND {