@microsoft/1ds-post-js 3.1.10 → 3.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +124 -6
- package/bundle/{ms.post-3.1.10.gbl.js → ms.post-3.2.1.gbl.js} +1502 -725
- package/bundle/ms.post-3.2.1.gbl.js.map +1 -0
- package/bundle/ms.post-3.2.1.gbl.min.js +7 -0
- package/bundle/ms.post-3.2.1.gbl.min.js.map +1 -0
- package/bundle/ms.post-3.2.1.integrity.json +46 -0
- package/bundle/{ms.post-3.1.10.js → ms.post-3.2.1.js} +1502 -725
- package/bundle/ms.post-3.2.1.js.map +1 -0
- package/bundle/ms.post-3.2.1.min.js +7 -0
- package/bundle/ms.post-3.2.1.min.js.map +1 -0
- package/bundle/ms.post.gbl.js +1501 -724
- 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 +1501 -724
- 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 +264 -149
- 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.d.ts +1 -0
- package/dist-esm/src/Constants.js +2 -1
- package/dist-esm/src/Constants.js.map +1 -1
- package/dist-esm/src/DataModels.d.ts +49 -0
- package/dist-esm/src/DataModels.js +1 -1
- package/dist-esm/src/EventBatch.js +1 -1
- package/dist-esm/src/HttpManager.d.ts +1 -1
- package/dist-esm/src/HttpManager.js +102 -58
- 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 +0 -4
- package/dist-esm/src/PostChannel.js +171 -104
- 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/typings/XDomainRequest.js +1 -1
- package/package.json +2 -2
- package/src/Constants.ts +1 -0
- package/src/DataModels.ts +62 -1
- package/src/HttpManager.ts +110 -69
- package/src/PostChannel.ts +203 -127
- package/src/RetryPolicy.ts +33 -38
- package/bundle/ms.post-3.1.10.gbl.js.map +0 -1
- package/bundle/ms.post-3.1.10.gbl.min.js +0 -7
- package/bundle/ms.post-3.1.10.gbl.min.js.map +0 -1
- package/bundle/ms.post-3.1.10.integrity.json +0 -46
- package/bundle/ms.post-3.1.10.js.map +0 -1
- package/bundle/ms.post-3.1.10.min.js +0 -7
- package/bundle/ms.post-3.1.10.min.js.map +0 -1
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*
|
|
2
|
-
* 1DS JS SDK POST plugin, 3.1
|
|
2
|
+
* 1DS JS SDK POST plugin, 3.2.1
|
|
3
3
|
* Copyright (c) Microsoft and contributors. All rights reserved.
|
|
4
4
|
* (Microsoft Internal Only)
|
|
5
5
|
*/
|
|
@@ -9,23 +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 { BaseTelemetryPlugin,
|
|
12
|
+
import { BaseTelemetryPlugin, EventsDiscardedReason, isValueAssigned, setProcessTelemetryTimings, isWindowObjectAvailable, arrForEach, doPerf, objForEachKey, optimizeObject, isChromium, getWindow, isNumber, mergeEvtNamespace, createUniqueNamespace, addPageUnloadEventListener, addPageHideEventListener, addPageShowEventListener, removePageUnloadEventListener, removePageHideEventListener, removePageShowEventListener, _throwInternal } from "@microsoft/1ds-core-js";
|
|
13
13
|
import { RT_PROFILE, NRT_PROFILE, BE_PROFILE, } from "./DataModels";
|
|
14
14
|
import { EventBatch } from "./EventBatch";
|
|
15
15
|
import { HttpManager } from "./HttpManager";
|
|
16
|
-
import
|
|
16
|
+
import { retryPolicyGetMillisToBackoffForRetry } from "./RetryPolicy";
|
|
17
17
|
import dynamicProto from "@microsoft/dynamicproto-js";
|
|
18
18
|
import { strMsaDeviceTicket } from "./Constants";
|
|
19
19
|
var FlushCheckTimer = 0.250; // This needs to be in seconds, so this is 250ms
|
|
20
20
|
var MaxNumberEventPerBatch = 500;
|
|
21
21
|
var EventsDroppedAtOneTime = 20;
|
|
22
22
|
var MaxSendAttempts = 6;
|
|
23
|
+
var MaxSyncUnloadSendAttempts = 2; // Assuming 2 based on beforeunload and unload
|
|
23
24
|
var MaxBackoffCount = 4;
|
|
24
25
|
var globalContext = isWindowObjectAvailable ? window : this;
|
|
25
26
|
var MaxConnections = 2;
|
|
26
|
-
var
|
|
27
|
+
var MaxRequestRetriesBeforeBackoff = 1;
|
|
27
28
|
var strEventsDiscarded = "eventsDiscarded";
|
|
28
29
|
var strOverrideInstrumentationKey = "overrideInstrumentationKey";
|
|
30
|
+
var strMaxEventRetryAttempts = "maxEventRetryAttempts";
|
|
31
|
+
var strMaxUnloadEventRetryAttempts = "maxUnloadEventRetryAttempts";
|
|
32
|
+
var strAddUnloadCb = "addUnloadCb";
|
|
29
33
|
/**
|
|
30
34
|
* Class that manages adding events to inbound queues and batching of events
|
|
31
35
|
* into requests.
|
|
@@ -36,7 +40,7 @@ var PostChannel = /** @class */ (function (_super) {
|
|
|
36
40
|
var _this = _super.call(this) || this;
|
|
37
41
|
_this.identifier = "PostChannel";
|
|
38
42
|
_this.priority = 1011;
|
|
39
|
-
_this.version = '3.1
|
|
43
|
+
_this.version = '3.2.1';
|
|
40
44
|
var _config;
|
|
41
45
|
var _isTeardownCalled = false;
|
|
42
46
|
var _flushCallbackQueue = [];
|
|
@@ -62,18 +66,12 @@ var PostChannel = /** @class */ (function (_super) {
|
|
|
62
66
|
var _delayedBatchReason;
|
|
63
67
|
var _optimizeObject = true;
|
|
64
68
|
var _isPageUnloadTriggered = false;
|
|
69
|
+
var _disableXhrSync = false;
|
|
70
|
+
var _maxEventSendAttempts = MaxSendAttempts;
|
|
71
|
+
var _maxUnloadEventSendAttempts = MaxSyncUnloadSendAttempts;
|
|
72
|
+
var _evtNamespace;
|
|
65
73
|
dynamicProto(PostChannel, _this, function (_self, _base) {
|
|
66
|
-
|
|
67
|
-
_clearQueues();
|
|
68
|
-
_setAutoLimits();
|
|
69
|
-
_httpManager = new HttpManager(MaxNumberEventPerBatch, MaxConnections, MaxRetries, {
|
|
70
|
-
requeue: _requeueEvents,
|
|
71
|
-
send: _sendingEvent,
|
|
72
|
-
sent: _eventsSentEvent,
|
|
73
|
-
drop: _eventsDropped,
|
|
74
|
-
rspFail: _eventsResponseFail,
|
|
75
|
-
oth: _otherEvent
|
|
76
|
-
});
|
|
74
|
+
_initDefaults();
|
|
77
75
|
// Special internal method to allow the DebugPlugin to hook embedded objects
|
|
78
76
|
_self["_getDbgPlgTargets"] = function () {
|
|
79
77
|
return [_httpManager];
|
|
@@ -82,63 +80,57 @@ var PostChannel = /** @class */ (function (_super) {
|
|
|
82
80
|
doPerf(core, function () { return "PostChannel:initialize"; }, function () {
|
|
83
81
|
var extendedCore = core;
|
|
84
82
|
_base.initialize(coreConfig, core, extensions);
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
if (_config.
|
|
97
|
-
|
|
83
|
+
try {
|
|
84
|
+
var hasAddUnloadCb = !!core[strAddUnloadCb];
|
|
85
|
+
_evtNamespace = mergeEvtNamespace(createUniqueNamespace(_self.identifier), core.evtNamespace && core.evtNamespace());
|
|
86
|
+
var ctx = _self._getTelCtx();
|
|
87
|
+
coreConfig.extensionConfig[_self.identifier] = coreConfig.extensionConfig[_self.identifier] || {};
|
|
88
|
+
_config = ctx.getExtCfg(_self.identifier);
|
|
89
|
+
_self._setTimeoutOverride = _config.setTimeoutOverride ? _config.setTimeoutOverride : setTimeout.bind(globalContext);
|
|
90
|
+
_self._clearTimeoutOverride = _config.clearTimeoutOverride ? _config.clearTimeoutOverride : clearTimeout.bind(globalContext);
|
|
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;
|
|
98
96
|
}
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
if (_config.eventsLimitInMem > 0) {
|
|
102
|
-
_queueSizeLimit = _config.eventsLimitInMem;
|
|
103
|
-
}
|
|
104
|
-
if (_config.immediateEventLimit > 0) {
|
|
105
|
-
_immediateQueueSizeLimit = _config.immediateEventLimit;
|
|
106
|
-
}
|
|
107
|
-
if (_config.autoFlushEventsLimit > 0) {
|
|
108
|
-
_autoFlushEventsLimit = _config.autoFlushEventsLimit;
|
|
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
|
-
function _handleUnloadEvents(evt) {
|
|
124
|
-
var theEvt = evt || getWindow().event; // IE 8 does not pass the event
|
|
125
|
-
if (theEvt.type !== "beforeunload") {
|
|
126
|
-
// Only set the unload trigger if not beforeunload event as beforeunload can be cancelled while the other events can't
|
|
127
|
-
_isPageUnloadTriggered = true;
|
|
128
|
-
_httpManager.setUnloading(_isPageUnloadTriggered);
|
|
97
|
+
if (_config.immediateEventLimit > 0) {
|
|
98
|
+
_immediateQueueSizeLimit = _config.immediateEventLimit;
|
|
129
99
|
}
|
|
130
|
-
|
|
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;
|
|
131
133
|
}
|
|
132
|
-
var excludePageUnloadEvents = coreConfig.disablePageUnloadEvents || [];
|
|
133
|
-
// When running in Web browsers try to send all telemetry if page is unloaded
|
|
134
|
-
addPageUnloadEventListener(_handleUnloadEvents, excludePageUnloadEvents);
|
|
135
|
-
addPageHideEventListener(_handleUnloadEvents, excludePageUnloadEvents);
|
|
136
|
-
addPageShowEventListener(function (evt) {
|
|
137
|
-
// Handle the page becoming visible again
|
|
138
|
-
_isPageUnloadTriggered = false;
|
|
139
|
-
_httpManager.setUnloading(_isPageUnloadTriggered);
|
|
140
|
-
}, coreConfig.disablePageShowEvents);
|
|
141
|
-
_self.setInitialized(true);
|
|
142
134
|
}, function () { return ({ coreConfig: coreConfig, core: core, extensions: extensions }); });
|
|
143
135
|
};
|
|
144
136
|
_self.processTelemetry = function (ev, itemCtx) {
|
|
@@ -173,6 +165,41 @@ var PostChannel = /** @class */ (function (_super) {
|
|
|
173
165
|
}
|
|
174
166
|
_self.processNext(event, itemCtx);
|
|
175
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
|
+
};
|
|
178
|
+
function _hookWParam(extendedCore) {
|
|
179
|
+
var existingGetWParamMethod = extendedCore.getWParam;
|
|
180
|
+
extendedCore.getWParam = function () {
|
|
181
|
+
var wparam = 0;
|
|
182
|
+
if (_config.ignoreMc1Ms0CookieProcessing) {
|
|
183
|
+
wparam = wparam | 2;
|
|
184
|
+
}
|
|
185
|
+
return wparam | existingGetWParamMethod();
|
|
186
|
+
};
|
|
187
|
+
}
|
|
188
|
+
// Moving event handlers out from the initialize closure so that any local variables can be garbage collected
|
|
189
|
+
function _handleUnloadEvents(evt) {
|
|
190
|
+
var theEvt = evt || getWindow().event; // IE 8 does not pass the event
|
|
191
|
+
if (theEvt.type !== "beforeunload") {
|
|
192
|
+
// Only set the unload trigger if not beforeunload event as beforeunload can be cancelled while the other events can't
|
|
193
|
+
_isPageUnloadTriggered = true;
|
|
194
|
+
_httpManager.setUnloading(_isPageUnloadTriggered);
|
|
195
|
+
}
|
|
196
|
+
_releaseAllQueues(2 /* SendBeacon */, 2 /* Unload */);
|
|
197
|
+
}
|
|
198
|
+
function _handleShowEvents(evt) {
|
|
199
|
+
// Handle the page becoming visible again
|
|
200
|
+
_isPageUnloadTriggered = false;
|
|
201
|
+
_httpManager.setUnloading(_isPageUnloadTriggered);
|
|
202
|
+
}
|
|
176
203
|
function _addEventToQueues(event, append) {
|
|
177
204
|
// If send attempt field is undefined we should set it to 0.
|
|
178
205
|
if (!event.sendAttempt) {
|
|
@@ -180,7 +207,7 @@ var PostChannel = /** @class */ (function (_super) {
|
|
|
180
207
|
}
|
|
181
208
|
// Add default latency
|
|
182
209
|
if (!event.latency) {
|
|
183
|
-
event.latency =
|
|
210
|
+
event.latency = 1 /* Normal */;
|
|
184
211
|
}
|
|
185
212
|
// Remove extra AI properties if present
|
|
186
213
|
if (event.ext && event.ext["trace"]) {
|
|
@@ -203,7 +230,7 @@ var PostChannel = /** @class */ (function (_super) {
|
|
|
203
230
|
// If the transmission is backed off then do not send synchronous events.
|
|
204
231
|
// We will convert these events to Real time latency instead.
|
|
205
232
|
if (_currentBackoffCount || _paused) {
|
|
206
|
-
event.latency =
|
|
233
|
+
event.latency = 3 /* RealTime */;
|
|
207
234
|
event.sync = false;
|
|
208
235
|
}
|
|
209
236
|
else {
|
|
@@ -221,7 +248,7 @@ var PostChannel = /** @class */ (function (_super) {
|
|
|
221
248
|
var evtLatency = event.latency;
|
|
222
249
|
var queueSize = _queueSize;
|
|
223
250
|
var queueLimit = _queueSizeLimit;
|
|
224
|
-
if (evtLatency ===
|
|
251
|
+
if (evtLatency === 4 /* Immediate */) {
|
|
225
252
|
queueSize = _immediateQueueSize;
|
|
226
253
|
queueLimit = _immediateQueueSizeLimit;
|
|
227
254
|
}
|
|
@@ -231,11 +258,11 @@ var PostChannel = /** @class */ (function (_super) {
|
|
|
231
258
|
eventDropped = !_addEventToProperQueue(event, append);
|
|
232
259
|
}
|
|
233
260
|
else {
|
|
234
|
-
var dropLatency =
|
|
261
|
+
var dropLatency = 1 /* Normal */;
|
|
235
262
|
var dropNumber = EventsDroppedAtOneTime;
|
|
236
|
-
if (evtLatency ===
|
|
263
|
+
if (evtLatency === 4 /* Immediate */) {
|
|
237
264
|
// Only drop other immediate events as they are not technically sharing the general queue
|
|
238
|
-
dropLatency =
|
|
265
|
+
dropLatency = 4 /* Immediate */;
|
|
239
266
|
dropNumber = 1;
|
|
240
267
|
}
|
|
241
268
|
// Drop old event from lower or equal latency
|
|
@@ -257,7 +284,7 @@ var PostChannel = /** @class */ (function (_super) {
|
|
|
257
284
|
var doFlush = _queueSize > eventLimit;
|
|
258
285
|
if (!doFlush && _autoFlushBatchLimit > 0) {
|
|
259
286
|
// Check the auto flush max batch size
|
|
260
|
-
for (var latency =
|
|
287
|
+
for (var latency = 1 /* Normal */; !doFlush && latency <= 3 /* RealTime */; latency++) {
|
|
261
288
|
var batchQueue = _batchQueues[latency];
|
|
262
289
|
if (batchQueue && batchQueue.batches) {
|
|
263
290
|
arrForEach(batchQueue.batches, function (theBatch) {
|
|
@@ -271,11 +298,6 @@ var PostChannel = /** @class */ (function (_super) {
|
|
|
271
298
|
}
|
|
272
299
|
_performAutoFlush(true, doFlush);
|
|
273
300
|
};
|
|
274
|
-
_self.teardown = function () {
|
|
275
|
-
_releaseAllQueues(2 /* SendBeacon */, 2 /* Unload */);
|
|
276
|
-
_isTeardownCalled = true;
|
|
277
|
-
_httpManager.teardown();
|
|
278
|
-
};
|
|
279
301
|
_self.pause = function () {
|
|
280
302
|
_clearScheduledTimer();
|
|
281
303
|
_paused = true;
|
|
@@ -324,7 +346,7 @@ var PostChannel = /** @class */ (function (_super) {
|
|
|
324
346
|
sendReason = sendReason || 1 /* ManualFlush */;
|
|
325
347
|
if (async) {
|
|
326
348
|
// Move all queued events to the HttpManager
|
|
327
|
-
_queueBatches(
|
|
349
|
+
_queueBatches(1 /* Normal */, 0 /* Batched */, sendReason);
|
|
328
350
|
// All events (should) have been queue -- lets just make sure the queue counts are correct to avoid queue exhaustion (previous bug #9685112)
|
|
329
351
|
_resetQueueCounts();
|
|
330
352
|
if (_flushCallbackTimerId == null) {
|
|
@@ -340,7 +362,7 @@ var PostChannel = /** @class */ (function (_super) {
|
|
|
340
362
|
}
|
|
341
363
|
else {
|
|
342
364
|
// Now cause all queued events to be sent synchronously
|
|
343
|
-
_sendEventsForLatencyAndAbove(
|
|
365
|
+
_sendEventsForLatencyAndAbove(1 /* Normal */, 1 /* Synchronous */, sendReason);
|
|
344
366
|
if (callback !== null && callback !== undefined) {
|
|
345
367
|
callback();
|
|
346
368
|
}
|
|
@@ -390,7 +412,7 @@ var PostChannel = /** @class */ (function (_super) {
|
|
|
390
412
|
_immediateTimerId = _createTimer(function () {
|
|
391
413
|
_immediateTimerId = null;
|
|
392
414
|
// Only try to send direct events
|
|
393
|
-
_sendEventsForLatencyAndAbove(
|
|
415
|
+
_sendEventsForLatencyAndAbove(4 /* Immediate */, 0 /* Batched */, 1 /* NormalSchedule */);
|
|
394
416
|
_scheduleTimer();
|
|
395
417
|
}, immediateTimeOut);
|
|
396
418
|
}
|
|
@@ -401,7 +423,7 @@ var PostChannel = /** @class */ (function (_super) {
|
|
|
401
423
|
if (_hasEvents()) {
|
|
402
424
|
_scheduledTimerId = _createTimer(function () {
|
|
403
425
|
_scheduledTimerId = null;
|
|
404
|
-
_sendEventsForLatencyAndAbove(_timerCount === 0 ?
|
|
426
|
+
_sendEventsForLatencyAndAbove(_timerCount === 0 ? 3 /* RealTime */ : 1 /* Normal */, 0 /* Batched */, 1 /* NormalSchedule */);
|
|
405
427
|
// Increment the count for next cycle
|
|
406
428
|
_timerCount++;
|
|
407
429
|
_timerCount %= 2;
|
|
@@ -427,6 +449,47 @@ var PostChannel = /** @class */ (function (_super) {
|
|
|
427
449
|
_scheduleTimer();
|
|
428
450
|
}
|
|
429
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
|
+
_httpManager = new HttpManager(MaxNumberEventPerBatch, MaxConnections, MaxRequestRetriesBeforeBackoff, {
|
|
482
|
+
requeue: _requeueEvents,
|
|
483
|
+
send: _sendingEvent,
|
|
484
|
+
sent: _eventsSentEvent,
|
|
485
|
+
drop: _eventsDropped,
|
|
486
|
+
rspFail: _eventsResponseFail,
|
|
487
|
+
oth: _otherEvent
|
|
488
|
+
});
|
|
489
|
+
_initializeProfiles();
|
|
490
|
+
_clearQueues();
|
|
491
|
+
_setAutoLimits();
|
|
492
|
+
}
|
|
430
493
|
function _createTimer(theTimerFunc, timeOut) {
|
|
431
494
|
// If the transmission is backed off make the timer at least 1 sec to allow for back off.
|
|
432
495
|
if (timeOut === 0 && _currentBackoffCount) {
|
|
@@ -434,7 +497,7 @@ var PostChannel = /** @class */ (function (_super) {
|
|
|
434
497
|
}
|
|
435
498
|
var timerMultiplier = 1000;
|
|
436
499
|
if (_currentBackoffCount) {
|
|
437
|
-
timerMultiplier =
|
|
500
|
+
timerMultiplier = retryPolicyGetMillisToBackoffForRetry(_currentBackoffCount - 1);
|
|
438
501
|
}
|
|
439
502
|
return _self._setTimeoutOverride(theTimerFunc, timeOut * timerMultiplier);
|
|
440
503
|
}
|
|
@@ -455,7 +518,7 @@ var PostChannel = /** @class */ (function (_super) {
|
|
|
455
518
|
}
|
|
456
519
|
if (!_paused) {
|
|
457
520
|
// Queue all the remaining requests to be sent. The requests will be sent using HTML5 Beacons if they are available.
|
|
458
|
-
_sendEventsForLatencyAndAbove(
|
|
521
|
+
_sendEventsForLatencyAndAbove(1 /* Normal */, sendType, sendReason);
|
|
459
522
|
}
|
|
460
523
|
}
|
|
461
524
|
/**
|
|
@@ -464,19 +527,19 @@ var PostChannel = /** @class */ (function (_super) {
|
|
|
464
527
|
* after flush are stored separately till we flush the current events.
|
|
465
528
|
*/
|
|
466
529
|
function _clearQueues() {
|
|
467
|
-
_batchQueues[
|
|
530
|
+
_batchQueues[4 /* Immediate */] = {
|
|
468
531
|
batches: [],
|
|
469
532
|
iKeyMap: {}
|
|
470
533
|
};
|
|
471
|
-
_batchQueues[
|
|
534
|
+
_batchQueues[3 /* RealTime */] = {
|
|
472
535
|
batches: [],
|
|
473
536
|
iKeyMap: {}
|
|
474
537
|
};
|
|
475
|
-
_batchQueues[
|
|
538
|
+
_batchQueues[2 /* CostDeferred */] = {
|
|
476
539
|
batches: [],
|
|
477
540
|
iKeyMap: {}
|
|
478
541
|
};
|
|
479
|
-
_batchQueues[
|
|
542
|
+
_batchQueues[1 /* Normal */] = {
|
|
480
543
|
batches: [],
|
|
481
544
|
iKeyMap: {}
|
|
482
545
|
};
|
|
@@ -484,7 +547,7 @@ var PostChannel = /** @class */ (function (_super) {
|
|
|
484
547
|
function _getEventBatch(iKey, latency, create) {
|
|
485
548
|
var batchQueue = _batchQueues[latency];
|
|
486
549
|
if (!batchQueue) {
|
|
487
|
-
latency =
|
|
550
|
+
latency = 1 /* Normal */;
|
|
488
551
|
batchQueue = _batchQueues[latency];
|
|
489
552
|
}
|
|
490
553
|
var eventBatch = batchQueue.iKeyMap[iKey];
|
|
@@ -516,7 +579,7 @@ var PostChannel = /** @class */ (function (_super) {
|
|
|
516
579
|
var latency = event.latency;
|
|
517
580
|
var eventBatch = _getEventBatch(event.iKey, latency, true);
|
|
518
581
|
if (eventBatch.addEvent(event)) {
|
|
519
|
-
if (latency !==
|
|
582
|
+
if (latency !== 4 /* Immediate */) {
|
|
520
583
|
_queueSize++;
|
|
521
584
|
// Check for auto flushing based on total events in the queue, but not for requeued or retry events
|
|
522
585
|
if (append && event.sendAttempt === 0) {
|
|
@@ -540,7 +603,7 @@ var PostChannel = /** @class */ (function (_super) {
|
|
|
540
603
|
var droppedEvents = eventBatch.split(0, dropNumber);
|
|
541
604
|
var droppedCount = droppedEvents.count();
|
|
542
605
|
if (droppedCount > 0) {
|
|
543
|
-
if (currentLatency ===
|
|
606
|
+
if (currentLatency === 4 /* Immediate */) {
|
|
544
607
|
_immediateQueueSize -= droppedCount;
|
|
545
608
|
}
|
|
546
609
|
else {
|
|
@@ -567,7 +630,7 @@ var PostChannel = /** @class */ (function (_super) {
|
|
|
567
630
|
var batchQueue = _batchQueues[latency];
|
|
568
631
|
if (batchQueue && batchQueue.batches) {
|
|
569
632
|
arrForEach(batchQueue.batches, function (theBatch) {
|
|
570
|
-
if (latency ===
|
|
633
|
+
if (latency === 4 /* Immediate */) {
|
|
571
634
|
immediateQueue += theBatch.count();
|
|
572
635
|
}
|
|
573
636
|
else {
|
|
@@ -576,7 +639,7 @@ var PostChannel = /** @class */ (function (_super) {
|
|
|
576
639
|
});
|
|
577
640
|
}
|
|
578
641
|
};
|
|
579
|
-
for (var latency =
|
|
642
|
+
for (var latency = 1 /* Normal */; latency <= 4 /* Immediate */; latency++) {
|
|
580
643
|
_loop_1(latency);
|
|
581
644
|
}
|
|
582
645
|
_queueSize = normalQueue;
|
|
@@ -591,7 +654,7 @@ var PostChannel = /** @class */ (function (_super) {
|
|
|
591
654
|
if (!isAsync || _httpManager.canSendRequest()) {
|
|
592
655
|
doPerf(_self.core, function () { return "PostChannel._queueBatches"; }, function () {
|
|
593
656
|
var droppedEvents = [];
|
|
594
|
-
var latencyToProcess =
|
|
657
|
+
var latencyToProcess = 4 /* Immediate */;
|
|
595
658
|
while (latencyToProcess >= latency) {
|
|
596
659
|
var batchQueue = _batchQueues[latencyToProcess];
|
|
597
660
|
if (batchQueue && batchQueue.batches && batchQueue.batches.length > 0) {
|
|
@@ -604,7 +667,7 @@ var PostChannel = /** @class */ (function (_super) {
|
|
|
604
667
|
else {
|
|
605
668
|
eventsQueued = eventsQueued || (theBatch && theBatch.count() > 0);
|
|
606
669
|
}
|
|
607
|
-
if (latencyToProcess ===
|
|
670
|
+
if (latencyToProcess === 4 /* Immediate */) {
|
|
608
671
|
_immediateQueueSize -= theBatch.count();
|
|
609
672
|
}
|
|
610
673
|
else {
|
|
@@ -641,7 +704,7 @@ var PostChannel = /** @class */ (function (_super) {
|
|
|
641
704
|
*/
|
|
642
705
|
function _flushImpl(callback, sendReason) {
|
|
643
706
|
// Add any additional queued events and cause all queued events to be sent asynchronously
|
|
644
|
-
_sendEventsForLatencyAndAbove(
|
|
707
|
+
_sendEventsForLatencyAndAbove(1 /* Normal */, 0 /* Batched */, sendReason);
|
|
645
708
|
_waitForIdleManager(function () {
|
|
646
709
|
// Only called AFTER the httpManager does not have any outstanding requests
|
|
647
710
|
if (callback) {
|
|
@@ -692,16 +755,21 @@ var PostChannel = /** @class */ (function (_super) {
|
|
|
692
755
|
*/
|
|
693
756
|
function _requeueEvents(batches, reason) {
|
|
694
757
|
var droppedEvents = [];
|
|
758
|
+
var maxSendAttempts = _maxEventSendAttempts;
|
|
759
|
+
if (_isPageUnloadTriggered) {
|
|
760
|
+
// If a page unlaod has been triggered reduce the number of times we try to "retry"
|
|
761
|
+
maxSendAttempts = _maxUnloadEventSendAttempts;
|
|
762
|
+
}
|
|
695
763
|
arrForEach(batches, function (theBatch) {
|
|
696
764
|
if (theBatch && theBatch.count() > 0) {
|
|
697
765
|
arrForEach(theBatch.events(), function (theEvent) {
|
|
698
766
|
if (theEvent) {
|
|
699
767
|
// Check if the request being added back is for a sync event in which case mark it no longer a sync event
|
|
700
768
|
if (theEvent.sync) {
|
|
701
|
-
theEvent.latency =
|
|
769
|
+
theEvent.latency = 4 /* Immediate */;
|
|
702
770
|
theEvent.sync = false;
|
|
703
771
|
}
|
|
704
|
-
if (theEvent.sendAttempt <
|
|
772
|
+
if (theEvent.sendAttempt < maxSendAttempts) {
|
|
705
773
|
// Reset the event timings
|
|
706
774
|
setProcessTelemetryTimings(theEvent, _self.identifier);
|
|
707
775
|
_addEventToQueues(theEvent, false);
|
|
@@ -729,7 +797,7 @@ var PostChannel = /** @class */ (function (_super) {
|
|
|
729
797
|
notifyFunc.apply(manager, theArgs);
|
|
730
798
|
}
|
|
731
799
|
catch (e) {
|
|
732
|
-
_self.diagLog()
|
|
800
|
+
_throwInternal(_self.diagLog(), 1 /* CRITICAL */, 74 /* NotificationException */, evtName + " notification failed: " + e);
|
|
733
801
|
}
|
|
734
802
|
}
|
|
735
803
|
}
|
|
@@ -805,7 +873,6 @@ var PostChannel = /** @class */ (function (_super) {
|
|
|
805
873
|
// Removed Stub for PostChannel.prototype.initialize.
|
|
806
874
|
// Removed Stub for PostChannel.prototype.processTelemetry.
|
|
807
875
|
// Removed Stub for PostChannel.prototype.setEventQueueLimits.
|
|
808
|
-
// Removed Stub for PostChannel.prototype.teardown.
|
|
809
876
|
// Removed Stub for PostChannel.prototype.pause.
|
|
810
877
|
// Removed Stub for PostChannel.prototype.resume.
|
|
811
878
|
// Removed Stub for PostChannel.prototype.addResponseHandler.
|