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

Spark 586376 add calling rtms to u2c #4053

Open
wants to merge 2 commits into
base: wxcc
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion packages/@webex/plugin-cc/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export default {
},
serviceData: {
indicator: 'contactcenter',
// TODO: This should be dynamic based on the environment
// This is now being read dynamically based on the environment in WebCallingService registerWebCallingLine method
domain: 'rtw.prod-us1.rtmsprod.net',
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Remove hardcoded production domain.

While the comment indicates this is being read dynamically, the hardcoded production domain should be removed to prevent accidental use.

-        domain: 'rtw.prod-us1.rtmsprod.net',
+        domain: '', // Set dynamically in WebCallingService
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
domain: 'rtw.prod-us1.rtmsprod.net',
domain: '', // Set dynamically in WebCallingService

},
},
Expand Down
7 changes: 7 additions & 0 deletions packages/@webex/plugin-cc/src/services/WebCallingService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,13 @@ export default class WebCallingService extends EventEmitter {
}

public async registerWebCallingLine(): Promise<void> {
/** overriding RTMS URL with u2c catalogue wcc-calling-rtms service */
await this.webex.internal.services.waitForCatalog('postauth');
const rtmsURL = this.webex.internal.services.get('wcc-calling-rtms-domain');
if (rtmsURL) {
this.callingClientConfig.serviceData.domain = rtmsURL;
}

this.callingClient = await createClient(this.webex as any, this.callingClientConfig);
this.line = Object.values(this.callingClient.getLines())[0];

Expand Down
2 changes: 2 additions & 0 deletions packages/@webex/plugin-cc/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,8 @@ export interface WebexSDK {
};
presence: unknown;
services: {
get: (service: string) => string;
waitForCatalog: (service: string) => Promise<void>;
_hostCatalog: Record<string, ServiceHost[]>;
_serviceUrls: {
mobius: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,13 @@ describe('WebCallingService', () => {
logger: {
log: jest.fn(),
error: jest.fn(),
info: jest.fn()
info: jest.fn(),
},
internal: {
services: {
waitForCatalog: jest.fn().mockResolvedValue(undefined),
get: jest.fn().mockReturnValue('rtw.prod-us1.rtmsprod.net'),
},
},
} as unknown as WebexSDK;

Expand All @@ -63,7 +69,7 @@ describe('WebCallingService', () => {
answer: jest.fn(),
mute: jest.fn(),
isMuted: jest.fn().mockReturnValue(true),
end: jest.fn()
end: jest.fn(),
};

webRTCCalling.call = mockCall;
Expand Down Expand Up @@ -101,7 +107,39 @@ describe('WebCallingService', () => {
expect(line.register).toHaveBeenCalled();
expect(LoggerProxy.log).toHaveBeenCalledWith(
`WxCC-SDK: Desktop registered successfully, mobiusDeviceId: ${deviceInfo.mobiusDeviceId}`,
{"method": "registerWebCallingLine", "module": WEB_CALLING_SERVICE_FILE}
{method: 'registerWebCallingLine', module: WEB_CALLING_SERVICE_FILE}
);
}, 20000); // Increased timeout to 20 seconds

it('should register WebCallingLine with custom rtms url', async () => {
webex.internal.services.get = jest.fn().mockReturnValue('rtw.prod-us2.rtmsprod.net');

line = callingClient.getLines().line1 as ILine;
const deviceInfo = {
mobiusDeviceId: 'device123',
status: 'registered',
setError: jest.fn(),
getError: jest.fn(),
type: 'line',
id: 'line1',
};

const registeredHandler = jest.fn();
const lineOnSpy = jest.spyOn(line, 'on').mockImplementation((event, handler) => {
if (event === LINE_EVENTS.REGISTERED) {
registeredHandler.mockImplementation(handler);
handler(deviceInfo);
}
});
expect(config.cc.callingClientConfig.serviceData.domain).toBe('rtw.prod-us1.rtmsprod.net');
await expect(webRTCCalling.registerWebCallingLine()).resolves.toBeUndefined();
expect(config.cc.callingClientConfig.serviceData.domain).toBe('rtw.prod-us2.rtmsprod.net');
expect(createClient).toHaveBeenCalledWith(webex, config.cc.callingClientConfig);
expect(lineOnSpy).toHaveBeenCalledWith(LINE_EVENTS.REGISTERED, expect.any(Function));
expect(line.register).toHaveBeenCalled();
expect(LoggerProxy.log).toHaveBeenCalledWith(
`WxCC-SDK: Desktop registered successfully, mobiusDeviceId: ${deviceInfo.mobiusDeviceId}`,
{method: 'registerWebCallingLine', module: WEB_CALLING_SERVICE_FILE}
);
}, 20000); // Increased timeout to 20 seconds

Expand Down Expand Up @@ -169,7 +207,7 @@ describe('WebCallingService', () => {
const mockStream = {
outputStream: {
getAudioTracks: jest.fn().mockReturnValue(['']),
}
},
};

const localAudioStream = mockStream as unknown as LocalMicrophoneStream;
Expand All @@ -183,10 +221,14 @@ describe('WebCallingService', () => {

it('should log error and throw when call.answer fails', () => {
const error = new Error('Failed to answer');
mockCall.answer.mockImplementation(() => { throw error; });
mockCall.answer.mockImplementation(() => {
throw error;
});

expect(() => webRTCCalling.answerCall(localAudioStream, 'task-id')).toThrow(error);
expect(webex.logger.error).toHaveBeenCalledWith(`Failed to answer call for task-id. Error: ${error}`);
expect(webex.logger.error).toHaveBeenCalledWith(
`Failed to answer call for task-id. Error: ${error}`
);
});

it('should log when there is no call to answer', () => {
Expand All @@ -201,7 +243,7 @@ describe('WebCallingService', () => {
const mockStream = {
outputStream: {
getAudioTracks: jest.fn().mockReturnValue(['']),
}
},
};

const localAudioStream = mockStream as unknown as LocalMicrophoneStream;
Expand Down Expand Up @@ -231,10 +273,14 @@ describe('WebCallingService', () => {

it('should log error and throw when call.end fails', () => {
const error = new Error('Failed to end call');
mockCall.end.mockImplementation(() => { throw error; });
mockCall.end.mockImplementation(() => {
throw error;
});

expect(() => webRTCCalling.declineCall('task-id')).toThrow(error);
expect(webex.logger.error).toHaveBeenCalledWith(`Failed to end call: task-id. Error: ${error}`);
expect(webex.logger.error).toHaveBeenCalledWith(
`Failed to end call: task-id. Error: ${error}`
);
});

it('should log when there is no call to end', () => {
Expand Down
Loading