@openreplay/tracker 5.0.2-beta → 5.0.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.
Files changed (135) hide show
  1. package/cjs/app/guards.d.ts +21 -0
  2. package/cjs/app/guards.js +37 -0
  3. package/cjs/app/index.d.ts +118 -0
  4. package/cjs/app/index.js +438 -0
  5. package/cjs/app/logger.d.ts +26 -0
  6. package/cjs/app/logger.js +45 -0
  7. package/cjs/app/messages.gen.d.ts +63 -0
  8. package/cjs/app/messages.gen.js +551 -0
  9. package/cjs/app/nodes.d.ts +18 -0
  10. package/cjs/app/nodes.js +82 -0
  11. package/cjs/app/observer/iframe_observer.d.ts +4 -0
  12. package/cjs/app/observer/iframe_observer.js +23 -0
  13. package/cjs/app/observer/iframe_offsets.d.ts +8 -0
  14. package/cjs/app/observer/iframe_offsets.js +59 -0
  15. package/cjs/app/observer/observer.d.ts +23 -0
  16. package/cjs/app/observer/observer.js +340 -0
  17. package/cjs/app/observer/shadow_root_observer.d.ts +4 -0
  18. package/cjs/app/observer/shadow_root_observer.js +21 -0
  19. package/cjs/app/observer/top_observer.d.ts +24 -0
  20. package/cjs/app/observer/top_observer.js +113 -0
  21. package/cjs/app/sanitizer.d.ts +24 -0
  22. package/cjs/app/sanitizer.js +76 -0
  23. package/cjs/app/session.d.ts +38 -0
  24. package/cjs/app/session.js +114 -0
  25. package/cjs/app/ticker.d.ts +12 -0
  26. package/cjs/app/ticker.js +42 -0
  27. package/cjs/common/interaction.d.ts +24 -0
  28. package/cjs/common/interaction.js +2 -0
  29. package/cjs/common/messages.gen.d.ts +427 -0
  30. package/cjs/common/messages.gen.js +4 -0
  31. package/cjs/index.d.ts +47 -0
  32. package/cjs/index.js +254 -0
  33. package/cjs/modules/connection.d.ts +2 -0
  34. package/cjs/modules/connection.js +15 -0
  35. package/cjs/modules/console.d.ts +6 -0
  36. package/cjs/modules/console.js +119 -0
  37. package/cjs/modules/constructedStyleSheets.d.ts +4 -0
  38. package/cjs/modules/constructedStyleSheets.js +131 -0
  39. package/cjs/modules/cssrules.d.ts +2 -0
  40. package/cjs/modules/cssrules.js +99 -0
  41. package/cjs/modules/exception.d.ts +16 -0
  42. package/cjs/modules/exception.js +77 -0
  43. package/cjs/modules/focus.d.ts +2 -0
  44. package/cjs/modules/focus.js +45 -0
  45. package/cjs/modules/fonts.d.ts +2 -0
  46. package/cjs/modules/fonts.js +57 -0
  47. package/cjs/modules/img.d.ts +2 -0
  48. package/cjs/modules/img.js +110 -0
  49. package/cjs/modules/input.d.ts +16 -0
  50. package/cjs/modules/input.js +163 -0
  51. package/cjs/modules/mouse.d.ts +2 -0
  52. package/cjs/modules/mouse.js +148 -0
  53. package/cjs/modules/network.d.ts +28 -0
  54. package/cjs/modules/network.js +203 -0
  55. package/cjs/modules/performance.d.ts +7 -0
  56. package/cjs/modules/performance.js +53 -0
  57. package/cjs/modules/scroll.d.ts +2 -0
  58. package/cjs/modules/scroll.js +79 -0
  59. package/cjs/modules/timing.d.ts +7 -0
  60. package/cjs/modules/timing.js +160 -0
  61. package/cjs/modules/viewport.d.ts +2 -0
  62. package/cjs/modules/viewport.js +43 -0
  63. package/cjs/package.json +1 -0
  64. package/cjs/utils.d.ts +13 -0
  65. package/cjs/utils.js +71 -0
  66. package/cjs/vendors/finder/finder.d.ts +12 -0
  67. package/cjs/vendors/finder/finder.js +352 -0
  68. package/lib/app/guards.d.ts +21 -0
  69. package/lib/app/guards.js +26 -0
  70. package/lib/app/index.d.ts +118 -0
  71. package/lib/app/index.js +434 -0
  72. package/lib/app/logger.d.ts +26 -0
  73. package/lib/app/logger.js +41 -0
  74. package/lib/app/messages.gen.d.ts +63 -0
  75. package/lib/app/messages.gen.js +486 -0
  76. package/lib/app/nodes.d.ts +18 -0
  77. package/lib/app/nodes.js +79 -0
  78. package/lib/app/observer/iframe_observer.d.ts +4 -0
  79. package/lib/app/observer/iframe_observer.js +20 -0
  80. package/lib/app/observer/iframe_offsets.d.ts +8 -0
  81. package/lib/app/observer/iframe_offsets.js +56 -0
  82. package/lib/app/observer/observer.d.ts +23 -0
  83. package/lib/app/observer/observer.js +337 -0
  84. package/lib/app/observer/shadow_root_observer.d.ts +4 -0
  85. package/lib/app/observer/shadow_root_observer.js +18 -0
  86. package/lib/app/observer/top_observer.d.ts +24 -0
  87. package/lib/app/observer/top_observer.js +110 -0
  88. package/lib/app/sanitizer.d.ts +24 -0
  89. package/lib/app/sanitizer.js +72 -0
  90. package/lib/app/session.d.ts +38 -0
  91. package/lib/app/session.js +111 -0
  92. package/lib/app/ticker.d.ts +12 -0
  93. package/lib/app/ticker.js +39 -0
  94. package/lib/common/interaction.d.ts +24 -0
  95. package/lib/common/interaction.js +1 -0
  96. package/lib/common/messages.gen.d.ts +427 -0
  97. package/lib/common/messages.gen.js +3 -0
  98. package/lib/common/tsconfig.tsbuildinfo +1 -0
  99. package/lib/index.d.ts +47 -0
  100. package/lib/index.js +248 -0
  101. package/lib/modules/connection.d.ts +2 -0
  102. package/lib/modules/connection.js +12 -0
  103. package/lib/modules/console.d.ts +6 -0
  104. package/lib/modules/console.js +116 -0
  105. package/lib/modules/constructedStyleSheets.d.ts +4 -0
  106. package/lib/modules/constructedStyleSheets.js +126 -0
  107. package/lib/modules/cssrules.d.ts +2 -0
  108. package/lib/modules/cssrules.js +97 -0
  109. package/lib/modules/exception.d.ts +16 -0
  110. package/lib/modules/exception.js +71 -0
  111. package/lib/modules/focus.d.ts +2 -0
  112. package/lib/modules/focus.js +42 -0
  113. package/lib/modules/fonts.d.ts +2 -0
  114. package/lib/modules/fonts.js +54 -0
  115. package/lib/modules/img.d.ts +2 -0
  116. package/lib/modules/img.js +107 -0
  117. package/lib/modules/input.d.ts +16 -0
  118. package/lib/modules/input.js +158 -0
  119. package/lib/modules/mouse.d.ts +2 -0
  120. package/lib/modules/mouse.js +145 -0
  121. package/lib/modules/network.d.ts +28 -0
  122. package/lib/modules/network.js +200 -0
  123. package/lib/modules/performance.d.ts +7 -0
  124. package/lib/modules/performance.js +49 -0
  125. package/lib/modules/scroll.d.ts +2 -0
  126. package/lib/modules/scroll.js +76 -0
  127. package/lib/modules/timing.d.ts +7 -0
  128. package/lib/modules/timing.js +157 -0
  129. package/lib/modules/viewport.d.ts +2 -0
  130. package/lib/modules/viewport.js +40 -0
  131. package/lib/utils.d.ts +13 -0
  132. package/lib/utils.js +61 -0
  133. package/lib/vendors/finder/finder.d.ts +12 -0
  134. package/lib/vendors/finder/finder.js +348 -0
  135. package/package.json +1 -1
