Skip to content

Commit

Permalink
feat(plugin-cc): review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
Kesari3008 committed Dec 2, 2024
1 parent e756062 commit cfe40f6
Show file tree
Hide file tree
Showing 19 changed files with 385 additions and 395 deletions.
33 changes: 15 additions & 18 deletions docs/samples/contact-center/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,23 +78,16 @@ function toggleDisplay(elementId, status) {
}
}

const taskControlEvents = new CustomEvent('task:incoming', {
const taskEvents = new CustomEvent('task:incoming', {
detail: {
task: task,
},
});

function registerListeners(taskControl) {
taskControl.on('task:incoming', (task) => {
task = task;
taskControlEvents.detail.task = task;

incomingCallListener.dispatchEvent(taskControlEvents);
})

taskControl.on('task:assigned', (task) => {
// TODO: Activate the call control buttons once the call is accepted and refctor this
function registerListeners(task) {
task.on('task:assigned', (task) => {
console.log('Call has been accepted');
// TODO: Activate the call control buttons once the call is accepted
})
}

Expand Down Expand Up @@ -188,8 +181,12 @@ function register() {
console.error('Event subscription failed', error);
})

taskControl = webex.cc.taskControl;
registerListeners(taskControl);
webex.cc.on('task:incoming', (task) => {
task = task;
taskEvents.detail.task = task;

incomingCallListener.dispatchEvent(taskEvents);
})
}

async function handleAgentLogin(e) {
Expand Down Expand Up @@ -278,10 +275,10 @@ async function fetchBuddyAgents() {
}

incomingCallListener.addEventListener('task:incoming', (event) => {
taskId = event.detail.task.interactionId;
const callerDisplay = event.detail.task.interaction.callAssociatedDetails.ani;
taskId = event.detail.task.data.interactionId;
const callerDisplay = event.detail.task.data.interaction.callAssociatedDetails.ani;

if (taskControl.webCallingService.loginOption === 'BROWSER') {
if (task.webCallingService.loginOption === 'BROWSER') {
answerElm.disabled = false;
declineElm.disabled = false;

Expand All @@ -294,14 +291,14 @@ incomingCallListener.addEventListener('task:incoming', (event) => {
function answer() {
answerElm.disabled = true;
declineElm.disabled = true;
webex.cc.taskControl.accept(taskId);
task.accept(taskId);
incomingDetailsElm.innerText = 'Call Accepted';
}

function decline() {
answerElm.disabled = true;
declineElm.disabled = true;
webex.cc.taskControl.decline(taskId);
task.decline(taskId);
incomingDetailsElm.innerText = 'No incoming calls';
}

Expand Down
28 changes: 21 additions & 7 deletions packages/@webex/plugin-cc/src/cc.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {WebexPlugin} from '@webex/webex-core';
import EventEmitter from 'events';
import {
SetStateResponse,
CCPluginConfig,
Expand All @@ -14,7 +15,6 @@ import {
SubscribeRequest,
} from './types';
import {READY, CC_FILE, EMPTY_STRING} from './constants';
import WebCallingService from './services/WebCallingService';
import {AGENT, WEB_RTC_PREFIX} from './services/constants';
import Services from './services';
import HttpRequest from './services/core/HttpRequest';
Expand All @@ -23,22 +23,26 @@ import {StateChange, Logout} from './services/agent/types';
import {getErrorDetails} from './services/core/Utils';
import {Profile, WelcomeEvent} from './services/config/types';
import {AGENT_STATE_AVAILABLE} from './services/config/constants';
import {ConnectionLostDetails} from './services/core/WebSocket/types';
import TaskControl from './services/TaskControl';
import {ConnectionLostDetails} from './services/core/websocket/types';
import TaskManager from './services/task/TaskManager';
import WebCallingService from './services/WebCallingService';
import {ITask, TASK_EVENTS} from './services/task/types';

export default class ContactCenter extends WebexPlugin implements IContactCenter {
namespace = 'cc';
private $config: CCPluginConfig;
private $webex: WebexSDK;
private eventEmitter: EventEmitter;
private agentConfig: Profile;
private webCallingService: WebCallingService;
private services: Services;
private httpRequest: HttpRequest;
private taskControl: TaskControl;
private taskManager: TaskManager;

constructor(...args) {
super(...args);

this.eventEmitter = new EventEmitter();
// @ts-ignore
this.$webex = this.webex;

Expand All @@ -59,16 +63,26 @@ export default class ContactCenter extends WebexPlugin implements IContactCenter
});

this.webCallingService = new WebCallingService(this.$webex, this.$config.callingClientConfig);
this.taskControl = new TaskControl(
this.taskManager = TaskManager.getTaskManager(
this.services.contact,
this.services.webSocketManager,
this.webCallingService
this.webCallingService,
this.services.webSocketManager
);

this.incomingTaskListener();
LoggerProxy.initialize(this.$webex.logger);
});
}

/**
* An Incoming Call listener.
*/
private incomingTaskListener() {
this.taskManager.on(TASK_EVENTS.TASK_INCOMING, (task: ITask) => {
this.eventEmitter.emit(TASK_EVENTS.TASK_INCOMING, task);
});
}

/**
* This is used for making the CC SDK ready by setting up the cc mercury connection.
*/
Expand Down
111 changes: 0 additions & 111 deletions packages/@webex/plugin-cc/src/services/TaskControl/index.ts

This file was deleted.

47 changes: 0 additions & 47 deletions packages/@webex/plugin-cc/src/services/WebSocket/config.ts

This file was deleted.

70 changes: 0 additions & 70 deletions packages/@webex/plugin-cc/src/services/WebSocket/index.ts

This file was deleted.

Loading

0 comments on commit cfe40f6

Please sign in to comment.