@microsoft/applicationinsights-channel-js 2.8.0-nightly.2202-06 → 2.8.0-nightly.2204-06

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.
Files changed (41) hide show
  1. package/browser/applicationinsights-channel-js.integrity.json +9 -9
  2. package/browser/applicationinsights-channel-js.js +1666 -1012
  3. package/browser/applicationinsights-channel-js.js.map +1 -1
  4. package/browser/applicationinsights-channel-js.min.js +2 -2
  5. package/browser/applicationinsights-channel-js.min.js.map +1 -1
  6. package/dist/applicationinsights-channel-js.api.json +56 -58
  7. package/dist/applicationinsights-channel-js.api.md +0 -2
  8. package/dist/applicationinsights-channel-js.d.ts +1 -2
  9. package/dist/applicationinsights-channel-js.js +1666 -1012
  10. package/dist/applicationinsights-channel-js.js.map +1 -1
  11. package/dist/applicationinsights-channel-js.min.js +2 -2
  12. package/dist/applicationinsights-channel-js.min.js.map +1 -1
  13. package/dist/applicationinsights-channel-js.rollup.d.ts +1 -2
  14. package/dist-esm/EnvelopeCreator.js +5 -5
  15. package/dist-esm/EnvelopeCreator.js.map +1 -1
  16. package/dist-esm/Interfaces.js +1 -1
  17. package/dist-esm/Offline.js +77 -65
  18. package/dist-esm/Offline.js.map +1 -1
  19. package/dist-esm/SendBuffer.js +7 -7
  20. package/dist-esm/SendBuffer.js.map +1 -1
  21. package/dist-esm/Sender.js +73 -63
  22. package/dist-esm/Sender.js.map +1 -1
  23. package/dist-esm/Serializer.js +10 -10
  24. package/dist-esm/Serializer.js.map +1 -1
  25. package/dist-esm/TelemetryProcessors/Sample.js +3 -3
  26. package/dist-esm/TelemetryProcessors/Sample.js.map +1 -1
  27. package/dist-esm/TelemetryProcessors/SamplingScoreGenerators/HashCodeScoreGenerator.js +1 -1
  28. package/dist-esm/TelemetryProcessors/SamplingScoreGenerators/SamplingScoreGenerator.js +1 -1
  29. package/dist-esm/applicationinsights-channel-js.js +1 -1
  30. package/package.json +4 -4
  31. package/src/EnvelopeCreator.ts +8 -8
  32. package/src/Offline.ts +88 -76
  33. package/src/SendBuffer.ts +14 -14
  34. package/src/Sender.ts +106 -113
  35. package/src/Serializer.ts +17 -21
  36. package/src/TelemetryProcessors/Sample.ts +1 -1
  37. package/src/TelemetryProcessors/SamplingScoreGenerators/HashCodeScoreGenerator.ts +3 -1
  38. package/types/Offline.d.ts +8 -11
  39. package/types/Sender.d.ts +0 -1
  40. package/types/TelemetryProcessors/Sample.d.ts +2 -2
  41. package/types/tsdoc-metadata.json +1 -1
package/src/Offline.ts CHANGED
@@ -1,92 +1,104 @@
1
- import { getWindow, getDocument, getNavigator, isUndefined, isNullOrUndefined, attachEvent } from "@microsoft/applicationinsights-core-js";
2
- import dynamicProto from "@microsoft/dynamicproto-js";
1
+ import { getWindow, getDocument, getNavigator, isUndefined, isNullOrUndefined, createUniqueNamespace, mergeEvtNamespace, eventOn, eventOff } from "@microsoft/applicationinsights-core-js";
2
+
3
+ export interface IOfflineListener {
4
+ isOnline: () => boolean;
5
+ isListening: () => boolean;
6
+ unload: () => void;
7
+ }
8
+
9
+ function _disableEvents(target: any, evtNamespace: string | string[]) {
10
+ eventOff(target, null, null, evtNamespace);
11
+ }
3
12
 
4
13
  /**
5
- * @description Monitors browser for offline events
6
- * @export default - Offline: Static instance of OfflineListener
7
- * @class OfflineListener
14
+ * Create a new OfflineListener instance to monitor browser online / offline events
15
+ * @param parentEvtNamespace - The parent event namespace to append to any specific events for this instance
8
16
  */
