UNPKG

@microsoft/1ds-post-js

Version:

Microsoft Application Insights JavaScript SDK - 1ds-post-channel-js

79 lines 2.81 kB
/* * 1DS JS SDK POST plugin, 4.4.3 * Copyright (c) Microsoft and contributors. All rights reserved. * (Microsoft Internal Only) */ /** * ClockSkewManager.ts * @author Abhilash Panwar (abpanwar) * @copyright Microsoft 2018 */ /** * Factory function to create a ClockSkewManager instance. * @returns A new IClockSkewManager instance. * @internal */ export function createClockSkewManager() { var _allowRequestSending = true; var _shouldAddClockSkewHeaders = true; var _isFirstRequest = true; var _clockSkewHeaderValue = "use-collector-delta"; var _clockSkewSet = false; return { /** * Determine if requests can be sent. * @returns True if requests can be sent, false otherwise. */ allowRequestSending: function () { return _allowRequestSending; }, /** * Tells the ClockSkewManager that it should assume that the first request has now been sent, * If this method had not yet been called AND the clock Skew had not been set this will set * allowRequestSending to false until setClockSet() is called. */ firstRequestSent: function () { if (_isFirstRequest) { _isFirstRequest = false; if (!_clockSkewSet) { // Block sending until we get the first clock Skew _allowRequestSending = false; } } }, /** * Determine if clock skew headers should be added to the request. * @returns True if clock skew headers should be added, false otherwise. */ shouldAddClockSkewHeaders: function () { return _shouldAddClockSkewHeaders; }, /** * Gets the clock skew header value. * @returns The clock skew header value. */ getClockSkewHeaderValue: function () { return _clockSkewHeaderValue; }, /** * Sets the clock skew header value. Once clock skew is set this method * is no-op. * @param timeDeltaInMillis - Time delta to be saved as the clock skew header value. */ setClockSkew: function (timeDeltaInMillis) { if (!_clockSkewSet) { if (timeDeltaInMillis) { _clockSkewHeaderValue = timeDeltaInMillis; _shouldAddClockSkewHeaders = true; _clockSkewSet = true; } else { _shouldAddClockSkewHeaders = false; } // Unblock sending _allowRequestSending = true; } } }; } //# sourceMappingURL=ClockSkewManager.js.map