Skip to content
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
46 changes: 24 additions & 22 deletions packages/calling/src/SDKConnector/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,29 @@ export type Model = {
};
};

export type WDMDevice = {
url: string;
userId: string;
orgId: string;
version: string;
callingBehavior: string;
registered?: boolean;
webSocketUrl?: string;
register?: () => Promise<unknown>;
refresh?: () => Promise<unknown>;
/** WDM / device-registration settings (e.g. `webrtc-calling-over-ws`). */
settings?: Record<string, {value?: boolean} | undefined>;
features: {
developer: {
models: Model[];
get: (key: string) => {value: boolean} | undefined;
};
entitlement: {
models: Model[];
};
};
};

export type ServiceCatalog = {
serviceGroups: {
// cSpell:disable
Expand Down Expand Up @@ -99,28 +122,7 @@ export interface WebexSDK {
updateFeature?: (featureToggle: unknown) => void;
};
calendar: unknown;
device: {
url: string;
userId: string;
orgId: string;
version: string;
callingBehavior: string;
registered?: boolean;
webSocketUrl?: string;
register?: () => Promise<unknown>;
refresh?: () => Promise<unknown>;
/** WDM / device-registration settings (e.g. `webrtc-calling-over-ws`). */
settings?: Record<string, {value?: boolean} | undefined>;
features: {
developer: {
models: Model[];
get: (key: string) => {value: boolean} | undefined;
};
entitlement: {
models: Model[];
};
};
};
device: WDMDevice;
encryption: {
decryptText: (encryptionKeyUrl: string, encryptedData?: string) => Promise<string>;
encryptText: (encryptionKeyUrl: string, text?: string) => Promise<string>;
Expand Down
87 changes: 87 additions & 0 deletions packages/calling/src/common/Utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ import {
modifySdpForIPv4,
uploadLogs,
handleCallingClientErrors,
resolveCallingBackend,
getCallingBackEnd,
} from './Utils';
import {
getVoicemailListJsonWXC,
Expand Down Expand Up @@ -2081,3 +2083,88 @@ describe('uploadLogs', () => {
);
});
});

describe('resolveCallingBackend', () => {
const createDevice = (callingBehavior: string, entitlementKeys: string[]) => ({
url: 'https://wdm.example.com/devices/123',
userId: 'user-id',
orgId: 'org-id',
version: '1.0',
callingBehavior,
features: {
developer: {models: [], get: jest.fn()},
entitlement: {
models: entitlementKeys.map((key) => ({_values: {key}})),
},
},
});

it.each([
['bc-sp-basic', CALLING_BACKEND.WXC],
['bc-sp-standard', CALLING_BACKEND.WXC],
])(
'returns WXC when callingBehavior is NATIVE_WEBEX_TEAMS_CALLING and entitlement is %s',
(entitlement, expected) => {
const device = createDevice('NATIVE_WEBEX_TEAMS_CALLING', [entitlement]);

expect(resolveCallingBackend(device)).toBe(expected);
}
);

it('returns BWRKS when callingBehavior is NATIVE_WEBEX_TEAMS_CALLING and entitlement is broadworks-connector', () => {
const device = createDevice('NATIVE_WEBEX_TEAMS_CALLING', ['broadworks-connector']);

expect(resolveCallingBackend(device)).toBe(CALLING_BACKEND.BWRKS);
});

it('returns UCM when callingBehavior is NATIVE_SIP_CALL_TO_UCM', () => {
const device = createDevice('NATIVE_SIP_CALL_TO_UCM', []);

expect(resolveCallingBackend(device)).toBe(CALLING_BACKEND.UCM);
});

it('returns INVALID when callingBehavior is unknown', () => {
const device = createDevice('UNKNOWN_BEHAVIOR', []);

expect(resolveCallingBackend(device)).toBe(CALLING_BACKEND.INVALID);
});

it('returns INVALID when callingBehavior is NATIVE_WEBEX_TEAMS_CALLING but no matching entitlement', () => {
const device = createDevice('NATIVE_WEBEX_TEAMS_CALLING', ['some-other-entitlement']);

expect(resolveCallingBackend(device)).toBe(CALLING_BACKEND.INVALID);
});

it('matches the first qualifying entitlement when multiple are present', () => {
const device = createDevice('NATIVE_WEBEX_TEAMS_CALLING', [
'broadworks-connector',
'bc-sp-basic',
]);

expect(resolveCallingBackend(device)).toBe(CALLING_BACKEND.BWRKS);
});
});

describe('getCallingBackEnd', () => {
it('passes webex.internal.device to resolveCallingBackend and returns its result', () => {
const device = {
url: 'https://wdm.example.com/devices/123',
userId: 'user-id',
orgId: 'org-id',
version: '1.0',
callingBehavior: 'NATIVE_SIP_CALL_TO_UCM',
features: {
developer: {models: [], get: jest.fn()},
entitlement: {models: []},
},
};

const mockWebex = {internal: {device}} as any;

const result = getCallingBackEnd(mockWebex);

expect(result).toBe(resolveCallingBackend(device));
expect(resolveCallingBackend(device)).toBe(CALLING_BACKEND.UCM);
expect(result).toBe(CALLING_BACKEND.UCM);
});
});
26 changes: 18 additions & 8 deletions packages/calling/src/common/Utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ import {
WEBEX_API_BTS,
BW_XSI_ENDPOINT_VERSION_WITH_SLASH,
} from './constants';
import {Model, WebexSDK} from '../SDKConnector/types';
import {Model, WDMDevice, WebexSDK} from '../SDKConnector/types';
import SDKConnector from '../SDKConnector';
import {CallSettingResponse} from '../CallSettings/types';
import {ContactResponse} from '../Contacts/types';
Expand Down Expand Up @@ -1216,16 +1216,16 @@ export const waitForMsecs = (msec: number) =>
});

