noibu-react-native 0.2.1 → 0.2.3
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 +1 -1
- package/android/src/main/java/com/noibu/sessionreplay/reactnative/NoibuSessionReplayModule.kt +10 -0
- package/dist/api/clientConfig.js +225 -217
- package/dist/api/metroplexSocket.js +406 -416
- package/dist/constants.js +14 -2
- package/dist/entry/init.js +58 -56
- package/dist/monitors/appNavigationMonitor.js +2 -3
- package/dist/monitors/clickMonitor.js +16 -9
- package/dist/monitors/errorMonitor.js +30 -8
- package/dist/monitors/gqlErrorValidator.js +4 -4
- package/dist/monitors/httpDataBundler.js +525 -713
- package/dist/monitors/integrations/react-native-navigation-integration.js +4 -2
- package/dist/monitors/requestMonitor.js +350 -365
- package/dist/pageVisit/eventDebouncer.js +110 -0
- package/dist/pageVisit/pageVisitEventError.js +1 -1
- package/dist/pageVisit/pageVisitEventHTTP.js +78 -93
- package/dist/react/ErrorBoundary.js +18 -15
- package/dist/sessionRecorder/nativeSessionRecorderSubscription.js +3 -2
- package/dist/sessionRecorder/sessionRecorder.js +151 -150
- package/dist/{api → src/api}/clientConfig.d.ts +1 -1
- package/dist/{api → src/api}/metroplexSocket.d.ts +25 -25
- package/dist/{constants.d.ts → src/constants.d.ts} +44 -0
- package/dist/{entry → src/entry}/init.d.ts +1 -1
- package/dist/{monitors → src/monitors}/clickMonitor.d.ts +1 -1
- package/dist/{monitors → src/monitors}/gqlErrorValidator.d.ts +6 -6
- package/dist/src/monitors/httpDataBundler.d.ts +127 -0
- package/dist/src/monitors/requestMonitor.d.ts +10 -0
- package/dist/src/pageVisit/eventDebouncer.d.ts +31 -0
- package/dist/src/pageVisit/pageVisitEventHTTP.d.ts +25 -0
- package/dist/{sessionRecorder → src/sessionRecorder}/types.d.ts +1 -1
- package/dist/{storage → src/storage}/rnStorageProvider.d.ts +1 -1
- package/dist/{storage → src/storage}/storage.d.ts +1 -1
- package/dist/{storage → src/storage}/storageProvider.d.ts +3 -3
- package/dist/{utils → src/utils}/function.d.ts +25 -4
- package/dist/{utils → src/utils}/object.d.ts +9 -4
- package/dist/src/utils/piiRedactor.d.ts +11 -0
- package/dist/src/utils/polyfills.d.ts +7 -0
- package/dist/storage/rnStorageProvider.js +7 -5
- package/dist/storage/storage.js +43 -35
- package/dist/storage/storageProvider.js +23 -19
- package/dist/types/Config.d.ts +24 -20
- package/dist/types/PageVisit.types.d.ts +151 -0
- package/dist/types/PageVisitMetrics.types.d.ts +27 -0
- package/dist/types/RRWeb.d.ts +48 -0
- package/dist/types/StoredPageVisit.types.d.ts +2 -4
- package/dist/types/WrappedObjects.d.ts +6 -0
- package/dist/utils/function.js +110 -76
- package/dist/utils/object.js +58 -6
- package/dist/utils/piiRedactor.js +98 -0
- package/dist/utils/polyfills.js +24 -0
- package/package.json +24 -9
- package/dist/monitors/httpDataBundler.d.ts +0 -161
- package/dist/monitors/requestMonitor.d.ts +0 -10
- package/dist/pageVisit/pageVisitEventHTTP.d.ts +0 -18
- package/dist/types/PageVisit.d.ts +0 -22
- package/dist/types/globals.d.ts +0 -45
- /package/dist/{api → src/api}/helpCode.d.ts +0 -0
- /package/dist/{api → src/api}/inputManager.d.ts +0 -0
- /package/dist/{api → src/api}/storedMetrics.d.ts +0 -0
- /package/dist/{api → src/api}/storedPageVisit.d.ts +0 -0
- /package/dist/{const_matchers.d.ts → src/const_matchers.d.ts} +0 -0
- /package/dist/{entry → src/entry}/index.d.ts +0 -0
- /package/dist/{monitors → src/monitors}/appNavigationMonitor.d.ts +0 -0
- /package/dist/{monitors → src/monitors}/errorMonitor.d.ts +0 -0
- /package/dist/{monitors → src/monitors}/inputMonitor.d.ts +0 -0
- /package/dist/{monitors → src/monitors}/integrations/react-native-navigation-integration.d.ts +0 -0
- /package/dist/{monitors → src/monitors}/keyboardInputMonitor.d.ts +0 -0
- /package/dist/{monitors → src/monitors}/pageMonitor.d.ts +0 -0
- /package/dist/{pageVisit → src/pageVisit}/pageVisit.d.ts +0 -0
- /package/dist/{pageVisit → src/pageVisit}/pageVisitEventError.d.ts +0 -0
- /package/dist/{pageVisit → src/pageVisit}/userStep.d.ts +0 -0
- /package/dist/{react → src/react}/ErrorBoundary.d.ts +0 -0
- /package/dist/{sessionRecorder → src/sessionRecorder}/nativeSessionRecorderSubscription.d.ts +0 -0
- /package/dist/{sessionRecorder → src/sessionRecorder}/sessionRecorder.d.ts +0 -0
- /package/dist/{utils → src/utils}/date.d.ts +0 -0
- /package/dist/{utils → src/utils}/eventlistener.d.ts +0 -0
- /package/dist/{utils → src/utils}/log.d.ts +0 -0
- /package/dist/{utils → src/utils}/performance.d.ts +0 -0
- /package/dist/{utils → src/utils}/stacktrace-parser.d.ts +0 -0
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { __awaiter } from 'tslib';
|
|
1
2
|
import uuid from 'react-native-uuid';
|
|
2
3
|
import { getUserAgent, stringifyJSON, getVideoRecorderType } from '../utils/function.js';
|
|
3
4
|
import { addSafeEventListener } from '../utils/eventlistener.js';
|
|
@@ -10,40 +11,8 @@ import { isDateOverwritten } from '../utils/date.js';
|
|
|
10
11
|
import { unwrapNoibuWrapped } from '../utils/object.js';
|
|
11
12
|
import { noibuLog } from '../utils/log.js';
|
|
12
13
|
|
|
13
|
-
/** @module MetroplexSocket */
|
|
14
14
|
/** Manages the socket to Metroplex */
|
|
15
15
|
class MetroplexSocket {
|
|
16
|
-
_initialURL;
|
|
17
|
-
ackedOnce;
|
|
18
|
-
connectionCount;
|
|
19
|
-
// promise that will resolve once the socket is connected and metroplex has acknowledged
|
|
20
|
-
connectionPromise;
|
|
21
|
-
connectionURL;
|
|
22
|
-
currentConnectionAttempts;
|
|
23
|
-
forceClosed;
|
|
24
|
-
helpCodeCb;
|
|
25
|
-
initialReferingURL;
|
|
26
|
-
static instance;
|
|
27
|
-
instanceId;
|
|
28
|
-
isRetryLoopDisabled;
|
|
29
|
-
latestReceivedSeqNumStoredTime;
|
|
30
|
-
latestReceivedSeqNumber;
|
|
31
|
-
messageSequenceNum;
|
|
32
|
-
metroRetryFrequencyMS;
|
|
33
|
-
metroplexTypeLock;
|
|
34
|
-
pageVisitInfoSent;
|
|
35
|
-
postURL;
|
|
36
|
-
previousMessageType;
|
|
37
|
-
retryMessageQueue;
|
|
38
|
-
retryMetroplexInterval;
|
|
39
|
-
scriptInstanceId;
|
|
40
|
-
sessionLength;
|
|
41
|
-
sessionStartTime;
|
|
42
|
-
sessionTimestamp;
|
|
43
|
-
socket;
|
|
44
|
-
socketInstanceId;
|
|
45
|
-
socketCloseCodes;
|
|
46
|
-
socketOpens;
|
|
47
16
|
/**
|
|
48
17
|
* Creates an instance of metroplex
|
|
49
18
|
* id of script, to make sure only a single socket is open
|
|
@@ -165,50 +134,54 @@ class MetroplexSocket {
|
|
|
165
134
|
* Queues the message if the connection isn't open yet.
|
|
166
135
|
* returns true if message was sent succefully, false otherwise
|
|
167
136
|
*/
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
137
|
+
sendMessage(type, payload) {
|
|
138
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
139
|
+
noibuLog('sendMessage start', { type, payload: JSON.stringify(payload) });
|
|
140
|
+
// if we have a lock on this specific type, we dont send it
|
|
141
|
+
if (type in this.metroplexTypeLock ||
|
|
142
|
+
ClientConfig.getInstance().isClientDisabled) {
|
|
143
|
+
noibuLog('sendMessage quitting due to', {
|
|
144
|
+
typeInLock: type in this.metroplexTypeLock,
|
|
145
|
+
isClientDisabled: ClientConfig.getInstance().isClientDisabled,
|
|
146
|
+
});
|
|
147
|
+
return false;
|
|
148
|
+
}
|
|
149
|
+
const payloadData = payload;
|
|
150
|
+
if (type !== WORK_REQUEST_ATT_NAME) {
|
|
151
|
+
// Increasing the message sequence number for every message we send to metroplex
|
|
152
|
+
// and move the data to the retry queue.
|
|
153
|
+
this._addSeqNumToPayload(type, payloadData);
|
|
154
|
+
// push the message to the retry queue immediately in case socket isnt connected
|
|
155
|
+
this.retryMessageQueue.push({ payload: payloadData, type });
|
|
156
|
+
StoredPageVisit.getInstance().checkAndStoreRetryQueue(this.retryMessageQueue, yield this.getPageInformation());
|
|
157
|
+
}
|
|
158
|
+
// send the socket message if we are connected and have sent page visit info
|
|
159
|
+
if (this.isConnected() && this.pageVisitInfoSent) {
|
|
160
|
+
// sending the data to metroplex
|
|
161
|
+
yield this._sendSocketMessage(payloadData);
|
|
162
|
+
}
|
|
163
|
+
this.previousMessageType = type;
|
|
164
|
+
// Only update the last message send if its a page visit with user action
|
|
165
|
+
// ensure this is done regardless of whether socket is connected or not,
|
|
166
|
+
// so that pagehide will post PV if user is active but socket is not
|
|
167
|
+
if (type === PV_METROPLEX_TYPE && payload[PAGE_VISIT_PART_ATT_NAME]) {
|
|
168
|
+
const events = payload[PAGE_VISIT_PART_ATT_NAME][PV_EVENTS_ATT_NAME]
|
|
169
|
+
? payload[PAGE_VISIT_PART_ATT_NAME][PV_EVENTS_ATT_NAME]
|
|
170
|
+
: [];
|
|
171
|
+
yield this._updateLatestPvTimestamp(events);
|
|
172
|
+
}
|
|
173
|
+
return true;
|
|
174
|
+
});
|
|
204
175
|
}
|
|
205
176
|
/** Updates the latest pv message sent timestamp if events contain any user steps
|
|
206
177
|
*/
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
178
|
+
_updateLatestPvTimestamp(events) {
|
|
179
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
180
|
+
const userstepsEvents = events.filter(ev => ev[TYPE_ATT_NAME] === USERSTEP_EVENT_TYPE);
|
|
181
|
+
if (userstepsEvents.length > 0) {
|
|
182
|
+
yield ClientConfig.getInstance().updateLastActiveTime(new Date());
|
|
183
|
+
}
|
|
184
|
+
});
|
|
212
185
|
}
|
|
213
186
|
/** returns true if the socket is either connecting or connected to metroplex */
|
|
214
187
|
isConnected() {
|
|
@@ -231,77 +204,79 @@ class MetroplexSocket {
|
|
|
231
204
|
}
|
|
232
205
|
/** Connects the web socket to metroplex and calls callback upon successfully connecting
|
|
233
206
|
*/
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
}
|
|
241
|
-
this.currentConnectionAttempts += 1;
|
|
242
|
-
this.socket = new WebSocket(this.connectionURL, undefined, {
|
|
243
|
-
headers: {
|
|
244
|
-
'User-Agent': await getUserAgent(), // must pass useragent explicitly
|
|
245
|
-
},
|
|
246
|
-
});
|
|
247
|
-
this.socketInstanceId = uuid.v4();
|
|
248
|
-
this.socket.onerror = error => {
|
|
249
|
-
noibuLog('metroplex handleConnect, onerror', { error });
|
|
250
|
-
// use for metrics
|
|
251
|
-
// there is no useful error message/description from this event
|
|
252
|
-
};
|
|
253
|
-
// once the socket closes
|
|
254
|
-
this.socket.onclose = async (event) => {
|
|
255
|
-
noibuLog('metroplex handleConnect, onclose', { event });
|
|
256
|
-
// Reset this to prevent sending messages before the PVI is sent on reconnect
|
|
257
|
-
this.pageVisitInfoSent = false;
|
|
258
|
-
// we do not reconnect if the page is unloading
|
|
259
|
-
if (this.forceClosed) {
|
|
260
|
-
return;
|
|
261
|
-
}
|
|
262
|
-
// track socket closure codes and times
|
|
263
|
-
this.socketCloseCodes.push(`${!isDateOverwritten() ? new Date().toISOString() : ''}:${event.code}`);
|
|
264
|
-
// we are already in the process of reconnecting
|
|
265
|
-
// we do not attempt to reconnect yet
|
|
266
|
-
if (this.isConnecting()) {
|
|
267
|
-
return;
|
|
268
|
-
}
|
|
269
|
-
// Clear the interval that resends unconfirmed msgs so we don't try send while the socket
|
|
270
|
-
// is and starting back up, after which it will be restarted
|
|
271
|
-
if (this.retryMetroplexInterval) {
|
|
272
|
-
clearInterval(this.retryMetroplexInterval);
|
|
273
|
-
}
|
|
274
|
-
// if we tried reconnecting too many times we abandon
|
|
275
|
-
if (this.currentConnectionAttempts >=
|
|
276
|
-
GET_MAX_METROPLEX_RECONNECTION_NUMBER()) {
|
|
277
|
-
// if we tried beyond the threshold, we block ourselves a short
|
|
278
|
-
// while fix the issue
|
|
279
|
-
await ClientConfig.getInstance().lockClientUntilNextPage('Too many reconnection attempts, locking until next page');
|
|
280
|
-
return;
|
|
281
|
-
}
|
|
282
|
-
// if we tried reconnecting too many times we abandon
|
|
283
|
-
if (this.connectionCount >= MAX_METROPLEX_CONNECTION_COUNT) {
|
|
284
|
-
// if we tried beyond the threshold, we block ourselves a short
|
|
285
|
-
// while while fix the issue
|
|
286
|
-
await ClientConfig.getInstance().lockClientUntilNextPage('Too many connections, locking until next page');
|
|
207
|
+
handleConnect(forceOpen) {
|
|
208
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
209
|
+
noibuLog('metroplex handleConnect');
|
|
210
|
+
// if we are connected or about to connect, we do not reset
|
|
211
|
+
// the socket information
|
|
212
|
+
if (!forceOpen && (this.isConnected() || this.isConnecting())) {
|
|
287
213
|
return;
|
|
288
214
|
}
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
//
|
|
302
|
-
this.
|
|
303
|
-
|
|
304
|
-
|
|
215
|
+
this.currentConnectionAttempts += 1;
|
|
216
|
+
this.socket = new WebSocket(this.connectionURL, undefined, {
|
|
217
|
+
headers: {
|
|
218
|
+
'User-Agent': yield getUserAgent(), // must pass useragent explicitly
|
|
219
|
+
},
|
|
220
|
+
});
|
|
221
|
+
this.socketInstanceId = uuid.v4();
|
|
222
|
+
this.socket.onerror = error => {
|
|
223
|
+
noibuLog('metroplex handleConnect, onerror', { error });
|
|
224
|
+
// use for metrics
|
|
225
|
+
// there is no useful error message/description from this event
|
|
226
|
+
};
|
|
227
|
+
// once the socket closes
|
|
228
|
+
this.socket.onclose = (event) => __awaiter(this, void 0, void 0, function* () {
|
|
229
|
+
noibuLog('metroplex handleConnect, onclose', { event });
|
|
230
|
+
// Reset this to prevent sending messages before the PVI is sent on reconnect
|
|
231
|
+
this.pageVisitInfoSent = false;
|
|
232
|
+
// we do not reconnect if the page is unloading
|
|
233
|
+
if (this.forceClosed) {
|
|
234
|
+
return;
|
|
235
|
+
}
|
|
236
|
+
// track socket closure codes and times
|
|
237
|
+
this.socketCloseCodes.push(`${!isDateOverwritten() ? new Date().toISOString() : ''}:${event.code}`);
|
|
238
|
+
// we are already in the process of reconnecting
|
|
239
|
+
// we do not attempt to reconnect yet
|
|
240
|
+
if (this.isConnecting()) {
|
|
241
|
+
return;
|
|
242
|
+
}
|
|
243
|
+
// Clear the interval that resends unconfirmed msgs so we don't try send while the socket
|
|
244
|
+
// is and starting back up, after which it will be restarted
|
|
245
|
+
if (this.retryMetroplexInterval) {
|
|
246
|
+
clearInterval(this.retryMetroplexInterval);
|
|
247
|
+
}
|
|
248
|
+
// if we tried reconnecting too many times we abandon
|
|
249
|
+
if (this.currentConnectionAttempts >=
|
|
250
|
+
GET_MAX_METROPLEX_RECONNECTION_NUMBER()) {
|
|
251
|
+
// if we tried beyond the threshold, we block ourselves a short
|
|
252
|
+
// while fix the issue
|
|
253
|
+
yield ClientConfig.getInstance().lockClientUntilNextPage('Too many reconnection attempts, locking until next page');
|
|
254
|
+
return;
|
|
255
|
+
}
|
|
256
|
+
// if we tried reconnecting too many times we abandon
|
|
257
|
+
if (this.connectionCount >= MAX_METROPLEX_CONNECTION_COUNT) {
|
|
258
|
+
// if we tried beyond the threshold, we block ourselves a short
|
|
259
|
+
// while while fix the issue
|
|
260
|
+
yield ClientConfig.getInstance().lockClientUntilNextPage('Too many connections, locking until next page');
|
|
261
|
+
return;
|
|
262
|
+
}
|
|
263
|
+
// try to reconnect on close but after a certain delay based off unsuccessful connections
|
|
264
|
+
setTimeout(() => {
|
|
265
|
+
this.handleConnect(false);
|
|
266
|
+
}, Math.pow(this.currentConnectionAttempts, 2) * GET_METROPLEX_CONSECUTIVE_CONNECTION_DELAY());
|
|
267
|
+
});
|
|
268
|
+
// everytime we get a message from the socket
|
|
269
|
+
this.socket.onmessage = event => {
|
|
270
|
+
noibuLog('metroplex handleConnect, onmessage', { event });
|
|
271
|
+
this._onSocketMessage(event);
|
|
272
|
+
};
|
|
273
|
+
// the moment we open the socket
|
|
274
|
+
this.socket.onopen = () => {
|
|
275
|
+
// track socket open codes and times
|
|
276
|
+
this.socketOpens.push(`${!isDateOverwritten() ? new Date().toISOString() : ''}`);
|
|
277
|
+
this._onSocketOpen();
|
|
278
|
+
};
|
|
279
|
+
});
|
|
305
280
|
}
|
|
306
281
|
/**
|
|
307
282
|
* connectSocket will establish a websocket connection to the metroplex
|
|
@@ -328,95 +303,96 @@ class MetroplexSocket {
|
|
|
328
303
|
if (isPageVisit) {
|
|
329
304
|
this.sessionLength = delta;
|
|
330
305
|
}
|
|
331
|
-
return {
|
|
332
|
-
...payload,
|
|
333
|
-
[END_AT_ATT_NAME]: new Date(this.sessionTimestamp.getTime() + delta).toISOString(),
|
|
334
|
-
};
|
|
306
|
+
return Object.assign(Object.assign({}, payload), { [END_AT_ATT_NAME]: new Date(this.sessionTimestamp.getTime() + delta).toISOString() });
|
|
335
307
|
}
|
|
336
308
|
/** open handler for socket */
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
309
|
+
_onSocketOpen() {
|
|
310
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
311
|
+
// if we are not connected, we do not send any messages
|
|
312
|
+
if (!this.isConnected() || ClientConfig.getInstance().isClientDisabled) {
|
|
313
|
+
return;
|
|
314
|
+
}
|
|
315
|
+
yield this._sendSocketMessage(yield this.getPageInformation());
|
|
316
|
+
// Set this to allow normal page visit and video frag messages to be sent
|
|
317
|
+
this.pageVisitInfoSent = true;
|
|
318
|
+
this.currentConnectionAttempts = 0;
|
|
319
|
+
// Resend the pagevisit or video message type before sending data so reset the prev type
|
|
320
|
+
this.previousMessageType = '';
|
|
321
|
+
// attempt to send the unconfirmed messages again
|
|
322
|
+
yield this._sendUnconfirmedMessages(false);
|
|
323
|
+
// setting up the socket retry mechanism
|
|
324
|
+
this.setupRetryMechanism();
|
|
325
|
+
// increasing the connection count everytime we connect
|
|
326
|
+
this.connectionCount += 1;
|
|
327
|
+
});
|
|
354
328
|
}
|
|
355
329
|
/** message handler for socket
|
|
356
330
|
* @param {} event
|
|
357
331
|
*/
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
332
|
+
_onSocketMessage(event) {
|
|
333
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
334
|
+
switch (event.data) {
|
|
335
|
+
case STOP_STORING_VID_SOCKET_MESSAGE:
|
|
336
|
+
// stopping vids from being sent
|
|
337
|
+
this.metroplexTypeLock[VIDEO_METROPLEX_TYPE] = true;
|
|
338
|
+
StoredMetrics.getInstance().setDidCutVideo();
|
|
339
|
+
break;
|
|
340
|
+
case STOP_STORING_PV_SOCKET_MESSAGE:
|
|
341
|
+
// stopping pv from being sent
|
|
342
|
+
this.metroplexTypeLock[PV_METROPLEX_TYPE] = true;
|
|
343
|
+
StoredMetrics.getInstance().setDidCutPv();
|
|
344
|
+
break;
|
|
345
|
+
case BLOCK_SOCKET_MESSAGE:
|
|
346
|
+
// we are disabling collect for 1 day if we get the
|
|
347
|
+
// block message from metroplex. We are probably on it
|
|
348
|
+
yield ClientConfig.getInstance().lockClient(1440, 'Metroplex blocked script');
|
|
349
|
+
this.close();
|
|
350
|
+
break;
|
|
351
|
+
case CLOSE_CONNECTION_FORCEFULLY:
|
|
352
|
+
this.close();
|
|
353
|
+
break;
|
|
354
|
+
case OK_SOCKET_MESSAGE:
|
|
355
|
+
// we do nothing on an OK
|
|
356
|
+
break;
|
|
357
|
+
default:
|
|
358
|
+
// we now need to check if we receive text that contains
|
|
359
|
+
// the text SEQ_NUM. if that is true, then its a seq num
|
|
360
|
+
// and we need to clear out the retry queue.
|
|
361
|
+
if (event.data.includes(SEQ_NUM_ATT_NAME)) {
|
|
362
|
+
const seqNumSplit = event.data.split(`${SEQ_NUM_ATT_NAME}:`);
|
|
363
|
+
if (seqNumSplit.length < 2) {
|
|
364
|
+
ClientConfig.getInstance().postNoibuErrorAndOptionallyDisableClient(`Invalid message received from metroplex while clearing retry queue ${event.data}`, false, SEVERITY.error);
|
|
365
|
+
break;
|
|
366
|
+
}
|
|
367
|
+
// the second element in the string split is the sequence number
|
|
368
|
+
const seqNum = parseInt(seqNumSplit[1], 10);
|
|
369
|
+
// ignore sequence num if this is just page info, it will always be -1 and we don't want
|
|
370
|
+
// to disable the retry loop on this
|
|
371
|
+
if (seqNum === -1) {
|
|
372
|
+
break;
|
|
373
|
+
}
|
|
374
|
+
// we disable the retry loop if we start running behind
|
|
375
|
+
if (seqNum <= this.latestReceivedSeqNumber) {
|
|
376
|
+
this.isRetryLoopDisabled = true;
|
|
377
|
+
}
|
|
378
|
+
else {
|
|
379
|
+
this.isRetryLoopDisabled = false;
|
|
380
|
+
// setting the latest received seqNum
|
|
381
|
+
this.latestReceivedSeqNumber = seqNum;
|
|
382
|
+
// clear the retry queue when for this seqNum and below
|
|
383
|
+
this._clearRetryQueue(seqNum);
|
|
384
|
+
}
|
|
385
|
+
if (!this.ackedOnce) {
|
|
386
|
+
this.ackedOnce = true;
|
|
387
|
+
}
|
|
391
388
|
}
|
|
392
|
-
|
|
393
|
-
const seqNum = parseInt(seqNumSplit[1], 10);
|
|
394
|
-
// ignore sequence num if this is just page info, it will always be -1 and we don't want
|
|
395
|
-
// to disable the retry loop on this
|
|
396
|
-
if (seqNum === -1) {
|
|
389
|
+
if (this._tryProcessHelpCodeResponse(event.data)) {
|
|
397
390
|
break;
|
|
398
391
|
}
|
|
399
|
-
// we disable the retry loop if we start running behind
|
|
400
|
-
if (seqNum <= this.latestReceivedSeqNumber) {
|
|
401
|
-
this.isRetryLoopDisabled = true;
|
|
402
|
-
}
|
|
403
|
-
else {
|
|
404
|
-
this.isRetryLoopDisabled = false;
|
|
405
|
-
// setting the latest received seqNum
|
|
406
|
-
this.latestReceivedSeqNumber = seqNum;
|
|
407
|
-
// clear the retry queue when for this seqNum and below
|
|
408
|
-
this._clearRetryQueue(seqNum);
|
|
409
|
-
}
|
|
410
|
-
if (!this.ackedOnce) {
|
|
411
|
-
this.ackedOnce = true;
|
|
412
|
-
}
|
|
413
|
-
}
|
|
414
|
-
if (this._tryProcessHelpCodeResponse(event.data)) {
|
|
415
392
|
break;
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
}
|
|
393
|
+
// still need to collect the id sent back from metroplex
|
|
394
|
+
}
|
|
395
|
+
});
|
|
420
396
|
}
|
|
421
397
|
/**
|
|
422
398
|
* Returns true if the message's payload has the payload type given and has a sequence
|
|
@@ -437,37 +413,39 @@ class MetroplexSocket {
|
|
|
437
413
|
this._messagePayloadHasLargerSeqNum(message, PAGE_VISIT_VID_FRAG_ATT_NAME, seqNum));
|
|
438
414
|
}
|
|
439
415
|
/** will resend everything that is in the retry queue */
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
}
|
|
447
|
-
// We always send if this is on socket open
|
|
448
|
-
if (socketWasAlreadyOpen) {
|
|
449
|
-
// we do not send the messages to metroplex if we are falling behind on received
|
|
450
|
-
// sequence numbers
|
|
451
|
-
const someTimeAgo = new Date();
|
|
452
|
-
someTimeAgo.setMilliseconds(someTimeAgo.getMilliseconds() - this.metroRetryFrequencyMS);
|
|
453
|
-
if (someTimeAgo < this.latestReceivedSeqNumStoredTime) {
|
|
416
|
+
_sendUnconfirmedMessages(socketWasAlreadyOpen) {
|
|
417
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
418
|
+
noibuLog('_sendUnconfirmedMessages');
|
|
419
|
+
// we only check once. If the socket is disconnected midway, the events would
|
|
420
|
+
// still be in the retry queue.
|
|
421
|
+
if (!this.isConnected() || ClientConfig.getInstance().isClientDisabled) {
|
|
454
422
|
return;
|
|
455
423
|
}
|
|
456
|
-
//
|
|
457
|
-
if (
|
|
458
|
-
|
|
424
|
+
// We always send if this is on socket open
|
|
425
|
+
if (socketWasAlreadyOpen) {
|
|
426
|
+
// we do not send the messages to metroplex if we are falling behind on received
|
|
427
|
+
// sequence numbers
|
|
428
|
+
const someTimeAgo = new Date();
|
|
429
|
+
someTimeAgo.setMilliseconds(someTimeAgo.getMilliseconds() - this.metroRetryFrequencyMS);
|
|
430
|
+
if (someTimeAgo < this.latestReceivedSeqNumStoredTime) {
|
|
431
|
+
return;
|
|
432
|
+
}
|
|
433
|
+
// we do not resend messages to metroplex if we are running behind
|
|
434
|
+
if (this.isRetryLoopDisabled) {
|
|
435
|
+
return;
|
|
436
|
+
}
|
|
459
437
|
}
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
}
|
|
438
|
+
// removing all the messages with a blocked type from the retry queue
|
|
439
|
+
this.retryMessageQueue = this.retryMessageQueue.filter(message => !(message.type in this.metroplexTypeLock));
|
|
440
|
+
// we dont remove any items from this queue in this function
|
|
441
|
+
for (let i = 0; i < this.retryMessageQueue.length; i += 1) {
|
|
442
|
+
const { type, payload } = this.retryMessageQueue[i];
|
|
443
|
+
// sending the data to metroplex
|
|
444
|
+
// eslint-disable-next-line no-await-in-loop
|
|
445
|
+
yield this._sendSocketMessage(payload);
|
|
446
|
+
this.previousMessageType = type;
|
|
447
|
+
}
|
|
448
|
+
});
|
|
471
449
|
}
|
|
472
450
|
/** sets up the interval to empty the queue as we receive confirmation messages from metroplex */
|
|
473
451
|
setupRetryMechanism() {
|
|
@@ -485,143 +463,149 @@ class MetroplexSocket {
|
|
|
485
463
|
* will handle the final moments of a page being active. It
|
|
486
464
|
* will try to empty both the queues with beacons.
|
|
487
465
|
*/
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
466
|
+
_handleUnload() {
|
|
467
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
468
|
+
// closing the socket since the page is unloading
|
|
469
|
+
this.close();
|
|
470
|
+
// if we disable the client within the pagevisit, we do not
|
|
471
|
+
// post anything during the unloading.
|
|
472
|
+
if (ClientConfig.getInstance().isClientDisabled) {
|
|
473
|
+
return;
|
|
474
|
+
}
|
|
475
|
+
// Don't send the final complete PV if the session has become inactive
|
|
476
|
+
// we already sent the PV when went inactive
|
|
477
|
+
if (ClientConfig.getInstance().isInactive()) {
|
|
478
|
+
return;
|
|
479
|
+
}
|
|
480
|
+
yield this.postFullPageVisit(MAX_BEACON_PAYLOAD_SIZE);
|
|
481
|
+
});
|
|
502
482
|
}
|
|
503
483
|
/**
|
|
504
484
|
* will post full page visit to metroplex. It
|
|
505
485
|
* will try to empty both the queues with beacons.
|
|
506
486
|
*/
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
}
|
|
511
|
-
// debug counters
|
|
512
|
-
const postInfo = [];
|
|
513
|
-
const numDropped = {
|
|
514
|
-
[VIDEO_METROPLEX_TYPE]: 0,
|
|
515
|
-
[PV_METROPLEX_TYPE]: 0,
|
|
516
|
-
};
|
|
517
|
-
let currentMsgPayloadSize = 0;
|
|
518
|
-
let currentCompletePv = {
|
|
519
|
-
[PAGE_VISIT_INFORMATION_ATT_NAME]: await this.getPageInformation(),
|
|
520
|
-
[PAGE_VISIT_PART_ATT_NAME]: [],
|
|
521
|
-
[PAGE_VISIT_VID_FRAG_ATT_NAME]: [],
|
|
522
|
-
[PAGE_VISIT_HTTP_DATA_ATT_NAME]: [],
|
|
523
|
-
[VIDEO_PART_COUNT_ATT_NAME]: this.connectionCount,
|
|
524
|
-
};
|
|
525
|
-
currentCompletePv[PAGE_VISIT_INFORMATION_ATT_NAME][IS_LAST_ATT_NAME] = true;
|
|
526
|
-
const pageInfo = await this.getPageInformation();
|
|
527
|
-
this.retryMessageQueue.forEach(msg => {
|
|
528
|
-
// can't use two variables types in obj deconstruction
|
|
529
|
-
// eslint-disable-next-line prefer-const
|
|
530
|
-
let { type, payload } = msg;
|
|
531
|
-
// If the message is larger than the beacon limit then skip to the next message
|
|
532
|
-
const currentPayloadSize = new Blob([stringifyJSON(payload)]).size;
|
|
533
|
-
if (currentPayloadSize > maxMessageSize) {
|
|
534
|
-
// increment dropped count for this type
|
|
535
|
-
numDropped[type] += 1;
|
|
487
|
+
postFullPageVisit(maxMessageSize) {
|
|
488
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
489
|
+
if (this.retryMessageQueue.length === 0) {
|
|
536
490
|
return;
|
|
537
491
|
}
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
492
|
+
// debug counters
|
|
493
|
+
const postInfo = [];
|
|
494
|
+
const numDropped = {
|
|
495
|
+
[VIDEO_METROPLEX_TYPE]: 0,
|
|
496
|
+
[PV_METROPLEX_TYPE]: 0,
|
|
497
|
+
};
|
|
498
|
+
let currentMsgPayloadSize = 0;
|
|
499
|
+
let currentCompletePv = {
|
|
500
|
+
[PAGE_VISIT_INFORMATION_ATT_NAME]: yield this.getPageInformation(),
|
|
501
|
+
[PAGE_VISIT_PART_ATT_NAME]: [],
|
|
502
|
+
[PAGE_VISIT_VID_FRAG_ATT_NAME]: [],
|
|
503
|
+
[PAGE_VISIT_HTTP_DATA_ATT_NAME]: [],
|
|
504
|
+
[VIDEO_PART_COUNT_ATT_NAME]: this.connectionCount,
|
|
505
|
+
};
|
|
506
|
+
currentCompletePv[PAGE_VISIT_INFORMATION_ATT_NAME][IS_LAST_ATT_NAME] = true;
|
|
507
|
+
const pageInfo = yield this.getPageInformation();
|
|
508
|
+
this.retryMessageQueue.forEach(msg => {
|
|
509
|
+
// can't use two variables types in obj deconstruction
|
|
510
|
+
// eslint-disable-next-line prefer-const
|
|
511
|
+
let { type, payload } = msg;
|
|
512
|
+
// If the message is larger than the beacon limit then skip to the next message
|
|
513
|
+
const currentPayloadSize = new Blob([stringifyJSON(payload)]).size;
|
|
514
|
+
if (currentPayloadSize > maxMessageSize) {
|
|
515
|
+
// increment dropped count for this type
|
|
516
|
+
numDropped[type] += 1;
|
|
517
|
+
return;
|
|
518
|
+
}
|
|
519
|
+
currentMsgPayloadSize += currentPayloadSize;
|
|
520
|
+
if (currentMsgPayloadSize >= maxMessageSize) {
|
|
521
|
+
this.postMessage(currentCompletePv);
|
|
522
|
+
// add to post info
|
|
523
|
+
let postInfoMessage = `Vid: ${currentCompletePv[PAGE_VISIT_VID_FRAG_ATT_NAME].length}`;
|
|
524
|
+
postInfoMessage += ` PV: ${currentCompletePv[PAGE_VISIT_PART_ATT_NAME].length}`;
|
|
525
|
+
postInfoMessage += ` HTTP: ${currentCompletePv[PAGE_VISIT_HTTP_DATA_ATT_NAME].length},`;
|
|
526
|
+
postInfo.push(postInfoMessage);
|
|
527
|
+
// resetting currentCompletePv, since we need to keep adding
|
|
528
|
+
// events to a blank object to send to metroplex.
|
|
529
|
+
// retain the video part count, so we don't overwrite anything
|
|
530
|
+
currentCompletePv = {
|
|
531
|
+
[PAGE_VISIT_INFORMATION_ATT_NAME]: pageInfo,
|
|
532
|
+
[PAGE_VISIT_PART_ATT_NAME]: [],
|
|
533
|
+
[PAGE_VISIT_VID_FRAG_ATT_NAME]: [],
|
|
534
|
+
[PAGE_VISIT_HTTP_DATA_ATT_NAME]: [],
|
|
535
|
+
[VIDEO_PART_COUNT_ATT_NAME]: currentCompletePv[VIDEO_PART_COUNT_ATT_NAME],
|
|
536
|
+
};
|
|
537
|
+
currentCompletePv[PAGE_VISIT_INFORMATION_ATT_NAME][IS_LAST_ATT_NAME] =
|
|
538
|
+
true;
|
|
539
|
+
// resetting the message size based on what is being added
|
|
540
|
+
currentMsgPayloadSize = currentPayloadSize;
|
|
541
|
+
}
|
|
542
|
+
switch (type) {
|
|
543
|
+
case VIDEO_METROPLEX_TYPE:
|
|
544
|
+
currentCompletePv[PAGE_VISIT_VID_FRAG_ATT_NAME].push(payload[PAGE_VISIT_VID_FRAG_ATT_NAME]);
|
|
545
|
+
break;
|
|
546
|
+
case PV_METROPLEX_TYPE:
|
|
547
|
+
currentCompletePv[PAGE_VISIT_PART_ATT_NAME].push(payload[PAGE_VISIT_PART_ATT_NAME]);
|
|
548
|
+
break;
|
|
549
|
+
case HTTP_DATA_METROPLEX_TYPE:
|
|
550
|
+
currentCompletePv[PAGE_VISIT_HTTP_DATA_ATT_NAME].push(payload[PAGE_VISIT_HTTP_DATA_ATT_NAME]);
|
|
551
|
+
break;
|
|
552
|
+
}
|
|
553
|
+
});
|
|
554
|
+
this.postMessage(currentCompletePv);
|
|
555
|
+
// debug log if large retry message queue
|
|
556
|
+
if (this.retryMessageQueue.length > 100) {
|
|
542
557
|
let postInfoMessage = `Vid: ${currentCompletePv[PAGE_VISIT_VID_FRAG_ATT_NAME].length}`;
|
|
543
558
|
postInfoMessage += ` PV: ${currentCompletePv[PAGE_VISIT_PART_ATT_NAME].length}`;
|
|
544
559
|
postInfoMessage += ` HTTP: ${currentCompletePv[PAGE_VISIT_HTTP_DATA_ATT_NAME].length},`;
|
|
545
560
|
postInfo.push(postInfoMessage);
|
|
546
|
-
//
|
|
547
|
-
//
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
561
|
+
// we completed posted the full pv, send the confirmation debug logs
|
|
562
|
+
// build the debug message
|
|
563
|
+
let message = 'POST Full PV complete';
|
|
564
|
+
// POST counts
|
|
565
|
+
message += `, POSTs count: ${postInfo.length}`;
|
|
566
|
+
message += `, POSTs info: ${stringifyJSON(postInfo)}`;
|
|
567
|
+
// Initial retry message queue size
|
|
568
|
+
message += `, Retry message queue size: ${this.retryMessageQueue.length}`;
|
|
569
|
+
// Num drops
|
|
570
|
+
if (numDropped[VIDEO_METROPLEX_TYPE] > 0) {
|
|
571
|
+
message += `, Video parts dropped: ${numDropped[VIDEO_METROPLEX_TYPE]}`;
|
|
572
|
+
}
|
|
573
|
+
if (numDropped[PV_METROPLEX_TYPE] > 0) {
|
|
574
|
+
message += `, Page visit parts dropped: ${numDropped[PV_METROPLEX_TYPE]}`;
|
|
575
|
+
}
|
|
576
|
+
if (numDropped[HTTP_DATA_METROPLEX_TYPE] > 0) {
|
|
577
|
+
message += `, HTTP data parts dropped: ${numDropped[HTTP_DATA_METROPLEX_TYPE]}`;
|
|
578
|
+
}
|
|
579
|
+
// Sequence info
|
|
580
|
+
message += `, Sequence Info: Latest ${this.messageSequenceNum}`;
|
|
581
|
+
message += ` Ack'd ${this.latestReceivedSeqNumStoredTime} ${this.latestReceivedSeqNumber}`;
|
|
582
|
+
// if client was disabled (due to inactive or otherwise) enable briefly so the
|
|
583
|
+
// debug message gets through
|
|
584
|
+
const clientDisabled = ClientConfig.getInstance().isClientDisabled;
|
|
585
|
+
ClientConfig.getInstance().isClientDisabled = false;
|
|
586
|
+
ClientConfig.getInstance().postNoibuErrorAndOptionallyDisableClient(message, clientDisabled, SEVERITY.warn);
|
|
571
587
|
}
|
|
572
588
|
});
|
|
573
|
-
this.postMessage(currentCompletePv);
|
|
574
|
-
// debug log if large retry message queue
|
|
575
|
-
if (this.retryMessageQueue.length > 100) {
|
|
576
|
-
let postInfoMessage = `Vid: ${currentCompletePv[PAGE_VISIT_VID_FRAG_ATT_NAME].length}`;
|
|
577
|
-
postInfoMessage += ` PV: ${currentCompletePv[PAGE_VISIT_PART_ATT_NAME].length}`;
|
|
578
|
-
postInfoMessage += ` HTTP: ${currentCompletePv[PAGE_VISIT_HTTP_DATA_ATT_NAME].length},`;
|
|
579
|
-
postInfo.push(postInfoMessage);
|
|
580
|
-
// we completed posted the full pv, send the confirmation debug logs
|
|
581
|
-
// build the debug message
|
|
582
|
-
let message = 'POST Full PV complete';
|
|
583
|
-
// POST counts
|
|
584
|
-
message += `, POSTs count: ${postInfo.length}`;
|
|
585
|
-
message += `, POSTs info: ${stringifyJSON(postInfo)}`;
|
|
586
|
-
// Initial retry message queue size
|
|
587
|
-
message += `, Retry message queue size: ${this.retryMessageQueue.length}`;
|
|
588
|
-
// Num drops
|
|
589
|
-
if (numDropped[VIDEO_METROPLEX_TYPE] > 0) {
|
|
590
|
-
message += `, Video parts dropped: ${numDropped[VIDEO_METROPLEX_TYPE]}`;
|
|
591
|
-
}
|
|
592
|
-
if (numDropped[PV_METROPLEX_TYPE] > 0) {
|
|
593
|
-
message += `, Page visit parts dropped: ${numDropped[PV_METROPLEX_TYPE]}`;
|
|
594
|
-
}
|
|
595
|
-
if (numDropped[HTTP_DATA_METROPLEX_TYPE] > 0) {
|
|
596
|
-
message += `, HTTP data parts dropped: ${numDropped[HTTP_DATA_METROPLEX_TYPE]}`;
|
|
597
|
-
}
|
|
598
|
-
// Sequence info
|
|
599
|
-
message += `, Sequence Info: Latest ${this.messageSequenceNum}`;
|
|
600
|
-
message += ` Ack'd ${this.latestReceivedSeqNumStoredTime} ${this.latestReceivedSeqNumber}`;
|
|
601
|
-
// if client was disabled (due to inactive or otherwise) enable briefly so the
|
|
602
|
-
// debug message gets through
|
|
603
|
-
const clientDisabled = ClientConfig.getInstance().isClientDisabled;
|
|
604
|
-
ClientConfig.getInstance().isClientDisabled = false;
|
|
605
|
-
ClientConfig.getInstance().postNoibuErrorAndOptionallyDisableClient(message, clientDisabled, SEVERITY.warn);
|
|
606
|
-
}
|
|
607
589
|
}
|
|
608
590
|
/**
|
|
609
591
|
* will send a message to metroplex via a post request that will outlive the current page
|
|
610
592
|
*/
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
593
|
+
postMessage(msg) {
|
|
594
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
595
|
+
const updatedMsg = msg;
|
|
596
|
+
// ensure a unique video part number each call
|
|
597
|
+
updatedMsg[VIDEO_PART_COUNT_ATT_NAME] += 1;
|
|
598
|
+
// we send the remainder elements
|
|
599
|
+
unwrapNoibuWrapped(fetch)(this.postURL, {
|
|
600
|
+
method: 'POST',
|
|
601
|
+
headers: {
|
|
602
|
+
'content-type': 'application/json',
|
|
603
|
+
'User-Agent': yield getUserAgent(),
|
|
604
|
+
},
|
|
605
|
+
body: stringifyJSON(updatedMsg),
|
|
606
|
+
// keep alive outlives the current page, its the same as beacon
|
|
607
|
+
keepalive: true,
|
|
608
|
+
});
|
|
625
609
|
});
|
|
626
610
|
}
|
|
627
611
|
/**
|
|
@@ -629,60 +613,66 @@ class MetroplexSocket {
|
|
|
629
613
|
* is active and returns true. If inactive the session and socket are closed
|
|
630
614
|
* and this method returns false.
|
|
631
615
|
*/
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
this.socket
|
|
643
|
-
|
|
616
|
+
_sendSocketMessage(payload) {
|
|
617
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
618
|
+
noibuLog('_sendSocketMessage');
|
|
619
|
+
const closeIfInactive = yield this.closeIfInactive();
|
|
620
|
+
if (closeIfInactive) {
|
|
621
|
+
noibuLog('_sendSocketMessage dropped due to', { closeIfInactive });
|
|
622
|
+
return;
|
|
623
|
+
}
|
|
624
|
+
const payloadJson = stringifyJSON(payload);
|
|
625
|
+
noibuLog(`_sendSocketMessage sending: ${payloadJson}`);
|
|
626
|
+
if (this.socket) {
|
|
627
|
+
this.socket.send(payloadJson);
|
|
628
|
+
}
|
|
629
|
+
});
|
|
644
630
|
}
|
|
645
631
|
/**
|
|
646
632
|
* Closes the socket connection if the session is inactive. Returns true if the
|
|
647
633
|
* session is inactive
|
|
648
634
|
*/
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
635
|
+
closeIfInactive() {
|
|
636
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
637
|
+
const inactive = ClientConfig.getInstance().isInactive();
|
|
638
|
+
// if we weren't already inactive, go to inactive state
|
|
639
|
+
if (inactive && !ClientConfig.getInstance().isClientDisabled) {
|
|
640
|
+
// lock the client for 1 minute, since the lock expires
|
|
641
|
+
// only on new page loads this will lock the client until
|
|
642
|
+
// the next page is loaded.
|
|
643
|
+
yield ClientConfig.getInstance().lockClientUntilNextPage('Session is inactive, locking until next page');
|
|
644
|
+
this.close();
|
|
645
|
+
Promise.all([
|
|
646
|
+
// post metrics now so we don't include events after going inactive
|
|
647
|
+
StoredMetrics.getInstance().postMetrics(),
|
|
648
|
+
// post retry queue now so we don't include event after going inactive
|
|
649
|
+
this.postFullPageVisit(MAX_BEACON_PAYLOAD_SIZE),
|
|
650
|
+
]);
|
|
651
|
+
}
|
|
652
|
+
return inactive;
|
|
653
|
+
});
|
|
666
654
|
}
|
|
667
655
|
/** will get page information, calling this will increase the connection count */
|
|
668
|
-
|
|
669
|
-
return {
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
656
|
+
getPageInformation() {
|
|
657
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
658
|
+
return {
|
|
659
|
+
[BROWSER_ID_ATT_NAME]: ClientConfig.getInstance().browserId,
|
|
660
|
+
[PV_ID_ATT_NAME]: ClientConfig.getInstance().pageVisitId,
|
|
661
|
+
[VER_ATT_NAME]: CURRENT_PV_VERSION,
|
|
662
|
+
[PV_SEQ_ATT_NAME]: yield ClientConfig.getInstance().getPageVisitSeq(),
|
|
663
|
+
[ON_URL_ATT_NAME]: this._initialURL,
|
|
664
|
+
[REF_URL_ATT_NAME]: this.initialReferingURL,
|
|
665
|
+
[STARTED_AT_ATT_NAME]: this.sessionTimestamp.toISOString(),
|
|
666
|
+
[CONN_COUNT_ATT_NAME]: this.connectionCount,
|
|
667
|
+
[COLLECT_VER_ATT_NAME]: CURRENT_NOIBUJS_VERSION,
|
|
668
|
+
[IS_LAST_ATT_NAME]: false,
|
|
669
|
+
[SCRIPT_ID_ATT_NAME]: GET_SCRIPT_ID(),
|
|
670
|
+
[SCRIPT_INSTANCE_ID_ATT_NAME]: this.scriptInstanceId,
|
|
671
|
+
[METROPLEX_SOCKET_INSTANCE_ID_ATT_NAME]: this.instanceId,
|
|
672
|
+
[SOCKET_INSTANCE_ID_ATT_NAME]: this.socketInstanceId,
|
|
673
|
+
[VIDEO_RECORDER_ATT_NAME]: yield getVideoRecorderType(),
|
|
674
|
+
};
|
|
675
|
+
});
|
|
686
676
|
}
|
|
687
677
|
/**
|
|
688
678
|
* Try to parse help code response and fire custom event
|