Skip to content

Commit

Permalink
fix(mobius): mobius cluster should be inferred from serviceUrl in hos…
Browse files Browse the repository at this point in the history
…tCatalog (webex#3858)

Co-authored-by: Shreyas Sharma <[email protected]>
  • Loading branch information
bhabalan and Shreyas281299 authored Oct 1, 2024
1 parent bf7c1ba commit 2a9f66c
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 2 deletions.
35 changes: 35 additions & 0 deletions packages/calling/src/CallingClient/CallingClient.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import {
mockCatalogUSInt,
mockCatalogUS,
mockCatalogEUInt,
mockUSServiceHosts,
} from './callingClientFixtures';
import Line from './line';
import {filterMobiusUris} from '../common/Utils';
Expand All @@ -67,6 +68,40 @@ describe('CallingClient Tests', () => {
});
}

describe('CallingClient pick Mobius cluster using Service Host Tests', () => {
afterAll(() => {
callManager.removeAllListeners();
webex.internal.services['_serviceUrls']['mobius'] =
'https://mobius.aintgen-a-1.int.infra.webex.com/api/v1';
webex.internal.services['_hostCatalog'] = mockCatalogUS;
});

it('should set mobiusServiceHost correctly when URL is valid', async () => {
webex.internal.services._hostCatalog = mockCatalogEU;
webex.internal.services['_serviceUrls']['mobius'] =
'https://mobius-eu-central-1.prod.infra.webex.com/api/v1';
const urlSpy = jest.spyOn(window, 'URL').mockImplementation((url) => new window.URL(url));
const callingClient = await createClient(webex, {logger: {level: LOGGER.INFO}});

expect(urlSpy).toHaveBeenCalledWith(
'https://mobius-eu-central-1.prod.infra.webex.com/api/v1'
);

expect(callingClient['mobiusClusters']).toStrictEqual(mockEUServiceHosts);

urlSpy.mockRestore();
});

it('should use default mobius service host when Service URL is invalid', async () => {
webex.internal.services._hostCatalog = mockCatalogUS;
webex.internal.services._serviceUrls.mobius = 'invalid-url';

const callingClient = await createClient(webex, {logger: {level: LOGGER.INFO}});

expect(callingClient['mobiusClusters']).toStrictEqual(mockUSServiceHosts);
});
});

describe('ServiceData tests', () => {
let callingClient: ICallingClient | undefined;

Expand Down
14 changes: 12 additions & 2 deletions packages/calling/src/CallingClient/CallingClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ export class CallingClient extends Eventing<CallingClientEventTypes> implements
: {indicator: ServiceIndicator.CALLING, domain: ''};

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

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

this.primaryMobiusUris = [];
this.backupMobiusUris = [];
let mobiusServiceHost = '';
try {
mobiusServiceHost = new URL(this.webex.internal.services._serviceUrls.mobius).host;
} catch (error) {
log.warn(`Failed to parse mobius service URL`, {
file: CALLING_CLIENT_FILE,
method: this.constructor.name,
});
}

this.mobiusClusters =
(mobiusServiceHost && this.webex.internal.services._hostCatalog[mobiusServiceHost]) ||
this.webex.internal.services._hostCatalog[MOBIUS_US_PROD] ||
this.webex.internal.services._hostCatalog[MOBIUS_EU_PROD] ||
this.webex.internal.services._hostCatalog[MOBIUS_US_INT] ||
Expand All @@ -124,8 +136,6 @@ export class CallingClient extends Eventing<CallingClientEventTypes> implements

this.registerSessionsListener();

log.setLogger(logLevel, CALLING_CLIENT_FILE);

this.registerCallsClearedListener();
}

Expand Down

0 comments on commit 2a9f66c

Please sign in to comment.