@neroom/nevision 0.1.9 → 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
@@ -210,22 +210,6 @@ function NevisionRecorder({
210
210
  };
211
211
  eventsBufferRef.current.push(customEvent);
212
212
  };
213
- const handleVisibilityChangeForTimeline = () => {
214
- if (document.visibilityState === "hidden") {
215
- emitPageLifecycleEvent("page_hidden");
216
- } else {
217
- emitPageLifecycleEvent("page_visible");
218
- }
219
- };
220
- const handleWindowFocusForTimeline = () => {
221
- emitPageLifecycleEvent("page_focus");
222
- };
223
- const handleWindowBlurForTimeline = () => {
224
- emitPageLifecycleEvent("page_blur");
225
- };
226
- document.addEventListener("visibilitychange", handleVisibilityChangeForTimeline);
227
- window.addEventListener("focus", handleWindowFocusForTimeline);
228
- window.addEventListener("blur", handleWindowBlurForTimeline);
229
213
  intervalId = setInterval(() => {
230
214
  sendChunk(apiUrl, sessionId);
231
215
  }, CHUNK_INTERVAL);
@@ -242,24 +226,33 @@ function NevisionRecorder({
242
226
  };
243
227
  const handleVisibilityChange = () => {
244
228
  if (document.visibilityState === "hidden") {
229
+ emitPageLifecycleEvent("page_hidden");
245
230
  handleFinalSync(false);
231
+ } else {
232
+ emitPageLifecycleEvent("page_visible");
246
233
  }
247
234
  };
248
235
  const handleBeforeUnload = () => {
249
236
  handleFinalSync(true);
250
237
  };
251
238
  const handlePageHide = (e) => {
239
+ emitPageLifecycleEvent("page_hidden");
252
240
  handleFinalSync(!e.persisted);
253
241
  };
254
242
  const handleWindowBlur = () => {
255
- if (eventsBufferRef.current.length > 0 && sessionIdRef.current) {
243
+ emitPageLifecycleEvent("page_blur");
244
+ if (sessionIdRef.current) {
256
245
  sendChunk(apiUrl, sessionIdRef.current, true);
257
246
  }
258
247
  };
248
+ const handleWindowFocus = () => {
249
+ emitPageLifecycleEvent("page_focus");
250
+ };
259
251
  document.addEventListener("visibilitychange", handleVisibilityChange);
260
252
  window.addEventListener("beforeunload", handleBeforeUnload);
261
253
  window.addEventListener("pagehide", handlePageHide);
262
254
  window.addEventListener("blur", handleWindowBlur);
255
+ window.addEventListener("focus", handleWindowFocus);
263
256
  } catch (error) {
264
257
  onErrorRef.current?.(error instanceof Error ? error : new Error(String(error)));
265
258
  }
package/dist/index.mjs CHANGED
@@ -176,22 +176,6 @@ function NevisionRecorder({
176
176
  };
177
177
  eventsBufferRef.current.push(customEvent);
178
178
  };
179
- const handleVisibilityChangeForTimeline = () => {
180
- if (document.visibilityState === "hidden") {
181
- emitPageLifecycleEvent("page_hidden");
182
- } else {
183
- emitPageLifecycleEvent("page_visible");
184
- }
185
- };
186
- const handleWindowFocusForTimeline = () => {
187
- emitPageLifecycleEvent("page_focus");
188
- };
189
- const handleWindowBlurForTimeline = () => {
190
- emitPageLifecycleEvent("page_blur");
191
- };
192
- document.addEventListener("visibilitychange", handleVisibilityChangeForTimeline);
193
- window.addEventListener("focus", handleWindowFocusForTimeline);
194
- window.addEventListener("blur", handleWindowBlurForTimeline);
195
179
  intervalId = setInterval(() => {
196
180
  sendChunk(apiUrl, sessionId);
197
181
  }, CHUNK_INTERVAL);
@@ -208,24 +192,33 @@ function NevisionRecorder({
208
192
  };
209
193
  const handleVisibilityChange = () => {
210
194
  if (document.visibilityState === "hidden") {
195
+ emitPageLifecycleEvent("page_hidden");
211
196
  handleFinalSync(false);
197
+ } else {
198
+ emitPageLifecycleEvent("page_visible");
212
199
  }
213
200
  };
214
201
  const handleBeforeUnload = () => {
215
202
  handleFinalSync(true);
216
203
  };
217
204
  const handlePageHide = (e) => {
205
+ emitPageLifecycleEvent("page_hidden");
218
206
  handleFinalSync(!e.persisted);
219
207
  };
220
208
  const handleWindowBlur = () => {
221
- if (eventsBufferRef.current.length > 0 && sessionIdRef.current) {
209
+ emitPageLifecycleEvent("page_blur");
210
+ if (sessionIdRef.current) {
222
211
  sendChunk(apiUrl, sessionIdRef.current, true);
223
212
  }
224
213
  };
214
+ const handleWindowFocus = () => {
215
+ emitPageLifecycleEvent("page_focus");
216
+ };
225
217
  document.addEventListener("visibilitychange", handleVisibilityChange);
226
218
  window.addEventListener("beforeunload", handleBeforeUnload);
227
219
  window.addEventListener("pagehide", handlePageHide);
228
220
  window.addEventListener("blur", handleWindowBlur);
221
+ window.addEventListener("focus", handleWindowFocus);
229
222
  } catch (error) {
230
223
  onErrorRef.current?.(error instanceof Error ? error : new Error(String(error)));
231
224
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@neroom/nevision",
3
- "version": "0.1.9",
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",