@sailfish-ai/recorder 1.3.0 → 1.4.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.
package/dist/index.js CHANGED
@@ -4,6 +4,7 @@ import { gatherAndCacheDeviceInfo } from "./deviceInfo";
4
4
  import { sendRecordingEvents } from "./eventCache";
5
5
  import { fetchCaptureSettings, sendDomainsToNotPropagateHeaderTo, startRecordingSession, } from "./graphql";
6
6
  import { initializeRecording } from "./recording";
7
+ import { sendMessage } from "./websocket";
7
8
  // Default list of domains to ignore
8
9
  const DOMAINS_TO_NOT_PROPAGATE_HEADER_TO_DEFAULT = [
9
10
  "t.co",
@@ -37,6 +38,7 @@ export const DEFAULT_CONSOLE_RECORDING_SETTINGS = {
37
38
  },
38
39
  logger: "console",
39
40
  };
41
+ const PERSIST_SESSION_FOR_REOPENING_TABS = false;
40
42
  // export const DEFAULT_NETWORK_CAPTURE_SETTINGS: NetworkRecordOptions = {
41
43
  // initiatorTypes: ["fetch", "xmlhttprequest"],
42
44
  // ignoreRequestFn: (request) => {
@@ -56,26 +58,80 @@ export const DEFAULT_CONSOLE_RECORDING_SETTINGS = {
56
58
  // recordInitialRequests: false,
57
59
  // };
58
60
  // Functions
59
- // Function to get the current sessionId from sessionStorage
61
+ function sendUserDeviceUuid() {
62
+ const userDeviceUuid = getOrSetUserDeviceUuid();
63
+ const message = {
64
+ type: "userDeviceUuid",
65
+ userDeviceUuid,
66
+ };
67
+ sendMessage(message);
68
+ }
69
+ function sendTimeZone() {
70
+ const timezone = Intl.DateTimeFormat().resolvedOptions().timeZone;
71
+ const message = {
72
+ type: "timeZone",
73
+ timezone,
74
+ };
75
+ sendMessage(message);
76
+ }
77
+ // Send standard information like userDeviceUuid and timeZone
78
+ sendUserDeviceUuid();
79
+ sendTimeZone();
80
+ // Function to get or set the device & program UUID in localStorage
81
+ function getOrSetUserDeviceUuid() {
82
+ let userDeviceUuid = localStorage.getItem("sailfishUserDeviceUuid");
83
+ if (!userDeviceUuid) {
84
+ userDeviceUuid = uuidv4();
85
+ localStorage.setItem("sailfishUserDeviceUuid", userDeviceUuid);
86
+ }
87
+ return userDeviceUuid;
88
+ }
89
+ // Function to generate a unique key for storing sessionId in localStorage
90
+ function getTabKey() {
91
+ let tabKey = sessionStorage.getItem("sailfishTabKey");
92
+ if (!tabKey) {
93
+ tabKey = uuidv4();
94
+ sessionStorage.setItem("sailfishTabKey", tabKey);
95
+ }
96
+ return tabKey;
97
+ }
98
+ // Function to get or set the current sessionId in sessionStorage
60
99
  function getOrSetSessionId(forceNew = false) {
61
100
  let sessionId = sessionStorage.getItem("sailfishSessionId");
62
101
  if (!sessionId || forceNew) {
63
- sessionId = uuidv4();
102
+ const tabKey = getTabKey();
103
+ const storedSessionId = PERSIST_SESSION_FOR_REOPENING_TABS
104
+ ? localStorage.getItem(`sailfishSessionId_${tabKey}`)
105
+ : null;
106
+ if (storedSessionId && !forceNew) {
107
+ sessionId = storedSessionId;
108
+ }
109
+ else {
110
+ sessionId = uuidv4();
111
+ }
64
112
  sessionStorage.setItem("sailfishSessionId", sessionId);
65
113
  }
66
114
  return sessionId;
67
115
  }
68
- // Function to reset the sessionId when the page becomes visible again
116
+ // Function to store the current sessionId in localStorage on page unload
117
+ function storeSessionId() {
118
+ if (PERSIST_SESSION_FOR_REOPENING_TABS) {
119
+ const tabKey = getTabKey();
120
+ const sessionId = sessionStorage.getItem("sailfishSessionId");
121
+ if (sessionId) {
122
+ localStorage.setItem(`sailfishSessionId_${tabKey}`, sessionId);
123
+ }
124
+ }
125
+ }
126
+ // Function to handle resetting the sessionId when the page becomes visible again
69
127
  function handleVisibilityChange() {
70
128
  if (document.visibilityState === "visible") {
71
- getOrSetSessionId(true); // Force a new sessionId when the user returns to the page
129
+ getOrSetSessionId(); // Restore sessionId when the user returns to the page
72
130
  }
73
131
  }
74
132
  // Initialize event listeners for visibility change and page unload
75
133
  document.addEventListener("visibilitychange", handleVisibilityChange);
76
- window.addEventListener("beforeunload", () => {
77
- sessionStorage.removeItem("sailfishSessionId");
78
- });
134
+ window.addEventListener("beforeunload", storeSessionId);
79
135
  function storeCredentialsAndConnection({ apiKey, backendApi, }) {
80
136
  sessionStorage.setItem("sailfishApiKey", apiKey);
81
137
  sessionStorage.setItem("sailfishBackendApi", backendApi);
@@ -0,0 +1,16 @@
1
+ // mapUuid.tsx
2
+ import { sendMessage } from "./websocket";
3
+ export function sendMapUuidIfAvailable() {
4
+ if (window.sfMapUuid) {
5
+ const mapUuidMessage = {
6
+ type: "mapUuid",
7
+ data: {
8
+ mapUuid: window.sfMapUuid,
9
+ },
10
+ };
11
+ sendMessage(mapUuidMessage);
12
+ }
13
+ else {
14
+ console.log("window.sfMapUuid is not set. Please install @sailfish/sf-map-utils as a dev dependency and include it in your build process.");
15
+ }
16
+ }