Skip to content

Commit 2a9f66c

Browse files
fix(mobius): mobius cluster should be inferred from serviceUrl in hostCatalog (webex#3858)
Co-authored-by: Shreyas Sharma <[email protected]>
1 parent bf7c1ba commit 2a9f66c

File tree

2 files changed

+47
-2
lines changed

2 files changed

+47
-2
lines changed

packages/calling/src/CallingClient/CallingClient.test.ts

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ import {
4141
mockCatalogUSInt,
4242
mockCatalogUS,
4343
mockCatalogEUInt,
44+
mockUSServiceHosts,
4445
} from './callingClientFixtures';
4546
import Line from './line';
4647
import {filterMobiusUris} from '../common/Utils';
@@ -67,6 +68,40 @@ describe('CallingClient Tests', () => {
6768
});
6869
}
6970

71+
describe('CallingClient pick Mobius cluster using Service Host Tests', () => {
72+
afterAll(() => {
73+
callManager.removeAllListeners();
74+
webex.internal.services['_serviceUrls']['mobius'] =
75+
'https://mobius.aintgen-a-1.int.infra.webex.com/api/v1';
76+
webex.internal.services['_hostCatalog'] = mockCatalogUS;
77+
});
78+
79+
it('should set mobiusServiceHost correctly when URL is valid', async () => {
80+
webex.internal.services._hostCatalog = mockCatalogEU;
81+
webex.internal.services['_serviceUrls']['mobius'] =
82+
'https://mobius-eu-central-1.prod.infra.webex.com/api/v1';
83+
const urlSpy = jest.spyOn(window, 'URL').mockImplementation((url) => new window.URL(url));
84+
const callingClient = await createClient(webex, {logger: {level: LOGGER.INFO}});
85+
86+
expect(urlSpy).toHaveBeenCalledWith(
87+
'https://mobius-eu-central-1.prod.infra.webex.com/api/v1'
88+
);
89+
90+
expect(callingClient['mobiusClusters']).toStrictEqual(mockEUServiceHosts);
91+
92+
urlSpy.mockRestore();
93+
});
94+
95+
it('should use default mobius service host when Service URL is invalid', async () => {
96+
webex.internal.services._hostCatalog = mockCatalogUS;
97+
webex.internal.services._serviceUrls.mobius = 'invalid-url';
98+
99+
const callingClient = await createClient(webex, {logger: {level: LOGGER.INFO}});
100+
101+
expect(callingClient['mobiusClusters']).toStrictEqual(mockUSServiceHosts);
102+
});
103+
});
104+
70105
describe('ServiceData tests', () => {
71106
let callingClient: ICallingClient | undefined;
72107

packages/calling/src/CallingClient/CallingClient.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ export class CallingClient extends Eventing<CallingClientEventTypes> implements
106106
: {indicator: ServiceIndicator.CALLING, domain: ''};
107107

108108
const logLevel = this.sdkConfig?.logger?.level ? this.sdkConfig.logger.level : LOGGER.ERROR;
109+
log.setLogger(logLevel, CALLING_CLIENT_FILE);
109110
validateServiceData(serviceData);
110111

111112
this.callManager = getCallManager(this.webex, serviceData.indicator);
@@ -115,7 +116,18 @@ export class CallingClient extends Eventing<CallingClientEventTypes> implements
115116

116117
this.primaryMobiusUris = [];
117118
this.backupMobiusUris = [];
119+
let mobiusServiceHost = '';
120+
try {
121+
mobiusServiceHost = new URL(this.webex.internal.services._serviceUrls.mobius).host;
122+
} catch (error) {
123+
log.warn(`Failed to parse mobius service URL`, {
124+
file: CALLING_CLIENT_FILE,
125+
method: this.constructor.name,
126+
});
127+
}
128+
118129
this.mobiusClusters =
130+
(mobiusServiceHost && this.webex.internal.services._hostCatalog[mobiusServiceHost]) ||
119131
this.webex.internal.services._hostCatalog[MOBIUS_US_PROD] ||
120132
this.webex.internal.services._hostCatalog[MOBIUS_EU_PROD] ||
121133
this.webex.internal.services._hostCatalog[MOBIUS_US_INT] ||
@@ -124,8 +136,6 @@ export class CallingClient extends Eventing<CallingClientEventTypes> implements
124136

125137
this.registerSessionsListener();
126138

127-
log.setLogger(logLevel, CALLING_CLIENT_FILE);
128-
129139
this.registerCallsClearedListener();
130140
}
131141

0 commit comments

Comments
 (0)