Skip to content
Closed
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/calling/src/CallingClient/CallingClient.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -526,7 +526,7 @@ describe('CallingClient Tests', () => {
expect.stringContaining('Mercury down, waiting for connection to be up'),
{
file: CALLING_CLIENT_FILE,
method: 'handleMercuryOffline',
method: 'handleTransportOffline',
}
);
expect(callingClient['mercuryDownTimestamp']).toEqual(expect.any(String));
Expand Down
125 changes: 91 additions & 34 deletions packages/calling/src/CallingClient/CallingClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
import {LOGGER} from '../Logger/types';
import SDKConnector from '../SDKConnector';
import {ClientRegionInfo, ISDKConnector, ServiceHost, WebexSDK} from '../SDKConnector/types';
import CallingTransport from '../CallingTransport';
import {Eventing} from '../Events/impl';
import {
CallingClientEventTypes,
Expand Down Expand Up @@ -63,6 +64,11 @@ import {
} from '../Metrics/types';
import {getMetricManager} from '../Metrics';
import windowsChromiumIceWarmup from './windowsChromiumIceWarmupUtils';
import {
CallingTransportConnectionSource,
CallingTransportConnectionState,
CallingTransportConnectionStateChangeEvent,
} from '../CallingTransport/types';

/**
* The `CallingClient` module provides a set of APIs for line registration and calling functionalities within the SDK.
Expand Down Expand Up @@ -110,6 +116,10 @@ export class CallingClient extends Eventing<CallingClientEventTypes> implements

private mercuryUpTimestamp = '';

private mobiusSocketDownTimestamp = '';

private mobiusSocketUpTimestamp = '';

/**
* @ignore
*/
Expand Down Expand Up @@ -284,27 +294,64 @@ export class CallingClient extends Eventing<CallingClientEventTypes> implements
this.networkUpTimestamp = new Date().toISOString();
};

private handleMercuryOffline = () => {
log.warn(`Mercury down, waiting for connection to be up`, {
private handleTransportConnectionChange = async (
event: CallingTransportConnectionStateChangeEvent
) => {
if (event.state === CallingTransportConnectionState.OFFLINE) {
this.handleTransportOffline(event.source);

return;
}

await this.handleTransportOnline(event.source);
};

private handleTransportOffline(source: CallingTransportConnectionSource) {
const timestamp = new Date().toISOString();
const isMercury = source === CallingTransportConnectionSource.MERCURY;
const label = isMercury ? 'Mercury' : 'Mobius socket';
const connectionAction = isMercury
? CONNECTION_ACTION.MERCURY_DOWN
: CONNECTION_ACTION.MOBIUS_SOCKET_DOWN;

if (isMercury) {
this.mercuryDownTimestamp = timestamp;
} else {
this.mobiusSocketDownTimestamp = timestamp;
}

log.warn(`${label} down, waiting for connection to be up`, {
file: CALLING_CLIENT_FILE,
method: METHODS.MERCURY_OFFLINE,
method: METHODS.TRANSPORT_OFFLINE,
});
this.mercuryDownTimestamp = new Date().toISOString();

this.metricManager.submitConnectionMetrics(
METRIC_EVENT.CONNECTION_ERROR,
CONNECTION_ACTION.MERCURY_DOWN,
connectionAction,
METRIC_TYPE.BEHAVIORAL,
this.mercuryDownTimestamp,
this.mercuryUpTimestamp
isMercury ? this.mercuryDownTimestamp : this.mobiusSocketDownTimestamp,
isMercury ? this.mercuryUpTimestamp : this.mobiusSocketUpTimestamp
);
};
}

private async handleTransportOnline(source: CallingTransportConnectionSource) {
const timestamp = new Date().toISOString();
const isMercury = source === CallingTransportConnectionSource.MERCURY;
const connectionAction = isMercury
? CONNECTION_ACTION.MERCURY_UP
: CONNECTION_ACTION.MOBIUS_SOCKET_UP;

if (isMercury) {
this.mercuryUpTimestamp = timestamp;
} else {
this.mobiusSocketUpTimestamp = timestamp;
}

private handleMercuryOnline = async () => {
log.info(METHOD_START_MESSAGE, {
file: CALLING_CLIENT_FILE,
method: METHODS.MERCURY_ONLINE,
method: METHODS.TRANSPORT_ONLINE,
});
this.mercuryUpTimestamp = new Date().toISOString();

if (this.isNetworkDown) {
const callCheckInterval = setInterval(async () => {
if (!Object.keys(this.callManager.getActiveCalls()).length) {
Expand Down Expand Up @@ -332,19 +379,22 @@ export class CallingClient extends Eventing<CallingClientEventTypes> implements
this.networkDownTimestamp,
this.networkUpTimestamp
);
} else {
if (Object.keys(this.callManager.getActiveCalls()).length) {
await this.checkCallStatus();
}
this.metricManager.submitConnectionMetrics(
METRIC_EVENT.CONNECTION_ERROR,
CONNECTION_ACTION.MERCURY_UP,
METRIC_TYPE.BEHAVIORAL,
this.mercuryDownTimestamp,
this.mercuryUpTimestamp
);

return;
}
};

if (Object.keys(this.callManager.getActiveCalls()).length) {
await this.checkCallStatus();
}

this.metricManager.submitConnectionMetrics(
METRIC_EVENT.CONNECTION_ERROR,
connectionAction,
METRIC_TYPE.BEHAVIORAL,
isMercury ? this.mercuryDownTimestamp : this.mobiusSocketDownTimestamp,
isMercury ? this.mercuryUpTimestamp : this.mobiusSocketUpTimestamp
);
}

private setupNetworkEventListeners(): void {
if (typeof window !== 'undefined' && window.addEventListener) {
Expand All @@ -353,13 +403,7 @@ export class CallingClient extends Eventing<CallingClientEventTypes> implements
window.addEventListener('offline', this.handleNetworkOffline);
}

this.webex.internal.mercury.on('offline', () => {
this.handleMercuryOffline();
});

this.webex.internal.mercury.on('online', () => {
this.handleMercuryOnline();
});
CallingTransport.onConnectionStateChange(this.handleTransportConnectionChange);
}

/**
Expand All @@ -374,7 +418,7 @@ export class CallingClient extends Eventing<CallingClientEventTypes> implements
const regionInfo = {} as RegionInfo;

try {
const response = <WebexRequestPayload>await this.webex.request({
const response = <WebexRequestPayload>await CallingTransport.request({
uri: `${DISCOVERY_URL}`,
method: HTTP_METHODS.GET,
addAuthHeader: false,
Expand Down Expand Up @@ -505,7 +549,7 @@ export class CallingClient extends Eventing<CallingClientEventTypes> implements
}
try {
// eslint-disable-next-line no-await-in-loop
const response = <WebexRequestPayload>await this.webex.request({
const response = <WebexRequestPayload>await CallingTransport.request({
uri: `${this.mobiusHost}${URL_ENDPOINT}?regionCode=${clientRegion}&countryCode=${countryCode}`,
method: HTTP_METHODS.GET,
headers: {
Expand Down Expand Up @@ -667,7 +711,7 @@ export class CallingClient extends Eventing<CallingClientEventTypes> implements
file: CALLING_CLIENT_FILE,
method: METHODS.REGISTER_SESSIONS_LISTENER,
});
this.sdkConnector.registerListener<CallSessionEvent>(
CallingTransport.on<CallSessionEvent>(
MOBIUS_EVENT_KEYS.CALL_SESSION_EVENT_INCLUSIVE,
async (event?: CallSessionEvent) => {
if (event && event.data.userSessions.userSessions) {
Expand Down Expand Up @@ -745,7 +789,7 @@ export class CallingClient extends Eventing<CallingClientEventTypes> implements
)}`;
try {
// eslint-disable-next-line no-await-in-loop
const response = <WebexRequestPayload>await this.webex.request({
const response = <WebexRequestPayload>await CallingTransport.request({
uri,
method: HTTP_METHODS.GET,
service: ALLOWED_SERVICES.MOBIUS,
Expand Down Expand Up @@ -830,6 +874,19 @@ export class CallingClient extends Eventing<CallingClientEventTypes> implements

return result;
}

public removeAllListeners(event?: keyof CallingClientEventTypes): this {
if (!event) {
if (typeof window !== 'undefined' && window.removeEventListener) {
window.removeEventListener('online', this.handleNetworkOnline);
window.removeEventListener('offline', this.handleNetworkOffline);
}

CallingTransport.offConnectionStateChange();
}

return super.removeAllListeners(event);
}
}

/**
Expand Down
13 changes: 7 additions & 6 deletions packages/calling/src/CallingClient/calling/call.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ import {
TRANSFER_ENDPOINT,
} from '../constants';
import SDKConnector from '../../SDKConnector';
import CallingTransport from '../../CallingTransport';
import {Eventing} from '../../Events/impl';
import {
CALL_EVENT_KEYS,
Expand Down Expand Up @@ -2324,7 +2325,7 @@ export class Call extends Eventing<CallEventTypes> implements ICall {
},
};

return this.webex.request({
return CallingTransport.request({
uri: `${this.mobiusUrl}${DEVICES_ENDPOINT_RESOURCE}/${this.deviceId}/${CALL_ENDPOINT_RESOURCE}`,
method: HTTP_METHODS.POST,
service: ALLOWED_SERVICES.MOBIUS,
Expand Down Expand Up @@ -2355,7 +2356,7 @@ export class Call extends Eventing<CallEventTypes> implements ICall {
method: 'patch',
});

return this.webex.request({
return CallingTransport.request({
// Sample uri: http://localhost/api/v1/calling/web/devices/{deviceid}/calls/{callid}

uri: `${this.mobiusUrl}${DEVICES_ENDPOINT_RESOURCE}/${this.deviceId}/${CALLS_ENDPOINT_RESOURCE}/${this.callId}`,
Expand Down Expand Up @@ -2431,14 +2432,14 @@ export class Call extends Eventing<CallEventTypes> implements ICall {
}
}

return this.webex.request(request);
return CallingTransport.request(request);
}

/**
* Sends Call status to Mobius.
*/
public async postStatus(): Promise<WebexRequestPayload> {
return this.webex.request({
return CallingTransport.request({
uri: `${this.mobiusUrl}${DEVICES_ENDPOINT_RESOURCE}/${this.deviceId}/${CALLS_ENDPOINT_RESOURCE}/${this.callId}/${CALL_STATUS_RESOURCE}`,
method: HTTP_METHODS.POST,
service: ALLOWED_SERVICES.MOBIUS,
Expand Down Expand Up @@ -2623,7 +2624,7 @@ export class Call extends Eventing<CallEventTypes> implements ICall {
method: METHODS.POST_MEDIA,
});

return this.webex.request({
return CallingTransport.request({
uri: `${this.mobiusUrl}${DEVICES_ENDPOINT_RESOURCE}/${this.deviceId}/${CALLS_ENDPOINT_RESOURCE}/${this.callId}/${MEDIA_ENDPOINT_RESOURCE}`,
method: HTTP_METHODS.POST,
service: ALLOWED_SERVICES.MOBIUS,
Expand Down Expand Up @@ -2804,7 +2805,7 @@ export class Call extends Eventing<CallEventTypes> implements ICall {
private async delete(): Promise<MobiusCallResponse> {
const disconnectMetrics = await this.getCallStats();

return this.webex.request({
return CallingTransport.request({
uri: `${this.mobiusUrl}${DEVICES_ENDPOINT_RESOURCE}/${this.deviceId}/${CALLS_ENDPOINT_RESOURCE}/${this.callId}`,
method: HTTP_METHODS.DELETE,
service: ALLOWED_SERVICES.MOBIUS,
Expand Down
3 changes: 2 additions & 1 deletion packages/calling/src/CallingClient/calling/callManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {CALL_MANAGER_FILE, METHODS} from '../constants';
import {CALLING_CLIENT_EVENT_KEYS, CallEventTypes, LINE_EVENT_KEYS} from '../../Events/types';
import {Eventing} from '../../Events/impl';
import SDKConnector from '../../SDKConnector';
import CallingTransport from '../../CallingTransport';
import {ISDKConnector, WebexSDK} from '../../SDKConnector/types';
import {CallDetails, CallDirection, CorrelationId, ServiceIndicator} from '../../common/types';
import {
Expand Down Expand Up @@ -127,7 +128,7 @@ export class CallManager extends Eventing<CallEventTypes> implements ICallManage
* A listener for Mobius events.
*/
private listenForWsEvents() {
this.sdkConnector.registerListener('event:mobius', async (event) => {
CallingTransport.on('event:mobius', async (event) => {
this.dequeueWsEvents(event);
});
log.info('Successfully registered listener for Mobius events', {
Expand Down
4 changes: 2 additions & 2 deletions packages/calling/src/CallingClient/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -216,8 +216,8 @@ export const METHODS = {
SET_MOBIUS_SERVERS: 'setMobiusServers',
HANDLE_CONNECTION_RESTORATION: 'handleConnectionRestoration',
RECONNECT_ON_FAILURE: 'reconnectOnFailure',
MERCURY_OFFLINE: 'handleMercuryOffline',
MERCURY_ONLINE: 'handleMercuryOnline',
TRANSPORT_OFFLINE: 'handleTransportOffline',
TRANSPORT_ONLINE: 'handleTransportOnline',
NETWORK_OFFLINE: 'handleNetworkOffline',
NETWORK_ONLINE: 'handleNetworkOnline',
GET_CLIENT_REGION_INFO: 'getClientRegionInfo',
Expand Down
5 changes: 3 additions & 2 deletions packages/calling/src/CallingClient/registration/register.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {LOGGER} from '../../Logger/types';
import log from '../../Logger';
import {FailoverCacheState, IRegistration} from './types';
import SDKConnector from '../../SDKConnector';
import CallingTransport from '../../CallingTransport';
import {
ALLOWED_SERVICES,
Devices,
Expand Down Expand Up @@ -257,7 +258,7 @@ export class Registration implements IRegistration {
serviceData: this.jwe ? {...this.serviceData, jwe: this.jwe} : this.serviceData,
};

return <WebexRequestPayload>this.webex.request({
return <WebexRequestPayload>CallingTransport.request({
uri: `${url}device`,
method: HTTP_METHODS.POST,
headers: {
Expand Down Expand Up @@ -490,7 +491,7 @@ export class Registration implements IRegistration {
try {
const baseUri = mobiusUrl.replace(URL_ENDPOINT, '/');
// eslint-disable-next-line no-await-in-loop
const response = await this.webex.request({
const response = await CallingTransport.request({
uri: `${baseUri}ping`,
method: HTTP_METHODS.GET,
headers: {
Expand Down
Loading
Loading