@microsoft/1ds-post-js 3.1.11 → 3.2.2
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 +2 -2
- package/bundle/{ms.post-3.1.11.gbl.js → ms.post-3.2.2.gbl.js} +1278 -548
- package/bundle/ms.post-3.2.2.gbl.js.map +1 -0
- package/bundle/ms.post-3.2.2.gbl.min.js +7 -0
- package/bundle/ms.post-3.2.2.gbl.min.js.map +1 -0
- package/bundle/ms.post-3.2.2.integrity.json +46 -0
- package/bundle/{ms.post-3.1.11.js → ms.post-3.2.2.js} +1278 -548
- package/bundle/ms.post-3.2.2.js.map +1 -0
- package/bundle/ms.post-3.2.2.min.js +7 -0
- package/bundle/ms.post-3.2.2.min.js.map +1 -0
- package/bundle/ms.post.gbl.js +1277 -547
- package/bundle/ms.post.gbl.js.map +1 -1
- package/bundle/ms.post.gbl.min.js +2 -2
- package/bundle/ms.post.gbl.min.js.map +1 -1
- package/bundle/ms.post.integrity.json +17 -17
- package/bundle/ms.post.js +1277 -547
- package/bundle/ms.post.js.map +1 -1
- package/bundle/ms.post.min.js +2 -2
- package/bundle/ms.post.min.js.map +1 -1
- package/dist/ms.post.js +212 -128
- package/dist/ms.post.js.map +1 -1
- package/dist/ms.post.min.js +2 -2
- package/dist/ms.post.min.js.map +1 -1
- package/dist-esm/src/BatchNotificationActions.js +1 -1
- package/dist-esm/src/ClockSkewManager.js +1 -1
- package/dist-esm/src/Constants.js +1 -1
- package/dist-esm/src/DataModels.js +1 -1
- package/dist-esm/src/EventBatch.js +1 -1
- package/dist-esm/src/HttpManager.d.ts +2 -1
- package/dist-esm/src/HttpManager.js +45 -40
- package/dist-esm/src/HttpManager.js.map +1 -1
- package/dist-esm/src/Index.js +1 -1
- package/dist-esm/src/KillSwitch.js +1 -1
- package/dist-esm/src/PostChannel.d.ts +2 -9
- package/dist-esm/src/PostChannel.js +151 -97
- package/dist-esm/src/PostChannel.js.map +1 -1
- package/dist-esm/src/RetryPolicy.d.ts +20 -25
- package/dist-esm/src/RetryPolicy.js +35 -44
- package/dist-esm/src/RetryPolicy.js.map +1 -1
- package/dist-esm/src/Serializer.js +1 -1
- package/dist-esm/src/TimeoutOverrideWrapper.d.ts +18 -0
- package/dist-esm/src/TimeoutOverrideWrapper.js +28 -0
- package/dist-esm/src/TimeoutOverrideWrapper.js.map +1 -0
- package/dist-esm/src/typings/XDomainRequest.js +1 -1
- package/package.json +3 -3
- package/src/HttpManager.ts +48 -51
- package/src/PostChannel.ts +186 -119
- package/src/RetryPolicy.ts +33 -38
- package/src/TimeoutOverrideWrapper.ts +29 -0
- package/bundle/ms.post-3.1.11.gbl.js.map +0 -1
- package/bundle/ms.post-3.1.11.gbl.min.js +0 -7
- package/bundle/ms.post-3.1.11.gbl.min.js.map +0 -1
- package/bundle/ms.post-3.1.11.integrity.json +0 -46
- package/bundle/ms.post-3.1.11.js.map +0 -1
- package/bundle/ms.post-3.1.11.min.js +0 -7
- package/bundle/ms.post-3.1.11.min.js.map +0 -1
package/dist-esm/src/Index.js
CHANGED
|
@@ -1,8 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* PostManager.ts
|
|
3
|
-
* @author Abhilash Panwar (abpanwar); Hector Hernandez (hectorh); Nev Wylie (newylie)
|
|
4
|
-
* @copyright Microsoft 2018-2020
|
|
5
|
-
*/
|
|
6
1
|
import { BaseTelemetryPlugin, IChannelControls, IExtendedConfiguration, NotificationManager, IPlugin, ITelemetryItem, IAppInsightsCore, IProcessTelemetryContext, SendRequestReason } from "@microsoft/1ds-core-js";
|
|
7
2
|
import { IPostChannel } from "./DataModels";
|
|
8
3
|
/**
|
|
@@ -14,7 +9,9 @@ export default class PostChannel extends BaseTelemetryPlugin implements IChannel
|
|
|
14
9
|
priority: number;
|
|
15
10
|
version: string;
|
|
16
11
|
_notificationManager: NotificationManager | undefined;
|
|
12
|
+
/** @deprecated This property is not intended to be used directly please let us know if you have taken a dependency on this property as it may be removed in a future release */
|
|
17
13
|
_setTimeoutOverride: typeof setTimeout;
|
|
14
|
+
/** @deprecated This property is not intended to be used directly please let us know if you have taken a dependency on this property as it may be removed in a future release */
|
|
18
15
|
_clearTimeoutOverride: typeof clearTimeout;
|
|
19
16
|
constructor();
|
|
20
17
|
/**
|
|
@@ -39,10 +36,6 @@ export default class PostChannel extends BaseTelemetryPlugin implements IChannel
|
|
|
39
36
|
* without waiting for the normal schedule timers. Passing undefined, null or a value less than or equal to zero will disable the auto flush.
|
|
40
37
|
*/
|
|
41
38
|
setEventQueueLimits(eventLimit: number, autoFlushLimit?: number): void;
|
|
42
|
-
/**
|
|
43
|
-
* Batch all current events in the queues and send them.
|
|
44
|
-
*/
|
|
45
|
-
teardown(): void;
|
|
46
39
|
/**
|
|
47
40
|
* Pause the transmission of any requests
|
|
48
41
|
*/
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*
|
|
2
|
-
* 1DS JS SDK POST plugin, 3.
|
|
2
|
+
* 1DS JS SDK POST plugin, 3.2.2
|
|
3
3
|
* Copyright (c) Microsoft and contributors. All rights reserved.
|
|
4
4
|
* (Microsoft Internal Only)
|
|
5
5
|
*/
|
|
@@ -9,26 +9,27 @@ import { __extendsFn as __extends } from "@microsoft/applicationinsights-shims";
|
|
|
9
9
|
* @author Abhilash Panwar (abpanwar); Hector Hernandez (hectorh); Nev Wylie (newylie)
|
|
10
10
|
* @copyright Microsoft 2018-2020
|
|
11
11
|
*/
|
|
12
|
-
import
|
|
12
|
+
import dynamicProto from "@microsoft/dynamicproto-js";
|
|
13
|
+
import { BaseTelemetryPlugin, EventsDiscardedReason, isValueAssigned, setProcessTelemetryTimings, arrForEach, doPerf, objForEachKey, optimizeObject, isChromium, getWindow, isNumber, mergeEvtNamespace, createUniqueNamespace, addPageUnloadEventListener, addPageHideEventListener, addPageShowEventListener, removePageUnloadEventListener, removePageHideEventListener, removePageShowEventListener, _throwInternal, objDefineAccessors } from "@microsoft/1ds-core-js";
|
|
13
14
|
import { RT_PROFILE, NRT_PROFILE, BE_PROFILE, } from "./DataModels";
|
|
14
15
|
import { EventBatch } from "./EventBatch";
|
|
15
16
|
import { HttpManager } from "./HttpManager";
|
|
16
|
-
import
|
|
17
|
-
import dynamicProto from "@microsoft/dynamicproto-js";
|
|
17
|
+
import { retryPolicyGetMillisToBackoffForRetry } from "./RetryPolicy";
|
|
18
18
|
import { strMsaDeviceTicket } from "./Constants";
|
|
19
|
+
import { createTimeoutWrapper } from "./TimeoutOverrideWrapper";
|
|
19
20
|
var FlushCheckTimer = 0.250; // This needs to be in seconds, so this is 250ms
|
|
20
21
|
var MaxNumberEventPerBatch = 500;
|
|
21
22
|
var EventsDroppedAtOneTime = 20;
|
|
22
23
|
var MaxSendAttempts = 6;
|
|
23
24
|
var MaxSyncUnloadSendAttempts = 2; // Assuming 2 based on beforeunload and unload
|
|
24
25
|
var MaxBackoffCount = 4;
|
|
25
|
-
var globalContext = isWindowObjectAvailable ? window : this;
|
|
26
26
|
var MaxConnections = 2;
|
|
27
27
|
var MaxRequestRetriesBeforeBackoff = 1;
|
|
28
28
|
var strEventsDiscarded = "eventsDiscarded";
|
|
29
29
|
var strOverrideInstrumentationKey = "overrideInstrumentationKey";
|
|
30
30
|
var strMaxEventRetryAttempts = "maxEventRetryAttempts";
|
|
31
31
|
var strMaxUnloadEventRetryAttempts = "maxUnloadEventRetryAttempts";
|
|
32
|
+
var strAddUnloadCb = "addUnloadCb";
|
|
32
33
|
/**
|
|
33
34
|
* Class that manages adding events to inbound queues and batching of events
|
|
34
35
|
* into requests.
|
|
@@ -39,7 +40,7 @@ var PostChannel = /** @class */ (function (_super) {
|
|
|
39
40
|
var _this = _super.call(this) || this;
|
|
40
41
|
_this.identifier = "PostChannel";
|
|
41
42
|
_this.priority = 1011;
|
|
42
|
-
_this.version = '3.
|
|
43
|
+
_this.version = '3.2.2';
|
|
43
44
|
var _config;
|
|
44
45
|
var _isTeardownCalled = false;
|
|
45
46
|
var _flushCallbackQueue = [];
|
|
@@ -68,18 +69,10 @@ var PostChannel = /** @class */ (function (_super) {
|
|
|
68
69
|
var _disableXhrSync = false;
|
|
69
70
|
var _maxEventSendAttempts = MaxSendAttempts;
|
|
70
71
|
var _maxUnloadEventSendAttempts = MaxSyncUnloadSendAttempts;
|
|
72
|
+
var _evtNamespace;
|
|
73
|
+
var _timeoutWrapper;
|
|
71
74
|
dynamicProto(PostChannel, _this, function (_self, _base) {
|
|
72
|
-
|
|
73
|
-
_clearQueues();
|
|
74
|
-
_setAutoLimits();
|
|
75
|
-
_httpManager = new HttpManager(MaxNumberEventPerBatch, MaxConnections, MaxRequestRetriesBeforeBackoff, {
|
|
76
|
-
requeue: _requeueEvents,
|
|
77
|
-
send: _sendingEvent,
|
|
78
|
-
sent: _eventsSentEvent,
|
|
79
|
-
drop: _eventsDropped,
|
|
80
|
-
rspFail: _eventsResponseFail,
|
|
81
|
-
oth: _otherEvent
|
|
82
|
-
});
|
|
75
|
+
_initDefaults();
|
|
83
76
|
// Special internal method to allow the DebugPlugin to hook embedded objects
|
|
84
77
|
_self["_getDbgPlgTargets"] = function () {
|
|
85
78
|
return [_httpManager];
|
|
@@ -88,50 +81,56 @@ var PostChannel = /** @class */ (function (_super) {
|
|
|
88
81
|
doPerf(core, function () { return "PostChannel:initialize"; }, function () {
|
|
89
82
|
var extendedCore = core;
|
|
90
83
|
_base.initialize(coreConfig, core, extensions);
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
84
|
+
try {
|
|
85
|
+
var hasAddUnloadCb = !!core[strAddUnloadCb];
|
|
86
|
+
_evtNamespace = mergeEvtNamespace(createUniqueNamespace(_self.identifier), core.evtNamespace && core.evtNamespace());
|
|
87
|
+
var ctx = _self._getTelCtx();
|
|
88
|
+
coreConfig.extensionConfig[_self.identifier] = coreConfig.extensionConfig[_self.identifier] || {};
|
|
89
|
+
_config = ctx.getExtCfg(_self.identifier);
|
|
90
|
+
_timeoutWrapper = createTimeoutWrapper(_config.setTimeoutOverride, _config.clearTimeoutOverride);
|
|
91
|
+
// Only try and use the optimizeObject() if this appears to be a chromium based browser and it has not been explicitly disabled
|
|
92
|
+
_optimizeObject = !_config.disableOptimizeObj && isChromium();
|
|
93
|
+
_hookWParam(extendedCore);
|
|
94
|
+
if (_config.eventsLimitInMem > 0) {
|
|
95
|
+
_queueSizeLimit = _config.eventsLimitInMem;
|
|
96
|
+
}
|
|
97
|
+
if (_config.immediateEventLimit > 0) {
|
|
98
|
+
_immediateQueueSizeLimit = _config.immediateEventLimit;
|
|
99
|
+
}
|
|
100
|
+
if (_config.autoFlushEventsLimit > 0) {
|
|
101
|
+
_autoFlushEventsLimit = _config.autoFlushEventsLimit;
|
|
102
|
+
}
|
|
103
|
+
_disableXhrSync = _config.disableXhrSync;
|
|
104
|
+
if (isNumber(_config[strMaxEventRetryAttempts])) {
|
|
105
|
+
_maxEventSendAttempts = _config[strMaxEventRetryAttempts];
|
|
106
|
+
}
|
|
107
|
+
if (isNumber(_config[strMaxUnloadEventRetryAttempts])) {
|
|
108
|
+
_maxUnloadEventSendAttempts = _config[strMaxUnloadEventRetryAttempts];
|
|
109
|
+
}
|
|
110
|
+
_setAutoLimits();
|
|
111
|
+
if (_config.httpXHROverride && _config.httpXHROverride.sendPOST) {
|
|
112
|
+
_xhrOverride = _config.httpXHROverride;
|
|
113
|
+
}
|
|
114
|
+
if (isValueAssigned(coreConfig.anonCookieName)) {
|
|
115
|
+
_httpManager.addQueryStringParameter("anoncknm", coreConfig.anonCookieName);
|
|
116
|
+
}
|
|
117
|
+
_httpManager.sendHook = _config.payloadPreprocessor;
|
|
118
|
+
_httpManager.sendListener = _config.payloadListener;
|
|
119
|
+
// Override endpointUrl if provided in Post config
|
|
120
|
+
var endpointUrl = _config.overrideEndpointUrl ? _config.overrideEndpointUrl : coreConfig.endpointUrl;
|
|
121
|
+
_self._notificationManager = coreConfig.extensionConfig.NotificationManager;
|
|
122
|
+
_httpManager.initialize(endpointUrl, _self.core, _self, _xhrOverride, _config);
|
|
123
|
+
var excludePageUnloadEvents = coreConfig.disablePageUnloadEvents || [];
|
|
124
|
+
// When running in Web browsers try to send all telemetry if page is unloaded
|
|
125
|
+
addPageUnloadEventListener(_handleUnloadEvents, excludePageUnloadEvents, _evtNamespace);
|
|
126
|
+
addPageHideEventListener(_handleUnloadEvents, excludePageUnloadEvents, _evtNamespace);
|
|
127
|
+
addPageShowEventListener(_handleShowEvents, coreConfig.disablePageShowEvents, _evtNamespace);
|
|
128
|
+
}
|
|
129
|
+
catch (e) {
|
|
130
|
+
// resetting the initialized state because of failure
|
|
131
|
+
_self.setInitialized(false);
|
|
132
|
+
throw e;
|
|
133
|
+
}
|
|
135
134
|
}, function () { return ({ coreConfig: coreConfig, core: core, extensions: extensions }); });
|
|
136
135
|
};
|
|
137
136
|
_self.processTelemetry = function (ev, itemCtx) {
|
|
@@ -166,6 +165,16 @@ var PostChannel = /** @class */ (function (_super) {
|
|
|
166
165
|
}
|
|
167
166
|
_self.processNext(event, itemCtx);
|
|
168
167
|
};
|
|
168
|
+
_self._doTeardown = function (unloadCtx, unloadState) {
|
|
169
|
+
_releaseAllQueues(2 /* SendBeacon */, 2 /* Unload */);
|
|
170
|
+
_isTeardownCalled = true;
|
|
171
|
+
_httpManager.teardown();
|
|
172
|
+
removePageUnloadEventListener(null, _evtNamespace);
|
|
173
|
+
removePageHideEventListener(null, _evtNamespace);
|
|
174
|
+
removePageShowEventListener(null, _evtNamespace);
|
|
175
|
+
// Just register to remove all events associated with this namespace
|
|
176
|
+
_initDefaults();
|
|
177
|
+
};
|
|
169
178
|
function _hookWParam(extendedCore) {
|
|
170
179
|
var existingGetWParamMethod = extendedCore.getWParam;
|
|
171
180
|
extendedCore.getWParam = function () {
|
|
@@ -198,7 +207,7 @@ var PostChannel = /** @class */ (function (_super) {
|
|
|
198
207
|
}
|
|
199
208
|
// Add default latency
|
|
200
209
|
if (!event.latency) {
|
|
201
|
-
event.latency =
|
|
210
|
+
event.latency = 1 /* Normal */;
|
|
202
211
|
}
|
|
203
212
|
// Remove extra AI properties if present
|
|
204
213
|
if (event.ext && event.ext["trace"]) {
|
|
@@ -221,7 +230,7 @@ var PostChannel = /** @class */ (function (_super) {
|
|
|
221
230
|
// If the transmission is backed off then do not send synchronous events.
|
|
222
231
|
// We will convert these events to Real time latency instead.
|
|
223
232
|
if (_currentBackoffCount || _paused) {
|
|
224
|
-
event.latency =
|
|
233
|
+
event.latency = 3 /* RealTime */;
|
|
225
234
|
event.sync = false;
|
|
226
235
|
}
|
|
227
236
|
else {
|
|
@@ -239,7 +248,7 @@ var PostChannel = /** @class */ (function (_super) {
|
|
|
239
248
|
var evtLatency = event.latency;
|
|
240
249
|
var queueSize = _queueSize;
|
|
241
250
|
var queueLimit = _queueSizeLimit;
|
|
242
|
-
if (evtLatency ===
|
|
251
|
+
if (evtLatency === 4 /* Immediate */) {
|
|
243
252
|
queueSize = _immediateQueueSize;
|
|
244
253
|
queueLimit = _immediateQueueSizeLimit;
|
|
245
254
|
}
|
|
@@ -249,11 +258,11 @@ var PostChannel = /** @class */ (function (_super) {
|
|
|
249
258
|
eventDropped = !_addEventToProperQueue(event, append);
|
|
250
259
|
}
|
|
251
260
|
else {
|
|
252
|
-
var dropLatency =
|
|
261
|
+
var dropLatency = 1 /* Normal */;
|
|
253
262
|
var dropNumber = EventsDroppedAtOneTime;
|
|
254
|
-
if (evtLatency ===
|
|
263
|
+
if (evtLatency === 4 /* Immediate */) {
|
|
255
264
|
// Only drop other immediate events as they are not technically sharing the general queue
|
|
256
|
-
dropLatency =
|
|
265
|
+
dropLatency = 4 /* Immediate */;
|
|
257
266
|
dropNumber = 1;
|
|
258
267
|
}
|
|
259
268
|
// Drop old event from lower or equal latency
|
|
@@ -275,7 +284,7 @@ var PostChannel = /** @class */ (function (_super) {
|
|
|
275
284
|
var doFlush = _queueSize > eventLimit;
|
|
276
285
|
if (!doFlush && _autoFlushBatchLimit > 0) {
|
|
277
286
|
// Check the auto flush max batch size
|
|
278
|
-
for (var latency =
|
|
287
|
+
for (var latency = 1 /* Normal */; !doFlush && latency <= 3 /* RealTime */; latency++) {
|
|
279
288
|
var batchQueue = _batchQueues[latency];
|
|
280
289
|
if (batchQueue && batchQueue.batches) {
|
|
281
290
|
arrForEach(batchQueue.batches, function (theBatch) {
|
|
@@ -289,11 +298,6 @@ var PostChannel = /** @class */ (function (_super) {
|
|
|
289
298
|
}
|
|
290
299
|
_performAutoFlush(true, doFlush);
|
|
291
300
|
};
|
|
292
|
-
_self.teardown = function () {
|
|
293
|
-
_releaseAllQueues(2 /* SendBeacon */, 2 /* Unload */);
|
|
294
|
-
_isTeardownCalled = true;
|
|
295
|
-
_httpManager.teardown();
|
|
296
|
-
};
|
|
297
301
|
_self.pause = function () {
|
|
298
302
|
_clearScheduledTimer();
|
|
299
303
|
_paused = true;
|
|
@@ -342,7 +346,7 @@ var PostChannel = /** @class */ (function (_super) {
|
|
|
342
346
|
sendReason = sendReason || 1 /* ManualFlush */;
|
|
343
347
|
if (async) {
|
|
344
348
|
// Move all queued events to the HttpManager
|
|
345
|
-
_queueBatches(
|
|
349
|
+
_queueBatches(1 /* Normal */, 0 /* Batched */, sendReason);
|
|
346
350
|
// All events (should) have been queue -- lets just make sure the queue counts are correct to avoid queue exhaustion (previous bug #9685112)
|
|
347
351
|
_resetQueueCounts();
|
|
348
352
|
if (_flushCallbackTimerId == null) {
|
|
@@ -358,7 +362,7 @@ var PostChannel = /** @class */ (function (_super) {
|
|
|
358
362
|
}
|
|
359
363
|
else {
|
|
360
364
|
// Now cause all queued events to be sent synchronously
|
|
361
|
-
_sendEventsForLatencyAndAbove(
|
|
365
|
+
_sendEventsForLatencyAndAbove(1 /* Normal */, 1 /* Synchronous */, sendReason);
|
|
362
366
|
if (callback !== null && callback !== undefined) {
|
|
363
367
|
callback();
|
|
364
368
|
}
|
|
@@ -408,7 +412,7 @@ var PostChannel = /** @class */ (function (_super) {
|
|
|
408
412
|
_immediateTimerId = _createTimer(function () {
|
|
409
413
|
_immediateTimerId = null;
|
|
410
414
|
// Only try to send direct events
|
|
411
|
-
_sendEventsForLatencyAndAbove(
|
|
415
|
+
_sendEventsForLatencyAndAbove(4 /* Immediate */, 0 /* Batched */, 1 /* NormalSchedule */);
|
|
412
416
|
_scheduleTimer();
|
|
413
417
|
}, immediateTimeOut);
|
|
414
418
|
}
|
|
@@ -419,7 +423,7 @@ var PostChannel = /** @class */ (function (_super) {
|
|
|
419
423
|
if (_hasEvents()) {
|
|
420
424
|
_scheduledTimerId = _createTimer(function () {
|
|
421
425
|
_scheduledTimerId = null;
|
|
422
|
-
_sendEventsForLatencyAndAbove(_timerCount === 0 ?
|
|
426
|
+
_sendEventsForLatencyAndAbove(_timerCount === 0 ? 3 /* RealTime */ : 1 /* Normal */, 0 /* Batched */, 1 /* NormalSchedule */);
|
|
423
427
|
// Increment the count for next cycle
|
|
424
428
|
_timerCount++;
|
|
425
429
|
_timerCount %= 2;
|
|
@@ -445,6 +449,48 @@ var PostChannel = /** @class */ (function (_super) {
|
|
|
445
449
|
_scheduleTimer();
|
|
446
450
|
}
|
|
447
451
|
};
|
|
452
|
+
function _initDefaults() {
|
|
453
|
+
_config = null;
|
|
454
|
+
_isTeardownCalled = false;
|
|
455
|
+
_flushCallbackQueue = [];
|
|
456
|
+
_flushCallbackTimerId = null;
|
|
457
|
+
_paused = false;
|
|
458
|
+
_immediateQueueSize = 0;
|
|
459
|
+
_immediateQueueSizeLimit = 500;
|
|
460
|
+
_queueSize = 0;
|
|
461
|
+
_queueSizeLimit = 10000;
|
|
462
|
+
_profiles = {};
|
|
463
|
+
_currentProfile = RT_PROFILE;
|
|
464
|
+
_scheduledTimerId = null;
|
|
465
|
+
_immediateTimerId = null;
|
|
466
|
+
_currentBackoffCount = 0;
|
|
467
|
+
_timerCount = 0;
|
|
468
|
+
_xhrOverride = null;
|
|
469
|
+
_batchQueues = {};
|
|
470
|
+
_autoFlushEventsLimit = undefined;
|
|
471
|
+
// either MaxBatchSize * (1+ Max Connections) or _queueLimit / 6 (where 3 latency Queues [normal, realtime, cost deferred] * 2 [allow half full -- allow for retry])
|
|
472
|
+
_autoFlushBatchLimit = 0;
|
|
473
|
+
_delayedBatchSendLatency = -1;
|
|
474
|
+
_delayedBatchReason = null;
|
|
475
|
+
_optimizeObject = true;
|
|
476
|
+
_isPageUnloadTriggered = false;
|
|
477
|
+
_disableXhrSync = false;
|
|
478
|
+
_maxEventSendAttempts = MaxSendAttempts;
|
|
479
|
+
_maxUnloadEventSendAttempts = MaxSyncUnloadSendAttempts;
|
|
480
|
+
_evtNamespace = null;
|
|
481
|
+
_timeoutWrapper = createTimeoutWrapper();
|
|
482
|
+
_httpManager = new HttpManager(MaxNumberEventPerBatch, MaxConnections, MaxRequestRetriesBeforeBackoff, {
|
|
483
|
+
requeue: _requeueEvents,
|
|
484
|
+
send: _sendingEvent,
|
|
485
|
+
sent: _eventsSentEvent,
|
|
486
|
+
drop: _eventsDropped,
|
|
487
|
+
rspFail: _eventsResponseFail,
|
|
488
|
+
oth: _otherEvent
|
|
489
|
+
}, _timeoutWrapper);
|
|
490
|
+
_initializeProfiles();
|
|
491
|
+
_clearQueues();
|
|
492
|
+
_setAutoLimits();
|
|
493
|
+
}
|
|
448
494
|
function _createTimer(theTimerFunc, timeOut) {
|
|
449
495
|
// If the transmission is backed off make the timer at least 1 sec to allow for back off.
|
|
450
496
|
if (timeOut === 0 && _currentBackoffCount) {
|
|
@@ -452,13 +498,13 @@ var PostChannel = /** @class */ (function (_super) {
|
|
|
452
498
|
}
|
|
453
499
|
var timerMultiplier = 1000;
|
|
454
500
|
if (_currentBackoffCount) {
|
|
455
|
-
timerMultiplier =
|
|
501
|
+
timerMultiplier = retryPolicyGetMillisToBackoffForRetry(_currentBackoffCount - 1);
|
|
456
502
|
}
|
|
457
|
-
return
|
|
503
|
+
return _timeoutWrapper.set(theTimerFunc, timeOut * timerMultiplier);
|
|
458
504
|
}
|
|
459
505
|
function _clearScheduledTimer() {
|
|
460
506
|
if (_scheduledTimerId !== null) {
|
|
461
|
-
|
|
507
|
+
_timeoutWrapper.clear(_scheduledTimerId);
|
|
462
508
|
_scheduledTimerId = null;
|
|
463
509
|
_timerCount = 0;
|
|
464
510
|
}
|
|
@@ -468,12 +514,12 @@ var PostChannel = /** @class */ (function (_super) {
|
|
|
468
514
|
_clearScheduledTimer();
|
|
469
515
|
// Cancel all flush callbacks
|
|
470
516
|
if (_flushCallbackTimerId) {
|
|
471
|
-
|
|
517
|
+
_timeoutWrapper.clear(_flushCallbackTimerId);
|
|
472
518
|
_flushCallbackTimerId = null;
|
|
473
519
|
}
|
|
474
520
|
if (!_paused) {
|
|
475
521
|
// Queue all the remaining requests to be sent. The requests will be sent using HTML5 Beacons if they are available.
|
|
476
|
-
_sendEventsForLatencyAndAbove(
|
|
522
|
+
_sendEventsForLatencyAndAbove(1 /* Normal */, sendType, sendReason);
|
|
477
523
|
}
|
|
478
524
|
}
|
|
479
525
|
/**
|
|
@@ -482,19 +528,19 @@ var PostChannel = /** @class */ (function (_super) {
|
|
|
482
528
|
* after flush are stored separately till we flush the current events.
|
|
483
529
|
*/
|
|
484
530
|
function _clearQueues() {
|
|
485
|
-
_batchQueues[
|
|
531
|
+
_batchQueues[4 /* Immediate */] = {
|
|
486
532
|
batches: [],
|
|
487
533
|
iKeyMap: {}
|
|
488
534
|
};
|
|
489
|
-
_batchQueues[
|
|
535
|
+
_batchQueues[3 /* RealTime */] = {
|
|
490
536
|
batches: [],
|
|
491
537
|
iKeyMap: {}
|
|
492
538
|
};
|
|
493
|
-
_batchQueues[
|
|
539
|
+
_batchQueues[2 /* CostDeferred */] = {
|
|
494
540
|
batches: [],
|
|
495
541
|
iKeyMap: {}
|
|
496
542
|
};
|
|
497
|
-
_batchQueues[
|
|
543
|
+
_batchQueues[1 /* Normal */] = {
|
|
498
544
|
batches: [],
|
|
499
545
|
iKeyMap: {}
|
|
500
546
|
};
|
|
@@ -502,7 +548,7 @@ var PostChannel = /** @class */ (function (_super) {
|
|
|
502
548
|
function _getEventBatch(iKey, latency, create) {
|
|
503
549
|
var batchQueue = _batchQueues[latency];
|
|
504
550
|
if (!batchQueue) {
|
|
505
|
-
latency =
|
|
551
|
+
latency = 1 /* Normal */;
|
|
506
552
|
batchQueue = _batchQueues[latency];
|
|
507
553
|
}
|
|
508
554
|
var eventBatch = batchQueue.iKeyMap[iKey];
|
|
@@ -534,7 +580,7 @@ var PostChannel = /** @class */ (function (_super) {
|
|
|
534
580
|
var latency = event.latency;
|
|
535
581
|
var eventBatch = _getEventBatch(event.iKey, latency, true);
|
|
536
582
|
if (eventBatch.addEvent(event)) {
|
|
537
|
-
if (latency !==
|
|
583
|
+
if (latency !== 4 /* Immediate */) {
|
|
538
584
|
_queueSize++;
|
|
539
585
|
// Check for auto flushing based on total events in the queue, but not for requeued or retry events
|
|
540
586
|
if (append && event.sendAttempt === 0) {
|
|
@@ -558,7 +604,7 @@ var PostChannel = /** @class */ (function (_super) {
|
|
|
558
604
|
var droppedEvents = eventBatch.split(0, dropNumber);
|
|
559
605
|
var droppedCount = droppedEvents.count();
|
|
560
606
|
if (droppedCount > 0) {
|
|
561
|
-
if (currentLatency ===
|
|
607
|
+
if (currentLatency === 4 /* Immediate */) {
|
|
562
608
|
_immediateQueueSize -= droppedCount;
|
|
563
609
|
}
|
|
564
610
|
else {
|
|
@@ -585,7 +631,7 @@ var PostChannel = /** @class */ (function (_super) {
|
|
|
585
631
|
var batchQueue = _batchQueues[latency];
|
|
586
632
|
if (batchQueue && batchQueue.batches) {
|
|
587
633
|
arrForEach(batchQueue.batches, function (theBatch) {
|
|
588
|
-
if (latency ===
|
|
634
|
+
if (latency === 4 /* Immediate */) {
|
|
589
635
|
immediateQueue += theBatch.count();
|
|
590
636
|
}
|
|
591
637
|
else {
|
|
@@ -594,7 +640,7 @@ var PostChannel = /** @class */ (function (_super) {
|
|
|
594
640
|
});
|
|
595
641
|
}
|
|
596
642
|
};
|
|
597
|
-
for (var latency =
|
|
643
|
+
for (var latency = 1 /* Normal */; latency <= 4 /* Immediate */; latency++) {
|
|
598
644
|
_loop_1(latency);
|
|
599
645
|
}
|
|
600
646
|
_queueSize = normalQueue;
|
|
@@ -609,7 +655,7 @@ var PostChannel = /** @class */ (function (_super) {
|
|
|
609
655
|
if (!isAsync || _httpManager.canSendRequest()) {
|
|
610
656
|
doPerf(_self.core, function () { return "PostChannel._queueBatches"; }, function () {
|
|
611
657
|
var droppedEvents = [];
|
|
612
|
-
var latencyToProcess =
|
|
658
|
+
var latencyToProcess = 4 /* Immediate */;
|
|
613
659
|
while (latencyToProcess >= latency) {
|
|
614
660
|
var batchQueue = _batchQueues[latencyToProcess];
|
|
615
661
|
if (batchQueue && batchQueue.batches && batchQueue.batches.length > 0) {
|
|
@@ -622,7 +668,7 @@ var PostChannel = /** @class */ (function (_super) {
|
|
|
622
668
|
else {
|
|
623
669
|
eventsQueued = eventsQueued || (theBatch && theBatch.count() > 0);
|
|
624
670
|
}
|
|
625
|
-
if (latencyToProcess ===
|
|
671
|
+
if (latencyToProcess === 4 /* Immediate */) {
|
|
626
672
|
_immediateQueueSize -= theBatch.count();
|
|
627
673
|
}
|
|
628
674
|
else {
|
|
@@ -659,7 +705,7 @@ var PostChannel = /** @class */ (function (_super) {
|
|
|
659
705
|
*/
|
|
660
706
|
function _flushImpl(callback, sendReason) {
|
|
661
707
|
// Add any additional queued events and cause all queued events to be sent asynchronously
|
|
662
|
-
_sendEventsForLatencyAndAbove(
|
|
708
|
+
_sendEventsForLatencyAndAbove(1 /* Normal */, 0 /* Batched */, sendReason);
|
|
663
709
|
_waitForIdleManager(function () {
|
|
664
710
|
// Only called AFTER the httpManager does not have any outstanding requests
|
|
665
711
|
if (callback) {
|
|
@@ -721,7 +767,7 @@ var PostChannel = /** @class */ (function (_super) {
|
|
|
721
767
|
if (theEvent) {
|
|
722
768
|
// Check if the request being added back is for a sync event in which case mark it no longer a sync event
|
|
723
769
|
if (theEvent.sync) {
|
|
724
|
-
theEvent.latency =
|
|
770
|
+
theEvent.latency = 4 /* Immediate */;
|
|
725
771
|
theEvent.sync = false;
|
|
726
772
|
}
|
|
727
773
|
if (theEvent.sendAttempt < maxSendAttempts) {
|
|
@@ -752,7 +798,7 @@ var PostChannel = /** @class */ (function (_super) {
|
|
|
752
798
|
notifyFunc.apply(manager, theArgs);
|
|
753
799
|
}
|
|
754
800
|
catch (e) {
|
|
755
|
-
_self.diagLog()
|
|
801
|
+
_throwInternal(_self.diagLog(), 1 /* CRITICAL */, 74 /* NotificationException */, evtName + " notification failed: " + e);
|
|
756
802
|
}
|
|
757
803
|
}
|
|
758
804
|
}
|
|
@@ -822,13 +868,21 @@ var PostChannel = /** @class */ (function (_super) {
|
|
|
822
868
|
_autoFlushBatchLimit = 0;
|
|
823
869
|
}
|
|
824
870
|
}
|
|
871
|
+
// Provided for backward compatibility they are not "expected" to be in current use but they are public
|
|
872
|
+
objDefineAccessors(_self, "_setTimeoutOverride", function () { return _timeoutWrapper.set; }, function (value) {
|
|
873
|
+
// Recreate the timeout wrapper
|
|
874
|
+
_timeoutWrapper = createTimeoutWrapper(value, _timeoutWrapper.clear);
|
|
875
|
+
});
|
|
876
|
+
objDefineAccessors(_self, "_clearTimeoutOverride", function () { return _timeoutWrapper.clear; }, function (value) {
|
|
877
|
+
// Recreate the timeout wrapper
|
|
878
|
+
_timeoutWrapper = createTimeoutWrapper(_timeoutWrapper.set, value);
|
|
879
|
+
});
|
|
825
880
|
});
|
|
826
881
|
return _this;
|
|
827
882
|
}
|
|
828
883
|
// Removed Stub for PostChannel.prototype.initialize.
|
|
829
884
|
// Removed Stub for PostChannel.prototype.processTelemetry.
|
|
830
885
|
// Removed Stub for PostChannel.prototype.setEventQueueLimits.
|
|
831
|
-
// Removed Stub for PostChannel.prototype.teardown.
|
|
832
886
|
// Removed Stub for PostChannel.prototype.pause.
|
|
833
887
|
// Removed Stub for PostChannel.prototype.resume.
|
|
834
888
|
// Removed Stub for PostChannel.prototype.addResponseHandler.
|