@webex/calling 3.12.0-next.6 → 3.12.0-next.60
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/dist/CallingClient/CallingClient.js +454 -224
- package/dist/CallingClient/CallingClient.js.map +1 -1
- package/dist/CallingClient/CallingClient.test.js +513 -154
- package/dist/CallingClient/CallingClient.test.js.map +1 -1
- package/dist/CallingClient/calling/call.js +589 -445
- package/dist/CallingClient/calling/call.js.map +1 -1
- package/dist/CallingClient/calling/call.test.js +695 -445
- package/dist/CallingClient/calling/call.test.js.map +1 -1
- package/dist/CallingClient/calling/callManager.js +81 -31
- package/dist/CallingClient/calling/callManager.js.map +1 -1
- package/dist/CallingClient/calling/callManager.test.js +123 -0
- package/dist/CallingClient/calling/callManager.test.js.map +1 -1
- package/dist/CallingClient/calling/types.js +2 -0
- package/dist/CallingClient/calling/types.js.map +1 -1
- package/dist/CallingClient/constants.js +28 -3
- package/dist/CallingClient/constants.js.map +1 -1
- package/dist/CallingClient/line/index.js +4 -1
- package/dist/CallingClient/line/index.js.map +1 -1
- package/dist/CallingClient/line/line.test.js +16 -1
- package/dist/CallingClient/line/line.test.js.map +1 -1
- package/dist/CallingClient/registration/register.js +724 -407
- package/dist/CallingClient/registration/register.js.map +1 -1
- package/dist/CallingClient/registration/register.test.js +380 -58
- package/dist/CallingClient/registration/register.test.js.map +1 -1
- package/dist/CallingClient/registration/types.js.map +1 -1
- package/dist/CallingClient/registration/webWorker.js +41 -104
- package/dist/CallingClient/registration/webWorker.js.map +1 -1
- package/dist/CallingClient/registration/webWorker.test.js +39 -153
- package/dist/CallingClient/registration/webWorker.test.js.map +1 -1
- package/dist/CallingClient/registration/webWorkerStr.js +1 -1
- package/dist/CallingClient/registration/webWorkerStr.js.map +1 -1
- package/dist/CallingClient/types.js.map +1 -1
- package/dist/CallingClient/utils/constants.js +58 -0
- package/dist/CallingClient/utils/constants.js.map +1 -0
- package/dist/CallingClient/utils/index.js +63 -0
- package/dist/CallingClient/utils/index.js.map +1 -0
- package/dist/CallingClient/utils/mobiusSocketMapper.js +122 -0
- package/dist/CallingClient/utils/mobiusSocketMapper.js.map +1 -0
- package/dist/CallingClient/utils/mobiusSocketMapper.test.js +221 -0
- package/dist/CallingClient/utils/mobiusSocketMapper.test.js.map +1 -0
- package/dist/CallingClient/utils/request.js +435 -0
- package/dist/CallingClient/utils/request.js.map +1 -0
- package/dist/CallingClient/utils/request.test.js +999 -0
- package/dist/CallingClient/utils/request.test.js.map +1 -0
- package/dist/CallingClient/utils/types.js +7 -0
- package/dist/CallingClient/utils/types.js.map +1 -0
- package/dist/CallingClient/utils/wsFeatureFlag.js +70 -0
- package/dist/CallingClient/utils/wsFeatureFlag.js.map +1 -0
- package/dist/CallingClient/utils/wsFeatureFlag.test.js +139 -0
- package/dist/CallingClient/utils/wsFeatureFlag.test.js.map +1 -0
- package/dist/Contacts/ContactsClient.js +13 -11
- package/dist/Contacts/ContactsClient.js.map +1 -1
- package/dist/Contacts/ContactsClient.test.js +3 -8
- package/dist/Contacts/ContactsClient.test.js.map +1 -1
- package/dist/Events/types.js +11 -11
- package/dist/Events/types.js.map +1 -1
- package/dist/Metrics/index.js +63 -2
- package/dist/Metrics/index.js.map +1 -1
- package/dist/Metrics/index.test.js +357 -1
- package/dist/Metrics/index.test.js.map +1 -1
- package/dist/Metrics/types.js +19 -1
- package/dist/Metrics/types.js.map +1 -1
- package/dist/SDKConnector/types.js.map +1 -1
- package/dist/common/Utils.js +156 -51
- package/dist/common/Utils.js.map +1 -1
- package/dist/common/Utils.test.js +79 -0
- package/dist/common/Utils.test.js.map +1 -1
- package/dist/common/testUtil.js +8 -4
- package/dist/common/testUtil.js.map +1 -1
- package/dist/common/types.js +2 -0
- package/dist/common/types.js.map +1 -1
- package/dist/index.js +37 -5
- package/dist/index.js.map +1 -1
- package/dist/mobius-socket/config.js +24 -0
- package/dist/mobius-socket/config.js.map +1 -0
- package/dist/mobius-socket/errors.js +143 -0
- package/dist/mobius-socket/errors.js.map +1 -0
- package/dist/mobius-socket/errors.test.js +20 -0
- package/dist/mobius-socket/errors.test.js.map +1 -0
- package/dist/mobius-socket/index.js +57 -0
- package/dist/mobius-socket/index.js.map +1 -0
- package/dist/mobius-socket/mobius-socket-events.test.js +492 -0
- package/dist/mobius-socket/mobius-socket-events.test.js.map +1 -0
- package/dist/mobius-socket/mobius-socket.js +849 -0
- package/dist/mobius-socket/mobius-socket.js.map +1 -0
- package/dist/mobius-socket/mobius-socket.test.js +1898 -0
- package/dist/mobius-socket/mobius-socket.test.js.map +1 -0
- package/dist/mobius-socket/socket/constants.js +55 -0
- package/dist/mobius-socket/socket/constants.js.map +1 -0
- package/dist/mobius-socket/socket/index.js +15 -0
- package/dist/mobius-socket/socket/index.js.map +1 -0
- package/dist/mobius-socket/socket/socket-base.js +604 -0
- package/dist/mobius-socket/socket/socket-base.js.map +1 -0
- package/dist/mobius-socket/socket/socket.js +19 -0
- package/dist/mobius-socket/socket/socket.js.map +1 -0
- package/dist/mobius-socket/socket/socket.shim.js +26 -0
- package/dist/mobius-socket/socket/socket.shim.js.map +1 -0
- package/dist/mobius-socket/socket/types.js +7 -0
- package/dist/mobius-socket/socket/types.js.map +1 -0
- package/dist/mobius-socket/socket.test.js +727 -0
- package/dist/mobius-socket/socket.test.js.map +1 -0
- package/dist/mobius-socket/test/mocha-helpers.js +23 -0
- package/dist/mobius-socket/test/mocha-helpers.js.map +1 -0
- package/dist/mobius-socket/test/promise-tick.js +28 -0
- package/dist/mobius-socket/test/promise-tick.js.map +1 -0
- package/dist/mobius-socket/types.js +7 -0
- package/dist/mobius-socket/types.js.map +1 -0
- package/dist/module/CallingClient/CallingClient.js +126 -10
- package/dist/module/CallingClient/calling/call.js +177 -61
- package/dist/module/CallingClient/calling/callManager.js +39 -7
- package/dist/module/CallingClient/calling/types.js +2 -0
- package/dist/module/CallingClient/constants.js +24 -0
- package/dist/module/CallingClient/line/index.js +2 -2
- package/dist/module/CallingClient/registration/register.js +239 -63
- package/dist/module/CallingClient/registration/webWorker.js +42 -61
- package/dist/module/CallingClient/registration/webWorkerStr.js +47 -82
- package/dist/module/CallingClient/utils/constants.js +36 -0
- package/dist/module/CallingClient/utils/index.js +5 -0
- package/dist/module/CallingClient/utils/mobiusSocketMapper.js +72 -0
- package/dist/module/CallingClient/utils/request.js +211 -0
- package/dist/module/CallingClient/utils/types.js +1 -0
- package/dist/module/CallingClient/utils/wsFeatureFlag.js +41 -0
- package/dist/module/Contacts/ContactsClient.js +1 -1
- package/dist/module/Events/types.js +4 -10
- package/dist/module/Metrics/index.js +48 -1
- package/dist/module/Metrics/types.js +18 -0
- package/dist/module/common/Utils.js +60 -17
- package/dist/module/common/testUtil.js +5 -1
- package/dist/module/common/types.js +2 -0
- package/dist/module/index.js +3 -2
- package/dist/module/mobius-socket/config.js +15 -0
- package/dist/module/mobius-socket/errors.js +58 -0
- package/dist/module/mobius-socket/index.js +24 -0
- package/dist/module/mobius-socket/mobius-socket.js +593 -0
- package/dist/module/mobius-socket/socket/constants.js +26 -0
- package/dist/module/mobius-socket/socket/index.js +4 -0
- package/dist/module/mobius-socket/socket/socket-base.js +368 -0
- package/dist/module/mobius-socket/socket/socket.js +9 -0
- package/dist/module/mobius-socket/socket/socket.shim.js +12 -0
- package/dist/module/mobius-socket/socket/types.js +1 -0
- package/dist/module/mobius-socket/types.js +1 -0
- package/dist/types/CallingClient/CallingClient.d.ts +8 -0
- package/dist/types/CallingClient/CallingClient.d.ts.map +1 -1
- package/dist/types/CallingClient/calling/call.d.ts +12 -0
- package/dist/types/CallingClient/calling/call.d.ts.map +1 -1
- package/dist/types/CallingClient/calling/callManager.d.ts +4 -2
- package/dist/types/CallingClient/calling/callManager.d.ts.map +1 -1
- package/dist/types/CallingClient/calling/types.d.ts +34 -9
- package/dist/types/CallingClient/calling/types.d.ts.map +1 -1
- package/dist/types/CallingClient/constants.d.ts +24 -0
- package/dist/types/CallingClient/constants.d.ts.map +1 -1
- package/dist/types/CallingClient/line/index.d.ts +1 -1
- package/dist/types/CallingClient/line/index.d.ts.map +1 -1
- package/dist/types/CallingClient/registration/register.d.ts +7 -1
- package/dist/types/CallingClient/registration/register.d.ts.map +1 -1
- package/dist/types/CallingClient/registration/types.d.ts +4 -2
- package/dist/types/CallingClient/registration/types.d.ts.map +1 -1
- package/dist/types/CallingClient/registration/webWorker.d.ts.map +1 -1
- package/dist/types/CallingClient/registration/webWorkerStr.d.ts +1 -1
- package/dist/types/CallingClient/registration/webWorkerStr.d.ts.map +1 -1
- package/dist/types/CallingClient/types.d.ts +1 -0
- package/dist/types/CallingClient/types.d.ts.map +1 -1
- package/dist/types/CallingClient/utils/constants.d.ts +35 -0
- package/dist/types/CallingClient/utils/constants.d.ts.map +1 -0
- package/dist/types/CallingClient/utils/index.d.ts +6 -0
- package/dist/types/CallingClient/utils/index.d.ts.map +1 -0
- package/dist/types/CallingClient/utils/mobiusSocketMapper.d.ts +5 -0
- package/dist/types/CallingClient/utils/mobiusSocketMapper.d.ts.map +1 -0
- package/dist/types/CallingClient/utils/request.d.ts +28 -0
- package/dist/types/CallingClient/utils/request.d.ts.map +1 -0
- package/dist/types/CallingClient/utils/types.d.ts +34 -0
- package/dist/types/CallingClient/utils/types.d.ts.map +1 -0
- package/dist/types/CallingClient/utils/wsFeatureFlag.d.ts +4 -0
- package/dist/types/CallingClient/utils/wsFeatureFlag.d.ts.map +1 -0
- package/dist/types/Events/types.d.ts +14 -13
- package/dist/types/Events/types.d.ts.map +1 -1
- package/dist/types/Metrics/index.d.ts.map +1 -1
- package/dist/types/Metrics/types.d.ts +19 -2
- package/dist/types/Metrics/types.d.ts.map +1 -1
- package/dist/types/SDKConnector/types.d.ts +37 -12
- package/dist/types/SDKConnector/types.d.ts.map +1 -1
- package/dist/types/common/Utils.d.ts +11 -3
- package/dist/types/common/Utils.d.ts.map +1 -1
- package/dist/types/common/testUtil.d.ts +4 -1
- package/dist/types/common/testUtil.d.ts.map +1 -1
- package/dist/types/common/types.d.ts +3 -0
- package/dist/types/common/types.d.ts.map +1 -1
- package/dist/types/index.d.ts +4 -2
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/mobius-socket/config.d.ts +17 -0
- package/dist/types/mobius-socket/config.d.ts.map +1 -0
- package/dist/types/mobius-socket/errors.d.ts +32 -0
- package/dist/types/mobius-socket/errors.d.ts.map +1 -0
- package/dist/types/mobius-socket/index.d.ts +14 -0
- package/dist/types/mobius-socket/index.d.ts.map +1 -0
- package/dist/types/mobius-socket/mobius-socket.d.ts +48 -0
- package/dist/types/mobius-socket/mobius-socket.d.ts.map +1 -0
- package/dist/types/mobius-socket/socket/constants.d.ts +27 -0
- package/dist/types/mobius-socket/socket/constants.d.ts.map +1 -0
- package/dist/types/mobius-socket/socket/index.d.ts +5 -0
- package/dist/types/mobius-socket/socket/index.d.ts.map +1 -0
- package/dist/types/mobius-socket/socket/socket-base.d.ts +43 -0
- package/dist/types/mobius-socket/socket/socket-base.d.ts.map +1 -0
- package/dist/types/mobius-socket/socket/socket.d.ts +6 -0
- package/dist/types/mobius-socket/socket/socket.d.ts.map +1 -0
- package/dist/types/mobius-socket/socket/socket.shim.d.ts +6 -0
- package/dist/types/mobius-socket/socket/socket.shim.d.ts.map +1 -0
- package/dist/types/mobius-socket/socket/types.d.ts +61 -0
- package/dist/types/mobius-socket/socket/types.d.ts.map +1 -0
- package/dist/types/mobius-socket/types.d.ts +21 -0
- package/dist/types/mobius-socket/types.d.ts.map +1 -0
- package/package.json +20 -5
- package/src/mobius-socket/socket/socket.shim.ts +22 -0
- package/src/mobius-socket/socket/socket.ts +14 -0
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { v4 as uuid } from 'uuid';
|
|
2
1
|
import { METHOD_START_MESSAGE } from '../../common/constants';
|
|
3
2
|
import { emitFinalFailure, handleRegistrationErrors, uploadLogs } from '../../common';
|
|
4
3
|
import webWorkerStr from './webWorkerStr';
|
|
@@ -8,8 +7,9 @@ import { getCallManager } from '../calling';
|
|
|
8
7
|
import log from '../../Logger';
|
|
9
8
|
import SDKConnector from '../../SDKConnector';
|
|
10
9
|
import { ALLOWED_SERVICES, HTTP_METHODS, RegistrationStatus, ServiceIndicator, WorkerMessageType, } from '../../common/types';
|
|
11
|
-
import { CALLING_USER_AGENT, CISCO_DEVICE_URL, DEVICES_ENDPOINT_RESOURCE, SPARK_USER_AGENT,
|
|
10
|
+
import { CALLING_USER_AGENT, CISCO_DEVICE_URL, DEVICES_ENDPOINT_RESOURCE, SPARK_USER_AGENT, BASE_REG_RETRY_TIMER_VAL_IN_SEC, BASE_REG_TIMER_MFACTOR, SEC_TO_MSEC_MFACTOR, REG_RANDOM_T_FACTOR_UPPER_LIMIT, REG_TRY_BACKUP_TIMER_VAL_IN_SEC, MINUTES_TO_SEC_MFACTOR, REG_429_RETRY_UTIL, REG_FAILBACK_429_MAX_RETRIES, FAILBACK_UTIL, REGISTRATION_FILE, DEFAULT_REHOMING_INTERVAL_MIN, DEFAULT_REHOMING_INTERVAL_MAX, DEFAULT_KEEPALIVE_INTERVAL, FAILOVER_UTIL, REGISTER_UTIL, RETRY_TIMER_UPPER_LIMIT, KEEPALIVE_UTIL, REGISTRATION_UTIL, METHODS, URL_ENDPOINT, RECONNECT_ON_FAILURE_UTIL, FAILOVER_CACHE_PREFIX, } from '../constants';
|
|
12
11
|
import { LINE_EVENTS } from '../line/types';
|
|
12
|
+
import { APIRequest } from '../utils/request';
|
|
13
13
|
export class Registration {
|
|
14
14
|
sdkConnector;
|
|
15
15
|
webex;
|
|
@@ -36,6 +36,7 @@ export class Registration {
|
|
|
36
36
|
retryAfter;
|
|
37
37
|
scheduled429Retry = false;
|
|
38
38
|
webWorker;
|
|
39
|
+
apiRequest;
|
|
39
40
|
constructor(webex, serviceData, mutex, lineEmitter, logLevel, jwe) {
|
|
40
41
|
this.jwe = jwe;
|
|
41
42
|
this.sdkConnector = SDKConnector;
|
|
@@ -57,6 +58,12 @@ export class Registration {
|
|
|
57
58
|
this.lineEmitter = lineEmitter;
|
|
58
59
|
this.primaryMobiusUris = [];
|
|
59
60
|
this.backupMobiusUris = [];
|
|
61
|
+
this.apiRequest = APIRequest.getInstance({ webex: this.webex });
|
|
62
|
+
}
|
|
63
|
+
getServerType(url) {
|
|
64
|
+
return ((this.primaryMobiusUris.includes(url) && 'PRIMARY') ||
|
|
65
|
+
(this.backupMobiusUris?.includes(url) && 'BACKUP') ||
|
|
66
|
+
'UNKNOWN');
|
|
60
67
|
}
|
|
61
68
|
getFailoverCacheKey() {
|
|
62
69
|
return `${FAILOVER_CACHE_PREFIX}.${this.userId || 'unknown'}`;
|
|
@@ -131,16 +138,22 @@ export class Registration {
|
|
|
131
138
|
}
|
|
132
139
|
async deleteRegistration(url, deviceId, deviceUrl) {
|
|
133
140
|
let response;
|
|
141
|
+
const requestObj = {
|
|
142
|
+
uri: `${url}${DEVICES_ENDPOINT_RESOURCE}/${deviceId}`,
|
|
143
|
+
method: HTTP_METHODS.DELETE,
|
|
144
|
+
headers: {
|
|
145
|
+
[CISCO_DEVICE_URL]: deviceUrl,
|
|
146
|
+
[SPARK_USER_AGENT]: CALLING_USER_AGENT,
|
|
147
|
+
},
|
|
148
|
+
service: ALLOWED_SERVICES.MOBIUS,
|
|
149
|
+
};
|
|
150
|
+
if (this.apiRequest.isSocketEnabled()) {
|
|
151
|
+
requestObj.body = {
|
|
152
|
+
deviceId,
|
|
153
|
+
};
|
|
154
|
+
}
|
|
134
155
|
try {
|
|
135
|
-
response = await
|
|
136
|
-
method: HTTP_METHODS.DELETE,
|
|
137
|
-
headers: {
|
|
138
|
-
[CISCO_DEVICE_URL]: deviceUrl,
|
|
139
|
-
Authorization: await this.webex.credentials.getUserToken(),
|
|
140
|
-
trackingId: `${WEBEX_WEB_CLIENT}_${uuid()}`,
|
|
141
|
-
[SPARK_USER_AGENT]: CALLING_USER_AGENT,
|
|
142
|
-
},
|
|
143
|
-
});
|
|
156
|
+
response = await this.apiRequest.makeRequest(requestObj);
|
|
144
157
|
}
|
|
145
158
|
catch (error) {
|
|
146
159
|
log.warn(`Delete failed with Mobius: ${JSON.stringify(error)}`, {
|
|
@@ -151,7 +164,7 @@ export class Registration {
|
|
|
151
164
|
}
|
|
152
165
|
this.setStatus(RegistrationStatus.INACTIVE);
|
|
153
166
|
this.lineEmitter(LINE_EVENTS.UNREGISTERED);
|
|
154
|
-
return response
|
|
167
|
+
return response;
|
|
155
168
|
}
|
|
156
169
|
async postRegistration(url) {
|
|
157
170
|
const deviceInfo = {
|
|
@@ -159,7 +172,7 @@ export class Registration {
|
|
|
159
172
|
clientDeviceUri: this.webex.internal.device.url,
|
|
160
173
|
serviceData: this.jwe ? { ...this.serviceData, jwe: this.jwe } : this.serviceData,
|
|
161
174
|
};
|
|
162
|
-
return this.
|
|
175
|
+
return this.apiRequest.makeRequest({
|
|
163
176
|
uri: `${url}device`,
|
|
164
177
|
method: HTTP_METHODS.POST,
|
|
165
178
|
headers: {
|
|
@@ -171,7 +184,23 @@ export class Registration {
|
|
|
171
184
|
});
|
|
172
185
|
}
|
|
173
186
|
async restorePreviousRegistration(caller) {
|
|
187
|
+
const loggerContext = {
|
|
188
|
+
file: REGISTRATION_FILE,
|
|
189
|
+
method: METHODS.RESTORE_PREVIOUS_REGISTRATION,
|
|
190
|
+
};
|
|
191
|
+
log.info(`${METHOD_START_MESSAGE} - caller: ${caller}, activeMobiusUrl: ${this.activeMobiusUrl}`, loggerContext);
|
|
174
192
|
let abort = false;
|
|
193
|
+
if (this.apiRequest.isSocketEnabled() &&
|
|
194
|
+
`${this.apiRequest.getConnectedWebSocketUrl()}/` !== this.activeMobiusUrl) {
|
|
195
|
+
log.info(`Disconnecting from Mobius socket to restore previous registration.`, {
|
|
196
|
+
file: REGISTRATION_FILE,
|
|
197
|
+
method: 'restorePreviousRegistration',
|
|
198
|
+
});
|
|
199
|
+
await this.apiRequest.disconnectFromMobiusSocket({
|
|
200
|
+
code: 3050,
|
|
201
|
+
reason: 'done (permanent)',
|
|
202
|
+
});
|
|
203
|
+
}
|
|
175
204
|
if (this.activeMobiusUrl) {
|
|
176
205
|
abort = await this.attemptRegistrationWithServers(caller, [this.activeMobiusUrl]);
|
|
177
206
|
if (this.retryAfter) {
|
|
@@ -185,20 +214,31 @@ export class Registration {
|
|
|
185
214
|
abort = await this.attemptRegistrationWithServers(caller, this.backupMobiusUris);
|
|
186
215
|
}
|
|
187
216
|
else {
|
|
188
|
-
this.restartRegistration(caller);
|
|
217
|
+
await this.restartRegistration(caller);
|
|
189
218
|
}
|
|
190
219
|
this.retryAfter = undefined;
|
|
220
|
+
log.log(`restorePreviousRegistration completed via 429 retry-after path - caller: ${caller}`, loggerContext);
|
|
191
221
|
return true;
|
|
192
222
|
}
|
|
193
223
|
}
|
|
224
|
+
log.log(`restorePreviousRegistration completed - caller: ${caller}, deviceRegistered: ${this.isDeviceRegistered()}, abort: ${abort}`, loggerContext);
|
|
194
225
|
return abort;
|
|
195
226
|
}
|
|
196
227
|
async handle404KeepaliveFailure(caller) {
|
|
228
|
+
const loggerContext = {
|
|
229
|
+
file: REGISTRATION_FILE,
|
|
230
|
+
method: METHODS.HANDLE_404_KEEPALIVE_FAILURE,
|
|
231
|
+
};
|
|
232
|
+
log.info(`${METHOD_START_MESSAGE} - caller: ${caller}`, loggerContext);
|
|
197
233
|
if (caller === KEEPALIVE_UTIL) {
|
|
198
234
|
const abort = await this.attemptRegistrationWithServers(caller);
|
|
199
235
|
if (!abort && !this.isDeviceRegistered()) {
|
|
236
|
+
log.warn('Keepalive 404 recovery: re-registration did not complete, starting failover timer', loggerContext);
|
|
200
237
|
await this.startFailoverTimer();
|
|
201
238
|
}
|
|
239
|
+
else {
|
|
240
|
+
log.log(`Keepalive 404 recovery handled - deviceRegistered: ${this.isDeviceRegistered()}, abort: ${abort}`, loggerContext);
|
|
241
|
+
}
|
|
202
242
|
}
|
|
203
243
|
}
|
|
204
244
|
async handle429Retry(retryAfter, caller) {
|
|
@@ -228,7 +268,7 @@ export class Registration {
|
|
|
228
268
|
method: REG_429_RETRY_UTIL,
|
|
229
269
|
});
|
|
230
270
|
await this.startKeepaliveTimer(this.deviceInfo.device?.uri, this.deviceInfo.keepaliveInterval, 'UNKNOWN');
|
|
231
|
-
}, retryAfter * 1000);
|
|
271
|
+
}, (retryAfter - Number(this.deviceInfo.keepaliveInterval || 0)) * 1000);
|
|
232
272
|
}
|
|
233
273
|
else {
|
|
234
274
|
this.retryAfter = retryAfter;
|
|
@@ -279,6 +319,14 @@ export class Registration {
|
|
|
279
319
|
log.log(`Scheduled retry with primary in ${interval} seconds, number of attempts : ${attempt}`, loggerContext);
|
|
280
320
|
}
|
|
281
321
|
else if (this.backupMobiusUris.length) {
|
|
322
|
+
if (this.apiRequest.isSocketEnabled()) {
|
|
323
|
+
log.info('Disconnecting from primary Mobius socket for failover to backup servers', loggerContext);
|
|
324
|
+
await this.apiRequest.disconnectFromMobiusSocket({
|
|
325
|
+
code: 3050,
|
|
326
|
+
reason: 'done (permanent)',
|
|
327
|
+
});
|
|
328
|
+
log.log('Mobius socket disconnect complete prior to backup failover', loggerContext);
|
|
329
|
+
}
|
|
282
330
|
this.saveFailoverState({
|
|
283
331
|
attempt,
|
|
284
332
|
timeElapsed,
|
|
@@ -311,7 +359,7 @@ export class Registration {
|
|
|
311
359
|
await uploadLogs();
|
|
312
360
|
emitFinalFailure((clientError) => {
|
|
313
361
|
this.lineEmitter(LINE_EVENTS.ERROR, undefined, clientError);
|
|
314
|
-
}, loggerContext);
|
|
362
|
+
}, loggerContext, interval < 0 ? 'Timer threshold exceeded during failover' : undefined);
|
|
315
363
|
}
|
|
316
364
|
}
|
|
317
365
|
clearFailbackTimer() {
|
|
@@ -320,11 +368,25 @@ export class Registration {
|
|
|
320
368
|
this.failbackTimer = undefined;
|
|
321
369
|
}
|
|
322
370
|
}
|
|
371
|
+
async postKeepAlive(deviceUrl, url) {
|
|
372
|
+
return this.apiRequest.makeRequest({
|
|
373
|
+
uri: `${url}/status`,
|
|
374
|
+
method: HTTP_METHODS.POST,
|
|
375
|
+
headers: {
|
|
376
|
+
[CISCO_DEVICE_URL]: deviceUrl,
|
|
377
|
+
[SPARK_USER_AGENT]: CALLING_USER_AGENT,
|
|
378
|
+
},
|
|
379
|
+
body: {
|
|
380
|
+
deviceId: this.deviceInfo.device?.deviceId,
|
|
381
|
+
},
|
|
382
|
+
service: ALLOWED_SERVICES.MOBIUS,
|
|
383
|
+
});
|
|
384
|
+
}
|
|
323
385
|
async isPrimaryActive() {
|
|
324
386
|
let status;
|
|
325
387
|
for (const mobiusUrl of this.primaryMobiusUris) {
|
|
326
388
|
try {
|
|
327
|
-
const baseUri = mobiusUrl.replace(URL_ENDPOINT, '/');
|
|
389
|
+
const baseUri = mobiusUrl.replace(URL_ENDPOINT, '/').replace('wss://', 'https://');
|
|
328
390
|
const response = await this.webex.request({
|
|
329
391
|
uri: `${baseUri}ping`,
|
|
330
392
|
method: HTTP_METHODS.GET,
|
|
@@ -362,14 +424,23 @@ export class Registration {
|
|
|
362
424
|
this.rehomingIntervalMin);
|
|
363
425
|
}
|
|
364
426
|
initiateFailback() {
|
|
427
|
+
const loggerContext = {
|
|
428
|
+
file: REGISTRATION_FILE,
|
|
429
|
+
method: METHODS.INITIATE_FAILBACK,
|
|
430
|
+
};
|
|
365
431
|
if (this.isFailbackRequired()) {
|
|
366
432
|
if (!this.failbackTimer) {
|
|
367
433
|
this.failback429RetryAttempts = 0;
|
|
368
434
|
const intervalInMinutes = this.getFailbackInterval();
|
|
435
|
+
log.info(`Scheduling failback to primary - intervalMinutes: ${intervalInMinutes}`, loggerContext);
|
|
369
436
|
this.startFailbackTimer(intervalInMinutes * MINUTES_TO_SEC_MFACTOR);
|
|
370
437
|
}
|
|
438
|
+
else {
|
|
439
|
+
log.info('Failback timer already scheduled, skipping', loggerContext);
|
|
440
|
+
}
|
|
371
441
|
}
|
|
372
442
|
else {
|
|
443
|
+
log.info('Failback not required, clearing any pending failback timer', loggerContext);
|
|
373
444
|
this.failback429RetryAttempts = 0;
|
|
374
445
|
this.clearFailbackTimer();
|
|
375
446
|
}
|
|
@@ -382,15 +453,25 @@ export class Registration {
|
|
|
382
453
|
});
|
|
383
454
|
}
|
|
384
455
|
async executeFailback() {
|
|
456
|
+
const loggerContext = {
|
|
457
|
+
file: REGISTRATION_FILE,
|
|
458
|
+
method: METHODS.EXECUTE_FAILBACK,
|
|
459
|
+
};
|
|
460
|
+
log.info(METHOD_START_MESSAGE, loggerContext);
|
|
385
461
|
await this.mutex.runExclusive(async () => {
|
|
386
462
|
if (this.isFailbackRequired()) {
|
|
387
463
|
const primaryServerStatus = await this.isPrimaryActive();
|
|
388
464
|
if (Object.keys(this.callManager.getActiveCalls()).length === 0 && primaryServerStatus) {
|
|
389
|
-
log.info(`Attempting failback to primary.`,
|
|
390
|
-
file: REGISTRATION_FILE,
|
|
391
|
-
method: this.executeFailback.name,
|
|
392
|
-
});
|
|
465
|
+
log.info(`Attempting failback to primary.`, loggerContext);
|
|
393
466
|
await this.deregister();
|
|
467
|
+
if (this.apiRequest.isSocketEnabled()) {
|
|
468
|
+
log.info('Disconnecting from backup Mobius socket for failback to primary', loggerContext);
|
|
469
|
+
await this.apiRequest.disconnectFromMobiusSocket({
|
|
470
|
+
code: 3050,
|
|
471
|
+
reason: 'done (permanent)',
|
|
472
|
+
});
|
|
473
|
+
log.log('Mobius socket disconnect complete prior to primary failback', loggerContext);
|
|
474
|
+
}
|
|
394
475
|
const abort = await this.attemptRegistrationWithServers(FAILBACK_UTIL);
|
|
395
476
|
if (this.scheduled429Retry || abort || this.isDeviceRegistered()) {
|
|
396
477
|
return;
|
|
@@ -401,7 +482,7 @@ export class Registration {
|
|
|
401
482
|
return;
|
|
402
483
|
}
|
|
403
484
|
if (!this.isDeviceRegistered()) {
|
|
404
|
-
await this.restartRegistration(
|
|
485
|
+
await this.restartRegistration(loggerContext.method);
|
|
405
486
|
}
|
|
406
487
|
else {
|
|
407
488
|
this.failbackTimer = undefined;
|
|
@@ -409,10 +490,7 @@ export class Registration {
|
|
|
409
490
|
}
|
|
410
491
|
}
|
|
411
492
|
else {
|
|
412
|
-
log.info('Active calls present or primary Mobius is down, deferring failback to next cycle.',
|
|
413
|
-
file: REGISTRATION_FILE,
|
|
414
|
-
method: this.executeFailback.name,
|
|
415
|
-
});
|
|
493
|
+
log.info('Active calls present or primary Mobius is down, deferring failback to next cycle.', loggerContext);
|
|
416
494
|
this.failbackTimer = undefined;
|
|
417
495
|
this.initiateFailback();
|
|
418
496
|
}
|
|
@@ -442,12 +520,18 @@ export class Registration {
|
|
|
442
520
|
this.registrationStatus = value;
|
|
443
521
|
}
|
|
444
522
|
async restartRegistration(caller) {
|
|
523
|
+
const loggerContext = {
|
|
524
|
+
file: REGISTRATION_FILE,
|
|
525
|
+
method: METHODS.RESTART_REGISTRATION,
|
|
526
|
+
};
|
|
527
|
+
log.info(`${METHOD_START_MESSAGE} - caller: ${caller}`, loggerContext);
|
|
445
528
|
this.clearFailbackTimer();
|
|
446
529
|
this.failback429RetryAttempts = 0;
|
|
447
530
|
const abort = await this.attemptRegistrationWithServers(caller, this.primaryMobiusUris);
|
|
448
531
|
if (!abort && !this.isDeviceRegistered()) {
|
|
449
532
|
await this.startFailoverTimer();
|
|
450
533
|
}
|
|
534
|
+
log.log(`restartRegistration completed - caller: ${caller}, deviceRegistered: ${this.isDeviceRegistered()}, abort: ${abort}`, loggerContext);
|
|
451
535
|
}
|
|
452
536
|
async handleConnectionRestoration(retry) {
|
|
453
537
|
log.info(METHOD_START_MESSAGE, {
|
|
@@ -500,7 +584,13 @@ export class Registration {
|
|
|
500
584
|
};
|
|
501
585
|
}
|
|
502
586
|
async triggerRegistration() {
|
|
587
|
+
const loggerContext = {
|
|
588
|
+
file: REGISTRATION_FILE,
|
|
589
|
+
method: METHODS.TRIGGER_REGISTRATION,
|
|
590
|
+
};
|
|
591
|
+
log.info(METHOD_START_MESSAGE, loggerContext);
|
|
503
592
|
if (await this.resumeFailover()) {
|
|
593
|
+
log.info('Registration trigger handled by resumeFailover path', loggerContext);
|
|
504
594
|
return;
|
|
505
595
|
}
|
|
506
596
|
if (this.primaryMobiusUris.length > 0) {
|
|
@@ -508,43 +598,51 @@ export class Registration {
|
|
|
508
598
|
if (!this.isDeviceRegistered() && !abort) {
|
|
509
599
|
await this.startFailoverTimer();
|
|
510
600
|
}
|
|
601
|
+
log.log(`triggerRegistration completed - deviceRegistered: ${this.isDeviceRegistered()}, abort: ${abort}`, loggerContext);
|
|
602
|
+
}
|
|
603
|
+
else {
|
|
604
|
+
log.warn('triggerRegistration skipped: no primary Mobius URIs available', loggerContext);
|
|
511
605
|
}
|
|
512
606
|
}
|
|
513
607
|
async attemptRegistrationWithServers(caller, servers = this.primaryMobiusUris) {
|
|
608
|
+
const loggerContext = {
|
|
609
|
+
file: REGISTRATION_FILE,
|
|
610
|
+
method: REGISTER_UTIL,
|
|
611
|
+
};
|
|
514
612
|
let abort = false;
|
|
515
613
|
this.retryAfter = undefined;
|
|
614
|
+
let connectedWebSocketUrl;
|
|
516
615
|
if (this.failoverImmediately) {
|
|
517
616
|
return abort;
|
|
518
617
|
}
|
|
519
618
|
if (this.isDeviceRegistered()) {
|
|
520
|
-
log.info(`[${caller}] : Device already registered with : ${this.activeMobiusUrl}`,
|
|
521
|
-
file: REGISTRATION_FILE,
|
|
522
|
-
method: REGISTER_UTIL,
|
|
523
|
-
});
|
|
619
|
+
log.info(`[${caller}] : Device already registered with : ${this.activeMobiusUrl}`, loggerContext);
|
|
524
620
|
return abort;
|
|
525
621
|
}
|
|
622
|
+
if (servers.length) {
|
|
623
|
+
this.apiRequest.setSocketEnabled(servers[0].startsWith('wss://'));
|
|
624
|
+
}
|
|
526
625
|
for (const url of servers) {
|
|
527
|
-
const serverType =
|
|
528
|
-
(this.backupMobiusUris?.includes(url) && 'BACKUP') ||
|
|
529
|
-
'UNKNOWN';
|
|
626
|
+
const serverType = this.getServerType(url);
|
|
530
627
|
try {
|
|
531
628
|
abort = false;
|
|
532
629
|
this.registrationStatus = RegistrationStatus.INACTIVE;
|
|
533
630
|
this.lineEmitter(LINE_EVENTS.CONNECTING);
|
|
534
|
-
log.info(`[${caller}] : Mobius url to contact: ${url}`,
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
631
|
+
log.info(`[${caller}] : Mobius url to contact: ${url}`, loggerContext);
|
|
632
|
+
if (this.apiRequest.isSocketEnabled()) {
|
|
633
|
+
const wssNormalizedUrl = url.endsWith('/') ? url.slice(0, -1) : url;
|
|
634
|
+
log.info(`[${caller}] : Connecting to Mobius WebSocket - serverType: ${serverType}, wssUrl: ${wssNormalizedUrl}`, loggerContext);
|
|
635
|
+
connectedWebSocketUrl = await this.apiRequest.connectToMobiusSocket(wssNormalizedUrl);
|
|
636
|
+
connectedWebSocketUrl = connectedWebSocketUrl ? `${connectedWebSocketUrl}/` : undefined;
|
|
637
|
+
log.log(`[${caller}] : Mobius WebSocket connected - serverType: ${serverType}, connectedWebSocketUrl: ${connectedWebSocketUrl}`, loggerContext);
|
|
638
|
+
}
|
|
538
639
|
const resp = await this.postRegistration(url);
|
|
539
640
|
this.clearFailoverState();
|
|
540
641
|
this.deviceInfo = resp.body;
|
|
541
642
|
this.registrationStatus = RegistrationStatus.ACTIVE;
|
|
542
|
-
this.setActiveMobiusUrl(url);
|
|
643
|
+
this.setActiveMobiusUrl(connectedWebSocketUrl || url);
|
|
543
644
|
this.lineEmitter(LINE_EVENTS.REGISTERED, resp.body);
|
|
544
|
-
log.log(`Registration successful for deviceId: ${this.deviceInfo.device?.deviceId} userId: ${this.userId} responseTrackingId: ${resp.headers?.trackingid}`,
|
|
545
|
-
file: REGISTRATION_FILE,
|
|
546
|
-
method: METHODS.REGISTER,
|
|
547
|
-
});
|
|
645
|
+
log.log(`Registration successful for deviceId: ${this.deviceInfo.device?.deviceId} userId: ${this.userId} responseTrackingId: ${resp.headers?.trackingid}`, loggerContext);
|
|
548
646
|
this.setIntervalValues(this.deviceInfo);
|
|
549
647
|
this.metricManager.setDeviceInfo(this.deviceInfo);
|
|
550
648
|
this.metricManager.submitRegistrationMetric(METRIC_EVENT.REGISTRATION, REG_ACTION.REGISTER, METRIC_TYPE.BEHAVIORAL, caller, serverType, resp.headers?.trackingid ?? '', undefined, undefined);
|
|
@@ -554,22 +652,29 @@ export class Registration {
|
|
|
554
652
|
}
|
|
555
653
|
catch (err) {
|
|
556
654
|
const body = err;
|
|
557
|
-
|
|
558
|
-
if (
|
|
655
|
+
const { finalError, shouldDisconnect } = await handleRegistrationErrors(body, (clientError, isFinalError) => {
|
|
656
|
+
if (isFinalError) {
|
|
559
657
|
this.lineEmitter(LINE_EVENTS.ERROR, undefined, clientError);
|
|
560
658
|
}
|
|
561
659
|
else {
|
|
562
660
|
this.lineEmitter(LINE_EVENTS.UNREGISTERED);
|
|
563
661
|
}
|
|
564
662
|
this.metricManager.submitRegistrationMetric(METRIC_EVENT.REGISTRATION_ERROR, REG_ACTION.REGISTER, METRIC_TYPE.BEHAVIORAL, caller, serverType, body.headers?.trackingid ?? '', undefined, clientError);
|
|
565
|
-
}, { method: caller, file: REGISTRATION_FILE }, (retryAfter, retryCaller) => this.handle429Retry(retryAfter, retryCaller), this.restoreRegistrationCallBack());
|
|
663
|
+
}, { method: caller, file: REGISTRATION_FILE }, (retryAfter, retryCaller) => this.handle429Retry(retryAfter, retryCaller), this.restoreRegistrationCallBack(), servers.length);
|
|
664
|
+
abort = finalError;
|
|
566
665
|
if (this.registrationStatus === RegistrationStatus.ACTIVE) {
|
|
567
|
-
log.info(`[${caller}] : Device is already restored, active mobius url: ${this.activeMobiusUrl}`,
|
|
568
|
-
file: REGISTRATION_FILE,
|
|
569
|
-
method: this.attemptRegistrationWithServers.name,
|
|
570
|
-
});
|
|
666
|
+
log.info(`[${caller}] : Device is already restored, active mobius url: ${this.activeMobiusUrl}`, loggerContext);
|
|
571
667
|
break;
|
|
572
668
|
}
|
|
669
|
+
if (shouldDisconnect && this.apiRequest.isSocketEnabled()) {
|
|
670
|
+
connectedWebSocketUrl = undefined;
|
|
671
|
+
log.info(`[${caller}] : Tearing down Mobius WebSocket after registration error - serverType: ${serverType}`, loggerContext);
|
|
672
|
+
await this.apiRequest.disconnectFromMobiusSocket({
|
|
673
|
+
code: 3050,
|
|
674
|
+
reason: 'done (permanent)',
|
|
675
|
+
});
|
|
676
|
+
log.log(`[${caller}] : Mobius WebSocket disconnect complete after registration error - serverType: ${serverType}`, loggerContext);
|
|
677
|
+
}
|
|
573
678
|
if (abort) {
|
|
574
679
|
this.setStatus(RegistrationStatus.INACTIVE);
|
|
575
680
|
await uploadLogs();
|
|
@@ -584,7 +689,6 @@ export class Registration {
|
|
|
584
689
|
const RETRY_COUNT_THRESHOLD = this.isCCFlow ? 4 : 5;
|
|
585
690
|
await this.mutex.runExclusive(async () => {
|
|
586
691
|
if (this.isDeviceRegistered()) {
|
|
587
|
-
const accessToken = await this.webex.credentials.getUserToken();
|
|
588
692
|
if (!this.webWorker) {
|
|
589
693
|
const blob = new Blob([webWorkerStr], { type: 'application/javascript' });
|
|
590
694
|
const blobUrl = URL.createObjectURL(blob);
|
|
@@ -592,17 +696,38 @@ export class Registration {
|
|
|
592
696
|
URL.revokeObjectURL(blobUrl);
|
|
593
697
|
this.webWorker.postMessage({
|
|
594
698
|
type: WorkerMessageType.START_KEEPALIVE,
|
|
595
|
-
accessToken: String(accessToken),
|
|
596
|
-
deviceUrl: String(this.webex.internal.device.url),
|
|
597
699
|
interval,
|
|
598
700
|
retryCountThreshold: RETRY_COUNT_THRESHOLD,
|
|
599
|
-
url,
|
|
600
701
|
});
|
|
601
702
|
this.webWorker.onmessage = async (event) => {
|
|
602
703
|
const logContext = {
|
|
603
704
|
file: REGISTRATION_FILE,
|
|
604
705
|
method: KEEPALIVE_UTIL,
|
|
605
706
|
};
|
|
707
|
+
if (event.data.type === WorkerMessageType.SEND_KEEPALIVE) {
|
|
708
|
+
try {
|
|
709
|
+
const res = await this.postKeepAlive(String(this.webex.internal.device.url), url);
|
|
710
|
+
this.webWorker?.postMessage({
|
|
711
|
+
type: WorkerMessageType.KEEPALIVE_RESULT,
|
|
712
|
+
statusCode: res.statusCode,
|
|
713
|
+
});
|
|
714
|
+
}
|
|
715
|
+
catch (err) {
|
|
716
|
+
const error = {
|
|
717
|
+
headers: {
|
|
718
|
+
trackingid: err.headers?.trackingid,
|
|
719
|
+
'retry-after': err.headers['retry-after'],
|
|
720
|
+
},
|
|
721
|
+
statusCode: err.statusCode,
|
|
722
|
+
statusText: err.statusText,
|
|
723
|
+
type: err.type,
|
|
724
|
+
};
|
|
725
|
+
this.webWorker?.postMessage({
|
|
726
|
+
type: WorkerMessageType.KEEPALIVE_RESULT,
|
|
727
|
+
err: error,
|
|
728
|
+
});
|
|
729
|
+
}
|
|
730
|
+
}
|
|
606
731
|
if (event.data.type === WorkerMessageType.KEEPALIVE_SUCCESS) {
|
|
607
732
|
log.info(`Sent Keepalive, status: ${event.data.statusCode}`, logContext);
|
|
608
733
|
this.lineEmitter(LINE_EVENTS.RECONNECTED);
|
|
@@ -610,7 +735,7 @@ export class Registration {
|
|
|
610
735
|
if (event.data.type === WorkerMessageType.KEEPALIVE_FAILURE) {
|
|
611
736
|
const error = event.data.err;
|
|
612
737
|
log.warn(`Keep-alive missed ${event.data.keepAliveRetryCount} times. Status -> ${error.statusCode} `, logContext);
|
|
613
|
-
const abort = await handleRegistrationErrors(error, (clientError, finalError) => {
|
|
738
|
+
const { finalError: abort } = await handleRegistrationErrors(error, (clientError, finalError) => {
|
|
614
739
|
if (finalError) {
|
|
615
740
|
this.lineEmitter(LINE_EVENTS.ERROR, undefined, clientError);
|
|
616
741
|
}
|
|
@@ -649,19 +774,25 @@ export class Registration {
|
|
|
649
774
|
isReconnectPending() {
|
|
650
775
|
return this.reconnectPending;
|
|
651
776
|
}
|
|
652
|
-
async deregister() {
|
|
777
|
+
async deregister(closeMobiusWss = false) {
|
|
778
|
+
const loggerContext = {
|
|
779
|
+
file: REGISTRATION_FILE,
|
|
780
|
+
method: METHODS.DEREGISTER,
|
|
781
|
+
};
|
|
782
|
+
log.info(METHOD_START_MESSAGE, loggerContext);
|
|
653
783
|
try {
|
|
654
784
|
await this.deleteRegistration(this.activeMobiusUrl, this.deviceInfo.device?.deviceId, this.deviceInfo.device?.clientDeviceUri);
|
|
655
|
-
log.log('Registration successfully deregistered',
|
|
656
|
-
file: REGISTRATION_FILE,
|
|
657
|
-
method: METHODS.DEREGISTER,
|
|
658
|
-
});
|
|
785
|
+
log.log('Registration successfully deregistered', loggerContext);
|
|
659
786
|
}
|
|
660
787
|
catch (err) {
|
|
661
|
-
log.warn(`Delete failed with Mobius: ${JSON.stringify(err)}`,
|
|
662
|
-
|
|
663
|
-
|
|
788
|
+
log.warn(`Delete failed with Mobius: ${JSON.stringify(err)}`, loggerContext);
|
|
789
|
+
}
|
|
790
|
+
if (closeMobiusWss) {
|
|
791
|
+
await this.apiRequest.disconnectFromMobiusSocket({
|
|
792
|
+
code: 3050,
|
|
793
|
+
reason: 'done (permanent)',
|
|
664
794
|
});
|
|
795
|
+
log.log('Mobius socket disconnect complete after deregistration', loggerContext);
|
|
665
796
|
}
|
|
666
797
|
this.clearKeepaliveTimer();
|
|
667
798
|
this.setStatus(RegistrationStatus.INACTIVE);
|
|
@@ -683,7 +814,11 @@ export class Registration {
|
|
|
683
814
|
rehomingIntervalMin: DEFAULT_REHOMING_INTERVAL_MIN,
|
|
684
815
|
};
|
|
685
816
|
const stringToReplace = `${DEVICES_ENDPOINT_RESOURCE}/${restoreData.devices[0].deviceId}`;
|
|
686
|
-
|
|
817
|
+
let uri = restoreData.devices[0].uri.replace(stringToReplace, '');
|
|
818
|
+
if (this.apiRequest.isSocketEnabled()) {
|
|
819
|
+
uri = uri.replace('https://', 'wss://');
|
|
820
|
+
uri = !uri.endsWith('/') ? `${uri}/` : uri;
|
|
821
|
+
}
|
|
687
822
|
this.setActiveMobiusUrl(uri);
|
|
688
823
|
this.registrationStatus = RegistrationStatus.ACTIVE;
|
|
689
824
|
return true;
|
|
@@ -709,5 +844,46 @@ export class Registration {
|
|
|
709
844
|
}
|
|
710
845
|
}
|
|
711
846
|
}
|
|
847
|
+
async handleRegistrationDownEvent(event) {
|
|
848
|
+
const loggerContext = {
|
|
849
|
+
file: REGISTRATION_FILE,
|
|
850
|
+
method: METHODS.HANDLE_REGISTRATION_DOWN_EVENT,
|
|
851
|
+
};
|
|
852
|
+
log.info(`Registration down received - trackingId: ${event?.trackingId ?? 'unknown'}, eventId: ${event?.eventId ?? 'unknown'}`, loggerContext);
|
|
853
|
+
const [activeCall] = Object.values(this.callManager.getActiveCalls());
|
|
854
|
+
activeCall?.end();
|
|
855
|
+
await this.performRegistrationDownCleanup(METHODS.HANDLE_REGISTRATION_DOWN_EVENT);
|
|
856
|
+
}
|
|
857
|
+
async performRegistrationDownCleanup(caller) {
|
|
858
|
+
const loggerContext = {
|
|
859
|
+
file: REGISTRATION_FILE,
|
|
860
|
+
method: METHODS.HANDLE_REGISTRATION_DOWN_EVENT,
|
|
861
|
+
};
|
|
862
|
+
log.info(`[${caller}] : Running registration-down cleanup`, loggerContext);
|
|
863
|
+
await this.mutex.runExclusive(async () => {
|
|
864
|
+
this.clearFailbackTimer();
|
|
865
|
+
this.clearKeepaliveTimer();
|
|
866
|
+
this.reconnectPending = false;
|
|
867
|
+
this.scheduled429Retry = false;
|
|
868
|
+
this.failoverImmediately = false;
|
|
869
|
+
this.retryAfter = undefined;
|
|
870
|
+
this.registerRetry = false;
|
|
871
|
+
this.clearFailoverState();
|
|
872
|
+
this.setStatus(RegistrationStatus.INACTIVE);
|
|
873
|
+
if (this.apiRequest.isSocketEnabled()) {
|
|
874
|
+
try {
|
|
875
|
+
await this.apiRequest.disconnectFromMobiusSocket({
|
|
876
|
+
code: 3050,
|
|
877
|
+
reason: 'done (permanent)',
|
|
878
|
+
});
|
|
879
|
+
log.log('Mobius socket disconnect complete after registration-down', loggerContext);
|
|
880
|
+
}
|
|
881
|
+
catch (err) {
|
|
882
|
+
log.warn(`Mobius socket disconnect failed after registration-down: ${String(err)}`, loggerContext);
|
|
883
|
+
}
|
|
884
|
+
}
|
|
885
|
+
this.lineEmitter(LINE_EVENTS.UNREGISTERED);
|
|
886
|
+
});
|
|
887
|
+
}
|
|
712
888
|
}
|
|
713
889
|
export const createRegistration = (webex, serviceData, mutex, lineEmitter, logLevel, jwe) => new Registration(webex, serviceData, mutex, lineEmitter, logLevel, jwe);
|
|
@@ -1,73 +1,54 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { HTTP_METHODS, WorkerMessageType } from '../../common/types';
|
|
1
|
+
import { WorkerMessageType } from '../../common/types';
|
|
3
2
|
let keepaliveTimer;
|
|
3
|
+
let keepAliveRetryCount = 0;
|
|
4
|
+
let keepaliveInFlight = false;
|
|
5
|
+
const clearKeepaliveTimer = () => {
|
|
6
|
+
if (keepaliveTimer) {
|
|
7
|
+
clearInterval(keepaliveTimer);
|
|
8
|
+
keepaliveTimer = undefined;
|
|
9
|
+
}
|
|
10
|
+
};
|
|
4
11
|
const messageHandler = (event) => {
|
|
5
12
|
const { type } = event.data;
|
|
6
|
-
const postKeepAlive = async (accessToken, deviceUrl, url) => {
|
|
7
|
-
const response = await fetch(`${url}/status`, {
|
|
8
|
-
method: HTTP_METHODS.POST,
|
|
9
|
-
headers: {
|
|
10
|
-
'cisco-device-url': deviceUrl,
|
|
11
|
-
'spark-user-agent': 'webex-calling/beta',
|
|
12
|
-
Authorization: `${accessToken}`,
|
|
13
|
-
trackingId: `web_worker_${uuid()}`,
|
|
14
|
-
},
|
|
15
|
-
});
|
|
16
|
-
if (!response.ok) {
|
|
17
|
-
throw response;
|
|
18
|
-
}
|
|
19
|
-
return response;
|
|
20
|
-
};
|
|
21
13
|
if (type === WorkerMessageType.START_KEEPALIVE) {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
const statusCode = res.status;
|
|
33
|
-
if (keepAliveRetryCount > 0) {
|
|
34
|
-
postMessage({
|
|
35
|
-
type: WorkerMessageType.KEEPALIVE_SUCCESS,
|
|
36
|
-
statusCode,
|
|
37
|
-
});
|
|
38
|
-
}
|
|
39
|
-
keepAliveRetryCount = 0;
|
|
40
|
-
}
|
|
41
|
-
catch (err) {
|
|
42
|
-
const headers = {};
|
|
43
|
-
if (err.headers?.has('Retry-After')) {
|
|
44
|
-
headers['retry-after'] = err.headers.get('Retry-After');
|
|
45
|
-
}
|
|
46
|
-
if (err.headers?.has('Trackingid')) {
|
|
47
|
-
headers['trackingid'] = err.headers.get('Trackingid');
|
|
48
|
-
}
|
|
49
|
-
const error = {
|
|
50
|
-
headers,
|
|
51
|
-
statusCode: err.status,
|
|
52
|
-
statusText: err.statusText,
|
|
53
|
-
type: err.type,
|
|
54
|
-
};
|
|
55
|
-
keepAliveRetryCount += 1;
|
|
56
|
-
postMessage({
|
|
57
|
-
type: WorkerMessageType.KEEPALIVE_FAILURE,
|
|
58
|
-
err: error,
|
|
59
|
-
keepAliveRetryCount,
|
|
60
|
-
});
|
|
61
|
-
}
|
|
14
|
+
const { interval, retryCountThreshold } = event.data;
|
|
15
|
+
clearKeepaliveTimer();
|
|
16
|
+
keepAliveRetryCount = 0;
|
|
17
|
+
keepaliveInFlight = false;
|
|
18
|
+
keepaliveTimer = setInterval(() => {
|
|
19
|
+
if (keepAliveRetryCount < retryCountThreshold && !keepaliveInFlight) {
|
|
20
|
+
keepaliveInFlight = true;
|
|
21
|
+
postMessage({
|
|
22
|
+
type: WorkerMessageType.SEND_KEEPALIVE,
|
|
23
|
+
});
|
|
62
24
|
}
|
|
63
25
|
}, interval * 1000);
|
|
64
26
|
}
|
|
65
|
-
if (type === WorkerMessageType.
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
27
|
+
if (type === WorkerMessageType.KEEPALIVE_RESULT) {
|
|
28
|
+
keepaliveInFlight = false;
|
|
29
|
+
if (event.data.err === undefined) {
|
|
30
|
+
if (keepAliveRetryCount > 0) {
|
|
31
|
+
postMessage({
|
|
32
|
+
type: WorkerMessageType.KEEPALIVE_SUCCESS,
|
|
33
|
+
statusCode: event.data.statusCode,
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
keepAliveRetryCount = 0;
|
|
37
|
+
}
|
|
38
|
+
else {
|
|
39
|
+
keepAliveRetryCount += 1;
|
|
40
|
+
postMessage({
|
|
41
|
+
type: WorkerMessageType.KEEPALIVE_FAILURE,
|
|
42
|
+
err: event.data.err,
|
|
43
|
+
keepAliveRetryCount,
|
|
44
|
+
});
|
|
69
45
|
}
|
|
70
46
|
}
|
|
47
|
+
if (type === WorkerMessageType.CLEAR_KEEPALIVE) {
|
|
48
|
+
clearKeepaliveTimer();
|
|
49
|
+
keepAliveRetryCount = 0;
|
|
50
|
+
keepaliveInFlight = false;
|
|
51
|
+
}
|
|
71
52
|
};
|
|
72
53
|
self.addEventListener('message', messageHandler);
|
|
73
54
|
export default messageHandler;
|