@sailfish-ai/recorder 1.8.10 → 1.8.11
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 +1 -0
- package/dist/recorder.cjs +795 -779
- package/dist/recorder.js +801 -783
- package/dist/recorder.js.br +0 -0
- package/dist/recorder.js.gz +0 -0
- package/dist/recorder.umd.cjs +795 -779
- package/dist/session.js +42 -5
- package/dist/types/index.d.ts +1 -0
- package/dist/websocket.js +6 -4
- package/package.json +1 -1
package/dist/session.js
CHANGED
|
@@ -1,12 +1,49 @@
|
|
|
1
1
|
import { v4 as uuidv4 } from "uuid";
|
|
2
2
|
import { HAS_WINDOW } from "./runtimeEnv";
|
|
3
|
-
//
|
|
4
|
-
//
|
|
3
|
+
// Hybrid approach: use window.name as a temporary "refresh flag" and sessionStorage for persistence
|
|
4
|
+
// - window.name flag is removed immediately after reading, preserving customer's data
|
|
5
|
+
// - sessionStorage stores the actual session ID
|
|
6
|
+
// - beforeunload sets a flag in window.name to detect page refresh vs duplicate tab
|
|
7
|
+
const SESSION_ID_KEY = "sailfishSessionId";
|
|
8
|
+
const REFRESH_FLAG = "__sailfish_refresh__";
|
|
9
|
+
// Cache the resolved session ID to avoid regenerating on multiple calls
|
|
10
|
+
let resolvedSessionId = null;
|
|
5
11
|
export function getOrSetSessionId() {
|
|
6
12
|
if (!HAS_WINDOW)
|
|
7
13
|
return uuidv4();
|
|
8
|
-
if
|
|
9
|
-
|
|
14
|
+
// Return cached session ID if already resolved
|
|
15
|
+
if (resolvedSessionId) {
|
|
16
|
+
return resolvedSessionId;
|
|
10
17
|
}
|
|
11
|
-
|
|
18
|
+
// Check if window.name contains our refresh flag
|
|
19
|
+
const isRefresh = window.name.startsWith(REFRESH_FLAG);
|
|
20
|
+
// Remove our flag and restore customer's original window.name
|
|
21
|
+
if (isRefresh) {
|
|
22
|
+
window.name = window.name.substring(REFRESH_FLAG.length);
|
|
23
|
+
}
|
|
24
|
+
if (isRefresh) {
|
|
25
|
+
// Page refresh - reuse existing session ID from sessionStorage
|
|
26
|
+
const existingSessionId = window.sessionStorage.getItem(SESSION_ID_KEY);
|
|
27
|
+
if (existingSessionId) {
|
|
28
|
+
resolvedSessionId = existingSessionId;
|
|
29
|
+
return existingSessionId;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
// New tab or duplicate tab - generate new session ID
|
|
33
|
+
const sessionId = uuidv4();
|
|
34
|
+
resolvedSessionId = sessionId;
|
|
35
|
+
try {
|
|
36
|
+
window.sessionStorage.setItem(SESSION_ID_KEY, sessionId);
|
|
37
|
+
}
|
|
38
|
+
catch (error) {
|
|
39
|
+
// Ignore storage errors, use in-memory session ID
|
|
40
|
+
}
|
|
41
|
+
return sessionId;
|
|
42
|
+
}
|
|
43
|
+
// Set up beforeunload listener to mark page refresh
|
|
44
|
+
if (HAS_WINDOW) {
|
|
45
|
+
window.addEventListener("beforeunload", () => {
|
|
46
|
+
// Prepend our flag to preserve customer's window.name
|
|
47
|
+
window.name = REFRESH_FLAG + window.name;
|
|
48
|
+
});
|
|
12
49
|
}
|
package/dist/types/index.d.ts
CHANGED
|
@@ -31,6 +31,7 @@ export * from "./graphql";
|
|
|
31
31
|
export { openReportIssueModal } from "./inAppReportIssueModal";
|
|
32
32
|
export * from "./recording";
|
|
33
33
|
export * from "./sendSailfishMessages";
|
|
34
|
+
export { getOrSetSessionId } from "./session";
|
|
34
35
|
export * from "./types";
|
|
35
36
|
export * from "./utils";
|
|
36
37
|
export * from "./websocket";
|
package/dist/websocket.js
CHANGED
|
@@ -364,7 +364,12 @@ export function sendMessage(message) {
|
|
|
364
364
|
...message,
|
|
365
365
|
app_url: message?.app_url ?? window?.location?.href,
|
|
366
366
|
});
|
|
367
|
-
|
|
367
|
+
// Check isDraining to prevent out-of-order delivery during reconnection
|
|
368
|
+
// When draining buffered events, queue new messages to maintain order
|
|
369
|
+
if (isDraining || !isWebSocketOpen(webSocket)) {
|
|
370
|
+
saveNotifyMessageToIDB(msg);
|
|
371
|
+
}
|
|
372
|
+
else {
|
|
368
373
|
try {
|
|
369
374
|
webSocket.send(msg);
|
|
370
375
|
}
|
|
@@ -372,9 +377,6 @@ export function sendMessage(message) {
|
|
|
372
377
|
saveNotifyMessageToIDB(msg);
|
|
373
378
|
}
|
|
374
379
|
}
|
|
375
|
-
else {
|
|
376
|
-
saveNotifyMessageToIDB(msg);
|
|
377
|
-
}
|
|
378
380
|
}
|
|
379
381
|
function getWebSocketHost(url) {
|
|
380
382
|
const parser = document.createElement("a");
|