@webex/calling 3.8.0-web-workers-keepalive.2 → 3.8.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/dist/CallHistory/CallHistory.js +100 -63
- package/dist/CallHistory/CallHistory.js.map +1 -1
- package/dist/CallHistory/CallHistory.test.js +115 -19
- package/dist/CallHistory/CallHistory.test.js.map +1 -1
- package/dist/CallHistory/constants.js +9 -1
- package/dist/CallHistory/constants.js.map +1 -1
- package/dist/CallSettings/CallSettings.js +46 -13
- package/dist/CallSettings/CallSettings.js.map +1 -1
- package/dist/CallSettings/UcmBackendConnector.js +62 -18
- package/dist/CallSettings/UcmBackendConnector.js.map +1 -1
- package/dist/CallSettings/UcmBackendConnector.test.js +70 -7
- package/dist/CallSettings/UcmBackendConnector.test.js.map +1 -1
- package/dist/CallSettings/WxCallBackendConnector.js +153 -103
- package/dist/CallSettings/WxCallBackendConnector.js.map +1 -1
- package/dist/CallSettings/WxCallBackendConnector.test.js +52 -15
- package/dist/CallSettings/WxCallBackendConnector.test.js.map +1 -1
- package/dist/CallSettings/constants.js +15 -1
- package/dist/CallSettings/constants.js.map +1 -1
- package/dist/CallingClient/CallingClient.js +220 -159
- package/dist/CallingClient/CallingClient.js.map +1 -1
- package/dist/CallingClient/CallingClient.test.js +53 -24
- package/dist/CallingClient/CallingClient.test.js.map +1 -1
- package/dist/CallingClient/calling/call.js +251 -189
- package/dist/CallingClient/calling/call.js.map +1 -1
- package/dist/CallingClient/calling/call.test.js +96 -41
- package/dist/CallingClient/calling/call.test.js.map +1 -1
- package/dist/CallingClient/calling/callManager.js +73 -48
- package/dist/CallingClient/calling/callManager.js.map +1 -1
- package/dist/CallingClient/calling/callManager.test.js +96 -37
- package/dist/CallingClient/calling/callManager.test.js.map +1 -1
- package/dist/CallingClient/constants.js +105 -3
- package/dist/CallingClient/constants.js.map +1 -1
- package/dist/CallingClient/line/index.js +47 -18
- package/dist/CallingClient/line/index.js.map +1 -1
- package/dist/CallingClient/line/line.test.js +12 -6
- package/dist/CallingClient/line/line.test.js.map +1 -1
- package/dist/CallingClient/registration/register.js +591 -529
- package/dist/CallingClient/registration/register.js.map +1 -1
- package/dist/CallingClient/registration/register.test.js +806 -457
- package/dist/CallingClient/registration/register.test.js.map +1 -1
- package/dist/CallingClient/registration/types.js.map +1 -1
- package/dist/Contacts/ContactsClient.js +156 -102
- package/dist/Contacts/ContactsClient.js.map +1 -1
- package/dist/Contacts/ContactsClient.test.js +197 -49
- package/dist/Contacts/ContactsClient.test.js.map +1 -1
- package/dist/Contacts/constants.js +11 -1
- package/dist/Contacts/constants.js.map +1 -1
- package/dist/Errors/types.js +2 -0
- package/dist/Errors/types.js.map +1 -1
- package/dist/Events/impl/index.js +1 -1
- package/dist/Events/impl/index.js.map +1 -1
- package/dist/Metrics/index.js +102 -41
- package/dist/Metrics/index.js.map +1 -1
- package/dist/Metrics/index.test.js +10 -4
- package/dist/Metrics/index.test.js.map +1 -1
- package/dist/Metrics/types.js +4 -1
- package/dist/Metrics/types.js.map +1 -1
- package/dist/SDKConnector/types.js.map +1 -1
- package/dist/Voicemail/BroadworksBackendConnector.js +154 -91
- package/dist/Voicemail/BroadworksBackendConnector.js.map +1 -1
- package/dist/Voicemail/BroadworksBackendConnector.test.js +99 -19
- package/dist/Voicemail/BroadworksBackendConnector.test.js.map +1 -1
- package/dist/Voicemail/UcmBackendConnector.js +105 -54
- package/dist/Voicemail/UcmBackendConnector.js.map +1 -1
- package/dist/Voicemail/UcmBackendConnector.test.js +127 -17
- package/dist/Voicemail/UcmBackendConnector.test.js.map +1 -1
- package/dist/Voicemail/Voicemail.js +198 -79
- package/dist/Voicemail/Voicemail.js.map +1 -1
- package/dist/Voicemail/Voicemail.test.js +188 -23
- package/dist/Voicemail/Voicemail.test.js.map +1 -1
- package/dist/Voicemail/WxCallBackendConnector.js +123 -76
- package/dist/Voicemail/WxCallBackendConnector.js.map +1 -1
- package/dist/Voicemail/WxCallBackendConnector.test.js +69 -6
- package/dist/Voicemail/WxCallBackendConnector.test.js.map +1 -1
- package/dist/Voicemail/constants.js +25 -1
- package/dist/Voicemail/constants.js.map +1 -1
- package/dist/common/Utils.js +168 -104
- package/dist/common/Utils.js.map +1 -1
- package/dist/common/Utils.test.js +199 -35
- package/dist/common/Utils.test.js.map +1 -1
- package/dist/common/constants.js +2 -1
- package/dist/common/constants.js.map +1 -1
- package/dist/common/types.js +1 -8
- package/dist/common/types.js.map +1 -1
- package/dist/module/CallHistory/CallHistory.js +32 -13
- package/dist/module/CallHistory/constants.js +6 -0
- package/dist/module/CallSettings/CallSettings.js +36 -3
- package/dist/module/CallSettings/UcmBackendConnector.js +50 -5
- package/dist/module/CallSettings/WxCallBackendConnector.js +54 -18
- package/dist/module/CallSettings/constants.js +12 -0
- package/dist/module/CallingClient/CallingClient.js +54 -16
- package/dist/module/CallingClient/calling/call.js +172 -121
- package/dist/module/CallingClient/calling/callManager.js +51 -26
- package/dist/module/CallingClient/constants.js +102 -2
- package/dist/module/CallingClient/line/index.js +37 -8
- package/dist/module/CallingClient/registration/register.js +151 -108
- package/dist/module/Contacts/ContactsClient.js +65 -21
- package/dist/module/Contacts/constants.js +10 -0
- package/dist/module/Errors/types.js +2 -0
- package/dist/module/Events/impl/index.js +1 -1
- package/dist/module/Metrics/index.js +57 -2
- package/dist/module/Metrics/types.js +3 -0
- package/dist/module/Voicemail/BroadworksBackendConnector.js +66 -17
- package/dist/module/Voicemail/UcmBackendConnector.js +51 -11
- package/dist/module/Voicemail/Voicemail.js +109 -9
- package/dist/module/Voicemail/WxCallBackendConnector.js +50 -17
- package/dist/module/Voicemail/constants.js +21 -0
- package/dist/module/common/Utils.js +51 -12
- package/dist/module/common/constants.js +1 -0
- package/dist/module/common/types.js +0 -7
- package/dist/types/CallHistory/CallHistory.d.ts.map +1 -1
- package/dist/types/CallHistory/constants.d.ts +6 -0
- package/dist/types/CallHistory/constants.d.ts.map +1 -1
- package/dist/types/CallSettings/CallSettings.d.ts.map +1 -1
- package/dist/types/CallSettings/UcmBackendConnector.d.ts.map +1 -1
- package/dist/types/CallSettings/WxCallBackendConnector.d.ts.map +1 -1
- package/dist/types/CallSettings/constants.d.ts +12 -0
- package/dist/types/CallSettings/constants.d.ts.map +1 -1
- package/dist/types/CallingClient/CallingClient.d.ts +2 -3
- package/dist/types/CallingClient/CallingClient.d.ts.map +1 -1
- package/dist/types/CallingClient/calling/call.d.ts.map +1 -1
- package/dist/types/CallingClient/calling/callManager.d.ts.map +1 -1
- package/dist/types/CallingClient/constants.d.ts +102 -2
- package/dist/types/CallingClient/constants.d.ts.map +1 -1
- package/dist/types/CallingClient/line/index.d.ts.map +1 -1
- package/dist/types/CallingClient/registration/register.d.ts +5 -2
- package/dist/types/CallingClient/registration/register.d.ts.map +1 -1
- package/dist/types/CallingClient/registration/types.d.ts +1 -0
- package/dist/types/CallingClient/registration/types.d.ts.map +1 -1
- package/dist/types/Contacts/ContactsClient.d.ts.map +1 -1
- package/dist/types/Contacts/constants.d.ts +10 -0
- package/dist/types/Contacts/constants.d.ts.map +1 -1
- package/dist/types/Errors/types.d.ts +2 -0
- package/dist/types/Errors/types.d.ts.map +1 -1
- package/dist/types/Metrics/index.d.ts +1 -1
- package/dist/types/Metrics/index.d.ts.map +1 -1
- package/dist/types/Metrics/types.d.ts +7 -2
- package/dist/types/Metrics/types.d.ts.map +1 -1
- package/dist/types/SDKConnector/types.d.ts +8 -2
- package/dist/types/SDKConnector/types.d.ts.map +1 -1
- package/dist/types/Voicemail/BroadworksBackendConnector.d.ts.map +1 -1
- package/dist/types/Voicemail/UcmBackendConnector.d.ts.map +1 -1
- package/dist/types/Voicemail/Voicemail.d.ts +1 -1
- package/dist/types/Voicemail/Voicemail.d.ts.map +1 -1
- package/dist/types/Voicemail/WxCallBackendConnector.d.ts.map +1 -1
- package/dist/types/Voicemail/constants.d.ts +21 -0
- package/dist/types/Voicemail/constants.d.ts.map +1 -1
- package/dist/types/common/Utils.d.ts +4 -4
- package/dist/types/common/Utils.d.ts.map +1 -1
- package/dist/types/common/constants.d.ts +1 -0
- package/dist/types/common/constants.d.ts.map +1 -1
- package/dist/types/common/types.d.ts +11 -11
- package/dist/types/common/types.d.ts.map +1 -1
- package/package.json +4 -5
- package/dist/CallingClient/registration/webWorker.js +0 -115
- package/dist/CallingClient/registration/webWorker.js.map +0 -1
- package/dist/CallingClient/registration/webWorker.test.js +0 -256
- package/dist/CallingClient/registration/webWorker.test.js.map +0 -1
- package/dist/module/CallingClient/registration/webWorker.js +0 -59
- package/dist/types/CallingClient/registration/webWorker.d.ts +0 -2
- package/dist/types/CallingClient/registration/webWorker.d.ts.map +0 -1
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { v4 as uuid } from 'uuid';
|
|
2
|
-
import {
|
|
3
|
-
import { emitFinalFailure, handleRegistrationErrors } from '../../common';
|
|
4
|
-
import { METRIC_EVENT, METRIC_TYPE, REG_ACTION } from '../../Metrics/types';
|
|
2
|
+
import { METHOD_START_MESSAGE } from '../../common/constants';
|
|
3
|
+
import { emitFinalFailure, handleRegistrationErrors, uploadLogs } from '../../common';
|
|
4
|
+
import { METRIC_EVENT, METRIC_TYPE, REG_ACTION, } from '../../Metrics/types';
|
|
5
5
|
import { getMetricManager } from '../../Metrics';
|
|
6
6
|
import { getCallManager } from '../calling';
|
|
7
7
|
import log from '../../Logger';
|
|
8
8
|
import SDKConnector from '../../SDKConnector';
|
|
9
|
-
import { ALLOWED_SERVICES, HTTP_METHODS, RegistrationStatus, ServiceIndicator,
|
|
10
|
-
import { CALLING_USER_AGENT, CISCO_DEVICE_URL, DEVICES_ENDPOINT_RESOURCE, SPARK_USER_AGENT, WEBEX_WEB_CLIENT, 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,
|
|
9
|
+
import { ALLOWED_SERVICES, HTTP_METHODS, RegistrationStatus, ServiceIndicator, } from '../../common/types';
|
|
10
|
+
import { CALLING_USER_AGENT, CISCO_DEVICE_URL, DEVICES_ENDPOINT_RESOURCE, SPARK_USER_AGENT, WEBEX_WEB_CLIENT, 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, REG_TRY_BACKUP_TIMER_VAL_FOR_CC_IN_SEC, FAILOVER_UTIL, REGISTER_UTIL, RETRY_TIMER_UPPER_LIMIT, KEEPALIVE_UTIL, REGISTRATION_UTIL, METHODS, } from '../constants';
|
|
11
11
|
import { LINE_EVENTS } from '../line/types';
|
|
12
12
|
export class Registration {
|
|
13
13
|
sdkConnector;
|
|
@@ -18,6 +18,7 @@ export class Registration {
|
|
|
18
18
|
registrationStatus;
|
|
19
19
|
failbackTimer;
|
|
20
20
|
activeMobiusUrl;
|
|
21
|
+
keepaliveTimer;
|
|
21
22
|
rehomingIntervalMin;
|
|
22
23
|
rehomingIntervalMax;
|
|
23
24
|
mutex;
|
|
@@ -32,7 +33,8 @@ export class Registration {
|
|
|
32
33
|
jwe;
|
|
33
34
|
isCCFlow = false;
|
|
34
35
|
failoverImmediately = false;
|
|
35
|
-
|
|
36
|
+
retryAfter;
|
|
37
|
+
scheduled429Retry = false;
|
|
36
38
|
constructor(webex, serviceData, mutex, lineEmitter, logLevel, jwe) {
|
|
37
39
|
this.jwe = jwe;
|
|
38
40
|
this.sdkConnector = SDKConnector;
|
|
@@ -59,14 +61,29 @@ export class Registration {
|
|
|
59
61
|
return this.activeMobiusUrl;
|
|
60
62
|
}
|
|
61
63
|
setActiveMobiusUrl(url) {
|
|
62
|
-
log.info(
|
|
64
|
+
log.info(`${METHOD_START_MESSAGE} with ${url}`, {
|
|
65
|
+
method: METHODS.UPDATE_ACTIVE_MOBIUS,
|
|
66
|
+
file: REGISTRATION_FILE,
|
|
67
|
+
});
|
|
63
68
|
this.activeMobiusUrl = url;
|
|
64
69
|
this.callManager.updateActiveMobius(url);
|
|
65
70
|
}
|
|
66
71
|
setMobiusServers(primaryMobiusUris, backupMobiusUris) {
|
|
72
|
+
log.log(METHOD_START_MESSAGE, { method: METHODS.SET_MOBIUS_SERVERS, file: REGISTRATION_FILE });
|
|
67
73
|
this.primaryMobiusUris = primaryMobiusUris;
|
|
68
74
|
this.backupMobiusUris = backupMobiusUris;
|
|
69
75
|
}
|
|
76
|
+
async postKeepAlive(url) {
|
|
77
|
+
return this.webex.request({
|
|
78
|
+
uri: `${url}/status`,
|
|
79
|
+
method: HTTP_METHODS.POST,
|
|
80
|
+
headers: {
|
|
81
|
+
[CISCO_DEVICE_URL]: this.webex.internal.device.url,
|
|
82
|
+
[SPARK_USER_AGENT]: CALLING_USER_AGENT,
|
|
83
|
+
},
|
|
84
|
+
service: ALLOWED_SERVICES.MOBIUS,
|
|
85
|
+
});
|
|
86
|
+
}
|
|
70
87
|
async deleteRegistration(url, deviceId, deviceUrl) {
|
|
71
88
|
let response;
|
|
72
89
|
try {
|
|
@@ -81,7 +98,10 @@ export class Registration {
|
|
|
81
98
|
});
|
|
82
99
|
}
|
|
83
100
|
catch (error) {
|
|
84
|
-
log.warn(`Delete failed with Mobius`, {
|
|
101
|
+
log.warn(`Delete failed with Mobius ${error}`, {
|
|
102
|
+
file: REGISTRATION_FILE,
|
|
103
|
+
method: METHODS.DEREGISTER,
|
|
104
|
+
});
|
|
85
105
|
}
|
|
86
106
|
this.setStatus(RegistrationStatus.INACTIVE);
|
|
87
107
|
this.lineEmitter(LINE_EVENTS.UNREGISTERED);
|
|
@@ -111,21 +131,27 @@ export class Registration {
|
|
|
111
131
|
}
|
|
112
132
|
return abort;
|
|
113
133
|
}
|
|
114
|
-
async
|
|
115
|
-
if (
|
|
116
|
-
|
|
134
|
+
async handle429Retry(retryAfter, caller) {
|
|
135
|
+
if (caller === FAILBACK_UTIL) {
|
|
136
|
+
if (this.failback429RetryAttempts >= REG_FAILBACK_429_MAX_RETRIES) {
|
|
137
|
+
return;
|
|
138
|
+
}
|
|
139
|
+
this.clearFailbackTimer();
|
|
140
|
+
this.failback429RetryAttempts += 1;
|
|
141
|
+
log.log(`Received 429 while rehoming, 429 retry count : ${this.failback429RetryAttempts}`, {
|
|
142
|
+
file: REGISTRATION_FILE,
|
|
143
|
+
method: REG_429_RETRY_UTIL,
|
|
144
|
+
});
|
|
145
|
+
const interval = this.getRegRetryInterval(this.failback429RetryAttempts);
|
|
146
|
+
this.startFailbackTimer(interval);
|
|
147
|
+
this.scheduled429Retry = true;
|
|
148
|
+
const abort = await this.restorePreviousRegistration(REG_429_RETRY_UTIL);
|
|
149
|
+
if (!abort && !this.isDeviceRegistered()) {
|
|
150
|
+
await this.restartRegistration(REG_429_RETRY_UTIL);
|
|
151
|
+
}
|
|
117
152
|
}
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
log.log(`Received 429 while rehoming, 429 retry count : ${this.failback429RetryAttempts}`, {
|
|
121
|
-
file: REGISTRATION_FILE,
|
|
122
|
-
method: FAILBACK_429_RETRY_UTIL,
|
|
123
|
-
});
|
|
124
|
-
const interval = this.getRegRetryInterval(this.failback429RetryAttempts);
|
|
125
|
-
this.startFailbackTimer(interval);
|
|
126
|
-
const abort = await this.restorePreviousRegistration(FAILBACK_429_RETRY_UTIL);
|
|
127
|
-
if (!abort && !this.isDeviceRegistered()) {
|
|
128
|
-
await this.restartRegistration(FAILBACK_429_RETRY_UTIL);
|
|
153
|
+
else {
|
|
154
|
+
this.retryAfter = retryAfter;
|
|
129
155
|
}
|
|
130
156
|
}
|
|
131
157
|
getRegRetryInterval(attempt = 1) {
|
|
@@ -138,7 +164,7 @@ export class Registration {
|
|
|
138
164
|
async startFailoverTimer(attempt = 1, timeElapsed = 0) {
|
|
139
165
|
const loggerContext = {
|
|
140
166
|
file: REGISTRATION_FILE,
|
|
141
|
-
method:
|
|
167
|
+
method: FAILOVER_UTIL,
|
|
142
168
|
};
|
|
143
169
|
let interval = this.getRegRetryInterval(attempt);
|
|
144
170
|
const TIMER_THRESHOLD = this.isCCFlow
|
|
@@ -148,12 +174,18 @@ export class Registration {
|
|
|
148
174
|
const excessVal = timeElapsed + interval - TIMER_THRESHOLD;
|
|
149
175
|
interval -= excessVal;
|
|
150
176
|
}
|
|
177
|
+
if (this.retryAfter != null && interval < this.retryAfter) {
|
|
178
|
+
this.failoverImmediately = this.retryAfter + timeElapsed > TIMER_THRESHOLD;
|
|
179
|
+
}
|
|
151
180
|
let abort;
|
|
152
181
|
if (interval > BASE_REG_RETRY_TIMER_VAL_IN_SEC && !this.failoverImmediately) {
|
|
153
182
|
const scheduledTime = Math.floor(Date.now() / 1000);
|
|
183
|
+
if (this.retryAfter != null) {
|
|
184
|
+
interval = Math.max(interval, this.retryAfter);
|
|
185
|
+
}
|
|
154
186
|
setTimeout(async () => {
|
|
155
187
|
await this.mutex.runExclusive(async () => {
|
|
156
|
-
abort = await this.attemptRegistrationWithServers(
|
|
188
|
+
abort = await this.attemptRegistrationWithServers(FAILOVER_UTIL);
|
|
157
189
|
const currentTime = Math.floor(Date.now() / 1000);
|
|
158
190
|
if (!abort && !this.isDeviceRegistered()) {
|
|
159
191
|
await this.startFailoverTimer(attempt + 1, timeElapsed + (currentTime - scheduledTime));
|
|
@@ -163,15 +195,19 @@ export class Registration {
|
|
|
163
195
|
log.log(`Scheduled retry with primary in ${interval} seconds, number of attempts : ${attempt}`, loggerContext);
|
|
164
196
|
}
|
|
165
197
|
else if (this.backupMobiusUris.length) {
|
|
166
|
-
log.
|
|
198
|
+
log.info('Failing over to backup servers.', loggerContext);
|
|
167
199
|
this.failoverImmediately = false;
|
|
168
|
-
abort = await this.attemptRegistrationWithServers(
|
|
200
|
+
abort = await this.attemptRegistrationWithServers(FAILOVER_UTIL, this.backupMobiusUris);
|
|
169
201
|
if (!abort && !this.isDeviceRegistered()) {
|
|
170
202
|
interval = this.getRegRetryInterval();
|
|
203
|
+
if (this.retryAfter != null && this.retryAfter < RETRY_TIMER_UPPER_LIMIT) {
|
|
204
|
+
interval = interval < this.retryAfter ? this.retryAfter : interval;
|
|
205
|
+
}
|
|
171
206
|
setTimeout(async () => {
|
|
172
207
|
await this.mutex.runExclusive(async () => {
|
|
173
|
-
abort = await this.attemptRegistrationWithServers(
|
|
208
|
+
abort = await this.attemptRegistrationWithServers(FAILOVER_UTIL, this.backupMobiusUris);
|
|
174
209
|
if (!abort && !this.isDeviceRegistered()) {
|
|
210
|
+
await uploadLogs();
|
|
175
211
|
emitFinalFailure((clientError) => {
|
|
176
212
|
this.lineEmitter(LINE_EVENTS.ERROR, undefined, clientError);
|
|
177
213
|
}, loggerContext);
|
|
@@ -182,6 +218,7 @@ export class Registration {
|
|
|
182
218
|
}
|
|
183
219
|
}
|
|
184
220
|
else {
|
|
221
|
+
await uploadLogs();
|
|
185
222
|
emitFinalFailure((clientError) => {
|
|
186
223
|
this.lineEmitter(LINE_EVENTS.ERROR, undefined, clientError);
|
|
187
224
|
}, loggerContext);
|
|
@@ -230,19 +267,20 @@ export class Registration {
|
|
|
230
267
|
});
|
|
231
268
|
await this.deregister();
|
|
232
269
|
const abort = await this.attemptRegistrationWithServers(FAILBACK_UTIL);
|
|
233
|
-
if (
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
270
|
+
if (this.scheduled429Retry || abort || this.isDeviceRegistered()) {
|
|
271
|
+
return;
|
|
272
|
+
}
|
|
273
|
+
const abortNew = await this.restorePreviousRegistration(FAILBACK_UTIL);
|
|
274
|
+
if (abortNew) {
|
|
275
|
+
this.clearFailbackTimer();
|
|
276
|
+
return;
|
|
277
|
+
}
|
|
278
|
+
if (!this.isDeviceRegistered()) {
|
|
279
|
+
await this.restartRegistration(this.executeFailback.name);
|
|
280
|
+
}
|
|
281
|
+
else {
|
|
282
|
+
this.failbackTimer = undefined;
|
|
283
|
+
this.initiateFailback();
|
|
246
284
|
}
|
|
247
285
|
}
|
|
248
286
|
else {
|
|
@@ -287,9 +325,13 @@ export class Registration {
|
|
|
287
325
|
}
|
|
288
326
|
}
|
|
289
327
|
async handleConnectionRestoration(retry) {
|
|
328
|
+
log.info(METHOD_START_MESSAGE, {
|
|
329
|
+
method: METHODS.HANDLE_CONNECTION_RESTORATION,
|
|
330
|
+
file: REGISTRATION_FILE,
|
|
331
|
+
});
|
|
290
332
|
await this.mutex.runExclusive(async () => {
|
|
291
333
|
if (retry) {
|
|
292
|
-
log.
|
|
334
|
+
log.log('Mercury connection is up again, re-registering with Webex Calling if needed', {
|
|
293
335
|
file: REGISTRATION_FILE,
|
|
294
336
|
method: this.handleConnectionRestoration.name,
|
|
295
337
|
});
|
|
@@ -334,7 +376,7 @@ export class Registration {
|
|
|
334
376
|
}
|
|
335
377
|
async triggerRegistration() {
|
|
336
378
|
if (this.primaryMobiusUris.length > 0) {
|
|
337
|
-
const abort = await this.attemptRegistrationWithServers(
|
|
379
|
+
const abort = await this.attemptRegistrationWithServers(REGISTRATION_UTIL, this.primaryMobiusUris);
|
|
338
380
|
if (!this.isDeviceRegistered() && !abort) {
|
|
339
381
|
await this.startFailoverTimer();
|
|
340
382
|
}
|
|
@@ -342,34 +384,42 @@ export class Registration {
|
|
|
342
384
|
}
|
|
343
385
|
async attemptRegistrationWithServers(caller, servers = this.primaryMobiusUris) {
|
|
344
386
|
let abort = false;
|
|
387
|
+
this.retryAfter = undefined;
|
|
345
388
|
if (this.failoverImmediately) {
|
|
346
389
|
return abort;
|
|
347
390
|
}
|
|
348
391
|
if (this.isDeviceRegistered()) {
|
|
349
|
-
log.
|
|
392
|
+
log.info(`[${caller}] : Device already registered with : ${this.activeMobiusUrl}`, {
|
|
350
393
|
file: REGISTRATION_FILE,
|
|
351
|
-
method:
|
|
394
|
+
method: REGISTER_UTIL,
|
|
352
395
|
});
|
|
353
396
|
return abort;
|
|
354
397
|
}
|
|
355
398
|
for (const url of servers) {
|
|
399
|
+
const serverType = (this.primaryMobiusUris.includes(url) && 'PRIMARY') ||
|
|
400
|
+
(this.backupMobiusUris?.includes(url) && 'BACKUP') ||
|
|
401
|
+
'UNKNOWN';
|
|
356
402
|
try {
|
|
357
403
|
abort = false;
|
|
358
404
|
this.registrationStatus = RegistrationStatus.INACTIVE;
|
|
359
405
|
this.lineEmitter(LINE_EVENTS.CONNECTING);
|
|
360
|
-
log.
|
|
406
|
+
log.info(`[${caller}] : Mobius url to contact: ${url}`, {
|
|
361
407
|
file: REGISTRATION_FILE,
|
|
362
|
-
method:
|
|
408
|
+
method: REGISTER_UTIL,
|
|
363
409
|
});
|
|
364
410
|
const resp = await this.postRegistration(url);
|
|
365
411
|
this.deviceInfo = resp.body;
|
|
366
412
|
this.registrationStatus = RegistrationStatus.ACTIVE;
|
|
367
413
|
this.lineEmitter(LINE_EVENTS.REGISTERED, resp.body);
|
|
414
|
+
log.log(`Registration successful for deviceId: ${this.deviceInfo.device?.deviceId} userId: ${this.userId}`, {
|
|
415
|
+
file: REGISTRATION_FILE,
|
|
416
|
+
method: METHODS.REGISTER,
|
|
417
|
+
});
|
|
368
418
|
this.setActiveMobiusUrl(url);
|
|
369
419
|
this.setIntervalValues(this.deviceInfo);
|
|
370
420
|
this.metricManager.setDeviceInfo(this.deviceInfo);
|
|
371
|
-
this.metricManager.submitRegistrationMetric(METRIC_EVENT.REGISTRATION, REG_ACTION.REGISTER, METRIC_TYPE.BEHAVIORAL, undefined);
|
|
372
|
-
this.startKeepaliveTimer(this.deviceInfo.device?.uri, this.deviceInfo.keepaliveInterval);
|
|
421
|
+
this.metricManager.submitRegistrationMetric(METRIC_EVENT.REGISTRATION, REG_ACTION.REGISTER, METRIC_TYPE.BEHAVIORAL, caller, serverType, resp.headers?.trackingid ?? '', undefined, undefined);
|
|
422
|
+
this.startKeepaliveTimer(this.deviceInfo.device?.uri, this.deviceInfo.keepaliveInterval, serverType);
|
|
373
423
|
this.initiateFailback();
|
|
374
424
|
break;
|
|
375
425
|
}
|
|
@@ -382,8 +432,8 @@ export class Registration {
|
|
|
382
432
|
else {
|
|
383
433
|
this.lineEmitter(LINE_EVENTS.UNREGISTERED);
|
|
384
434
|
}
|
|
385
|
-
this.metricManager.submitRegistrationMetric(METRIC_EVENT.REGISTRATION_ERROR, REG_ACTION.REGISTER, METRIC_TYPE.BEHAVIORAL, clientError);
|
|
386
|
-
}, { method:
|
|
435
|
+
this.metricManager.submitRegistrationMetric(METRIC_EVENT.REGISTRATION_ERROR, REG_ACTION.REGISTER, METRIC_TYPE.BEHAVIORAL, caller, serverType, body.headers?.trackingid ?? '', undefined, clientError);
|
|
436
|
+
}, { method: caller, file: REGISTRATION_FILE }, (retryAfter, retryCaller) => this.handle429Retry(retryAfter, retryCaller), this.restoreRegistrationCallBack());
|
|
387
437
|
if (this.registrationStatus === RegistrationStatus.ACTIVE) {
|
|
388
438
|
log.info(`[${caller}] : Device is already restored, active mobius url: ${this.activeMobiusUrl}`, {
|
|
389
439
|
file: REGISTRATION_FILE,
|
|
@@ -395,76 +445,61 @@ export class Registration {
|
|
|
395
445
|
this.setStatus(RegistrationStatus.INACTIVE);
|
|
396
446
|
break;
|
|
397
447
|
}
|
|
398
|
-
else if (caller === this.executeFailback.name) {
|
|
399
|
-
const error = body.statusCode;
|
|
400
|
-
if (error === ERROR_CODE.TOO_MANY_REQUESTS) {
|
|
401
|
-
await this.scheduleFailback429Retry();
|
|
402
|
-
abort = true;
|
|
403
|
-
break;
|
|
404
|
-
}
|
|
405
|
-
}
|
|
406
448
|
}
|
|
407
449
|
}
|
|
408
450
|
return abort;
|
|
409
451
|
}
|
|
410
|
-
|
|
452
|
+
startKeepaliveTimer(url, interval, serverType) {
|
|
453
|
+
let keepAliveRetryCount = 0;
|
|
411
454
|
this.clearKeepaliveTimer();
|
|
412
455
|
const RETRY_COUNT_THRESHOLD = this.isCCFlow ? 4 : 5;
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
url,
|
|
425
|
-
});
|
|
426
|
-
this.webWorker.onmessage = async (event) => {
|
|
427
|
-
const logContext = {
|
|
428
|
-
file: REGISTRATION_FILE,
|
|
429
|
-
method: this.startKeepaliveTimer.name,
|
|
430
|
-
};
|
|
431
|
-
if (event.data.type === WorkerMessageType.KEEPALIVE_SUCCESS) {
|
|
432
|
-
log.info(`Sent Keepalive, status: ${event.data.statusCode}`, logContext);
|
|
456
|
+
this.keepaliveTimer = setInterval(async () => {
|
|
457
|
+
const logContext = {
|
|
458
|
+
file: REGISTRATION_FILE,
|
|
459
|
+
method: KEEPALIVE_UTIL,
|
|
460
|
+
};
|
|
461
|
+
await this.mutex.runExclusive(async () => {
|
|
462
|
+
if (this.isDeviceRegistered() && keepAliveRetryCount < RETRY_COUNT_THRESHOLD) {
|
|
463
|
+
try {
|
|
464
|
+
const res = await this.postKeepAlive(url);
|
|
465
|
+
log.log(`Sent Keepalive, status: ${res.statusCode}`, logContext);
|
|
466
|
+
if (keepAliveRetryCount > 0) {
|
|
433
467
|
this.lineEmitter(LINE_EVENTS.RECONNECTED);
|
|
434
468
|
}
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
if (abort || event.data.keepAliveRetryCount >= RETRY_COUNT_THRESHOLD) {
|
|
445
|
-
this.failoverImmediately = this.isCCFlow;
|
|
446
|
-
this.setStatus(RegistrationStatus.INACTIVE);
|
|
447
|
-
this.clearKeepaliveTimer();
|
|
448
|
-
this.clearFailbackTimer();
|
|
449
|
-
this.lineEmitter(LINE_EVENTS.UNREGISTERED);
|
|
450
|
-
if (!abort) {
|
|
451
|
-
await this.reconnectOnFailure(this.startKeepaliveTimer.name);
|
|
452
|
-
}
|
|
469
|
+
keepAliveRetryCount = 0;
|
|
470
|
+
}
|
|
471
|
+
catch (err) {
|
|
472
|
+
keepAliveRetryCount += 1;
|
|
473
|
+
const error = err;
|
|
474
|
+
log.warn(`Keep-alive missed ${keepAliveRetryCount} times. Status -> ${error.statusCode} `, logContext);
|
|
475
|
+
const abort = await handleRegistrationErrors(error, (clientError, finalError) => {
|
|
476
|
+
if (finalError) {
|
|
477
|
+
this.lineEmitter(LINE_EVENTS.ERROR, undefined, clientError);
|
|
453
478
|
}
|
|
454
|
-
|
|
455
|
-
|
|
479
|
+
this.metricManager.submitRegistrationMetric(METRIC_EVENT.REGISTRATION, REG_ACTION.KEEPALIVE_FAILURE, METRIC_TYPE.BEHAVIORAL, KEEPALIVE_UTIL, serverType, error.headers?.trackingid ?? '', keepAliveRetryCount, clientError);
|
|
480
|
+
}, { method: KEEPALIVE_UTIL, file: REGISTRATION_FILE });
|
|
481
|
+
if (abort || keepAliveRetryCount >= RETRY_COUNT_THRESHOLD) {
|
|
482
|
+
this.failoverImmediately = this.isCCFlow;
|
|
483
|
+
this.setStatus(RegistrationStatus.INACTIVE);
|
|
484
|
+
this.clearKeepaliveTimer();
|
|
485
|
+
this.clearFailbackTimer();
|
|
486
|
+
this.lineEmitter(LINE_EVENTS.UNREGISTERED);
|
|
487
|
+
if (!abort) {
|
|
488
|
+
await this.reconnectOnFailure(KEEPALIVE_UTIL);
|
|
456
489
|
}
|
|
457
490
|
}
|
|
458
|
-
|
|
491
|
+
else {
|
|
492
|
+
this.lineEmitter(LINE_EVENTS.RECONNECTING);
|
|
493
|
+
}
|
|
494
|
+
}
|
|
459
495
|
}
|
|
460
|
-
}
|
|
461
|
-
});
|
|
496
|
+
});
|
|
497
|
+
}, interval * 1000);
|
|
462
498
|
}
|
|
463
499
|
clearKeepaliveTimer() {
|
|
464
|
-
if (this.
|
|
465
|
-
this.
|
|
466
|
-
this.
|
|
467
|
-
this.webWorker = undefined;
|
|
500
|
+
if (this.keepaliveTimer) {
|
|
501
|
+
clearInterval(this.keepaliveTimer);
|
|
502
|
+
this.keepaliveTimer = undefined;
|
|
468
503
|
}
|
|
469
504
|
}
|
|
470
505
|
isReconnectPending() {
|
|
@@ -473,9 +508,16 @@ export class Registration {
|
|
|
473
508
|
async deregister() {
|
|
474
509
|
try {
|
|
475
510
|
await this.deleteRegistration(this.activeMobiusUrl, this.deviceInfo.device?.deviceId, this.deviceInfo.device?.clientDeviceUri);
|
|
511
|
+
log.log('Registration successfully deregistered', {
|
|
512
|
+
file: REGISTRATION_FILE,
|
|
513
|
+
method: METHODS.DEREGISTER,
|
|
514
|
+
});
|
|
476
515
|
}
|
|
477
516
|
catch (err) {
|
|
478
|
-
log.warn(`Delete failed with Mobius`, {
|
|
517
|
+
log.warn(`Delete failed with Mobius: ${err}`, {
|
|
518
|
+
file: REGISTRATION_FILE,
|
|
519
|
+
method: METHODS.DEREGISTER,
|
|
520
|
+
});
|
|
479
521
|
}
|
|
480
522
|
this.clearKeepaliveTimer();
|
|
481
523
|
this.setStatus(RegistrationStatus.INACTIVE);
|
|
@@ -504,6 +546,7 @@ export class Registration {
|
|
|
504
546
|
return false;
|
|
505
547
|
}
|
|
506
548
|
async reconnectOnFailure(caller) {
|
|
549
|
+
log.info(METHOD_START_MESSAGE, { method: METHODS.RECONNECT_ON_FAILURE, file: REGISTRATION_FILE });
|
|
507
550
|
this.reconnectPending = false;
|
|
508
551
|
if (!this.isDeviceRegistered()) {
|
|
509
552
|
if (Object.keys(this.callManager.getActiveCalls()).length === 0) {
|
|
@@ -516,7 +559,7 @@ export class Registration {
|
|
|
516
559
|
this.reconnectPending = true;
|
|
517
560
|
log.info('Active call(s) present, deferred reconnect till call cleanup.', {
|
|
518
561
|
file: REGISTRATION_FILE,
|
|
519
|
-
method:
|
|
562
|
+
method: METHODS.RECONNECT_ON_FAILURE,
|
|
520
563
|
});
|
|
521
564
|
}
|
|
522
565
|
}
|