Skip to content

Commit

Permalink
fix: reading RTMS URL dynamically based on region info in catalogue
Browse files Browse the repository at this point in the history
  • Loading branch information
rsarika committed Jan 22, 2025
1 parent d029d4f commit 241b5c2
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 10 deletions.
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',
},
},
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');
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

0 comments on commit 241b5c2

Please sign in to comment.