@@ -0,0 +1,113 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const observer_js_1 = require("./observer.js");
4
+ const guards_js_1 = require("../guards.js");
5
+ const iframe_observer_js_1 = require("./iframe_observer.js");
6
+ const shadow_root_observer_js_1 = require("./shadow_root_observer.js");
7
+ const iframe_offsets_js_1 = require("./iframe_offsets.js");
8
+ const messages_gen_js_1 = require("../messages.gen.js");
9
+ const utils_js_1 = require("../../utils.js");
10
+ const attachShadowNativeFn = utils_js_1.IN_BROWSER ? Element.prototype.attachShadow : () => new ShadowRoot();
11
+ class TopObserver extends observer_js_1.default {
12
+ constructor(app, options) {
13
+ super(app, true);
14
+ this.iframeOffsets = new iframe_offsets_js_1.default();
15
+ this.contextCallbacks = [];
16
+ // Attached once per Tracker instance
17
+ this.contextsSet = new Set();
18
+ this.iframeObservers = [];
19
+ this.shadowRootObservers = [];
20
+ this.options = Object.assign({
21
+ captureIFrames: true,
22
+ }, options);
23
+ // IFrames
24
+ this.app.nodes.attachNodeCallback((node) => {
25
+ if ((0, guards_js_1.hasTag)(node, 'iframe') &&
26
+ ((this.options.captureIFrames && !(0, utils_js_1.hasOpenreplayAttribute)(node, 'obscured')) ||
27
+ (0, utils_js_1.hasOpenreplayAttribute)(node, 'capture'))) {
28
+ this.handleIframe(node);
29
+ }
30
+ });
31
+ // ShadowDOM
32
+ this.app.nodes.attachNodeCallback((node) => {
33
+ if ((0, guards_js_1.isElementNode)(node) && node.shadowRoot !== null) {
34
+ this.handleShadowRoot(node.shadowRoot);
35
+ }
36
+ });
37
+ }
38
+ attachContextCallback(cb) {
39
+ this.contextCallbacks.push(cb);
40
+ }
41
+ getDocumentOffset(doc) {
42
+ return this.iframeOffsets.getDocumentOffset(doc);
43
+ }
44
+ handleIframe(iframe) {
45
+ let doc = null;
46
+ // setTimeout is required. Otherwise some event listeners (scroll, mousemove) applied in modules
47
+ // do not work on the iframe document when it 've been loaded dynamically ((why?))
48
+ const handle = this.app.safe(() => setTimeout(() => {
49
+ const id = this.app.nodes.getID(iframe);
50
+ if (id === undefined) {
51
+ //log
52
+ return;
53
+ }
54
+ const currentWin = iframe.contentWindow;
55
+ const currentDoc = iframe.contentDocument;
56
+ if (currentDoc && currentDoc !== doc) {
57
+ const observer = new iframe_observer_js_1.default(this.app);
58
+ this.iframeObservers.push(observer);
59
+ observer.observe(iframe); // TODO: call unregisterNode for the previous doc if present (incapsulate: one iframe - one observer)
60
+ doc = currentDoc;
61
+ this.iframeOffsets.observe(iframe);
62
+ }
63
+ if (currentWin &&
64
+ // Sometimes currentWin.window is null (not in specification). Such window object is not functional
65
+ currentWin === currentWin.window &&
66
+ !this.contextsSet.has(currentWin) // for each context callbacks called once per Tracker (TopObserver) instance
67
+ //TODO: more explicit logic
68
+ ) {
69
+ this.contextsSet.add(currentWin);
70
+ //@ts-ignore https://github.com/microsoft/TypeScript/issues/41684
71
+ this.contextCallbacks.forEach((cb) => cb(currentWin));
72
+ }
73
+ }, 0));
74
+ iframe.addEventListener('load', handle); // why app.attachEventListener not working?
75
+ handle();
76
+ }
77
+ handleShadowRoot(shRoot) {
78
+ const observer = new shadow_root_observer_js_1.default(this.app);
79
+ this.shadowRootObservers.push(observer);
80
+ observer.observe(shRoot.host);
81
+ }
82
+ observe() {
83
+ // Protection from several subsequent calls?
84
+ const observer = this;
85
+ Element.prototype.attachShadow = function () {
86
+ // eslint-disable-next-line
87
+ const shadow = attachShadowNativeFn.apply(this, arguments);
88
+ observer.handleShadowRoot(shadow);
89
+ return shadow;
90
+ };
91
+ // Can observe documentElement (<html>) here, because it is not supposed to be changing.
92
+ // However, it is possible in some exotic cases and may cause an ignorance of the newly created <html>
93
+ // In this case context.document have to be observed, but this will cause
94
+ // the change in the re-player behaviour caused by CreateDocument message:
95
+ // the 0-node ("fRoot") will become #document rather than documentElement as it is now.
96
+ // Alternatively - observe(#document) then bindNode(documentElement)
97
+ this.observeRoot(window.document, () => {
98
+ this.app.send((0, messages_gen_js_1.CreateDocument)());
99
+ // it has no node_id here
100
+ this.app.nodes.callNodeCallbacks(document, true);
101
+ }, window.document.documentElement);
102
+ }
103
+ disconnect() {
104
+ this.iframeOffsets.clear();
105
+ Element.prototype.attachShadow = attachShadowNativeFn;
106
+ this.iframeObservers.forEach((o) => o.disconnect());
107
+ this.iframeObservers = [];
108
+ this.shadowRootObservers.forEach((o) => o.disconnect());
109
+ this.shadowRootObservers = [];
110
+ super.disconnect();
111
+ }
112
+ }
113
+ exports.default = TopObserver;
@@ -0,0 +1,24 @@
1
+ import type App from './index.js';
2
+ export declare enum SanitizeLevel {
3
+ Plain = 0,
4
+ Obscured = 1,
5
+ Hidden = 2
6
+ }
7
+ export interface Options {
8
+ obscureTextEmails: boolean;
9
+ obscureTextNumbers: boolean;
10
+ domSanitizer?: (node: Element) => SanitizeLevel;
11
+ }
12
+ export default class Sanitizer {
13
+ private readonly app;
14
+ private readonly obscured;
15
+ private readonly hidden;
16
+ private readonly options;
17
+ constructor(app: App, options: Partial<Options>);
18
+ handleNode(id: number, parentID: number, node: Node): void;
19
+ sanitize(id: number, data: string): string;
20
+ isObscured(id: number): boolean;
21
+ isHidden(id: number): boolean;
22
+ getInnerTextSecure(el: HTMLElement): string;
23
+ clear(): void;
24
+ }
@@ -0,0 +1,76 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SanitizeLevel = void 0;
4
+ const utils_js_1 = require("../utils.js");
5
+ const guards_js_1 = require("./guards.js");
6
+ var SanitizeLevel;
7
+ (function (SanitizeLevel) {
8
+ SanitizeLevel[SanitizeLevel["Plain"] = 0] = "Plain";
9
+ SanitizeLevel[SanitizeLevel["Obscured"] = 1] = "Obscured";
10
+ SanitizeLevel[SanitizeLevel["Hidden"] = 2] = "Hidden";
11
+ })(SanitizeLevel = exports.SanitizeLevel || (exports.SanitizeLevel = {}));
12
+ class Sanitizer {
13
+ constructor(app, options) {
14
+ this.app = app;
15
+ this.obscured = new Set();
16
+ this.hidden = new Set();
17
+ this.options = Object.assign({
18
+ obscureTextEmails: true,
19
+ obscureTextNumbers: false,
20
+ }, options);
21
+ }
22
+ handleNode(id, parentID, node) {
23
+ if (this.obscured.has(parentID) ||
24
+ ((0, guards_js_1.isElementNode)(node) &&
25
+ ((0, utils_js_1.hasOpenreplayAttribute)(node, 'masked') || (0, utils_js_1.hasOpenreplayAttribute)(node, 'obscured')))) {
26
+ this.obscured.add(id);
27
+ }
28
+ if (this.hidden.has(parentID) ||
29
+ ((0, guards_js_1.isElementNode)(node) &&
30
+ ((0, utils_js_1.hasOpenreplayAttribute)(node, 'htmlmasked') || (0, utils_js_1.hasOpenreplayAttribute)(node, 'hidden')))) {
31
+ this.hidden.add(id);
32
+ }
33
+ if (this.options.domSanitizer !== undefined && (0, guards_js_1.isElementNode)(node)) {
34
+ const sanitizeLevel = this.options.domSanitizer(node);
35
+ if (sanitizeLevel === SanitizeLevel.Obscured) {
36
+ this.obscured.add(id);
37
+ }
38
+ if (sanitizeLevel === SanitizeLevel.Hidden) {
39
+ this.hidden.add(id);
40
+ }
41
+ }
42
+ }
43
+ sanitize(id, data) {
44
+ if (this.obscured.has(id)) {
45
+ // TODO: is it the best place to put trim() ? Might trimmed spaces be considered in layout in certain cases?
46
+ return data
47
+ .trim()
48
+ .replace(/[^\f\n\r\t\v\u00a0\u1680\u2000-\u200a\u2028\u2029\u202f\u205f\u3000\ufeff]/g, '█');
49
+ }
50
+ if (this.options.obscureTextNumbers) {
51
+ data = data.replace(/\d/g, '0');
52
+ }
53
+ if (this.options.obscureTextEmails) {
54
+ data = data.replace(/([^\s]+)@([^\s]+)\.([^\s]+)/g, (...f) => (0, utils_js_1.stars)(f[1]) + '@' + (0, utils_js_1.stars)(f[2]) + '.' + (0, utils_js_1.stars)(f[3]));
55
+ }
56
+ return data;
57
+ }
58
+ isObscured(id) {
59
+ return this.obscured.has(id);
60
+ }
61
+ isHidden(id) {
62
+ return this.hidden.has(id);
63
+ }
64
+ getInnerTextSecure(el) {
65
+ const id = this.app.nodes.getID(el);
66
+ if (!id) {
67
+ return '';
68
+ }
69
+ return this.sanitize(id, el.innerText);
70
+ }
71
+ clear() {
72
+ this.obscured.clear();
73
+ this.hidden.clear();
74
+ }
75
+ }
76
+ exports.default = Sanitizer;
@@ -0,0 +1,38 @@
1
+ import type App from './index.js';
2
+ interface SessionInfo {
3
+ sessionID: string | undefined;
4
+ metadata: Record<string, string>;
5
+ userID: string | null;
6
+ timestamp: number;
7
+ projectID?: string;
8
+ }
9
+ type OnUpdateCallback = (i: Partial<SessionInfo>) => void;
10
+ export type Options = {
11
+ session_token_key: string;
12
+ session_pageno_key: string;
13
+ };
14
+ export default class Session {
15
+ private readonly app;
16
+ private readonly options;
17
+ private metadata;
18
+ private userID;
19
+ private sessionID;
20
+ private readonly callbacks;
21
+ private timestamp;
22
+ private projectID;
23
+ constructor(app: App, options: Options);
24
+ attachUpdateCallback(cb: OnUpdateCallback): void;
25
+ private handleUpdate;
26
+ assign(newInfo: Partial<SessionInfo>): void;
27
+ setMetadata(key: string, value: string): void;
28
+ setUserID(userID: string): void;
29
+ private getPageNumber;
30
+ incPageNo(): number;
31
+ getSessionToken(): string | undefined;
32
+ setSessionToken(token: string): void;
33
+ applySessionHash(hash: string): void;
34
+ getSessionHash(): string | undefined;
35
+ getInfo(): SessionInfo;
36
+ reset(): void;
37
+ }
38
+ export {};
@@ -0,0 +1,114 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ class Session {
4
+ constructor(app, options) {
5
+ this.app = app;
6
+ this.options = options;
7
+ this.metadata = {};
8
+ this.userID = null;
9
+ this.callbacks = [];
10
+ this.timestamp = 0;
11
+ }
12
+ attachUpdateCallback(cb) {
13
+ this.callbacks.push(cb);
14
+ }
15
+ handleUpdate(newInfo) {
16
+ if (newInfo.userID == null) {
17
+ delete newInfo.userID;
18
+ }
19
+ if (newInfo.sessionID == null) {
20
+ delete newInfo.sessionID;
21
+ }
22
+ this.callbacks.forEach((cb) => cb(newInfo));
23
+ }
24
+ assign(newInfo) {
25
+ if (newInfo.userID !== undefined) {
26
+ // TODO clear nullable/undefinable types
27
+ this.userID = newInfo.userID;
28
+ }
29
+ if (newInfo.metadata !== undefined) {
30
+ Object.entries(newInfo.metadata).forEach(([k, v]) => (this.metadata[k] = v));
31
+ }
32
+ if (newInfo.sessionID !== undefined) {
33
+ this.sessionID = newInfo.sessionID;
34
+ }
35
+ if (newInfo.timestamp !== undefined) {
36
+ this.timestamp = newInfo.timestamp;
37
+ }
38
+ if (newInfo.projectID !== undefined) {
39
+ this.projectID = newInfo.projectID;
40
+ }
41
+ this.handleUpdate(newInfo);
42
+ }
43
+ setMetadata(key, value) {
44
+ this.metadata[key] = value;
45
+ this.handleUpdate({ metadata: { [key]: value } });
46
+ }
47
+ setUserID(userID) {
48
+ this.userID = userID;
49
+ this.handleUpdate({ userID });
50
+ }
51
+ getPageNumber() {
52
+ const pageNoStr = this.app.sessionStorage.getItem(this.options.session_pageno_key);
53
+ if (pageNoStr == null) {
54
+ return undefined;
55
+ }
56
+ return parseInt(pageNoStr);
57
+ }
58
+ incPageNo() {
59
+ let pageNo = this.getPageNumber();
60
+ if (pageNo === undefined) {
61
+ pageNo = 0;
62
+ }
63
+ else {
64
+ pageNo++;
65
+ }
66
+ this.app.sessionStorage.setItem(this.options.session_pageno_key, pageNo.toString());
67
+ return pageNo;
68
+ }
69
+ getSessionToken() {
70
+ return this.app.sessionStorage.getItem(this.options.session_token_key) || undefined;
71
+ }
72
+ setSessionToken(token) {
73
+ this.app.sessionStorage.setItem(this.options.session_token_key, token);
74
+ }
75
+ applySessionHash(hash) {
76
+ const hashParts = decodeURI(hash).split('&');
77
+ let token = hash;
78
+ let pageNoStr = '100500'; // back-compat for sessionToken
79
+ if (hashParts.length == 2) {
80
+ ;
81
+ [pageNoStr, token] = hashParts;
82
+ }
83
+ if (!pageNoStr || !token) {
84
+ return;
85
+ }
86
+ this.app.sessionStorage.setItem(this.options.session_token_key, token);
87
+ this.app.sessionStorage.setItem(this.options.session_pageno_key, pageNoStr);
88
+ }
89
+ getSessionHash() {
90
+ const pageNo = this.getPageNumber();
91
+ const token = this.getSessionToken();
92
+ if (pageNo === undefined || token === undefined) {
93
+ return;
94
+ }
95
+ return encodeURI(String(pageNo) + '&' + token);
96
+ }
97
+ getInfo() {
98
+ return {
99
+ sessionID: this.sessionID,
100
+ metadata: this.metadata,
101
+ userID: this.userID,
102
+ timestamp: this.timestamp,
103
+ projectID: this.projectID,
104
+ };
105
+ }
106
+ reset() {
107
+ this.app.sessionStorage.removeItem(this.options.session_token_key);
108
+ this.metadata = {};
109
+ this.userID = null;
110
+ this.sessionID = undefined;
111
+ this.timestamp = 0;
112
+ }
113
+ }
114
+ exports.default = Session;
@@ -0,0 +1,12 @@
1
+ import App from './index.js';
2
+ type Callback = () => void;
3
+ export default class Ticker {
4
+ private readonly app;
5
+ private timer;
6
+ private readonly callbacks;
7
+ constructor(app: App);
8
+ attach(callback: Callback, n?: number, useSafe?: boolean, thisArg?: any): void;
9
+ start(): void;
10
+ stop(): void;
11
+ }
12
+ export {};
@@ -0,0 +1,42 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ function wrap(callback, n) {
4
+ let t = 0;
5
+ return () => {
6
+ if (t++ >= n) {
7
+ t = 0;
8
+ callback();
9
+ }
10
+ };
11
+ }
12
+ class Ticker {
13
+ constructor(app) {
14
+ this.app = app;
15
+ this.timer = null;
16
+ this.callbacks = [];
17
+ }
18
+ attach(callback, n = 0, useSafe = true, thisArg) {
19
+ if (thisArg) {
20
+ callback = callback.bind(thisArg);
21
+ }
22
+ if (useSafe) {
23
+ callback = this.app.safe(callback);
24
+ }
25
+ this.callbacks.unshift(n ? wrap(callback, n) : callback) - 1;
26
+ }
27
+ start() {
28
+ if (this.timer === null) {
29
+ this.timer = setInterval(() => this.callbacks.forEach((cb) => {
30
+ if (cb)
31
+ cb();
32
+ }), 30);
33
+ }
34
+ }
35
+ stop() {
36
+ if (this.timer !== null) {
37
+ clearInterval(this.timer);
38
+ this.timer = null;
39
+ }
40
+ }
41
+ }
42
+ exports.default = Ticker;
@@ -0,0 +1,24 @@
1
+ import Message from './messages.gen.js';
2
+ export interface Options {
3
+ connAttemptCount?: number;
4
+ connAttemptGap?: number;
5
+ }
6
+ type Start = {
7
+ type: 'start';
8
+ ingestPoint: string;
9
+ pageNo: number;
10
+ timestamp: number;
11
+ url: string;
12
+ } & Options;
13
+ type Auth = {
14
+ type: 'auth';
15
+ token: string;
16
+ beaconSizeLimit?: number;
17
+ };
18
+ export type ToWorkerData = null | 'stop' | Start | Auth | Array<Message>;
19
+ type Failure = {
20
+ type: 'failure';
21
+ reason: string;
22
+ };
23
+ export type FromWorkerData = 'restart' | Failure | 'not_init';
24
+ export {};
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });