From b70f7bdc9bbf586dde3c61b1e683d5dc8e7afbfa Mon Sep 17 00:00:00 2001 From: rsarika <95286093+rsarika@users.noreply.github.com> Date: Wed, 13 Nov 2024 08:03:05 +0530 Subject: [PATCH] feat(cc): copy Agent req from agentx Desktop (#3955) Co-authored-by: Priya Co-authored-by: parv_gour Co-authored-by: pagour98 Co-authored-by: arungane Co-authored-by: Bharath Balan <62698609+bhabalan@users.noreply.github.com> Co-authored-by: Adhwaith Menon <111346225+adhmenon@users.noreply.github.com> Co-authored-by: adhmenon --- docs/samples/contact-center/app.js | 137 ++- docs/samples/contact-center/index.html | 59 +- docs/samples/contact-center/style.css | 894 +++++++++--------- .../@webex/plugin-cc/__mocks__/workerMock.js | 15 + packages/@webex/plugin-cc/package.json | 4 +- .../@webex/plugin-cc/src/AgentConfig/types.ts | 87 -- .../plugin-cc/src/AgentConfigService/types.ts | 140 --- packages/@webex/plugin-cc/src/HttpRequest.ts | 50 - .../plugin-cc/src/WebSocket/WebSocket.ts | 139 --- packages/@webex/plugin-cc/src/cc.ts | 275 ++++-- packages/@webex/plugin-cc/src/config.ts | 12 + packages/@webex/plugin-cc/src/constants.ts | 6 +- .../Agentconfig.ts} | 23 +- .../{AgentConfig => features}/constants.ts | 0 .../@webex/plugin-cc/src/features/types.ts | 35 + packages/@webex/plugin-cc/src/logger-proxy.ts | 9 + .../src/services/WebCallingService.ts | 63 ++ .../src/{ => services}/WebSocket/config.ts | 0 .../plugin-cc/src/services/WebSocket/index.ts | 70 ++ .../src/{ => services}/WebSocket/types.ts | 17 +- .../plugin-cc/src/services/agent/index.ts | 125 +++ .../plugin-cc/src/services/agent/types.ts | 147 +++ .../config/index.ts} | 49 +- .../plugin-cc/src/services/config/types.ts | 127 +++ .../plugin-cc/src/services/constants.ts | 9 + .../@webex/plugin-cc/src/services/core/Err.ts | 97 ++ .../src/services/core/GlobalTypes.ts | 14 + .../src/services/core/HttpRequest.ts | 37 + .../plugin-cc/src/services/core/Utils.ts | 24 + .../core/WebSocket/WebSocketManager.ts | 170 ++++ .../core/WebSocket/connection-service.ts | 144 +++ .../core/WebSocket/keepalive.worker.js | 88 ++ .../plugin-cc/src/services/core/aqm-reqs.ts | 248 +++++ .../plugin-cc/src/services/core/constants.ts | 11 + .../plugin-cc/src/services/core/types.ts | 48 + .../@webex/plugin-cc/src/services/index.ts | 21 + packages/@webex/plugin-cc/src/types.ts | 233 ++++- .../test/unit/spec/AgentConfig/AgentConfig.ts | 344 ------- .../AgentConfigService/AgentConfigService.ts | 211 ----- .../plugin-cc/test/unit/spec/HttpRequest.ts | 63 -- .../plugin-cc/test/unit/spec/WebSocket.ts | 195 ---- .../@webex/plugin-cc/test/unit/spec/cc.ts | 649 +++++++------ .../test/unit/spec/features/AgentConfig.ts | 463 +++++++++ .../unit/spec/services/WebCallingService.ts | 147 +++ .../test/unit/spec/services/agent/index.ts | 60 ++ .../test/unit/spec/services/config/index.ts | 252 +++++ .../unit/spec/services/core/HttpRequest.ts | 67 ++ .../core/WebSocket/WebSocketManager.ts | 372 ++++++++ .../core/WebSocket/connection-service.ts | 164 ++++ .../test/unit/spec/services/core/aqm-reqs.ts | 569 +++++++++++ packages/calling/src/index.ts | 1 + packages/webex/test/unit/spec/webex.js | 12 + 52 files changed, 5024 insertions(+), 2172 deletions(-) create mode 100644 packages/@webex/plugin-cc/__mocks__/workerMock.js delete mode 100644 packages/@webex/plugin-cc/src/AgentConfig/types.ts delete mode 100644 packages/@webex/plugin-cc/src/AgentConfigService/types.ts delete mode 100644 packages/@webex/plugin-cc/src/HttpRequest.ts delete mode 100644 packages/@webex/plugin-cc/src/WebSocket/WebSocket.ts rename packages/@webex/plugin-cc/src/{AgentConfig/AgentConfig.ts => features/Agentconfig.ts} (86%) rename packages/@webex/plugin-cc/src/{AgentConfig => features}/constants.ts (100%) create mode 100644 packages/@webex/plugin-cc/src/features/types.ts create mode 100644 packages/@webex/plugin-cc/src/logger-proxy.ts create mode 100644 packages/@webex/plugin-cc/src/services/WebCallingService.ts rename packages/@webex/plugin-cc/src/{ => services}/WebSocket/config.ts (100%) create mode 100644 packages/@webex/plugin-cc/src/services/WebSocket/index.ts rename packages/@webex/plugin-cc/src/{ => services}/WebSocket/types.ts (65%) create mode 100644 packages/@webex/plugin-cc/src/services/agent/index.ts create mode 100644 packages/@webex/plugin-cc/src/services/agent/types.ts rename packages/@webex/plugin-cc/src/{AgentConfigService/AgentConfigService.ts => services/config/index.ts} (73%) create mode 100644 packages/@webex/plugin-cc/src/services/config/types.ts create mode 100644 packages/@webex/plugin-cc/src/services/constants.ts create mode 100644 packages/@webex/plugin-cc/src/services/core/Err.ts create mode 100644 packages/@webex/plugin-cc/src/services/core/GlobalTypes.ts create mode 100644 packages/@webex/plugin-cc/src/services/core/HttpRequest.ts create mode 100644 packages/@webex/plugin-cc/src/services/core/Utils.ts create mode 100644 packages/@webex/plugin-cc/src/services/core/WebSocket/WebSocketManager.ts create mode 100644 packages/@webex/plugin-cc/src/services/core/WebSocket/connection-service.ts create mode 100644 packages/@webex/plugin-cc/src/services/core/WebSocket/keepalive.worker.js create mode 100644 packages/@webex/plugin-cc/src/services/core/aqm-reqs.ts create mode 100644 packages/@webex/plugin-cc/src/services/core/constants.ts create mode 100644 packages/@webex/plugin-cc/src/services/core/types.ts create mode 100644 packages/@webex/plugin-cc/src/services/index.ts delete mode 100644 packages/@webex/plugin-cc/test/unit/spec/AgentConfig/AgentConfig.ts delete mode 100644 packages/@webex/plugin-cc/test/unit/spec/AgentConfigService/AgentConfigService.ts delete mode 100644 packages/@webex/plugin-cc/test/unit/spec/HttpRequest.ts delete mode 100644 packages/@webex/plugin-cc/test/unit/spec/WebSocket.ts create mode 100644 packages/@webex/plugin-cc/test/unit/spec/features/AgentConfig.ts create mode 100644 packages/@webex/plugin-cc/test/unit/spec/services/WebCallingService.ts create mode 100644 packages/@webex/plugin-cc/test/unit/spec/services/agent/index.ts create mode 100644 packages/@webex/plugin-cc/test/unit/spec/services/config/index.ts create mode 100644 packages/@webex/plugin-cc/test/unit/spec/services/core/HttpRequest.ts create mode 100644 packages/@webex/plugin-cc/test/unit/spec/services/core/WebSocket/WebSocketManager.ts create mode 100644 packages/@webex/plugin-cc/test/unit/spec/services/core/WebSocket/connection-service.ts create mode 100644 packages/@webex/plugin-cc/test/unit/spec/services/core/aqm-reqs.ts diff --git a/docs/samples/contact-center/app.js b/docs/samples/contact-center/app.js index ce36776bd36..4144f3ac6f2 100644 --- a/docs/samples/contact-center/app.js +++ b/docs/samples/contact-center/app.js @@ -22,19 +22,25 @@ const tokenElm = document.querySelector('#access-token'); const saveElm = document.querySelector('#access-token-save'); const authStatusElm = document.querySelector('#access-token-status'); const registerBtn = document.querySelector('#webexcc-register'); - - -// Store and Grab `access-token` from localstorage -if (localStorage.getItem('date') > new Date().getTime()) { - tokenElm.value = localStorage.getItem('access-token'); +const teamsDropdown = document.querySelector('#teamsDropdown'); +const agentLogin = document.querySelector('#AgentLogin'); +const agentLoginButton = document.querySelector('#loginAgent'); +const dialNumber = document.querySelector('#dialNumber'); +const registerStatus = document.querySelector('#ws-connection-status'); +const logoutAgentElm = document.querySelector('#logoutAgent'); +const buddyAgentsDropdownElm = document.getElementById('buddyAgentsDropdown'); + +// Store and Grab `access-token` from sessionStorage +if (sessionStorage.getItem('date') > new Date().getTime()) { + tokenElm.value = sessionStorage.getItem('access-token'); } else { - localStorage.removeItem('access-token'); + sessionStorage.removeItem('access-token'); } tokenElm.addEventListener('change', (event) => { - localStorage.setItem('access-token', event.target.value); - localStorage.setItem('date', new Date().getTime() + (12 * 60 * 60 * 1000)); + sessionStorage.setItem('access-token', event.target.value); + sessionStorage.setItem('date', new Date().getTime() + (12 * 60 * 60 * 1000)); }); function changeAuthType() { @@ -94,7 +100,7 @@ function initWebex(e) { console.log('Authentication#initWebex() :: Webex Ready'); authStatusElm.innerText = 'Saved access token!'; - + registerStatus.innerHTML = 'Not Subscribed'; registerBtn.disabled = false; }); @@ -103,14 +109,115 @@ function initWebex(e) { credentialsFormElm.addEventListener('submit', initWebex); + function register() { - webex.cc.register().then((data) => { - console.log('Event subscription successful: ', data); - }).catch(() => { - console.log('Event subscription failed'); + webex.cc.register(true).then((agentProfile) => { + registerStatus.innerHTML = 'Subscribed'; + console.log('Event subscription successful: ', agentProfile); + teamsDropdown.innerHTML = ''; // Clear previously selected option on teamsDropdown + const listTeams = agentProfile.teams; + listTeams.forEach((team) => { + const option = document.createElement('option'); + option.value = team.id; + option.text = team.name; + teamsDropdown.add(option); + }); + const loginVoiceOptions = agentProfile.loginVoiceOptions; + agentLogin.innerHTML = ''; // Clear previously selected option on agentLogin. + dialNumber.value = ''; + dialNumber.disabled = 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); + }); + }).catch((error) => { + console.log('Event subscription failed', error); }) } +async function handleAgentLogin(e) { + const value = e.target.value; + agentDeviceType = value + if (value === 'AGENT_DN') { + dialNumber.disabled = false; + } else if (value === 'EXTENSION') { + dialNumber.disabled = false; + } else { + dialNumber.disabled = true; + } +} + +function doAgentLogin() { + webex.cc.stationLogin({teamId: teamsDropdown.value, loginOption: agentDeviceType, dialNumber: dialNumber.value}).then((response) => { + console.log('Agent Logged in successfully', response); + logoutAgentElm.classList.remove('hidden'); + // Re-Login Agent after 15 seconds for testing purpose + setTimeout(async () => { + try { + const response = await webex.cc.stationReLogin(); + + console.log('Agent Re-Login successful', response); + } catch (error) { + console.log('Agent Re-Login failed', error); + } + }, 15000); + } + ).catch((error) => { + if (error.message === 'AGENT_SESSION_ALREADY_EXISTS') { + logoutAgentElm.classList.remove('hidden'); + } + console.log('Agent Login failed', error); + }); +} + + +function logoutAgent() { + webex.cc.stationLogout({logoutReason: 'logout'}).then((response) => { + console.log('Agent logged out successfully', response); + + setTimeout(() => { + logoutAgentElm.classList.add('hidden'); + }, 1000); + } + ).catch((error) => { + console.log('Agent logout failed', error); + }); +} + +async function fetchBuddyAgents() { + try { + buddyAgentsDropdownElm.innerHTML = ''; // Clear previous options + const buddyAgentsResponse = await webex.cc.getBuddyAgents({mediaType: 'telephony'}); + + if (!buddyAgentsResponse || !buddyAgentsResponse.data) { + console.error('Failed to fetch buddy agents'); + buddyAgentsDropdownElm.innerHTML = `