@statsig/session-replay 0.0.1-beta.26 → 0.0.1-beta.27

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
@@ -1,9 +1,9 @@
1
1
  {
2
2
  "name": "@statsig/session-replay",
3
- "version": "0.0.1-beta.26",
3
+ "version": "0.0.1-beta.27",
4
4
  "dependencies": {
5
5
  "rrweb": "2.0.0-alpha.12",
6
- "@statsig/client-core": "0.0.1-beta.26"
6
+ "@statsig/client-core": "0.0.1-beta.27"
7
7
  },
8
8
  "devDependencies": {
9
9
  "@rrweb/types": "2.0.0-alpha.12"
@@ -11,5 +11,6 @@ export declare class SessionReplay {
11
11
  private _attemptToStartRecording;
12
12
  private _shutdown;
13
13
  private _flushWithSessionID;
14
+ private _logRecordingEvent;
14
15
  private _flush;
15
16
  }
@@ -56,7 +56,6 @@ class SessionReplay {
56
56
  }
57
57
  _attemptToStartRecording() {
58
58
  var _a;
59
- this._shutdown(); // Flush and end the previous session if any
60
59
  const values = this._client.getContext().values;
61
60
  if ((values === null || values === void 0 ? void 0 : values.can_record_session) !== true) {
62
61
  this._shutdown();
@@ -67,6 +66,9 @@ class SessionReplay {
67
66
  this._shutdown();
68
67
  return;
69
68
  }
69
+ if (this._replayer.isRecording()) {
70
+ return;
71
+ }
70
72
  client_core_1.StatsigMetadataProvider.add({ isRecordingSession: 'true' });
71
73
  this._replayer.record((e, d) => this._onRecordingEvent(e, d));
72
74
  }
@@ -85,6 +87,9 @@ class SessionReplay {
85
87
  }
86
88
  const data = this._sessionData;
87
89
  const payload = JSON.stringify(this._events);
90
+ this._logRecordingEvent(payload, data, sessionID);
91
+ }
92
+ _logRecordingEvent(payload, data, sessionID) {
88
93
  const { sdkVersion } = client_core_1.StatsigMetadataProvider.get();
89
94
  this._client.logEvent({
90
95
  eventName: 'statsig::session_recording',
@@ -97,28 +102,17 @@ class SessionReplay {
97
102
  session_replay_sdk_version: sdkVersion,
98
103
  },
99
104
  });
105
+ this._events = [];
100
106
  }
101
107
  _flush(payload, data) {
102
- const { sdkVersion } = client_core_1.StatsigMetadataProvider.get();
103
108
  this._client
104
109
  .getAsyncContext()
105
110
  .then((context) => {
106
- this._client.logEvent({
107
- eventName: 'statsig::session_recording',
108
- value: context.sessionID,
109
- metadata: {
110
- session_start_ts: String(data.startTime),
111
- session_end_ts: String(data.endTime),
112
- clicks_captured_cumulative: String(data.clickCount),
113
- rrweb_events: payload,
114
- session_replay_sdk_version: sdkVersion,
115
- },
116
- });
111
+ this._logRecordingEvent(payload, data, context.sessionID);
117
112
  })
118
113
  .catch((err) => {
119
114
  client_core_1.Log.error(err);
120
115
  });
121
- this._events = [];
122
116
  }
123
117
  }
124
118
  exports.SessionReplay = SessionReplay;
@@ -1,4 +1,4 @@
1
- import { eventWithTime } from '@rrweb/types';
1
+ import type { eventWithTime } from '@rrweb/types';
2
2
  import { Flatten } from '@statsig/client-core';
3
3
  export type ReplayEvent = Flatten<eventWithTime>;
4
4
  export type ReplaySessionData = {
@@ -14,4 +14,5 @@ export declare class SessionReplayClient {
14
14
  private _clickCount;
15
15
  record(callback: (latest: ReplayEvent, data: ReplaySessionData) => void, stopCallback?: () => void): void;
16
16
  stop(): void;
17
+ isRecording(): boolean;
17
18
  }
@@ -1,7 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.SessionReplayClient = void 0;
4
- const rrweb_1 = require("rrweb");
4
+ const types_1 = require("@rrweb/types");
5
+ const rrweb = require("rrweb");
5
6
  const TIMEOUT_MS = 1000 * 60 * 60 * 4; // 4 hours
6
7
  class SessionReplayClient {
7
8
  constructor() {
@@ -43,7 +44,7 @@ class SessionReplayClient {
43
44
  }
44
45
  }
45
46
  };
46
- this._stopFn = (0, rrweb_1.record)({ emit });
47
+ this._stopFn = _minifiedAwareRecord(emit);
47
48
  }
48
49
  stop() {
49
50
  if (this._stopFn) {
@@ -51,10 +52,21 @@ class SessionReplayClient {
51
52
  this._stopFn = undefined;
52
53
  }
53
54
  }
55
+ isRecording() {
56
+ return this._stopFn != null;
57
+ }
54
58
  }
55
59
  exports.SessionReplayClient = SessionReplayClient;
60
+ /**
61
+ * We do a simple concat of rrweb during minification.
62
+ * This function ensures we handle both "npm" and "<script ..>" install options.
63
+ */
64
+ function _minifiedAwareRecord(emit) {
65
+ const record = typeof rrweb === 'function' ? rrweb : rrweb.record;
66
+ return record({ emit });
67
+ }
56
68
  function _isClickEvent(event) {
57
- return (event.type === rrweb_1.EventType.IncrementalSnapshot &&
58
- event.data.source === rrweb_1.IncrementalSource.MouseInteraction &&
59
- event.data.type === rrweb_1.MouseInteractions.Click);
69
+ return (event.type === types_1.EventType.IncrementalSnapshot &&
70
+ event.data.source === types_1.IncrementalSource.MouseInteraction &&
71
+ event.data.type === types_1.MouseInteractions.Click);
60
72
  }