@neroom/nevision 0.1.8 → 0.1.10

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
@@ -196,6 +196,20 @@ function NevisionRecorder({
196
196
  if (stopFn) {
197
197
  stopFnRef.current = stopFn;
198
198
  }
199
+ const emitPageLifecycleEvent = (eventName) => {
200
+ const customEvent = {
201
+ type: 5,
202
+ // Custom event type in rrweb
203
+ data: {
204
+ tag: "page_lifecycle",
205
+ payload: {
206
+ event: eventName
207
+ }
208
+ },
209
+ timestamp: Date.now()
210
+ };
211
+ eventsBufferRef.current.push(customEvent);
212
+ };
199
213
  intervalId = setInterval(() => {
200
214
  sendChunk(apiUrl, sessionId);
201
215
  }, CHUNK_INTERVAL);
@@ -212,24 +226,33 @@ function NevisionRecorder({
212
226
  };
213
227
  const handleVisibilityChange = () => {
214
228
  if (document.visibilityState === "hidden") {
229
+ emitPageLifecycleEvent("page_hidden");
215
230
  handleFinalSync(false);
231
+ } else {
232
+ emitPageLifecycleEvent("page_visible");
216
233
  }
217
234
  };
218
235
  const handleBeforeUnload = () => {
219
236
  handleFinalSync(true);
220
237
  };
221
238
  const handlePageHide = (e) => {
239
+ emitPageLifecycleEvent("page_hidden");
222
240
  handleFinalSync(!e.persisted);
223
241
  };
224
242
  const handleWindowBlur = () => {
225
- if (eventsBufferRef.current.length > 0 && sessionIdRef.current) {
243
+ emitPageLifecycleEvent("page_blur");
244
+ if (sessionIdRef.current) {
226
245
  sendChunk(apiUrl, sessionIdRef.current, true);
227
246
  }
228
247
  };
248
+ const handleWindowFocus = () => {
249
+ emitPageLifecycleEvent("page_focus");
250
+ };
229
251
  document.addEventListener("visibilitychange", handleVisibilityChange);
230
252
  window.addEventListener("beforeunload", handleBeforeUnload);
231
253
  window.addEventListener("pagehide", handlePageHide);
232
254
  window.addEventListener("blur", handleWindowBlur);
255
+ window.addEventListener("focus", handleWindowFocus);
233
256
  } catch (error) {
234
257
  onErrorRef.current?.(error instanceof Error ? error : new Error(String(error)));
235
258
  }
package/dist/index.mjs CHANGED
@@ -162,6 +162,20 @@ function NevisionRecorder({
162
162
  if (stopFn) {
163
163
  stopFnRef.current = stopFn;
164
164
  }
165
+ const emitPageLifecycleEvent = (eventName) => {
166
+ const customEvent = {
167
+ type: 5,
168
+ // Custom event type in rrweb
169
+ data: {
170
+ tag: "page_lifecycle",
171
+ payload: {
172
+ event: eventName
173
+ }
174
+ },
175
+ timestamp: Date.now()
176
+ };
177
+ eventsBufferRef.current.push(customEvent);
178
+ };
165
179
  intervalId = setInterval(() => {
166
180
  sendChunk(apiUrl, sessionId);
167
181
  }, CHUNK_INTERVAL);
@@ -178,24 +192,33 @@ function NevisionRecorder({
178
192
  };
179
193
  const handleVisibilityChange = () => {
180
194
  if (document.visibilityState === "hidden") {
195
+ emitPageLifecycleEvent("page_hidden");
181
196
  handleFinalSync(false);
197
+ } else {
198
+ emitPageLifecycleEvent("page_visible");
182
199
  }
183
200
  };
184
201
  const handleBeforeUnload = () => {
185
202
  handleFinalSync(true);
186
203
  };
187
204
  const handlePageHide = (e) => {
205
+ emitPageLifecycleEvent("page_hidden");
188
206
  handleFinalSync(!e.persisted);
189
207
  };
190
208
  const handleWindowBlur = () => {
191
- if (eventsBufferRef.current.length > 0 && sessionIdRef.current) {
209
+ emitPageLifecycleEvent("page_blur");
210
+ if (sessionIdRef.current) {
192
211
  sendChunk(apiUrl, sessionIdRef.current, true);
193
212
  }
194
213
  };
214
+ const handleWindowFocus = () => {
215
+ emitPageLifecycleEvent("page_focus");
216
+ };
195
217
  document.addEventListener("visibilitychange", handleVisibilityChange);
196
218
  window.addEventListener("beforeunload", handleBeforeUnload);
197
219
  window.addEventListener("pagehide", handlePageHide);
198
220
  window.addEventListener("blur", handleWindowBlur);
221
+ window.addEventListener("focus", handleWindowFocus);
199
222
  } catch (error) {
200
223
  onErrorRef.current?.(error instanceof Error ? error : new Error(String(error)));
201
224
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@neroom/nevision",
3
- "version": "0.1.8",
3
+ "version": "0.1.10",
4
4
  "description": "React SDK for NEROOM/NEVISION session recording",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",