diff --git a/packages/@webex/plugin-cc/src/config.ts b/packages/@webex/plugin-cc/src/config.ts index 49fc9e6d461..b9be0610a10 100644 --- a/packages/@webex/plugin-cc/src/config.ts +++ b/packages/@webex/plugin-cc/src/config.ts @@ -17,7 +17,7 @@ export default { }, serviceData: { indicator: 'contactcenter', - // TODO: This should be dynamic based on the environment + // This is now being read dynamically based on the environment in WebCallingService registerWebCallingLine method domain: 'rtw.prod-us1.rtmsprod.net', }, }, diff --git a/packages/@webex/plugin-cc/src/services/WebCallingService.ts b/packages/@webex/plugin-cc/src/services/WebCallingService.ts index 7b4f899f81c..574b408c2ae 100644 --- a/packages/@webex/plugin-cc/src/services/WebCallingService.ts +++ b/packages/@webex/plugin-cc/src/services/WebCallingService.ts @@ -45,6 +45,13 @@ export default class WebCallingService extends EventEmitter { } public async registerWebCallingLine(): Promise { + /** overriding RTMS URL with u2c catalogue wcc-calling-rtms service */ + await this.webex.internal.services.waitForCatalog('postauth'); + const rtmsURL = this.webex.internal.services.get('wcc-calling-rtms'); + if (rtmsURL) { + this.callingClientConfig.serviceData.domain = rtmsURL; + } + this.callingClient = await createClient(this.webex as any, this.callingClientConfig); this.line = Object.values(this.callingClient.getLines())[0]; diff --git a/packages/@webex/plugin-cc/src/types.ts b/packages/@webex/plugin-cc/src/types.ts index 856edc44755..b9440369922 100644 --- a/packages/@webex/plugin-cc/src/types.ts +++ b/packages/@webex/plugin-cc/src/types.ts @@ -111,6 +111,8 @@ export interface WebexSDK { }; presence: unknown; services: { + get: (service: string) => string; + waitForCatalog: (service: string) => Promise; _hostCatalog: Record; _serviceUrls: { mobius: string; diff --git a/packages/@webex/plugin-cc/test/unit/spec/services/WebCallingService.ts b/packages/@webex/plugin-cc/test/unit/spec/services/WebCallingService.ts index e4fea2efdc9..b91cf03301b 100644 --- a/packages/@webex/plugin-cc/test/unit/spec/services/WebCallingService.ts +++ b/packages/@webex/plugin-cc/test/unit/spec/services/WebCallingService.ts @@ -36,7 +36,13 @@ describe('WebCallingService', () => { logger: { log: jest.fn(), error: jest.fn(), - info: jest.fn() + info: jest.fn(), + }, + internal: { + services: { + waitForCatalog: jest.fn().mockResolvedValue(undefined), + get: jest.fn().mockReturnValue('rtw.prod-us1.rtmsprod.net'), + }, }, } as unknown as WebexSDK; @@ -63,7 +69,7 @@ describe('WebCallingService', () => { answer: jest.fn(), mute: jest.fn(), isMuted: jest.fn().mockReturnValue(true), - end: jest.fn() + end: jest.fn(), }; webRTCCalling.call = mockCall; @@ -101,7 +107,39 @@ describe('WebCallingService', () => { expect(line.register).toHaveBeenCalled(); expect(LoggerProxy.log).toHaveBeenCalledWith( `WxCC-SDK: Desktop registered successfully, mobiusDeviceId: ${deviceInfo.mobiusDeviceId}`, - {"method": "registerWebCallingLine", "module": WEB_CALLING_SERVICE_FILE} + {method: 'registerWebCallingLine', module: WEB_CALLING_SERVICE_FILE} + ); + }, 20000); // Increased timeout to 20 seconds + + it('should register WebCallingLine with custom rtms url', async () => { + webex.internal.services.get = jest.fn().mockReturnValue('rtw.prod-us2.rtmsprod.net'); + + line = callingClient.getLines().line1 as ILine; + const deviceInfo = { + mobiusDeviceId: 'device123', + status: 'registered', + setError: jest.fn(), + getError: jest.fn(), + type: 'line', + id: 'line1', + }; + + const registeredHandler = jest.fn(); + const lineOnSpy = jest.spyOn(line, 'on').mockImplementation((event, handler) => { + if (event === LINE_EVENTS.REGISTERED) { + registeredHandler.mockImplementation(handler); + handler(deviceInfo); + } + }); + expect(config.cc.callingClientConfig.serviceData.domain).toBe('rtw.prod-us1.rtmsprod.net'); + await expect(webRTCCalling.registerWebCallingLine()).resolves.toBeUndefined(); + expect(config.cc.callingClientConfig.serviceData.domain).toBe('rtw.prod-us2.rtmsprod.net'); + expect(createClient).toHaveBeenCalledWith(webex, config.cc.callingClientConfig); + expect(lineOnSpy).toHaveBeenCalledWith(LINE_EVENTS.REGISTERED, expect.any(Function)); + expect(line.register).toHaveBeenCalled(); + expect(LoggerProxy.log).toHaveBeenCalledWith( + `WxCC-SDK: Desktop registered successfully, mobiusDeviceId: ${deviceInfo.mobiusDeviceId}`, + {method: 'registerWebCallingLine', module: WEB_CALLING_SERVICE_FILE} ); }, 20000); // Increased timeout to 20 seconds @@ -169,7 +207,7 @@ describe('WebCallingService', () => { const mockStream = { outputStream: { getAudioTracks: jest.fn().mockReturnValue(['']), - } + }, }; const localAudioStream = mockStream as unknown as LocalMicrophoneStream; @@ -183,10 +221,14 @@ describe('WebCallingService', () => { it('should log error and throw when call.answer fails', () => { const error = new Error('Failed to answer'); - mockCall.answer.mockImplementation(() => { throw error; }); + mockCall.answer.mockImplementation(() => { + throw error; + }); expect(() => webRTCCalling.answerCall(localAudioStream, 'task-id')).toThrow(error); - expect(webex.logger.error).toHaveBeenCalledWith(`Failed to answer call for task-id. Error: ${error}`); + expect(webex.logger.error).toHaveBeenCalledWith( + `Failed to answer call for task-id. Error: ${error}` + ); }); it('should log when there is no call to answer', () => { @@ -201,7 +243,7 @@ describe('WebCallingService', () => { const mockStream = { outputStream: { getAudioTracks: jest.fn().mockReturnValue(['']), - } + }, }; const localAudioStream = mockStream as unknown as LocalMicrophoneStream; @@ -231,10 +273,14 @@ describe('WebCallingService', () => { it('should log error and throw when call.end fails', () => { const error = new Error('Failed to end call'); - mockCall.end.mockImplementation(() => { throw error; }); + mockCall.end.mockImplementation(() => { + throw error; + }); expect(() => webRTCCalling.declineCall('task-id')).toThrow(error); - expect(webex.logger.error).toHaveBeenCalledWith(`Failed to end call: task-id. Error: ${error}`); + expect(webex.logger.error).toHaveBeenCalledWith( + `Failed to end call: task-id. Error: ${error}` + ); }); it('should log when there is no call to end', () => {