From 29e9b2d47bb5a8e3985914e08e744567ab9e5276 Mon Sep 17 00:00:00 2001 From: adhmenon Date: Tue, 26 Nov 2024 20:17:28 +0530 Subject: [PATCH 1/5] feat(cc-sdk): added-device-type-in-config --- docs/samples/contact-center/app.js | 5 ++- packages/@webex/plugin-cc/src/cc.ts | 31 ++++++++++++++- .../@webex/plugin-cc/test/unit/spec/cc.ts | 38 +++++++++++++++++++ 3 files changed, 70 insertions(+), 4 deletions(-) diff --git a/docs/samples/contact-center/app.js b/docs/samples/contact-center/app.js index b9a02172b19..a0a95d01edf 100644 --- a/docs/samples/contact-center/app.js +++ b/docs/samples/contact-center/app.js @@ -130,14 +130,15 @@ function register() { }); const loginVoiceOptions = agentProfile.loginVoiceOptions; agentLogin.innerHTML = ''; // Clear previously selected option on agentLogin. - dialNumber.value = ''; - dialNumber.disabled = true; + dialNumber.value = agentProfile.defaultDn ? agentProfile.defaultDn : ''; + dialNumber.disabled = agentProfile.defaultDn ? false : true; if(loginVoiceOptions.length > 0) agentLoginButton.disabled = false; loginVoiceOptions.forEach((voiceOptions)=> { const option = document.createElement('option'); option.text = voiceOptions; option.value = voiceOptions; agentLogin.add(option); + option.selected = agentProfile.isAgentLoggedIn && voiceOptions === agentProfile.deviceType; }); if (agentProfile.isAgentLoggedIn) { diff --git a/packages/@webex/plugin-cc/src/cc.ts b/packages/@webex/plugin-cc/src/cc.ts index 6479d6b9339..b333d461ed4 100644 --- a/packages/@webex/plugin-cc/src/cc.ts +++ b/packages/@webex/plugin-cc/src/cc.ts @@ -295,7 +295,7 @@ export default class ContactCenter extends WebexPlugin implements IContactCenter private async silentRelogin(): Promise { try { const reLoginResponse = await this.services.agent.reload(); - const {auxCodeId, agentId, lastStateChangeReason} = reLoginResponse.data; + const {auxCodeId, agentId, lastStateChangeReason, deviceType, dn} = reLoginResponse.data; if (lastStateChangeReason === 'agent-wss-disconnect') { LoggerProxy.info( @@ -310,7 +310,8 @@ export default class ContactCenter extends WebexPlugin implements IContactCenter }; await this.setAgentState(stateChangeData); } - // Updating isAgentLoggedIn as true to indicate to the end user + + await this.handleDeviceType(deviceType, dn); this.agentConfig.isAgentLoggedIn = true; } catch (error) { const {reason, error: detailedError} = getErrorDetails(error, 'silentReLogin', CC_FILE); @@ -325,4 +326,30 @@ export default class ContactCenter extends WebexPlugin implements IContactCenter throw detailedError; } } + + /** + * Handles the device type specific logic + */ + private async handleDeviceType(deviceType: string, dn: string): Promise { + switch (deviceType) { + case LoginOption.BROWSER: + await this.webCallingService.registerWebCallingLine(); + this.agentConfig.deviceType = LoginOption.BROWSER; + break; + case LoginOption.AGENT_DN: + this.agentConfig.deviceType = LoginOption.AGENT_DN; + this.agentConfig.defaultDn = dn; + break; + case LoginOption.EXTENSION: + this.agentConfig.deviceType = LoginOption.EXTENSION; + this.agentConfig.defaultDn = dn; + break; + default: + LoggerProxy.error(`Unsupported device type: ${deviceType}`, { + module: CC_FILE, + method: this.handleDeviceType.name, + }); + throw new Error(`Unsupported device type: ${deviceType}`); + } + } } diff --git a/packages/@webex/plugin-cc/test/unit/spec/cc.ts b/packages/@webex/plugin-cc/test/unit/spec/cc.ts index 500e3917d14..9a22360db6e 100644 --- a/packages/@webex/plugin-cc/test/unit/spec/cc.ts +++ b/packages/@webex/plugin-cc/test/unit/spec/cc.ts @@ -183,6 +183,8 @@ describe('webex.cc', () => { data: { auxCodeId: 'auxCodeId', agentId: 'agentId', + deviceType: LoginOption.EXTENSION, + dn: '12345', }, }); const configSpy = jest @@ -667,6 +669,8 @@ describe('webex.cc', () => { auxCodeId: 'auxCodeId', agentId: 'agentId', lastStateChangeReason: 'agent-wss-disconnect', + deviceType: LoginOption.BROWSER, + dn: '12345', }, }; @@ -695,6 +699,7 @@ describe('webex.cc', () => { agentId: 'agentId', }); expect(webex.cc.agentConfig.isAgentLoggedIn).toBe(true); + expect(webex.cc.agentConfig.deviceType).toBe(LoginOption.BROWSER); }); it('should handle AGENT_NOT_FOUND error silently', async () => { @@ -714,5 +719,38 @@ describe('webex.cc', () => { {module: CC_FILE, method: 'silentRelogin'} ); }); + + it('should handle errors during silent relogin', async () => { + const error = new Error('Error while performing silentReLogin'); + jest.spyOn(webex.cc.services.agent, 'reload').mockRejectedValue(error); + + await expect(webex.cc['silentRelogin']()).rejects.toThrow(error); + }); + + it('should update agentConfig with deviceType during silent relogin', async () => { + const mockReLoginResponse = { + data: { + auxCodeId: 'auxCodeId', + agentId: 'agentId', + lastStateChangeReason: 'agent-wss-disconnect', + deviceType: LoginOption.EXTENSION, + dn: '12345', + }, + }; + + // Mock the agentConfig + webex.cc.agentConfig = { + agentId: 'agentId', + agentProfileID: 'test-agent-profile-id', + isAgentLoggedIn: false, + } as Profile; + + jest.spyOn(webex.cc.services.agent, 'reload').mockResolvedValue(mockReLoginResponse); + + await webex.cc['silentRelogin'](); + + expect(webex.cc.agentConfig.deviceType).toBe(LoginOption.EXTENSION); + expect(webex.cc.agentConfig.defaultDn).toBe('12345'); + }); }); }); From 930a3b27f6999317b30a4a25c40e09326f8f79d6 Mon Sep 17 00:00:00 2001 From: adhmenon Date: Tue, 26 Nov 2024 20:41:36 +0530 Subject: [PATCH 2/5] feat(cc-sdk): fixed-logout-ui-change --- docs/samples/contact-center/app.js | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/samples/contact-center/app.js b/docs/samples/contact-center/app.js index a0a95d01edf..552af592833 100644 --- a/docs/samples/contact-center/app.js +++ b/docs/samples/contact-center/app.js @@ -208,6 +208,7 @@ function logoutAgent() { setTimeout(() => { logoutAgentElm.classList.add('hidden'); + agentLogin.selectedIndex = 0; }, 1000); } ).catch((error) => { From 2df33e70630fecab891eb0cdc9874c280938fc76 Mon Sep 17 00:00:00 2001 From: adhmenon Date: Tue, 26 Nov 2024 21:06:05 +0530 Subject: [PATCH 3/5] feat(cc-sdk): fixed-common-login-option-fix --- packages/@webex/plugin-cc/src/cc.ts | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/packages/@webex/plugin-cc/src/cc.ts b/packages/@webex/plugin-cc/src/cc.ts index b333d461ed4..f391a2e89fe 100644 --- a/packages/@webex/plugin-cc/src/cc.ts +++ b/packages/@webex/plugin-cc/src/cc.ts @@ -334,14 +334,8 @@ export default class ContactCenter extends WebexPlugin implements IContactCenter switch (deviceType) { case LoginOption.BROWSER: await this.webCallingService.registerWebCallingLine(); - this.agentConfig.deviceType = LoginOption.BROWSER; break; - case LoginOption.AGENT_DN: - this.agentConfig.deviceType = LoginOption.AGENT_DN; - this.agentConfig.defaultDn = dn; - break; - case LoginOption.EXTENSION: - this.agentConfig.deviceType = LoginOption.EXTENSION; + case (LoginOption.AGENT_DN, LoginOption.EXTENSION): this.agentConfig.defaultDn = dn; break; default: @@ -351,5 +345,6 @@ export default class ContactCenter extends WebexPlugin implements IContactCenter }); throw new Error(`Unsupported device type: ${deviceType}`); } + this.agentConfig.deviceType = deviceType as LoginOption; } } From e66bcde0fd445e48e4b9411b64655d265f6833d8 Mon Sep 17 00:00:00 2001 From: adhmenon Date: Wed, 27 Nov 2024 11:18:52 +0530 Subject: [PATCH 4/5] feat(cc-sdk): resolved-comments --- packages/@webex/plugin-cc/src/cc.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/@webex/plugin-cc/src/cc.ts b/packages/@webex/plugin-cc/src/cc.ts index f391a2e89fe..9dd28ab4e9f 100644 --- a/packages/@webex/plugin-cc/src/cc.ts +++ b/packages/@webex/plugin-cc/src/cc.ts @@ -311,7 +311,7 @@ export default class ContactCenter extends WebexPlugin implements IContactCenter await this.setAgentState(stateChangeData); } - await this.handleDeviceType(deviceType, dn); + await this.handleDeviceType(deviceType as LoginOption, dn); this.agentConfig.isAgentLoggedIn = true; } catch (error) { const {reason, error: detailedError} = getErrorDetails(error, 'silentReLogin', CC_FILE); @@ -330,7 +330,7 @@ export default class ContactCenter extends WebexPlugin implements IContactCenter /** * Handles the device type specific logic */ - private async handleDeviceType(deviceType: string, dn: string): Promise { + private async handleDeviceType(deviceType: LoginOption, dn: string): Promise { switch (deviceType) { case LoginOption.BROWSER: await this.webCallingService.registerWebCallingLine(); @@ -345,6 +345,6 @@ export default class ContactCenter extends WebexPlugin implements IContactCenter }); throw new Error(`Unsupported device type: ${deviceType}`); } - this.agentConfig.deviceType = deviceType as LoginOption; + this.agentConfig.deviceType = deviceType; } } From 1ee6fcaafa22d48cc257bc5b4f3f4c46ee08789a Mon Sep 17 00:00:00 2001 From: adhmenon Date: Wed, 27 Nov 2024 11:46:20 +0530 Subject: [PATCH 5/5] feat(cc-sdk): added-extra-tests --- packages/@webex/plugin-cc/src/cc.ts | 3 +- .../@webex/plugin-cc/test/unit/spec/cc.ts | 29 ++++++++++++++++++- 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/packages/@webex/plugin-cc/src/cc.ts b/packages/@webex/plugin-cc/src/cc.ts index 9dd28ab4e9f..3923243eedb 100644 --- a/packages/@webex/plugin-cc/src/cc.ts +++ b/packages/@webex/plugin-cc/src/cc.ts @@ -335,7 +335,8 @@ export default class ContactCenter extends WebexPlugin implements IContactCenter case LoginOption.BROWSER: await this.webCallingService.registerWebCallingLine(); break; - case (LoginOption.AGENT_DN, LoginOption.EXTENSION): + case LoginOption.AGENT_DN: + case LoginOption.EXTENSION: this.agentConfig.defaultDn = dn; break; default: diff --git a/packages/@webex/plugin-cc/test/unit/spec/cc.ts b/packages/@webex/plugin-cc/test/unit/spec/cc.ts index 9a22360db6e..6ea42da00c9 100644 --- a/packages/@webex/plugin-cc/test/unit/spec/cc.ts +++ b/packages/@webex/plugin-cc/test/unit/spec/cc.ts @@ -727,7 +727,7 @@ describe('webex.cc', () => { await expect(webex.cc['silentRelogin']()).rejects.toThrow(error); }); - it('should update agentConfig with deviceType during silent relogin', async () => { + it('should update agentConfig with deviceType during silent relogin for EXTENSION', async () => { const mockReLoginResponse = { data: { auxCodeId: 'auxCodeId', @@ -752,5 +752,32 @@ describe('webex.cc', () => { expect(webex.cc.agentConfig.deviceType).toBe(LoginOption.EXTENSION); expect(webex.cc.agentConfig.defaultDn).toBe('12345'); }); + + it('should update agentConfig with deviceType during silent relogin for AGENT_DN', async () => { + const mockReLoginResponse = { + data: { + auxCodeId: 'auxCodeId', + agentId: 'agentId', + lastStateChangeReason: 'agent-wss-disconnect', + deviceType: LoginOption.AGENT_DN, + dn: '67890', + subStatus: 'subStatusValue', + }, + }; + + // Mock the agentConfig + webex.cc.agentConfig = { + agentId: 'agentId', + agentProfileID: 'test-agent-profile-id', + isAgentLoggedIn: false, + } as Profile; + + jest.spyOn(webex.cc.services.agent, 'reload').mockResolvedValue(mockReLoginResponse); + + await webex.cc['silentRelogin'](); + + expect(webex.cc.agentConfig.deviceType).toBe(LoginOption.AGENT_DN); + expect(webex.cc.agentConfig.defaultDn).toBe('67890'); + }); }); });