/**
* Register calling backend.
* Determine the calling backend from the device object.
*
* @param webex -.
* @param device - The device object containing callingBehavior and entitlement features.
* @returns CallingBackEnd.
*/
export function getCallingBackEnd(webex: WebexSDK): CALLING_BACKEND {
const entModels: Model[] = webex.internal.device.features.entitlement.models;
export function resolveCallingBackend(device: WDMDevice): CALLING_BACKEND {
Comment thread
lismith2-cisco marked this conversation as resolved.
const entModels: Model[] = device.features.entitlement.models;
let callingBackend;

if (webex.internal.device.callingBehavior === NATIVE_WEBEX_TEAMS_CALLING) {
if (device.callingBehavior === NATIVE_WEBEX_TEAMS_CALLING) {
for (let i = 0; i < entModels.length; i += 1) {
if (
entModels[i][VALUES][KEY] === ENTITLEMENT_BASIC ||
Expand All @@ -1238,13 +1238,23 @@ export function getCallingBackEnd(webex: WebexSDK): CALLING_BACKEND {
break;
}
}
} else if (webex.internal.device.callingBehavior === NATIVE_SIP_CALL_TO_UCM) {
} else if (device.callingBehavior === NATIVE_SIP_CALL_TO_UCM) {
callingBackend = CALLING_BACKEND.UCM;
} else {
callingBackend = CALLING_BACKEND.INVALID;
}

return callingBackend as CALLING_BACKEND;
return callingBackend || CALLING_BACKEND.INVALID;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Slightly concerned by changing this (even though it should be fine/better), I'll leave that up to sdk team to decide.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I don't think this change will make any impact as the else case already covers this.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

the case is if device.callingBehavior === NATIVE_WEBEX_TEAMS_CALLING but none of the expected entitlements are found, in that case, callingBackend will be undefined

}

/**
* Register calling backend.
*
* @param webex -.
* @returns CallingBackEnd.
*/
export function getCallingBackEnd(webex: WebexSDK): CALLING_BACKEND {
return resolveCallingBackend(webex.internal.device);
}

/**
Expand Down
3 changes: 3 additions & 0 deletions packages/calling/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,13 @@ export {
CallDetails,
CallDirection,
CallType,
CALLING_BACKEND,
DisplayInformation,
SORT,
SORT_BY,
} from './common/types';
export {resolveCallingBackend} from './common/Utils';

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Export the documented getCallingBackend symbol

When consumers follow the new public API advertised by this change and import getCallingBackend from @webex/calling, the package still has no such named export; this entry point only exports resolveCallingBackend, while the deprecated wrapper's JSDoc also tells users to use getCallingBackend(device). Add or alias the exported function under the documented getCallingBackend name so the new API is actually available.

Useful? React with 👍 / 👎.

export {WDMDevice} from './SDKConnector/types';
export {CallError, LineError} from './Errors';
export {ICall, TransferType} from './CallingClient/calling/types';
export {LOGGER} from './Logger/types';
Expand Down
Loading