core-outline 1.1.14 → 1.1.16
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/package.json
CHANGED
|
@@ -5,6 +5,7 @@ import socket from "./socket";
|
|
|
5
5
|
|
|
6
6
|
import { EventType, eventWithTime, IncrementalSource, MouseInteractions } from "rrweb";
|
|
7
7
|
|
|
8
|
+
|
|
8
9
|
const CoreOutline = ({ children, data_source_id, data_source_secret }) => {
|
|
9
10
|
const [events, setEvents] = useState([]);
|
|
10
11
|
const [replayEvents, setReplayEvents] = useState([]);
|
|
@@ -38,7 +39,56 @@ const CoreOutline = ({ children, data_source_id, data_source_secret }) => {
|
|
|
38
39
|
});
|
|
39
40
|
return response;
|
|
40
41
|
}
|
|
42
|
+
|
|
43
|
+
const offLoadFunctionality = () => {
|
|
44
|
+
const data = JSON.stringify({
|
|
45
|
+
data_source_id: data_source_id,
|
|
46
|
+
sessionId: sessionId,
|
|
47
|
+
formatted_events: JSON.stringify(events),
|
|
48
|
+
raw_events: JSON.stringify(replayEvents),
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
socket.send({
|
|
52
|
+
topic: "session-data",
|
|
53
|
+
data_source_id: data_source_id,
|
|
54
|
+
session_id: localStorage.getItem("coreOutlineSessionId"),
|
|
55
|
+
start_date: new Date().toLocaleString(),
|
|
56
|
+
latitude: location.latitude,
|
|
57
|
+
longitude: location.longitude,
|
|
58
|
+
browser: browser,
|
|
59
|
+
event_id: "SESSION_END",
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
if (navigator.sendBeacon) {
|
|
63
|
+
navigator.sendBeacon(
|
|
64
|
+
`http://localhost:5000/upload-events`, data
|
|
65
|
+
);
|
|
66
|
+
}
|
|
67
|
+
else {
|
|
68
|
+
fetch(`http://localhost:5000/upload-events`, {
|
|
69
|
+
method: 'POST',
|
|
70
|
+
body: data,
|
|
71
|
+
keepalive: true,
|
|
72
|
+
headers: {
|
|
73
|
+
'Content-Type': 'application/json',
|
|
74
|
+
},
|
|
75
|
+
}).catch(err => console.error('Upload failed:', err));
|
|
76
|
+
}
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
|
|
41
80
|
useEffect(async () => {
|
|
81
|
+
const handleBeforeUnload = () => {
|
|
82
|
+
offLoadFunctionality();
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
const handleVisibilityChange = () => {
|
|
86
|
+
if (document.visibilityState === 'hidden') {
|
|
87
|
+
offLoadFunctionality();
|
|
88
|
+
}
|
|
89
|
+
};
|
|
90
|
+
window.addEventListener('beforeunload', handleBeforeUnload);
|
|
91
|
+
document.addEventListener('visibilitychange', handleVisibilityChange);
|
|
42
92
|
await authorizeApp(data_source_id, data_source_secret);
|
|
43
93
|
localStorage.setItem("coreOutlineSessionId", sessionId);
|
|
44
94
|
localStorage.setItem("coreOutlineDataSourceIdId", data_source_id);
|
|
@@ -55,6 +105,9 @@ const CoreOutline = ({ children, data_source_id, data_source_secret }) => {
|
|
|
55
105
|
});
|
|
56
106
|
|
|
57
107
|
return () => {
|
|
108
|
+
offLoadFunctionality();
|
|
109
|
+
window.removeEventListener('beforeunload', handleBeforeUnload);
|
|
110
|
+
document.removeEventListener('visibilitychange', handleVisibilityChange);
|
|
58
111
|
socket.send({
|
|
59
112
|
topic: "session-data",
|
|
60
113
|
data_source_id: data_source_id,
|
|
@@ -104,7 +157,6 @@ const CoreOutline = ({ children, data_source_id, data_source_secret }) => {
|
|
|
104
157
|
page_name: window.location.href,
|
|
105
158
|
event_id: "PAGE_NAVIGATION",
|
|
106
159
|
});
|
|
107
|
-
saveEvents(events);
|
|
108
160
|
};
|
|
109
161
|
|
|
110
162
|
window.addEventListener("popstate", handleNavigation);
|
|
@@ -142,7 +194,6 @@ const CoreOutline = ({ children, data_source_id, data_source_secret }) => {
|
|
|
142
194
|
return () => {
|
|
143
195
|
if (stopFn) {
|
|
144
196
|
stopFn();
|
|
145
|
-
saveEvents(events);
|
|
146
197
|
|
|
147
198
|
recorderActive.current = false;
|
|
148
199
|
}
|
|
@@ -182,7 +233,6 @@ const CoreOutline = ({ children, data_source_id, data_source_secret }) => {
|
|
|
182
233
|
return () => {
|
|
183
234
|
if (stopFn) {
|
|
184
235
|
stopFn();
|
|
185
|
-
saveEvents(events);
|
|
186
236
|
|
|
187
237
|
recorderActive.current = false;
|
|
188
238
|
}
|
|
@@ -239,21 +289,6 @@ const CoreOutline = ({ children, data_source_id, data_source_secret }) => {
|
|
|
239
289
|
};
|
|
240
290
|
}, []);
|
|
241
291
|
|
|
242
|
-
function saveEvents(events) {
|
|
243
|
-
const requestOptions = {
|
|
244
|
-
method: "PUT",
|
|
245
|
-
headers: {
|
|
246
|
-
"Content-Type": "application/json",
|
|
247
|
-
},
|
|
248
|
-
body: JSON.stringify(events),
|
|
249
|
-
};
|
|
250
|
-
fetch(`http://localhost:5000/generate-s3-url/${data_source_id}/${sessionId}`)
|
|
251
|
-
.then((response) => response.json())
|
|
252
|
-
.then((data) => {
|
|
253
|
-
const uploadURL = data.signed_url;
|
|
254
|
-
return fetch(uploadURL, requestOptions);
|
|
255
|
-
});
|
|
256
|
-
}
|
|
257
292
|
|
|
258
293
|
function saveEventsLocally(type = "formatted" || "raw") {
|
|
259
294
|
let blob = "";
|