From 0c5a54e85f0ceac9aee4913d09f964d6c0870e4d Mon Sep 17 00:00:00 2001 From: Adhwaith Menon <111346225+adhmenon@users.noreply.github.com> Date: Mon, 3 Feb 2025 10:43:58 +0530 Subject: [PATCH] fix(cc-sdk): fixed-relogin-issue (#4078) --- packages/@webex/plugin-cc/src/cc.ts | 5 +++++ packages/@webex/plugin-cc/test/unit/spec/cc.ts | 18 ++++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/packages/@webex/plugin-cc/src/cc.ts b/packages/@webex/plugin-cc/src/cc.ts index 31ecb8e9bf8..5f7c6541278 100644 --- a/packages/@webex/plugin-cc/src/cc.ts +++ b/packages/@webex/plugin-cc/src/cc.ts @@ -345,6 +345,10 @@ export default class ContactCenter extends WebexPlugin implements IContactCenter const reLoginResponse = await this.services.agent.reload(); const {auxCodeId, agentId, lastStateChangeReason, deviceType, dn} = reLoginResponse.data; + // To handle re-registration of event listeners on silent relogin + this.incomingTaskListener(); + this.taskManager.registerIncomingCallEvent(); + if (lastStateChangeReason === 'agent-wss-disconnect') { LoggerProxy.info( 'event=requestAutoStateChange | Requesting state change to available on socket reconnect', @@ -395,6 +399,7 @@ export default class ContactCenter extends WebexPlugin implements IContactCenter }); throw new Error(`Unsupported device type: ${deviceType}`); } + this.webCallingService.setLoginOption(deviceType); this.agentConfig.deviceType = deviceType; } } diff --git a/packages/@webex/plugin-cc/test/unit/spec/cc.ts b/packages/@webex/plugin-cc/test/unit/spec/cc.ts index 321a4f1433c..fbc97c687da 100644 --- a/packages/@webex/plugin-cc/test/unit/spec/cc.ts +++ b/packages/@webex/plugin-cc/test/unit/spec/cc.ts @@ -772,6 +772,16 @@ describe('webex.cc', () => { .mockResolvedValue({} as SetStateResponse); jest.spyOn(webex.cc.services.agent, 'reload').mockResolvedValue(mockReLoginResponse); + const registerWebCallingLineSpy = jest.spyOn( + webex.cc.webCallingService, + 'registerWebCallingLine' + ); + const registerIncomingCallEventSpy = jest.spyOn( + webex.cc.taskManager, + 'registerIncomingCallEvent' + ); + const incomingTaskListenerSpy = jest.spyOn(webex.cc, 'incomingTaskListener'); + const webSocketManagerOnSpy = jest.spyOn(webex.cc.services.webSocketManager, 'on'); await webex.cc['silentRelogin'](); expect(LoggerProxy.info).toHaveBeenCalledWith( @@ -786,6 +796,10 @@ describe('webex.cc', () => { }); expect(webex.cc.agentConfig.isAgentLoggedIn).toBe(true); expect(webex.cc.agentConfig.deviceType).toBe(LoginOption.BROWSER); + expect(registerWebCallingLineSpy).toHaveBeenCalled(); + expect(registerIncomingCallEventSpy).toHaveBeenCalled(); + expect(incomingTaskListenerSpy).toHaveBeenCalled(); + expect(webSocketManagerOnSpy).toHaveBeenCalledWith('message', expect.any(Function)); }); it('should handle AGENT_NOT_FOUND error silently', async () => { @@ -831,6 +845,10 @@ describe('webex.cc', () => { isAgentLoggedIn: false, } as Profile; + const registerWebCallingLineSpy = jest.spyOn( + webex.cc.webCallingService, + 'registerWebCallingLine' + ); jest.spyOn(webex.cc.services.agent, 'reload').mockResolvedValue(mockReLoginResponse); await webex.cc['silentRelogin']();