, function () { try { _self.sendHook(hookData_1, function (payload) { senderCalled_1 = true; if (!_customHttpInterface && !payload._thePayload) { payload._thePayload = payload._thePayload || orgPayloadData._thePayload; payload._sendReason = payload._sendReason || orgPayloadData._sendReason; } sender(payload); }, thePayload.isSync || thePayload.isTeardown); } catch (ex) { if (!senderCalled_1) { sender(orgPayloadData); } } }); } else { sender(orgPayloadData); } } }); }, function () { return ({ thePayload: thePayload, serializationStart: serializationStart, serializationCompleted: serializationCompleted, sendReason: sendReason }); }, thePayload.isSync); } if (thePayload.sizeExceed && thePayload.sizeExceed.length > 0) { _sendBatchesNotification(thePayload.sizeExceed, 8003 , thePayload.sendType); } if (thePayload.failedEvts && thePayload.failedEvts.length > 0) { _sendBatchesNotification(thePayload.failedEvts, 8002 , thePayload.sendType); } } function _addEventCompletedTimings(theEvents, sendEventCompleted) { if (_enableEventTimings) { arrForEach(theEvents, function (theEvent) { var timings = theEvent.timings = theEvent.timings || {}; _setTimingValue(timings, "sendEventCompleted", sendEventCompleted); }); } } function _retryRequestIfNeeded(status, headers, thePayload, sendReason) { var reason = 9000 ; var droppedBatches = null; var isRetrying = false; var backOffTrans = false; try { var shouldRetry = true; if (typeof status !== strShimUndefined) { if (headers) { _clockSkewManager.setClockSkew(headers[STR_TIME_DELTA_HEADER]); var killDuration = headers[STR_KILL_DURATION_HEADER] || headers["kill-duration-seconds"]; arrForEach(_killSwitch.setKillSwitchTenants(headers[STR_KILL_TOKENS_HEADER], killDuration), function (killToken) { arrForEach(thePayload.batches, function (theBatch) { if (theBatch.iKey() === killToken) { droppedBatches = droppedBatches || []; var removedEvents = theBatch.split(0); thePayload.numEvents -= removedEvents.count(); droppedBatches.push(removedEvents); } }); }); } if (status == 200 || status == 204) { reason = 200 ; return; } if (!retryPolicyShouldRetryForStatus(status) || thePayload.numEvents <= 0) { shouldRetry = false; } reason = 9000 + (status % 1000); } if (shouldRetry) { reason = 100 ; var retryCount_1 = thePayload.retryCnt; if (thePayload.sendType === 0 ) { if (retryCount_1 < maxRequestRetriesBeforeBackoff) { isRetrying = true; _doAction(function () { if (thePayload.sendType === 0 ) { _outstandingRequests--; } _sendBatches(thePayload.batches, retryCount_1 + 1, thePayload.isTeardown, _isUnloading ? 2 : thePayload.sendType, 5 ); }, _isUnloading, retryPolicyGetMillisToBackoffForRetry(retryCount_1)); } else { backOffTrans = true; if (_isUnloading) { reason = 8001 ; } } } } } finally { if (!isRetrying) { _clockSkewManager.setClockSkew(); _handleRequestFinished(thePayload, reason, sendReason, backOffTrans); } _sendBatchesNotification(droppedBatches, 8004 , thePayload.sendType); } } function _handleRequestFinished(thePayload, batchReason, sendReason, backOffTrans) { try { if (backOffTrans) { _postManager._backOffTransmission(); } if (batchReason === 200 ) { if (!backOffTrans && !thePayload.isSync) { _postManager._clearBackOff(); } _addCompleteTimings(thePayload.batches); } _sendBatchesNotification(thePayload.batches, batchReason, thePayload.sendType, true); } finally { if (thePayload.sendType === 0 ) { _outstandingRequests--; if (sendReason !== 5 ) { _self.sendQueuedRequests(thePayload.sendType, sendReason); } } } } function _addCompleteTimings(theBatches) { if (_enableEventTimings) { var sendEventCompleted_1 = getTime(); arrForEach(theBatches, function (theBatch) { if (theBatch && theBatch.count() > 0) { _addEventCompletedTimings(theBatch.events(), sendEventCompleted_1); } }); } } function _doAction(cb, isSync, interval) { if (isSync) { cb(); } else { timeoutOverride.set(cb, interval); } } function _convertAllHeadersToMap(headersString) { var headers = {}; if (isString(headersString)) { var headersArray = strTrim(headersString).split(/[\r\n]+/); arrForEach(headersArray, function (headerEntry) { if (headerEntry) { var idx = headerEntry.indexOf(": "); if (idx !== -1) { var header = strTrim(headerEntry.substring(0, idx)).toLowerCase(); var value = strTrim(headerEntry.substring(idx + 1)); headers[header] = value; } else { headers[strTrim(headerEntry)] = 1; } } }); } return headers; } function _getMsfpc(thePayload) { for (var lp = 0; lp < thePayload.batches.length; lp++) { var msfpc = thePayload.batches[lp].Msfpc(); if (msfpc) { return encodeURIComponent(msfpc); } } return STR_EMPTY; } function _handleCollectorResponse(responseText) { var responseHandlers = _self._responseHandlers; try { for (var i = 0; i < responseHandlers.length; i++) { try { responseHandlers[i](responseText); } catch (e) { _throwInternal(_logger, 1 , 519 , "Response handler failed: " + e); } } if (responseText) { var response = JSON.parse(responseText); if (isValueAssigned(response.webResult) && isValueAssigned(response.webResult[STR_MSFPC])) { _cookieMgr.set("MSFPC", response.webResult[STR_MSFPC], 365 * 86400); } } } catch (ex) { } } function _sendBatchesNotification(theBatches, batchReason, sendType, sendSync) { if (theBatches && theBatches.length > 0 && actions) { var theAction_1 = actions[_getNotificationAction(batchReason)]; if (theAction_1) { var isSyncRequest_1 = sendType !== 0 ; doPerf(_core, function () { return "HttpManager:_sendBatchesNotification"; }, function () { _doAction(function () { try { theAction_1.call(actions, theBatches, batchReason, isSyncRequest_1, sendType); } catch (e) { _throwInternal(_logger, 1 , 74 , "send request notification failed: " + e); } }, sendSync || isSyncRequest_1, 0); }, function () { return ({ batches: _createDebugBatches(theBatches), reason: batchReason, isSync: isSyncRequest_1, sendSync: sendSync, sendType: sendType }); }, !isSyncRequest_1); } } } function _getNotificationAction(reason) { var action = _eventActionMap[reason]; if (!isValueAssigned(action)) { action = STR_OTHER; if (reason >= 9000 && reason <= 9999 ) { action = STR_RESPONSE_FAIL; } else if (reason >= 8000 && reason <= 8999 ) { action = STR_DROPPED; } else if (reason >= 1000 && reason <= 1999 ) { action = STR_SENDING; } } return action; } }); } HttpManager.__ieDyn=1; return HttpManager; }()); function defaultSetTimeout(callback, ms) { var args = []; for (var _i = 2; _i < arguments.length; _i++) { args[_i - 2] = arguments[_i]; } return setTimeout(callback, ms, args); } function defaultClearTimeout(timeoutId) { clearTimeout(timeoutId); } function createTimeoutWrapper(argSetTimeout, argClearTimeout) { return { set: argSetTimeout || defaultSetTimeout, clear: argClearTimeout || defaultClearTimeout }; } var FlushCheckTimer = 0.250; var MaxNumberEventPerBatch = 500; var EventsDroppedAtOneTime = 20; var MaxSendAttempts = 6; var MaxSyncUnloadSendAttempts = 2; var MaxBackoffCount = 4; var MaxConnections = 2; var MaxRequestRetriesBeforeBackoff = 1; var strEventsDiscarded = "eventsDiscarded"; var strOverrideInstrumentationKey = "overrideInstrumentationKey"; var strMaxEventRetryAttempts = "maxEventRetryAttempts"; var strMaxUnloadEventRetryAttempts = "maxUnloadEventRetryAttempts"; var strAddUnloadCb = "addUnloadCb"; var PostChannel = /** @class */ (function (_super) { __extendsFn(PostChannel, _super); function PostChannel() { var _this = _super.call(this) || this; _this.identifier = "PostChannel"; _this.priority = 1011; _this.version = '3.2.13'; var _config; var _isTeardownCalled = false; var _flushCallbackQueue = []; var _flushCallbackTimerId = null; var _paused = false; var _immediateQueueSize = 0; var _immediateQueueSizeLimit = 500; var _queueSize = 0; var _queueSizeLimit = 10000; var _profiles = {}; var _currentProfile = RT_PROFILE; var _scheduledTimerId = null; var _immediateTimerId = null; var _currentBackoffCount = 0; var _timerCount = 0; var _xhrOverride; var _httpManager; var _batchQueues = {}; var _autoFlushEventsLimit; var _autoFlushBatchLimit; var _delayedBatchSendLatency = -1; var _delayedBatchReason; var _optimizeObject = true; var _isPageUnloadTriggered = false; var _maxEventSendAttempts = MaxSendAttempts; var _maxUnloadEventSendAttempts = MaxSyncUnloadSendAttempts; var _evtNamespace; var _timeoutWrapper; dynamicProto(PostChannel, _this, function (_self, _base) { _initDefaults(); _self["_getDbgPlgTargets"] = function () { return [_httpManager]; }; _self.initialize = function (coreConfig, core, extensions) { doPerf(core, function () { return "PostChannel:initialize"; }, function () { var extendedCore = core; _base.initialize(coreConfig, core, extensions); try { var hasAddUnloadCb = !!core[strAddUnloadCb]; _evtNamespace = mergeEvtNamespace(createUniqueNamespace(_self.identifier), core.evtNamespace && core.evtNamespace()); var ctx = _self._getTelCtx(); coreConfig.extensionConfig[_self.identifier] = coreConfig.extensionConfig[_self.identifier] || {}; _config = ctx.getExtCfg(_self.identifier); _timeoutWrapper = createTimeoutWrapper(_config.setTimeoutOverride, _config.clearTimeoutOverride); _optimizeObject = !_config.disableOptimizeObj && isChromium(); _hookWParam(extendedCore); if (_config.eventsLimitInMem > 0) { _queueSizeLimit = _config.eventsLimitInMem; } if (_config.immediateEventLimit > 0) { _immediateQueueSizeLimit = _config.immediateEventLimit; } if (_config.autoFlushEventsLimit > 0) { _autoFlushEventsLimit = _config.autoFlushEventsLimit; } if (isNumber(_config[strMaxEventRetryAttempts])) { _maxEventSendAttempts = _config[strMaxEventRetryAttempts]; } if (isNumber(_config[strMaxUnloadEventRetryAttempts])) { _maxUnloadEventSendAttempts = _config[strMaxUnloadEventRetryAttempts]; } _setAutoLimits(); if (_config.httpXHROverride && _config.httpXHROverride.sendPOST) { _xhrOverride = _config.httpXHROverride; } if (isValueAssigned(coreConfig.anonCookieName)) { _httpManager.addQueryStringParameter("anoncknm", coreConfig.anonCookieName); } _httpManager.sendHook = _config.payloadPreprocessor; _httpManager.sendListener = _config.payloadListener; var endpointUrl = _config.overrideEndpointUrl ? _config.overrideEndpointUrl : coreConfig.endpointUrl; _self._notificationManager = core.getNotifyMgr(); _httpManager.initialize(endpointUrl, _self.core, _self, _xhrOverride, _config); var excludePageUnloadEvents = coreConfig.disablePageUnloadEvents || []; addPageUnloadEventListener(_handleUnloadEvents, excludePageUnloadEvents, _evtNamespace); addPageHideEventListener(_handleUnloadEvents, excludePageUnloadEvents, _evtNamespace); addPageShowEventListener(_handleShowEvents, coreConfig.disablePageShowEvents, _evtNamespace); } catch (e) { _self.setInitialized(false); throw e; } }, function () { return ({ coreConfig: coreConfig, core: core, extensions: extensions }); }); }; _self.processTelemetry = function (ev, itemCtx) { setProcessTelemetryTimings(ev, _self.identifier); itemCtx = _self._getTelCtx(itemCtx); var channelConfig = itemCtx.getExtCfg(_self.identifier); var disableTelemetry = !!_config.disableTelemetry; if (channelConfig) { disableTelemetry = disableTelemetry || !!channelConfig.disableTelemetry; } var event = ev; if (!disableTelemetry && !_isTeardownCalled) { if (_config[strOverrideInstrumentationKey]) { event.iKey = _config[strOverrideInstrumentationKey]; } if (channelConfig && channelConfig[strOverrideInstrumentationKey]) { event.iKey = channelConfig[strOverrideInstrumentationKey]; } _addEventToQueues(event, true); if (_isPageUnloadTriggered) { _releaseAllQueues(2 , 2 ); } else { _scheduleTimer(); } } _self.processNext(event, itemCtx); }; _self._doTeardown = function (unloadCtx, unloadState) { _releaseAllQueues(2 , 2 ); _isTeardownCalled = true; _httpManager.teardown(); removePageUnloadEventListener(null, _evtNamespace); removePageHideEventListener(null, _evtNamespace); removePageShowEventListener(null, _evtNamespace); _initDefaults(); }; function _hookWParam(extendedCore) { var existingGetWParamMethod = extendedCore.getWParam; extendedCore.getWParam = function () { var wparam = 0; if (_config.ignoreMc1Ms0CookieProcessing) { wparam = wparam | 2; } return wparam | existingGetWParamMethod(); }; } function _handleUnloadEvents(evt) { var theEvt = evt || getWindow().event; if (theEvt.type !== "beforeunload") { _isPageUnloadTriggered = true; _httpManager.setUnloading(_isPageUnloadTriggered); } _releaseAllQueues(2 , 2 ); } function _handleShowEvents(evt) { _isPageUnloadTriggered = false; _httpManager.setUnloading(_isPageUnloadTriggered); } function _addEventToQueues(event, append) { if (!event.sendAttempt) { event.sendAttempt = 0; } if (!event.latency) { event.latency = 1 ; } if (event.ext && event.ext[STR_TRACE]) { delete (event.ext[STR_TRACE]); } if (event.ext && event.ext[STR_USER] && event.ext[STR_USER]["id"]) { delete (event.ext[STR_USER]["id"]); } if (_optimizeObject) { event.ext = optimizeObject(event.ext); if (event.baseData) { event.baseData = optimizeObject(event.baseData); } if (event.data) { event.data = optimizeObject(event.data); } } if (event.sync) { if (_currentBackoffCount || _paused) { event.latency = 3 ; event.sync = false; } else { if (_httpManager) { if (_optimizeObject) { event = optimizeObject(event); } _httpManager.sendSynchronousBatch(EventBatch.create(event.iKey, [event]), event.sync === true ? 1 : event.sync, 3 ); return; } } } var evtLatency = event.latency; var queueSize = _queueSize; var queueLimit = _queueSizeLimit; if (evtLatency === 4 ) { queueSize = _immediateQueueSize; queueLimit = _immediateQueueSizeLimit; } var eventDropped = false; if (queueSize < queueLimit) { eventDropped = !_addEventToProperQueue(event, append); } else { var dropLatency = 1 ; var dropNumber = EventsDroppedAtOneTime; if (evtLatency === 4 ) { dropLatency = 4 ; dropNumber = 1; } eventDropped = true; if (_dropEventWithLatencyOrLess(event.iKey, event.latency, dropLatency, dropNumber)) { eventDropped = !_addEventToProperQueue(event, append); } } if (eventDropped) { _notifyEvents(strEventsDiscarded, [event], EventsDiscardedReason.QueueFull); } } _self.setEventQueueLimits = function (eventLimit, autoFlushLimit) { _queueSizeLimit = eventLimit > 0 ? eventLimit : 10000; _autoFlushEventsLimit = autoFlushLimit > 0 ? autoFlushLimit : 0; _setAutoLimits(); var doFlush = _queueSize > eventLimit; if (!doFlush && _autoFlushBatchLimit > 0) { for (var latency = 1 ; !doFlush && latency <= 3 ; latency++) { var batchQueue = _batchQueues[latency]; if (batchQueue && batchQueue.batches) { arrForEach(batchQueue.batches, function (theBatch) { if (theBatch && theBatch.count() >= _autoFlushBatchLimit) { doFlush = true; } }); } } } _performAutoFlush(true, doFlush); }; _self.pause = function () { _clearScheduledTimer(); _paused = true; _httpManager.pause(); }; _self.resume = function () { _paused = false; _httpManager.resume(); _scheduleTimer(); }; _self.addResponseHandler = function (responseHandler) { _httpManager._responseHandlers.push(responseHandler); }; _self._loadTransmitProfiles = function (profiles) { _resetTransmitProfiles(); objForEachKey(profiles, function (profileName, profileValue) { var profLen = profileValue.length; if (profLen >= 2) { var directValue = (profLen > 2 ? profileValue[2] : 0); profileValue.splice(0, profLen - 2); if (profileValue[1] < 0) { profileValue[0] = -1; } if (profileValue[1] > 0 && profileValue[0] > 0) { var timerMultiplier = profileValue[0] / profileValue[1]; profileValue[0] = Math.ceil(timerMultiplier) * profileValue[1]; } if (directValue >= 0 && profileValue[1] >= 0 && directValue > profileValue[1]) { directValue = profileValue[1]; } profileValue.push(directValue); _profiles[profileName] = profileValue; } }); }; _self.flush = function (async, callback, sendReason) { if (async === void 0) { async = true; } if (!_paused) { sendReason = sendReason || 1 ; if (async) { if (_flushCallbackTimerId == null) { _clearScheduledTimer(); _queueBatches(1 , 0 , sendReason); _flushCallbackTimerId = _createTimer(function () { _flushCallbackTimerId = null; _flushImpl(callback, sendReason); }, 0); } else { _flushCallbackQueue.push(callback); } } else { var cleared = _clearScheduledTimer(); _sendEventsForLatencyAndAbove(1 , 1 , sendReason); if (callback !== null && callback !== undefined) { callback(); } if (cleared) { _scheduleTimer(); } } } }; _self.setMsaAuthTicket = function (ticket) { _httpManager.addHeader(STR_MSA_DEVICE_TICKET, ticket); }; _self.hasEvents = _hasEvents; _self._setTransmitProfile = function (profileName) { if (_currentProfile !== profileName && _profiles[profileName] !== undefined) { _clearScheduledTimer(); _currentProfile = profileName; _scheduleTimer(); } }; function _sendEventsForLatencyAndAbove(latency, sendType, sendReason) { var queued = _queueBatches(latency, sendType, sendReason); _httpManager.sendQueuedRequests(sendType, sendReason); return queued; } function _hasEvents() { return _queueSize > 0; } function _scheduleTimer() { if (_delayedBatchSendLatency >= 0 && _queueBatches(_delayedBatchSendLatency, 0 , _delayedBatchReason)) { _httpManager.sendQueuedRequests(0 , _delayedBatchReason); } if (_immediateQueueSize > 0 && !_immediateTimerId && !_paused) { var immediateTimeOut = _profiles[_currentProfile][2]; if (immediateTimeOut >= 0) { _immediateTimerId = _createTimer(function () { _immediateTimerId = null; _sendEventsForLatencyAndAbove(4 , 0 , 1 ); _scheduleTimer(); }, immediateTimeOut); } } var timeOut = _profiles[_currentProfile][1]; if (!_scheduledTimerId && !_flushCallbackTimerId && timeOut >= 0 && !_paused) { if (_hasEvents()) { _scheduledTimerId = _createTimer(function () { _scheduledTimerId = null; _sendEventsForLatencyAndAbove(_timerCount === 0 ? 3 : 1 , 0 , 1 ); _timerCount++; _timerCount %= 2; _scheduleTimer(); }, timeOut); } else { _timerCount = 0; } } } _self._backOffTransmission = function () { if (_currentBackoffCount < MaxBackoffCount) { _currentBackoffCount++; _clearScheduledTimer(); _scheduleTimer(); } }; _self._clearBackOff = function () { if (_currentBackoffCount) { _currentBackoffCount = 0; _clearScheduledTimer(); _scheduleTimer(); } }; function _initDefaults() { _config = null; _isTeardownCalled = false; _flushCallbackQueue = []; _flushCallbackTimerId = null; _paused = false; _immediateQueueSize = 0; _immediateQueueSizeLimit = 500; _queueSize = 0; _queueSizeLimit = 10000; _profiles = {}; _currentProfile = RT_PROFILE; _scheduledTimerId = null; _immediateTimerId = null; _currentBackoffCount = 0; _timerCount = 0; _xhrOverride = null; _batchQueues = {}; _autoFlushEventsLimit = undefined; _autoFlushBatchLimit = 0; _delayedBatchSendLatency = -1; _delayedBatchReason = null; _optimizeObject = true; _isPageUnloadTriggered = false; _maxEventSendAttempts = MaxSendAttempts; _maxUnloadEventSendAttempts = MaxSyncUnloadSendAttempts; _evtNamespace = null; _timeoutWrapper = createTimeoutWrapper(); _httpManager = new HttpManager(MaxNumberEventPerBatch, MaxConnections, MaxRequestRetriesBeforeBackoff, { requeue: _requeueEvents, send: _sendingEvent, sent: _eventsSentEvent, drop: _eventsDropped, rspFail: _eventsResponseFail, oth: _otherEvent }, _timeoutWrapper); _initializeProfiles(); _clearQueues(); _setAutoLimits(); } function _createTimer(theTimerFunc, timeOut) { if (timeOut === 0 && _currentBackoffCount) { timeOut = 1; } var timerMultiplier = 1000; if (_currentBackoffCount) { timerMultiplier = retryPolicyGetMillisToBackoffForRetry(_currentBackoffCount - 1); } return _timeoutWrapper.set(theTimerFunc, timeOut * timerMultiplier); } function _clearScheduledTimer() { if (_scheduledTimerId !== null) { _timeoutWrapper.clear(_scheduledTimerId); _scheduledTimerId = null; _timerCount = 0; return true; } return false; } function _releaseAllQueues(sendType, sendReason) { _clearScheduledTimer(); if (_flushCallbackTimerId) { _timeoutWrapper.clear(_flushCallbackTimerId); _flushCallbackTimerId = null; } if (!_paused) { _sendEventsForLatencyAndAbove(1 , sendType, sendReason); } } function _clearQueues() { _batchQueues[4 ] = { batches: [], iKeyMap: {} }; _batchQueues[3 ] = { batches: [], iKeyMap: {} }; _batchQueues[2 ] = { batches: [], iKeyMap: {} }; _batchQueues[1 ] = { batches: [], iKeyMap: {} }; } function _getEventBatch(iKey, latency, create) { var batchQueue = _batchQueues[latency]; if (!batchQueue) { latency = 1 ; batchQueue = _batchQueues[latency]; } var eventBatch = batchQueue.iKeyMap[iKey]; if (!eventBatch && create) { eventBatch = EventBatch.create(iKey); batchQueue.batches.push(eventBatch); batchQueue.iKeyMap[iKey] = eventBatch; } return eventBatch; } function _performAutoFlush(isAsync, doFlush) { if (_httpManager.canSendRequest() && !_currentBackoffCount) { if (_autoFlushEventsLimit > 0 && _queueSize > _autoFlushEventsLimit) { doFlush = true; } if (doFlush && _flushCallbackTimerId == null) { _self.flush(isAsync, null, 20 ); } } } function _addEventToProperQueue(event, append) { if (_optimizeObject) { event = optimizeObject(event); } var latency = event.latency; var eventBatch = _getEventBatch(event.iKey, latency, true); if (eventBatch.addEvent(event)) { if (latency !== 4 ) { _queueSize++; if (append && event.sendAttempt === 0) { _performAutoFlush(!event.sync, _autoFlushBatchLimit > 0 && eventBatch.count() >= _autoFlushBatchLimit); } } else { _immediateQueueSize++; } return true; } return false; } function _dropEventWithLatencyOrLess(iKey, latency, currentLatency, dropNumber) { while (currentLatency <= latency) { var eventBatch = _getEventBatch(iKey, latency, true); if (eventBatch && eventBatch.count() > 0) { var droppedEvents = eventBatch.split(0, dropNumber); var droppedCount = droppedEvents.count(); if (droppedCount > 0) { if (currentLatency === 4 ) { _immediateQueueSize -= droppedCount; } else { _queueSize -= droppedCount; } _notifyBatchEvents(strEventsDiscarded, [droppedEvents], EventsDiscardedReason.QueueFull); return true; } } currentLatency++; } _resetQueueCounts(); return false; } function _resetQueueCounts() { var immediateQueue = 0; var normalQueue = 0; var _loop_1 = function (latency) { var batchQueue = _batchQueues[latency]; if (batchQueue && batchQueue.batches) { arrForEach(batchQueue.batches, function (theBatch) { if (latency === 4 ) { immediateQueue += theBatch.count(); } else { normalQueue += theBatch.count(); } }); } }; for (var latency = 1 ; latency <= 4 ; latency++) { _loop_1(latency); } _queueSize = normalQueue; _immediateQueueSize = immediateQueue; } function _queueBatches(latency, sendType, sendReason) { var eventsQueued = false; var isAsync = sendType === 0 ; if (!isAsync || _httpManager.canSendRequest()) { doPerf(_self.core, function () { return "PostChannel._queueBatches"; }, function () { var droppedEvents = []; var latencyToProcess = 4 ; while (latencyToProcess >= latency) { var batchQueue = _batchQueues[latencyToProcess]; if (batchQueue && batchQueue.batches && batchQueue.batches.length > 0) { arrForEach(batchQueue.batches, function (theBatch) { if (!_httpManager.addBatch(theBatch)) { droppedEvents = droppedEvents.concat(theBatch.events()); } else { eventsQueued = eventsQueued || (theBatch && theBatch.count() > 0); } if (latencyToProcess === 4 ) { _immediateQueueSize -= theBatch.count(); } else { _queueSize -= theBatch.count(); } }); batchQueue.batches = []; batchQueue.iKeyMap = {}; } latencyToProcess--; } if (droppedEvents.length > 0) { _notifyEvents(strEventsDiscarded, droppedEvents, EventsDiscardedReason.KillSwitch); } if (eventsQueued && _delayedBatchSendLatency >= latency) { _delayedBatchSendLatency = -1; _delayedBatchReason = 0 ; } }, function () { return ({ latency: latency, sendType: sendType, sendReason: sendReason }); }, !isAsync); } else { _delayedBatchSendLatency = _delayedBatchSendLatency >= 0 ? Math.min(_delayedBatchSendLatency, latency) : latency; _delayedBatchReason = Math.max(_delayedBatchReason, sendReason); } return eventsQueued; } function _flushImpl(callback, sendReason) { _sendEventsForLatencyAndAbove(1 , 0 , sendReason); _resetQueueCounts(); _waitForIdleManager(function () { if (callback) { callback(); } if (_flushCallbackQueue.length > 0) { _flushCallbackTimerId = _createTimer(function () { _flushCallbackTimerId = null; _flushImpl(_flushCallbackQueue.shift(), sendReason); }, 0); } else { _flushCallbackTimerId = null; _scheduleTimer(); } }); } function _waitForIdleManager(callback) { if (_httpManager.isCompletelyIdle()) { callback(); } else { _flushCallbackTimerId = _createTimer(function () { _flushCallbackTimerId = null; _waitForIdleManager(callback); }, FlushCheckTimer); } } function _resetTransmitProfiles() { _clearScheduledTimer(); _initializeProfiles(); _currentProfile = RT_PROFILE; _scheduleTimer(); } function _initializeProfiles() { _profiles = {}; _profiles[RT_PROFILE] = [2, 1, 0]; _profiles[NRT_PROFILE] = [6, 3, 0]; _profiles[BE_PROFILE] = [18, 9, 0]; } function _requeueEvents(batches, reason) { var droppedEvents = []; var maxSendAttempts = _maxEventSendAttempts; if (_isPageUnloadTriggered) { maxSendAttempts = _maxUnloadEventSendAttempts; } arrForEach(batches, function (theBatch) { if (theBatch && theBatch.count() > 0) { arrForEach(theBatch.events(), function (theEvent) { if (theEvent) { if (theEvent.sync) { theEvent.latency = 4 ; theEvent.sync = false; } if (theEvent.sendAttempt < maxSendAttempts) { setProcessTelemetryTimings(theEvent, _self.identifier); _addEventToQueues(theEvent, false); } else { droppedEvents.push(theEvent); } } }); } }); if (droppedEvents.length > 0) { _notifyEvents(strEventsDiscarded, droppedEvents, EventsDiscardedReason.NonRetryableStatus); } if (_isPageUnloadTriggered) { _releaseAllQueues(2 , 2 ); } } function _callNotification(evtName, theArgs) { var manager = (_self._notificationManager || {}); var notifyFunc = manager[evtName]; if (notifyFunc) { try { notifyFunc.apply(manager, theArgs); } catch (e) { _throwInternal(_self.diagLog(), 1 , 74 , evtName + " notification failed: " + e); } } } function _notifyEvents(evtName, theEvents) { var extraArgs = []; for (var _i = 2; _i < arguments.length; _i++) { extraArgs[_i - 2] = arguments[_i]; } if (theEvents && theEvents.length > 0) { _callNotification(evtName, [theEvents].concat(extraArgs)); } } function _notifyBatchEvents(evtName, batches) { var extraArgs = []; for (var _i = 2; _i < arguments.length; _i++) { extraArgs[_i - 2] = arguments[_i]; } if (batches && batches.length > 0) { arrForEach(batches, function (theBatch) { if (theBatch && theBatch.count() > 0) { _callNotification(evtName, [theBatch.events()].concat(extraArgs)); } }); } } function _sendingEvent(batches, reason, isSyncRequest) { if (batches && batches.length > 0) { _callNotification("eventsSendRequest", [(reason >= 1000 && reason <= 1999 ? reason - 1000 : 0 ), isSyncRequest !== true]); } } function _eventsSentEvent(batches, reason) { _notifyBatchEvents("eventsSent", batches, reason); _scheduleTimer(); } function _eventsDropped(batches, reason) { _notifyBatchEvents(strEventsDiscarded, batches, (reason >= 8000 && reason <= 8999 ? reason - 8000 : EventsDiscardedReason.Unknown)); } function _eventsResponseFail(batches) { _notifyBatchEvents(strEventsDiscarded, batches, EventsDiscardedReason.NonRetryableStatus); _scheduleTimer(); } function _otherEvent(batches, reason) { _notifyBatchEvents(strEventsDiscarded, batches, EventsDiscardedReason.Unknown); _scheduleTimer(); } function _setAutoLimits() { if (!_config || !_config.disableAutoBatchFlushLimit) { _autoFlushBatchLimit = Math.max(MaxNumberEventPerBatch * (MaxConnections + 1), _queueSizeLimit / 6); } else { _autoFlushBatchLimit = 0; } } objDefineAccessors(_self, "_setTimeoutOverride", function () { return _timeoutWrapper.set; }, function (value) { _timeoutWrapper = createTimeoutWrapper(value, _timeoutWrapper.clear); }); objDefineAccessors(_self, "_clearTimeoutOverride", function () { return _timeoutWrapper.clear; }, function (value) { _timeoutWrapper = createTimeoutWrapper(_timeoutWrapper.set, value); }); }); return _this; } PostChannel.__ieDyn=1; return PostChannel; }(BaseTelemetryPlugin)); var PostChannel$1 = PostChannel; exports.BE_PROFILE = BE_PROFILE; exports.NRT_PROFILE = NRT_PROFILE; exports.PostChannel = PostChannel$1; exports.RT_PROFILE = RT_PROFILE; }));