diff --git a/docs/samples/contact-center/app.js b/docs/samples/contact-center/app.js
index b9a02172b19..552af592833 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) {
@@ -207,6 +208,7 @@ function logoutAgent() {
setTimeout(() => {
logoutAgentElm.classList.add('hidden');
+ agentLogin.selectedIndex = 0;
}, 1000);
}
).catch((error) => {
diff --git a/packages/@webex/plugin-cc/src/cc.ts b/packages/@webex/plugin-cc/src/cc.ts
index 6479d6b9339..3923243eedb 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 as LoginOption, dn);
this.agentConfig.isAgentLoggedIn = true;
} catch (error) {
const {reason, error: detailedError} = getErrorDetails(error, 'silentReLogin', CC_FILE);
@@ -325,4 +326,26 @@ export default class ContactCenter extends WebexPlugin implements IContactCenter
throw detailedError;
}
}
+
+ /**
+ * Handles the device type specific logic
+ */
+ private async handleDeviceType(deviceType: LoginOption, dn: string): Promise {
+ switch (deviceType) {
+ case LoginOption.BROWSER:
+ await this.webCallingService.registerWebCallingLine();
+ break;
+ case LoginOption.AGENT_DN:
+ case 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}`);
+ }
+ 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 500e3917d14..6ea42da00c9 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,65 @@ 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 for EXTENSION', 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');
+ });
+
+ 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');
+ });
});
});