@sailfish-ai/recorder 1.3.0 → 1.3.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",
@@ -55,27 +56,72 @@ export const DEFAULT_CONSOLE_RECORDING_SETTINGS = {
55
56
  // recordBody: true,
56
57
  // recordInitialRequests: false,
57
58
  // };
59
+ const PERSIST_SESSION_FOR_REOPENING_TABS = false;
58
60
  // Functions
59
- // Function to get the current sessionId from sessionStorage
61
+ // Function to get or set the device & program UUID in localStorage
62
+ function getOrSetUserDeviceUuid() {
63
+ let userDeviceUuid = localStorage.getItem("sailfishUserDeviceUuid");
64
+ if (!userDeviceUuid) {
65
+ userDeviceUuid = uuidv4();
66
+ localStorage.setItem("sailfishUserDeviceUuid", userDeviceUuid);
67
+ }
68
+ return userDeviceUuid;
69
+ }
70
+ // Function to generate a unique key for storing sessionId in localStorage
71
+ function getTabKey() {
72
+ let tabKey = sessionStorage.getItem("sailfishTabKey");
73
+ if (!tabKey) {
74
+ tabKey = uuidv4();
75
+ sessionStorage.setItem("sailfishTabKey", tabKey);
76
+ }
77
+ return tabKey;
78
+ }
79
+ // Function to get or set the current sessionId in sessionStorage
60
80
  function getOrSetSessionId(forceNew = false) {
61
81
  let sessionId = sessionStorage.getItem("sailfishSessionId");
62
82
  if (!sessionId || forceNew) {
63
- sessionId = uuidv4();
83
+ const tabKey = getTabKey();
84
+ const storedSessionId = PERSIST_SESSION_FOR_REOPENING_TABS
85
+ ? localStorage.getItem(`sailfishSessionId_${tabKey}`)
86
+ : null;
87
+ if (storedSessionId && !forceNew) {
88
+ sessionId = storedSessionId;
89
+ }
90
+ else {
91
+ sessionId = uuidv4();
92
+ }
64
93
  sessionStorage.setItem("sailfishSessionId", sessionId);
65
94
  }
66
95
  return sessionId;
67
96
  }
68
- // Function to reset the sessionId when the page becomes visible again
97
+ // Function to store the current sessionId in localStorage on page unload
98
+ function storeSessionId() {
99
+ if (PERSIST_SESSION_FOR_REOPENING_TABS) {
100
+ const tabKey = getTabKey();
101
+ const sessionId = sessionStorage.getItem("sailfishSessionId");
102
+ if (sessionId) {
103
+ localStorage.setItem(`sailfishSessionId_${tabKey}`, sessionId);
104
+ }
105
+ }
106
+ }
107
+ // Function to handle resetting the sessionId when the page becomes visible again
69
108
  function handleVisibilityChange() {
70
109
  if (document.visibilityState === "visible") {
71
- getOrSetSessionId(true); // Force a new sessionId when the user returns to the page
110
+ getOrSetSessionId(); // Restore sessionId when the user returns to the page
72
111
  }
73
112
  }
74
113
  // Initialize event listeners for visibility change and page unload
75
114
  document.addEventListener("visibilitychange", handleVisibilityChange);
76
- window.addEventListener("beforeunload", () => {
77
- sessionStorage.removeItem("sailfishSessionId");
78
- });
115
+ window.addEventListener("beforeunload", storeSessionId);
116
+ export function sendUserUuid() {
117
+ const userDeviceUuid = getOrSetUserDeviceUuid();
118
+ const message = {
119
+ type: "userDeviceUuid",
120
+ userDeviceUuid,
121
+ };
122
+ sendMessage(message);
123
+ }
124
+ sendUserUuid();
79
125
  function storeCredentialsAndConnection({ apiKey, backendApi, }) {
80
126
  sessionStorage.setItem("sailfishApiKey", apiKey);
81
127
  sessionStorage.setItem("sailfishBackendApi", backendApi);