@webex/calling 0.0.1-next.0 → 0.0.1-next.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +51 -66
- package/dist/module/CallHistory/CallHistory.js +84 -84
- package/dist/module/CallHistory/callHistoryFixtures.js +307 -307
- package/dist/module/CallHistory/constants.js +9 -9
- package/dist/module/CallHistory/types.js +1 -1
- package/dist/module/CallSettings/CallSettings.js +65 -65
- package/dist/module/CallSettings/UcmBackendConnector.js +100 -100
- package/dist/module/CallSettings/WxCallBackendConnector.js +287 -287
- package/dist/module/CallSettings/constants.js +11 -11
- package/dist/module/CallSettings/testFixtures.js +62 -62
- package/dist/module/CallSettings/types.js +1 -1
- package/dist/module/CallingClient/CallingClient.js +268 -268
- package/dist/module/CallingClient/callRecordFixtures.js +93 -93
- package/dist/module/CallingClient/calling/CallerId/index.js +169 -169
- package/dist/module/CallingClient/calling/CallerId/types.js +1 -1
- package/dist/module/CallingClient/calling/call.js +1649 -1649
- package/dist/module/CallingClient/calling/callManager.js +274 -274
- package/dist/module/CallingClient/calling/index.js +2 -2
- package/dist/module/CallingClient/calling/types.js +53 -53
- package/dist/module/CallingClient/callingClientFixtures.js +38 -38
- package/dist/module/CallingClient/constants.js +122 -122
- package/dist/module/CallingClient/line/index.js +110 -110
- package/dist/module/CallingClient/line/types.js +14 -14
- package/dist/module/CallingClient/registration/index.js +1 -1
- package/dist/module/CallingClient/registration/register.js +507 -507
- package/dist/module/CallingClient/registration/registerFixtures.js +28 -28
- package/dist/module/CallingClient/registration/types.js +1 -1
- package/dist/module/CallingClient/types.js +1 -1
- package/dist/module/Contacts/ContactsClient.js +487 -487
- package/dist/module/Contacts/constants.js +20 -20
- package/dist/module/Contacts/contactFixtures.js +284 -284
- package/dist/module/Contacts/types.js +10 -10
- package/dist/module/Errors/catalog/CallError.js +26 -26
- package/dist/module/Errors/catalog/CallingDeviceError.js +18 -18
- package/dist/module/Errors/catalog/ExtendedError.js +10 -10
- package/dist/module/Errors/catalog/LineError.js +24 -24
- package/dist/module/Errors/index.js +2 -2
- package/dist/module/Errors/types.js +48 -48
- package/dist/module/Events/impl/index.js +19 -19
- package/dist/module/Events/types.js +74 -74
- package/dist/module/Logger/index.js +114 -114
- package/dist/module/Logger/types.js +25 -25
- package/dist/module/Metrics/index.js +232 -232
- package/dist/module/Metrics/types.js +37 -37
- package/dist/module/SDKConnector/index.js +39 -39
- package/dist/module/SDKConnector/types.js +1 -1
- package/dist/module/SDKConnector/utils.js +12 -12
- package/dist/module/Voicemail/BroadworksBackendConnector.js +289 -289
- package/dist/module/Voicemail/UcmBackendConnector.js +275 -275
- package/dist/module/Voicemail/Voicemail.js +110 -110
- package/dist/module/Voicemail/WxCallBackendConnector.js +279 -279
- package/dist/module/Voicemail/constants.js +29 -29
- package/dist/module/Voicemail/types.js +1 -1
- package/dist/module/Voicemail/voicemailFixture.js +449 -449
- package/dist/module/common/Utils.js +802 -802
- package/dist/module/common/constants.js +40 -40
- package/dist/module/common/index.js +1 -1
- package/dist/module/common/testUtil.js +938 -938
- package/dist/module/common/types.js +57 -57
- package/dist/module/index.js +8 -8
- package/dist/types/CallHistory/CallHistory.d.ts +18 -18
- package/dist/types/CallHistory/callHistoryFixtures.d.ts +94 -94
- package/dist/types/CallHistory/constants.d.ts +9 -9
- package/dist/types/CallHistory/types.d.ts +20 -20
- package/dist/types/CallSettings/CallSettings.d.ts +19 -19
- package/dist/types/CallSettings/UcmBackendConnector.d.ts +19 -19
- package/dist/types/CallSettings/WxCallBackendConnector.d.ts +21 -21
- package/dist/types/CallSettings/constants.d.ts +11 -11
- package/dist/types/CallSettings/testFixtures.d.ts +15 -15
- package/dist/types/CallSettings/types.d.ts +107 -107
- package/dist/types/CallingClient/CallingClient.d.ts +37 -37
- package/dist/types/CallingClient/callRecordFixtures.d.ts +3 -3
- package/dist/types/CallingClient/calling/CallerId/index.d.ts +17 -17
- package/dist/types/CallingClient/calling/CallerId/types.d.ts +41 -41
- package/dist/types/CallingClient/calling/call.d.ts +94 -94
- package/dist/types/CallingClient/calling/call.d.ts.map +1 -1
- package/dist/types/CallingClient/calling/callManager.d.ts +21 -21
- package/dist/types/CallingClient/calling/index.d.ts +2 -2
- package/dist/types/CallingClient/calling/types.d.ts +203 -203
- package/dist/types/CallingClient/calling/types.d.ts.map +1 -1
- package/dist/types/CallingClient/callingClientFixtures.d.ts +18 -18
- package/dist/types/CallingClient/constants.d.ts +122 -122
- package/dist/types/CallingClient/line/index.d.ts +38 -38
- package/dist/types/CallingClient/line/types.d.ts +50 -50
- package/dist/types/CallingClient/registration/index.d.ts +1 -1
- package/dist/types/CallingClient/registration/register.d.ts +64 -64
- package/dist/types/CallingClient/registration/registerFixtures.d.ts +28 -28
- package/dist/types/CallingClient/registration/types.d.ts +20 -20
- package/dist/types/CallingClient/types.d.ts +29 -29
- package/dist/types/Contacts/ContactsClient.d.ts +27 -27
- package/dist/types/Contacts/constants.d.ts +19 -19
- package/dist/types/Contacts/contactFixtures.d.ts +280 -280
- package/dist/types/Contacts/types.d.ts +74 -74
- package/dist/types/Errors/catalog/CallError.d.ts +11 -11
- package/dist/types/Errors/catalog/CallingDeviceError.d.ts +10 -10
- package/dist/types/Errors/catalog/ExtendedError.d.ts +6 -6
- package/dist/types/Errors/catalog/LineError.d.ts +10 -10
- package/dist/types/Errors/index.d.ts +2 -2
- package/dist/types/Errors/types.d.ts +60 -60
- package/dist/types/Events/impl/index.d.ts +8 -8
- package/dist/types/Events/types.d.ts +283 -283
- package/dist/types/Logger/index.d.ts +12 -12
- package/dist/types/Logger/types.d.ts +25 -25
- package/dist/types/Metrics/index.d.ts +5 -5
- package/dist/types/Metrics/types.d.ts +42 -42
- package/dist/types/SDKConnector/index.d.ts +12 -12
- package/dist/types/SDKConnector/types.d.ts +128 -128
- package/dist/types/SDKConnector/utils.d.ts +5 -5
- package/dist/types/Voicemail/BroadworksBackendConnector.d.ts +27 -27
- package/dist/types/Voicemail/UcmBackendConnector.d.ts +34 -34
- package/dist/types/Voicemail/Voicemail.d.ts +27 -27
- package/dist/types/Voicemail/WxCallBackendConnector.d.ts +23 -23
- package/dist/types/Voicemail/constants.d.ts +29 -29
- package/dist/types/Voicemail/types.d.ts +133 -133
- package/dist/types/Voicemail/voicemailFixture.d.ts +349 -349
- package/dist/types/common/Utils.d.ts +34 -34
- package/dist/types/common/constants.d.ts +40 -40
- package/dist/types/common/index.d.ts +1 -1
- package/dist/types/common/testUtil.d.ts +3611 -3611
- package/dist/types/common/types.d.ts +191 -191
- package/dist/types/index.d.ts +8 -8
- package/package.json +6 -41
|
@@ -1,268 +1,268 @@
|
|
|
1
|
-
import * as Media from '@webex/internal-media-core';
|
|
2
|
-
import { Mutex } from 'async-mutex';
|
|
3
|
-
import { filterMobiusUris, handleCallingClientErrors, validateServiceData } from '../common/Utils';
|
|
4
|
-
import { ERROR_TYPE } from '../Errors/types';
|
|
5
|
-
import { LOGGER } from '../Logger/types';
|
|
6
|
-
import SDKConnector from '../SDKConnector';
|
|
7
|
-
import { Eventing } from '../Events/impl';
|
|
8
|
-
import { EVENT_KEYS, MOBIUS_EVENT_KEYS, SessionType, } from '../Events/types';
|
|
9
|
-
import { MobiusStatus, CallDirection, ServiceIndicator, ALLOWED_SERVICES, HTTP_METHODS, } from '../common/types';
|
|
10
|
-
import log from '../Logger';
|
|
11
|
-
import { getCallManager } from './calling/callManager';
|
|
12
|
-
import { CALLING_CLIENT_FILE, VALID_PHONE, CALLS_CLEARED_HANDLER_UTIL, CALLING_USER_AGENT, CISCO_DEVICE_URL, DISCOVERY_URL, GET_MOBIUS_SERVERS_UTIL, IP_ENDPOINT, SPARK_USER_AGENT, URL_ENDPOINT, NETWORK_FLAP_TIMEOUT, } from './constants';
|
|
13
|
-
import { CallingClientError } from '../Errors';
|
|
14
|
-
import Line from './line';
|
|
15
|
-
import { LINE_EVENTS, LineStatus } from './line/types';
|
|
16
|
-
import { METRIC_EVENT, REG_ACTION, METRIC_TYPE } from '../Metrics/types';
|
|
17
|
-
import { getMetricManager } from '../Metrics';
|
|
18
|
-
export class CallingClient extends Eventing {
|
|
19
|
-
sdkConnector;
|
|
20
|
-
webex;
|
|
21
|
-
mutex;
|
|
22
|
-
callManager;
|
|
23
|
-
metricManager;
|
|
24
|
-
sdkConfig;
|
|
25
|
-
primaryMobiusUris;
|
|
26
|
-
backupMobiusUris;
|
|
27
|
-
mediaEngine;
|
|
28
|
-
lineDict = {};
|
|
29
|
-
constructor(webex, config) {
|
|
30
|
-
super();
|
|
31
|
-
this.sdkConnector = SDKConnector;
|
|
32
|
-
if (!this.sdkConnector.getWebex()) {
|
|
33
|
-
SDKConnector.setWebex(webex);
|
|
34
|
-
}
|
|
35
|
-
this.mutex = new Mutex();
|
|
36
|
-
this.webex = this.sdkConnector.getWebex();
|
|
37
|
-
this.sdkConfig = config;
|
|
38
|
-
const serviceData = this.sdkConfig?.serviceData?.indicator
|
|
39
|
-
? this.sdkConfig.serviceData
|
|
40
|
-
: { indicator: ServiceIndicator.CALLING, domain: '' };
|
|
41
|
-
const logLevel = this.sdkConfig?.logger?.level ? this.sdkConfig.logger.level : LOGGER.ERROR;
|
|
42
|
-
validateServiceData(serviceData);
|
|
43
|
-
this.callManager = getCallManager(this.webex, serviceData.indicator);
|
|
44
|
-
this.metricManager = getMetricManager(this.webex, serviceData.indicator);
|
|
45
|
-
this.mediaEngine = Media;
|
|
46
|
-
this.primaryMobiusUris = [];
|
|
47
|
-
this.backupMobiusUris = [];
|
|
48
|
-
this.registerSessionsListener();
|
|
49
|
-
log.setLogger(logLevel, CALLING_CLIENT_FILE);
|
|
50
|
-
this.incomingCallListener();
|
|
51
|
-
this.registerCallsClearedListener();
|
|
52
|
-
}
|
|
53
|
-
async init() {
|
|
54
|
-
await this.getMobiusServers();
|
|
55
|
-
await this.createLine();
|
|
56
|
-
this.detectNetworkChange();
|
|
57
|
-
}
|
|
58
|
-
incomingCallListener() {
|
|
59
|
-
const logContext = {
|
|
60
|
-
file: CALLING_CLIENT_FILE,
|
|
61
|
-
method: this.incomingCallListener.name,
|
|
62
|
-
};
|
|
63
|
-
log.log('Listening for incoming calls... ', logContext);
|
|
64
|
-
this.callManager.on(EVENT_KEYS.INCOMING_CALL, (callObj) => {
|
|
65
|
-
this.emit(EVENT_KEYS.INCOMING_CALL, callObj);
|
|
66
|
-
});
|
|
67
|
-
}
|
|
68
|
-
async detectNetworkChange() {
|
|
69
|
-
let retry = false;
|
|
70
|
-
const line = Object.values(this.lineDict)[0];
|
|
71
|
-
setInterval(async () => {
|
|
72
|
-
if (!this.webex.internal.mercury.connected &&
|
|
73
|
-
!retry &&
|
|
74
|
-
!Object.keys(this.callManager.getActiveCalls()).length) {
|
|
75
|
-
log.warn(`Network has flapped, waiting for mercury connection to be up`, {
|
|
76
|
-
file: CALLING_CLIENT_FILE,
|
|
77
|
-
method: this.detectNetworkChange.name,
|
|
78
|
-
});
|
|
79
|
-
line.lineEmitter(LINE_EVENTS.UNREGISTERED);
|
|
80
|
-
line.registration.clearKeepaliveTimer();
|
|
81
|
-
retry = true;
|
|
82
|
-
}
|
|
83
|
-
if (retry && this.webex.internal.mercury.connected) {
|
|
84
|
-
retry = await line.registration.handleConnectionRestoration(retry);
|
|
85
|
-
}
|
|
86
|
-
}, NETWORK_FLAP_TIMEOUT);
|
|
87
|
-
}
|
|
88
|
-
async getClientRegionInfo() {
|
|
89
|
-
const regionInfo = {};
|
|
90
|
-
try {
|
|
91
|
-
const temp = await this.webex.request({
|
|
92
|
-
uri: `${this.webex.internal.services._serviceUrls.mobius}${URL_ENDPOINT}${IP_ENDPOINT}`,
|
|
93
|
-
method: HTTP_METHODS.GET,
|
|
94
|
-
headers: {
|
|
95
|
-
[CISCO_DEVICE_URL]: this.webex.internal.device.url,
|
|
96
|
-
[SPARK_USER_AGENT]: CALLING_USER_AGENT,
|
|
97
|
-
},
|
|
98
|
-
service: ALLOWED_SERVICES.MOBIUS,
|
|
99
|
-
});
|
|
100
|
-
const myIP = temp.body.ipv4;
|
|
101
|
-
const response = await this.webex.request({
|
|
102
|
-
uri: `${DISCOVERY_URL}/${myIP}`,
|
|
103
|
-
method: HTTP_METHODS.GET,
|
|
104
|
-
addAuthHeader: false,
|
|
105
|
-
headers: {
|
|
106
|
-
[SPARK_USER_AGENT]: null,
|
|
107
|
-
},
|
|
108
|
-
});
|
|
109
|
-
const clientRegionInfo = response.body;
|
|
110
|
-
regionInfo.clientRegion = clientRegionInfo?.clientRegion ? clientRegionInfo.clientRegion : '';
|
|
111
|
-
regionInfo.countryCode = clientRegionInfo?.countryCode ? clientRegionInfo.countryCode : '';
|
|
112
|
-
}
|
|
113
|
-
catch (err) {
|
|
114
|
-
handleCallingClientErrors(err, (clientError) => {
|
|
115
|
-
this.metricManager.submitRegistrationMetric(METRIC_EVENT.REGISTRATION_ERROR, REG_ACTION.REGISTER, METRIC_TYPE.BEHAVIORAL, clientError);
|
|
116
|
-
this.emit(EVENT_KEYS.ERROR, clientError);
|
|
117
|
-
}, { method: GET_MOBIUS_SERVERS_UTIL, file: CALLING_CLIENT_FILE });
|
|
118
|
-
regionInfo.clientRegion = '';
|
|
119
|
-
regionInfo.countryCode = '';
|
|
120
|
-
}
|
|
121
|
-
return regionInfo;
|
|
122
|
-
}
|
|
123
|
-
async getMobiusServers() {
|
|
124
|
-
let useDefault = false;
|
|
125
|
-
let clientRegion;
|
|
126
|
-
let countryCode;
|
|
127
|
-
if (this.sdkConfig?.discovery?.country && this.sdkConfig?.discovery?.region) {
|
|
128
|
-
log.info('Updating region and country from the SDK config', {
|
|
129
|
-
file: CALLING_CLIENT_FILE,
|
|
130
|
-
method: GET_MOBIUS_SERVERS_UTIL,
|
|
131
|
-
});
|
|
132
|
-
clientRegion = this.sdkConfig?.discovery?.region;
|
|
133
|
-
countryCode = this.sdkConfig?.discovery?.country;
|
|
134
|
-
}
|
|
135
|
-
else {
|
|
136
|
-
log.info('Updating region and country through Region discovery', {
|
|
137
|
-
file: CALLING_CLIENT_FILE,
|
|
138
|
-
method: GET_MOBIUS_SERVERS_UTIL,
|
|
139
|
-
});
|
|
140
|
-
const regionInfo = await this.getClientRegionInfo();
|
|
141
|
-
clientRegion = regionInfo.clientRegion;
|
|
142
|
-
countryCode = regionInfo.countryCode;
|
|
143
|
-
}
|
|
144
|
-
if (clientRegion && countryCode) {
|
|
145
|
-
log.log(`Found Region: ${clientRegion} and country: ${countryCode}, going to fetch Mobius server`, '');
|
|
146
|
-
try {
|
|
147
|
-
const temp = await this.webex.request({
|
|
148
|
-
uri: `${this.webex.internal.services._serviceUrls.mobius}${URL_ENDPOINT}?regionCode=${clientRegion}&countryCode=${countryCode}`,
|
|
149
|
-
method: HTTP_METHODS.GET,
|
|
150
|
-
headers: {
|
|
151
|
-
[CISCO_DEVICE_URL]: this.webex.internal.device.url,
|
|
152
|
-
[SPARK_USER_AGENT]: CALLING_USER_AGENT,
|
|
153
|
-
},
|
|
154
|
-
service: ALLOWED_SERVICES.MOBIUS,
|
|
155
|
-
});
|
|
156
|
-
log.log('Mobius Server found for the region', '');
|
|
157
|
-
const mobiusServers = temp.body;
|
|
158
|
-
const mobiusUris = filterMobiusUris(mobiusServers, this.webex.internal.services._serviceUrls.mobius);
|
|
159
|
-
this.primaryMobiusUris = mobiusUris.primary;
|
|
160
|
-
this.backupMobiusUris = mobiusUris.backup;
|
|
161
|
-
log.info(`Final list of Mobius Servers, primary: ${mobiusUris.primary} and backup: ${mobiusUris.backup}`, '');
|
|
162
|
-
}
|
|
163
|
-
catch (err) {
|
|
164
|
-
handleCallingClientErrors(err, (clientError) => {
|
|
165
|
-
this.metricManager.submitRegistrationMetric(METRIC_EVENT.REGISTRATION_ERROR, REG_ACTION.REGISTER, METRIC_TYPE.BEHAVIORAL, clientError);
|
|
166
|
-
this.emit(EVENT_KEYS.ERROR, clientError);
|
|
167
|
-
}, { method: GET_MOBIUS_SERVERS_UTIL, file: CALLING_CLIENT_FILE });
|
|
168
|
-
useDefault = true;
|
|
169
|
-
}
|
|
170
|
-
}
|
|
171
|
-
else {
|
|
172
|
-
useDefault = true;
|
|
173
|
-
}
|
|
174
|
-
if (useDefault) {
|
|
175
|
-
log.warn('Error in finding Mobius Servers. Will use the default URL.', '');
|
|
176
|
-
this.primaryMobiusUris = [
|
|
177
|
-
`${this.webex.internal.services._serviceUrls.mobius}${URL_ENDPOINT}`,
|
|
178
|
-
];
|
|
179
|
-
}
|
|
180
|
-
}
|
|
181
|
-
registerCallsClearedListener() {
|
|
182
|
-
const logContext = {
|
|
183
|
-
file: CALLING_CLIENT_FILE,
|
|
184
|
-
method: this.registerCallsClearedListener.name,
|
|
185
|
-
};
|
|
186
|
-
log.log('Registering listener for all calls cleared event', logContext);
|
|
187
|
-
this.callManager.on(EVENT_KEYS.ALL_CALLS_CLEARED, this.callsClearedHandler);
|
|
188
|
-
}
|
|
189
|
-
callsClearedHandler = async () => {
|
|
190
|
-
const { registration } = Object.values(this.lineDict)[0];
|
|
191
|
-
if (!registration.isDeviceRegistered()) {
|
|
192
|
-
await this.mutex.runExclusive(async () => {
|
|
193
|
-
if (registration.isReconnectPending()) {
|
|
194
|
-
log.log('All calls cleared, reconnecting', {
|
|
195
|
-
file: CALLING_CLIENT_FILE,
|
|
196
|
-
method: CALLS_CLEARED_HANDLER_UTIL,
|
|
197
|
-
});
|
|
198
|
-
await registration.reconnectOnFailure(CALLS_CLEARED_HANDLER_UTIL);
|
|
199
|
-
}
|
|
200
|
-
});
|
|
201
|
-
}
|
|
202
|
-
};
|
|
203
|
-
getLoggingLevel() {
|
|
204
|
-
return log.getLogLevel();
|
|
205
|
-
}
|
|
206
|
-
getCall = (correlationId) => {
|
|
207
|
-
return this.callManager.getCall(correlationId);
|
|
208
|
-
};
|
|
209
|
-
makeCall = (dest) => {
|
|
210
|
-
let call;
|
|
211
|
-
const { registration } = Object.values(this.lineDict)[0];
|
|
212
|
-
if (dest) {
|
|
213
|
-
const match = dest.address.match(VALID_PHONE);
|
|
214
|
-
if (match && match[0].length === dest.address.length) {
|
|
215
|
-
const sanitizedNumber = dest.address
|
|
216
|
-
.replace(/[^[*+]\d#]/gi, '')
|
|
217
|
-
.replace(/\s+/gi, '')
|
|
218
|
-
.replace(/-/gi, '');
|
|
219
|
-
const formattedDest = {
|
|
220
|
-
type: dest.type,
|
|
221
|
-
address: `tel:${sanitizedNumber}`,
|
|
222
|
-
};
|
|
223
|
-
call = this.callManager.createCall(formattedDest, CallDirection.OUTBOUND, registration.getDeviceInfo().device?.deviceId);
|
|
224
|
-
log.log(`New call created, callId: ${call.getCallId()}`, {});
|
|
225
|
-
}
|
|
226
|
-
else {
|
|
227
|
-
log.warn('Invalid phone number detected', {});
|
|
228
|
-
const err = new CallingClientError('An invalid phone number was detected. Check the number and try again.', {}, ERROR_TYPE.CALL_ERROR, MobiusStatus.ACTIVE);
|
|
229
|
-
this.emit(EVENT_KEYS.ERROR, err);
|
|
230
|
-
}
|
|
231
|
-
return call;
|
|
232
|
-
}
|
|
233
|
-
return undefined;
|
|
234
|
-
};
|
|
235
|
-
getSDKConnector() {
|
|
236
|
-
return this.sdkConnector;
|
|
237
|
-
}
|
|
238
|
-
registerSessionsListener() {
|
|
239
|
-
this.sdkConnector.registerListener(MOBIUS_EVENT_KEYS.CALL_SESSION_EVENT_INCLUSIVE, async (event) => {
|
|
240
|
-
if (event && event.data.userSessions.userSessions) {
|
|
241
|
-
const sessionArr = event?.data.userSessions.userSessions;
|
|
242
|
-
if (sessionArr.length === 1) {
|
|
243
|
-
if (sessionArr[0].sessionType !== SessionType.WEBEX_CALLING) {
|
|
244
|
-
return;
|
|
245
|
-
}
|
|
246
|
-
}
|
|
247
|
-
for (let i = 0; i < sessionArr.length; i += 1) {
|
|
248
|
-
if (sessionArr[i].sessionType !== SessionType.WEBEX_CALLING) {
|
|
249
|
-
sessionArr.splice(i, 1);
|
|
250
|
-
}
|
|
251
|
-
}
|
|
252
|
-
this.emit(EVENT_KEYS.USER_SESSION_INFO, event);
|
|
253
|
-
}
|
|
254
|
-
});
|
|
255
|
-
}
|
|
256
|
-
async createLine() {
|
|
257
|
-
const line = new Line(this.webex.internal.device.userId, this.webex.internal.device.url, LineStatus.INACTIVE, this.mutex, this.primaryMobiusUris, this.backupMobiusUris, this.getLoggingLevel(), this.sdkConfig?.serviceData);
|
|
258
|
-
this.lineDict[line.lineId] = line;
|
|
259
|
-
}
|
|
260
|
-
getLines() {
|
|
261
|
-
return this.lineDict;
|
|
262
|
-
}
|
|
263
|
-
}
|
|
264
|
-
export const createClient = async (webex, config) => {
|
|
265
|
-
const callingClientInstance = new CallingClient(webex, config);
|
|
266
|
-
await callingClientInstance.init();
|
|
267
|
-
return callingClientInstance;
|
|
268
|
-
};
|
|
1
|
+
import * as Media from '@webex/internal-media-core';
|
|
2
|
+
import { Mutex } from 'async-mutex';
|
|
3
|
+
import { filterMobiusUris, handleCallingClientErrors, validateServiceData } from '../common/Utils';
|
|
4
|
+
import { ERROR_TYPE } from '../Errors/types';
|
|
5
|
+
import { LOGGER } from '../Logger/types';
|
|
6
|
+
import SDKConnector from '../SDKConnector';
|
|
7
|
+
import { Eventing } from '../Events/impl';
|
|
8
|
+
import { EVENT_KEYS, MOBIUS_EVENT_KEYS, SessionType, } from '../Events/types';
|
|
9
|
+
import { MobiusStatus, CallDirection, ServiceIndicator, ALLOWED_SERVICES, HTTP_METHODS, } from '../common/types';
|
|
10
|
+
import log from '../Logger';
|
|
11
|
+
import { getCallManager } from './calling/callManager';
|
|
12
|
+
import { CALLING_CLIENT_FILE, VALID_PHONE, CALLS_CLEARED_HANDLER_UTIL, CALLING_USER_AGENT, CISCO_DEVICE_URL, DISCOVERY_URL, GET_MOBIUS_SERVERS_UTIL, IP_ENDPOINT, SPARK_USER_AGENT, URL_ENDPOINT, NETWORK_FLAP_TIMEOUT, } from './constants';
|
|
13
|
+
import { CallingClientError } from '../Errors';
|
|
14
|
+
import Line from './line';
|
|
15
|
+
import { LINE_EVENTS, LineStatus } from './line/types';
|
|
16
|
+
import { METRIC_EVENT, REG_ACTION, METRIC_TYPE } from '../Metrics/types';
|
|
17
|
+
import { getMetricManager } from '../Metrics';
|
|
18
|
+
export class CallingClient extends Eventing {
|
|
19
|
+
sdkConnector;
|
|
20
|
+
webex;
|
|
21
|
+
mutex;
|
|
22
|
+
callManager;
|
|
23
|
+
metricManager;
|
|
24
|
+
sdkConfig;
|
|
25
|
+
primaryMobiusUris;
|
|
26
|
+
backupMobiusUris;
|
|
27
|
+
mediaEngine;
|
|
28
|
+
lineDict = {};
|
|
29
|
+
constructor(webex, config) {
|
|
30
|
+
super();
|
|
31
|
+
this.sdkConnector = SDKConnector;
|
|
32
|
+
if (!this.sdkConnector.getWebex()) {
|
|
33
|
+
SDKConnector.setWebex(webex);
|
|
34
|
+
}
|
|
35
|
+
this.mutex = new Mutex();
|
|
36
|
+
this.webex = this.sdkConnector.getWebex();
|
|
37
|
+
this.sdkConfig = config;
|
|
38
|
+
const serviceData = this.sdkConfig?.serviceData?.indicator
|
|
39
|
+
? this.sdkConfig.serviceData
|
|
40
|
+
: { indicator: ServiceIndicator.CALLING, domain: '' };
|
|
41
|
+
const logLevel = this.sdkConfig?.logger?.level ? this.sdkConfig.logger.level : LOGGER.ERROR;
|
|
42
|
+
validateServiceData(serviceData);
|
|
43
|
+
this.callManager = getCallManager(this.webex, serviceData.indicator);
|
|
44
|
+
this.metricManager = getMetricManager(this.webex, serviceData.indicator);
|
|
45
|
+
this.mediaEngine = Media;
|
|
46
|
+
this.primaryMobiusUris = [];
|
|
47
|
+
this.backupMobiusUris = [];
|
|
48
|
+
this.registerSessionsListener();
|
|
49
|
+
log.setLogger(logLevel, CALLING_CLIENT_FILE);
|
|
50
|
+
this.incomingCallListener();
|
|
51
|
+
this.registerCallsClearedListener();
|
|
52
|
+
}
|
|
53
|
+
async init() {
|
|
54
|
+
await this.getMobiusServers();
|
|
55
|
+
await this.createLine();
|
|
56
|
+
this.detectNetworkChange();
|
|
57
|
+
}
|
|
58
|
+
incomingCallListener() {
|
|
59
|
+
const logContext = {
|
|
60
|
+
file: CALLING_CLIENT_FILE,
|
|
61
|
+
method: this.incomingCallListener.name,
|
|
62
|
+
};
|
|
63
|
+
log.log('Listening for incoming calls... ', logContext);
|
|
64
|
+
this.callManager.on(EVENT_KEYS.INCOMING_CALL, (callObj) => {
|
|
65
|
+
this.emit(EVENT_KEYS.INCOMING_CALL, callObj);
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
async detectNetworkChange() {
|
|
69
|
+
let retry = false;
|
|
70
|
+
const line = Object.values(this.lineDict)[0];
|
|
71
|
+
setInterval(async () => {
|
|
72
|
+
if (!this.webex.internal.mercury.connected &&
|
|
73
|
+
!retry &&
|
|
74
|
+
!Object.keys(this.callManager.getActiveCalls()).length) {
|
|
75
|
+
log.warn(`Network has flapped, waiting for mercury connection to be up`, {
|
|
76
|
+
file: CALLING_CLIENT_FILE,
|
|
77
|
+
method: this.detectNetworkChange.name,
|
|
78
|
+
});
|
|
79
|
+
line.lineEmitter(LINE_EVENTS.UNREGISTERED);
|
|
80
|
+
line.registration.clearKeepaliveTimer();
|
|
81
|
+
retry = true;
|
|
82
|
+
}
|
|
83
|
+
if (retry && this.webex.internal.mercury.connected) {
|
|
84
|
+
retry = await line.registration.handleConnectionRestoration(retry);
|
|
85
|
+
}
|
|
86
|
+
}, NETWORK_FLAP_TIMEOUT);
|
|
87
|
+
}
|
|
88
|
+
async getClientRegionInfo() {
|
|
89
|
+
const regionInfo = {};
|
|
90
|
+
try {
|
|
91
|
+
const temp = await this.webex.request({
|
|
92
|
+
uri: `${this.webex.internal.services._serviceUrls.mobius}${URL_ENDPOINT}${IP_ENDPOINT}`,
|
|
93
|
+
method: HTTP_METHODS.GET,
|
|
94
|
+
headers: {
|
|
95
|
+
[CISCO_DEVICE_URL]: this.webex.internal.device.url,
|
|
96
|
+
[SPARK_USER_AGENT]: CALLING_USER_AGENT,
|
|
97
|
+
},
|
|
98
|
+
service: ALLOWED_SERVICES.MOBIUS,
|
|
99
|
+
});
|
|
100
|
+
const myIP = temp.body.ipv4;
|
|
101
|
+
const response = await this.webex.request({
|
|
102
|
+
uri: `${DISCOVERY_URL}/${myIP}`,
|
|
103
|
+
method: HTTP_METHODS.GET,
|
|
104
|
+
addAuthHeader: false,
|
|
105
|
+
headers: {
|
|
106
|
+
[SPARK_USER_AGENT]: null,
|
|
107
|
+
},
|
|
108
|
+
});
|
|
109
|
+
const clientRegionInfo = response.body;
|
|
110
|
+
regionInfo.clientRegion = clientRegionInfo?.clientRegion ? clientRegionInfo.clientRegion : '';
|
|
111
|
+
regionInfo.countryCode = clientRegionInfo?.countryCode ? clientRegionInfo.countryCode : '';
|
|
112
|
+
}
|
|
113
|
+
catch (err) {
|
|
114
|
+
handleCallingClientErrors(err, (clientError) => {
|
|
115
|
+
this.metricManager.submitRegistrationMetric(METRIC_EVENT.REGISTRATION_ERROR, REG_ACTION.REGISTER, METRIC_TYPE.BEHAVIORAL, clientError);
|
|
116
|
+
this.emit(EVENT_KEYS.ERROR, clientError);
|
|
117
|
+
}, { method: GET_MOBIUS_SERVERS_UTIL, file: CALLING_CLIENT_FILE });
|
|
118
|
+
regionInfo.clientRegion = '';
|
|
119
|
+
regionInfo.countryCode = '';
|
|
120
|
+
}
|
|
121
|
+
return regionInfo;
|
|
122
|
+
}
|
|
123
|
+
async getMobiusServers() {
|
|
124
|
+
let useDefault = false;
|
|
125
|
+
let clientRegion;
|
|
126
|
+
let countryCode;
|
|
127
|
+
if (this.sdkConfig?.discovery?.country && this.sdkConfig?.discovery?.region) {
|
|
128
|
+
log.info('Updating region and country from the SDK config', {
|
|
129
|
+
file: CALLING_CLIENT_FILE,
|
|
130
|
+
method: GET_MOBIUS_SERVERS_UTIL,
|
|
131
|
+
});
|
|
132
|
+
clientRegion = this.sdkConfig?.discovery?.region;
|
|
133
|
+
countryCode = this.sdkConfig?.discovery?.country;
|
|
134
|
+
}
|
|
135
|
+
else {
|
|
136
|
+
log.info('Updating region and country through Region discovery', {
|
|
137
|
+
file: CALLING_CLIENT_FILE,
|
|
138
|
+
method: GET_MOBIUS_SERVERS_UTIL,
|
|
139
|
+
});
|
|
140
|
+
const regionInfo = await this.getClientRegionInfo();
|
|
141
|
+
clientRegion = regionInfo.clientRegion;
|
|
142
|
+
countryCode = regionInfo.countryCode;
|
|
143
|
+
}
|
|
144
|
+
if (clientRegion && countryCode) {
|
|
145
|
+
log.log(`Found Region: ${clientRegion} and country: ${countryCode}, going to fetch Mobius server`, '');
|
|
146
|
+
try {
|
|
147
|
+
const temp = await this.webex.request({
|
|
148
|
+
uri: `${this.webex.internal.services._serviceUrls.mobius}${URL_ENDPOINT}?regionCode=${clientRegion}&countryCode=${countryCode}`,
|
|
149
|
+
method: HTTP_METHODS.GET,
|
|
150
|
+
headers: {
|
|
151
|
+
[CISCO_DEVICE_URL]: this.webex.internal.device.url,
|
|
152
|
+
[SPARK_USER_AGENT]: CALLING_USER_AGENT,
|
|
153
|
+
},
|
|
154
|
+
service: ALLOWED_SERVICES.MOBIUS,
|
|
155
|
+
});
|
|
156
|
+
log.log('Mobius Server found for the region', '');
|
|
157
|
+
const mobiusServers = temp.body;
|
|
158
|
+
const mobiusUris = filterMobiusUris(mobiusServers, this.webex.internal.services._serviceUrls.mobius);
|
|
159
|
+
this.primaryMobiusUris = mobiusUris.primary;
|
|
160
|
+
this.backupMobiusUris = mobiusUris.backup;
|
|
161
|
+
log.info(`Final list of Mobius Servers, primary: ${mobiusUris.primary} and backup: ${mobiusUris.backup}`, '');
|
|
162
|
+
}
|
|
163
|
+
catch (err) {
|
|
164
|
+
handleCallingClientErrors(err, (clientError) => {
|
|
165
|
+
this.metricManager.submitRegistrationMetric(METRIC_EVENT.REGISTRATION_ERROR, REG_ACTION.REGISTER, METRIC_TYPE.BEHAVIORAL, clientError);
|
|
166
|
+
this.emit(EVENT_KEYS.ERROR, clientError);
|
|
167
|
+
}, { method: GET_MOBIUS_SERVERS_UTIL, file: CALLING_CLIENT_FILE });
|
|
168
|
+
useDefault = true;
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
else {
|
|
172
|
+
useDefault = true;
|
|
173
|
+
}
|
|
174
|
+
if (useDefault) {
|
|
175
|
+
log.warn('Error in finding Mobius Servers. Will use the default URL.', '');
|
|
176
|
+
this.primaryMobiusUris = [
|
|
177
|
+
`${this.webex.internal.services._serviceUrls.mobius}${URL_ENDPOINT}`,
|
|
178
|
+
];
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
registerCallsClearedListener() {
|
|
182
|
+
const logContext = {
|
|
183
|
+
file: CALLING_CLIENT_FILE,
|
|
184
|
+
method: this.registerCallsClearedListener.name,
|
|
185
|
+
};
|
|
186
|
+
log.log('Registering listener for all calls cleared event', logContext);
|
|
187
|
+
this.callManager.on(EVENT_KEYS.ALL_CALLS_CLEARED, this.callsClearedHandler);
|
|
188
|
+
}
|
|
189
|
+
callsClearedHandler = async () => {
|
|
190
|
+
const { registration } = Object.values(this.lineDict)[0];
|
|
191
|
+
if (!registration.isDeviceRegistered()) {
|
|
192
|
+
await this.mutex.runExclusive(async () => {
|
|
193
|
+
if (registration.isReconnectPending()) {
|
|
194
|
+
log.log('All calls cleared, reconnecting', {
|
|
195
|
+
file: CALLING_CLIENT_FILE,
|
|
196
|
+
method: CALLS_CLEARED_HANDLER_UTIL,
|
|
197
|
+
});
|
|
198
|
+
await registration.reconnectOnFailure(CALLS_CLEARED_HANDLER_UTIL);
|
|
199
|
+
}
|
|
200
|
+
});
|
|
201
|
+
}
|
|
202
|
+
};
|
|
203
|
+
getLoggingLevel() {
|
|
204
|
+
return log.getLogLevel();
|
|
205
|
+
}
|
|
206
|
+
getCall = (correlationId) => {
|
|
207
|
+
return this.callManager.getCall(correlationId);
|
|
208
|
+
};
|
|
209
|
+
makeCall = (dest) => {
|
|
210
|
+
let call;
|
|
211
|
+
const { registration } = Object.values(this.lineDict)[0];
|
|
212
|
+
if (dest) {
|
|
213
|
+
const match = dest.address.match(VALID_PHONE);
|
|
214
|
+
if (match && match[0].length === dest.address.length) {
|
|
215
|
+
const sanitizedNumber = dest.address
|
|
216
|
+
.replace(/[^[*+]\d#]/gi, '')
|
|
217
|
+
.replace(/\s+/gi, '')
|
|
218
|
+
.replace(/-/gi, '');
|
|
219
|
+
const formattedDest = {
|
|
220
|
+
type: dest.type,
|
|
221
|
+
address: `tel:${sanitizedNumber}`,
|
|
222
|
+
};
|
|
223
|
+
call = this.callManager.createCall(formattedDest, CallDirection.OUTBOUND, registration.getDeviceInfo().device?.deviceId);
|
|
224
|
+
log.log(`New call created, callId: ${call.getCallId()}`, {});
|
|
225
|
+
}
|
|
226
|
+
else {
|
|
227
|
+
log.warn('Invalid phone number detected', {});
|
|
228
|
+
const err = new CallingClientError('An invalid phone number was detected. Check the number and try again.', {}, ERROR_TYPE.CALL_ERROR, MobiusStatus.ACTIVE);
|
|
229
|
+
this.emit(EVENT_KEYS.ERROR, err);
|
|
230
|
+
}
|
|
231
|
+
return call;
|
|
232
|
+
}
|
|
233
|
+
return undefined;
|
|
234
|
+
};
|
|
235
|
+
getSDKConnector() {
|
|
236
|
+
return this.sdkConnector;
|
|
237
|
+
}
|
|
238
|
+
registerSessionsListener() {
|
|
239
|
+
this.sdkConnector.registerListener(MOBIUS_EVENT_KEYS.CALL_SESSION_EVENT_INCLUSIVE, async (event) => {
|
|
240
|
+
if (event && event.data.userSessions.userSessions) {
|
|
241
|
+
const sessionArr = event?.data.userSessions.userSessions;
|
|
242
|
+
if (sessionArr.length === 1) {
|
|
243
|
+
if (sessionArr[0].sessionType !== SessionType.WEBEX_CALLING) {
|
|
244
|
+
return;
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
for (let i = 0; i < sessionArr.length; i += 1) {
|
|
248
|
+
if (sessionArr[i].sessionType !== SessionType.WEBEX_CALLING) {
|
|
249
|
+
sessionArr.splice(i, 1);
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
this.emit(EVENT_KEYS.USER_SESSION_INFO, event);
|
|
253
|
+
}
|
|
254
|
+
});
|
|
255
|
+
}
|
|
256
|
+
async createLine() {
|
|
257
|
+
const line = new Line(this.webex.internal.device.userId, this.webex.internal.device.url, LineStatus.INACTIVE, this.mutex, this.primaryMobiusUris, this.backupMobiusUris, this.getLoggingLevel(), this.sdkConfig?.serviceData);
|
|
258
|
+
this.lineDict[line.lineId] = line;
|
|
259
|
+
}
|
|
260
|
+
getLines() {
|
|
261
|
+
return this.lineDict;
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
export const createClient = async (webex, config) => {
|
|
265
|
+
const callingClientInstance = new CallingClient(webex, config);
|
|
266
|
+
await callingClientInstance.init();
|
|
267
|
+
return callingClientInstance;
|
|
268
|
+
};
|