Skip to content

Commit

Permalink
Merge branch 'SPARK-562169-Task-API-Implementation' of https://github…
Browse files Browse the repository at this point in the history
….com/Kesari3008/webex-js-sdk into dev/adhmenon-SPARK-562170
  • Loading branch information
adhmenon committed Dec 6, 2024
2 parents daeb3e5 + 7988048 commit 441c992
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 16 deletions.
3 changes: 2 additions & 1 deletion docs/samples/contact-center/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -305,8 +305,9 @@ async function fetchBuddyAgents() {
}

incomingCallListener.addEventListener('task:incoming', (event) => {
taskId = event.detail.task.data.interactionId;
task = event.detail.task;
taskId = event.detail.task.data.interactionId;

const callerDisplay = event.detail.task.data.interaction.callAssociatedDetails.ani;
registerTaskListeners(task);

Expand Down
9 changes: 6 additions & 3 deletions packages/@webex/plugin-cc/src/cc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ export default class ContactCenter extends WebexPlugin implements IContactCenter
this.services.webSocketManager
);

this.incomingTaskListener();
LoggerProxy.initialize(this.$webex.logger);
});
}
Expand Down Expand Up @@ -187,9 +186,13 @@ export default class ContactCenter extends WebexPlugin implements IContactCenter
});

if (data.loginOption === LoginOption.BROWSER) {
await this.webCallingService.registerWebCallingLine(data.loginOption);
await this.webCallingService.registerWebCallingLine();
}

this.webCallingService.setLoginOption(data.loginOption);
this.incomingTaskListener();
this.taskManager.registerIncomingCallEvent();

await loginResponse;

return loginResponse;
Expand Down Expand Up @@ -359,7 +362,7 @@ export default class ContactCenter extends WebexPlugin implements IContactCenter
private async handleDeviceType(deviceType: LoginOption, dn: string): Promise<void> {
switch (deviceType) {
case LoginOption.BROWSER:
await this.webCallingService.registerWebCallingLine(deviceType);
await this.webCallingService.registerWebCallingLine();
break;
case LoginOption.AGENT_DN:
case LoginOption.EXTENSION:
Expand Down
7 changes: 5 additions & 2 deletions packages/@webex/plugin-cc/src/services/WebCallingService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ export default class WebCallingService extends EventEmitter {
this.callingClientConfig = callingClientConfig;
}

public setLoginOption(loginOption: LoginOption) {
this.loginOption = loginOption;
}

private handleMediaEvent = (track: MediaStreamTrack) => {
this.emit(CALL_EVENT_KEYS.REMOTE_MEDIA, track);
};
Expand All @@ -40,8 +44,7 @@ export default class WebCallingService extends EventEmitter {
this.call.off(CALL_EVENT_KEYS.REMOTE_MEDIA, this.handleMediaEvent);
}

public async registerWebCallingLine(loginOption: LoginOption): Promise<void> {
this.loginOption = loginOption;
public async registerWebCallingLine(): Promise<void> {
this.callingClient = await createClient(this.webex as any, this.callingClientConfig);
this.line = Object.values(this.callingClient.getLines())[0];

Expand Down
2 changes: 1 addition & 1 deletion packages/@webex/plugin-cc/src/services/task/TaskManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export default class TaskManager extends EventEmitter {
this.call = call;
};

private registerIncomingCallEvent() {
public registerIncomingCallEvent() {
this.webCallingService.on(LINE_EVENTS.INCOMING_CALL, this.handleIncomingWebCall);
}

Expand Down
20 changes: 11 additions & 9 deletions packages/@webex/plugin-cc/test/unit/spec/cc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,21 +132,12 @@ describe('webex.cc', () => {
});

it('should initialize services and logger proxy on READY event', () => {
const mockTask = {};
const onSpy = jest.spyOn(mockTaskManager, 'on');
const emitSpy = jest.spyOn(webex.cc.eventEmitter, 'emit');
const incomingCallCb = onSpy.mock.calls[0][1];
webex.once('READY', () => {
expect(Services.getInstance).toHaveBeenCalled();
expect(LoggerProxy.initialize).toHaveBeenCalledWith(webex.logger);
});

webex.emit('READY');
expect(onSpy).toHaveBeenCalledWith(TASK_EVENTS.TASK_INCOMING, incomingCallCb);

incomingCallCb(mockTask);

expect(emitSpy).toHaveBeenCalledWith(TASK_EVENTS.TASK_INCOMING, mockTask);
});

describe('cc.getDeviceId', () => {
Expand Down Expand Up @@ -365,6 +356,7 @@ describe('webex.cc', () => {

describe('stationLogin', () => {
it('should login successfully with LoginOption.BROWSER', async () => {
const mockTask = {};
const options = {
teamId: 'teamId',
loginOption: LoginOption.BROWSER,
Expand Down Expand Up @@ -401,6 +393,16 @@ describe('webex.cc', () => {
},
});
expect(result).toEqual({});

const onSpy = jest.spyOn(mockTaskManager, 'on');
const emitSpy = jest.spyOn(webex.cc.eventEmitter, 'emit');
const incomingCallCb = onSpy.mock.calls[0][1];

expect(onSpy).toHaveBeenCalledWith(TASK_EVENTS.TASK_INCOMING, incomingCallCb);

incomingCallCb(mockTask);

expect(emitSpy).toHaveBeenCalledWith(TASK_EVENTS.TASK_INCOMING, mockTask);
});

it('should login successfully with other LoginOption', async () => {
Expand Down

0 comments on commit 441c992

Please sign in to comment.