9
- export class OfflineListener {
10
- public static Offline = new OfflineListener;
11
- public isListening: boolean;
12
-
13
- constructor() {
14
- let _window = getWindow();
15
- let _document = getDocument();
16
- let isListening = false;
17
- let _onlineStatus: boolean = true;
18
-
19
- dynamicProto(OfflineListener, this, (_self) => {
20
- try {
21
- if (_window) {
22
- if (attachEvent(_window, "online", _setOnline)) {
23
- attachEvent(_window, "offline", _setOffline);
24
- isListening = true;
25
- }
26
- }
27
-
28
- if (_document) {
29
- // Also attach to the document.body or document
30
- let target:any = _document.body || _document;
31
-
32
- if (!isUndefined(target.ononline)) {
33
- target.ononline = _setOnline;
34
- target.onoffline = _setOffline;
35
- isListening = true;
36
-
37
- }
38
- }
17
+ export function createOfflineListener(parentEvtNamespace?: string | string[]): IOfflineListener {
18
+ let _document = getDocument();
19
+ var _navigator = getNavigator(); // Gets the window.navigator or workerNavigator depending on the global
20
+ let _isListening: boolean = false;
21
+ let _onlineStatus: boolean = true;
22
+ let _evtNamespace = mergeEvtNamespace(createUniqueNamespace("OfflineListener"), parentEvtNamespace);
39
23
 
40
- if (isListening) {
41
- // We are listening to events so lets set the current status rather than assuming we are online #1538
42
- var _navigator = getNavigator(); // Gets the window.navigator or workerNavigator depending on the global
43
- if (_navigator && !isNullOrUndefined(_navigator.onLine)) { // navigator.onLine is undefined in react-native
44
- _onlineStatus = _navigator.onLine;
45
- }
24
+ try {
25
+ if (_enableEvents(getWindow())) {
26
+ _isListening = true;
27
+ }
28
+
29
+ if (_document) {
30
+ // Also attach to the document.body or document
31
+ let target:any = _document.body || _document;
32
+
33
+ if (target.ononline) {
34
+ if (_enableEvents(target)) {
35
+ _isListening = true;
46
36
  }
47
- } catch (e) {
48
-
49
- // this makes react-native less angry
50
- isListening = false;
51
37
  }
52
-
53
- _self.isListening = isListening;
54
-
55
- _self.isOnline = (): boolean => {
56
- let result = true;
57
- var _navigator = getNavigator();
58
- if (isListening) {
59
- result = _onlineStatus
60
- } else if (_navigator && !isNullOrUndefined(_navigator.onLine)) { // navigator.onLine is undefined in react-native
61
- result = _navigator.onLine;
62
- }
38
+ }
63
39
 
64
- return result;
65
- };
66
-
67
- _self.isOffline = (): boolean => {
68
- return !_self.isOnline();
69
- };
70
-
71
- function _setOnline() {
72
- _onlineStatus = true;
40
+ if (_isListening) {
41
+ // We are listening to events so lets set the current status rather than assuming we are online #1538
42
+ if (_navigator && !isNullOrUndefined(_navigator.onLine)) { // navigator.onLine is undefined in react-native
43
+ _onlineStatus = _navigator.onLine;
73
44
  }
45
+ }
46
+ } catch (e) {
47
+ // this makes react-native less angry
48
+ _isListening = false;
49
+ }
74
50
 
75
- function _setOffline() {
76
- _onlineStatus = false;
51
+ function _enableEvents(target: any): boolean {
52
+ let enabled = false;
53
+ if (target) {
54
+ enabled = eventOn(target, "online", _setOnline, _evtNamespace);
55
+ if (enabled) {
56
+ eventOn(target, "offline", _setOffline, _evtNamespace);
77
57
  }
78
- });
58
+ }
59
+
60
+ return enabled;
79
61
  }
80
62
 
81
- public isOnline(): boolean {
82
- // @DynamicProtoStub -- DO NOT add any code as this will be removed during packaging
83
- return false;
63
+ function _setOnline() {
64
+ _onlineStatus = true;
84
65
  }
85
66
 
86
- public isOffline(): boolean {
87
- // @DynamicProtoStub -- DO NOT add any code as this will be removed during packaging
88
- return false;
67
+ function _setOffline() {
68
+ _onlineStatus = false;
89
69
  }
90
- }
91
70
 
92
- export const Offline = OfflineListener.Offline;
71
+ function _isOnline(): boolean {
72
+ let result = true;
73
+ if (_isListening) {
74
+ result = _onlineStatus
75
+ } else if (_navigator && !isNullOrUndefined(_navigator.onLine)) { // navigator.onLine is undefined in react-native
76
+ result = _navigator.onLine;
77
+ }
78
+
79
+ return result;
80
+ }
81
+
82
+ function _unload() {
83
+ let win = getWindow();
84
+ if (win && _isListening) {
85
+ _disableEvents(win, _evtNamespace);
86
+
87
+ if (_document) {
88
+ // Also attach to the document.body or document
89
+ let target:any = _document.body || _document;
90
+ if (!isUndefined(target.ononline)) {
91
+ _disableEvents(target, _evtNamespace);
92
+ }
93
+ }
94
+
95
+ _isListening = false;
96
+ }
97
+ }
98
+
99
+ return {
100
+ isOnline: _isOnline,
101
+ isListening: () => _isListening,
102
+ unload: _unload
103
+ };
104
+ }
package/src/SendBuffer.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { utlGetSessionStorage, utlSetSessionStorage } from "@microsoft/applicationinsights-common";
2
- import { IDiagnosticLogger, LoggingSeverity, _InternalMessageId, getJSON, arrForEach, isFunction, arrIndexOf, isString, dumpObj, isArray, getExceptionName } from "@microsoft/applicationinsights-core-js";
2
+ import { IDiagnosticLogger, eLoggingSeverity, _eInternalMessageId, getJSON, arrForEach, isFunction, arrIndexOf, isString, dumpObj, isArray, getExceptionName, _throwInternal } from "@microsoft/applicationinsights-core-js";
3
3
  import { ISenderConfig } from "./Interfaces";
4
4
  import dynamicProto from "@microsoft/dynamicproto-js";
5
5
 
@@ -70,9 +70,9 @@ abstract class BaseSendBuffer {
70
70
  if (_self.count() >= config.eventsLimitInMem()) {
71
71
  // sent internal log only once per page view
72
72
  if (!_bufferFullMessageSent) {
73
- logger.throwInternal(
74
- LoggingSeverity.WARNING,
75
- _InternalMessageId.InMemoryStorageBufferFull,
73
+ _throwInternal(logger,
74
+ eLoggingSeverity.WARNING,
75
+ _eInternalMessageId.InMemoryStorageBufferFull,
76
76
  "Maximum in-memory buffer size reached: " + _self.count(),
77
77
  true);
78
78
  _bufferFullMessageSent = true;
@@ -214,9 +214,9 @@ export class SessionStorageSendBuffer extends BaseSendBuffer implements ISendBuf
214
214
  if (_self.count() >= SessionStorageSendBuffer.MAX_BUFFER_SIZE) {
215
215
  // sent internal log only once per page view
216
216
  if (!_bufferFullMessageSent) {
217
- logger.throwInternal(
218
- LoggingSeverity.WARNING,
219
- _InternalMessageId.SessionStorageBufferFull,
217
+ _throwInternal(logger,
218
+ eLoggingSeverity.WARNING,
219
+ _eInternalMessageId.SessionStorageBufferFull,
220
220
  "Maximum buffer size reached: " + _self.count(),
221
221
  true);
222
222
  _bufferFullMessageSent = true;
@@ -248,9 +248,9 @@ export class SessionStorageSendBuffer extends BaseSendBuffer implements ISendBuf
248
248
  if (sentElements.length > SessionStorageSendBuffer.MAX_BUFFER_SIZE) {
249
249
  // We send telemetry normally. If the SENT_BUFFER is too big we don't add new elements
250
250
  // until we receive a response from the backend and the buffer has free space again (see clearSent method)
251
- logger.throwInternal(
252
- LoggingSeverity.CRITICAL,
253
- _InternalMessageId.SessionStorageBufferFull,
251
+ _throwInternal(logger,
252
+ eLoggingSeverity.CRITICAL,
253
+ _eInternalMessageId.SessionStorageBufferFull,
254
254
  "Sent buffer reached its maximum size: " + sentElements.length,
255
255
  true);
256
256
 
@@ -297,8 +297,8 @@ export class SessionStorageSendBuffer extends BaseSendBuffer implements ISendBuf
297
297
  }
298
298
  }
299
299
  } catch (e) {
300
- logger.throwInternal(LoggingSeverity.CRITICAL,
301
- _InternalMessageId.FailedToRestoreStorageBuffer,
300
+ _throwInternal(logger, eLoggingSeverity.CRITICAL,
301
+ _eInternalMessageId.FailedToRestoreStorageBuffer,
302
302
  " storage key: " + prefixedKey + ", " + getExceptionName(e),
303
303
  { exception: dumpObj(e) });
304
304
  }
@@ -317,8 +317,8 @@ export class SessionStorageSendBuffer extends BaseSendBuffer implements ISendBuf
317
317
  // telemetry is stored in the _buffer array so we won't loose any items
318
318
  utlSetSessionStorage(logger, prefixedKey, JSON.stringify([]));
319
319
 
320
- logger.throwInternal(LoggingSeverity.WARNING,
321
- _InternalMessageId.FailedToSetStorageBuffer,
320
+ _throwInternal(logger, eLoggingSeverity.WARNING,
321
+ _eInternalMessageId.FailedToSetStorageBuffer,
322
322
  " storage key: " + prefixedKey + ", " + getExceptionName(e) + ". Buffer cleared",
323
323
  { exception: dumpObj(e) });
324
324
  }