Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(cc-sdk): fixed-websocket-on-message-event-remove-logout #4044

Merged
merged 1 commit into from
Jan 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion packages/@webex/plugin-cc/src/cc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@ export default class ContactCenter extends WebexPlugin implements IContactCenter

await loginResponse;

this.services.webSocketManager.on('message', this.handleWebSocketMessage);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change will not affect any other functionality as it is only handling AGENT_STATE_CHANGE event. We were earlier listening to web socket events during register which would not have worked.
Checked that it works cleanly in the sample app.

Copy link
Contributor

@Kesari3008 Kesari3008 Jan 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where would we be switching off these listeners? Is that already taken care of somewhere?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's already being switched off on logout.

this.incomingTaskListener();
this.taskManager.registerIncomingCallEvent();

Expand Down Expand Up @@ -294,7 +295,6 @@ export default class ContactCenter extends WebexPlugin implements IContactCenter
*/
private setupEventListeners() {
this.services.connectionService.on('connectionLost', this.handleConnectionLost.bind(this));
this.services.webSocketManager.on('message', this.handleWebSocketMessage);
}

/**
Expand Down Expand Up @@ -355,6 +355,7 @@ export default class ContactCenter extends WebexPlugin implements IContactCenter

await this.handleDeviceType(deviceType as LoginOption, dn);
this.agentConfig.isAgentLoggedIn = true;
this.services.webSocketManager.on('message', this.handleWebSocketMessage);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need to add this for relogin as well (in those cases).

} catch (error) {
const {reason, error: detailedError} = getErrorDetails(error, 'silentReLogin', CC_FILE);
if (reason === 'AGENT_NOT_FOUND') {
Expand Down
38 changes: 15 additions & 23 deletions packages/@webex/plugin-cc/test/unit/spec/cc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -401,13 +401,28 @@ describe('webex.cc', () => {

const onSpy = jest.spyOn(mockTaskManager, 'on');
const emitSpy = jest.spyOn(webex.cc, 'trigger');
const ccEmitSpy = jest.spyOn(webex.cc, '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);
// Verify message event listener
const messageCallback = mockWebSocketManager.on.mock.calls.find(call => call[0] === 'message')[1];
const eventData = {
type: CC_EVENTS.AGENT_STATE_CHANGE,
data: { some: 'data' },
};

// Simulate receiving a message event
messageCallback(JSON.stringify(eventData));

expect(ccEmitSpy).toHaveBeenCalledWith(
AGENT_STATE_CHANGE,
eventData.data
);
});

it('should login successfully with other LoginOption', async () => {
Expand Down Expand Up @@ -854,29 +869,6 @@ describe('webex.cc', () => {
'connectionLost',
expect.any(Function)
);

expect(mockWebSocketManager.on).toHaveBeenCalledWith(
'message',
expect.any(Function)
);
});

it('should emit AGENT_STATE_CHANGE when message event is received', () => {
webex.cc.setupEventListeners();

const messageCallback = mockWebSocketManager.on.mock.calls[0][1];
const eventData = {
type: CC_EVENTS.AGENT_STATE_CHANGE,
data: { some: 'data' },
};

// Simulate receiving a message event
messageCallback(JSON.stringify(eventData));

expect(cCEmitSpy).toHaveBeenCalledWith(
AGENT_STATE_CHANGE,
eventData.data
);
});
});
});
Loading