@rejourneyco/react-native 1.0.13 → 1.0.14

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.
@@ -60,6 +60,7 @@ import kotlin.concurrent.withLock
60
60
  */
61
61
  sealed class SessionState {
62
62
  object Idle : SessionState()
63
+ data class Starting(val sessionId: String, val startTimeMs: Long) : SessionState()
63
64
  data class Active(val sessionId: String, val startTimeMs: Long) : SessionState()
64
65
  data class Paused(val sessionId: String, val startTimeMs: Long) : SessionState()
65
66
  object Terminated : SessionState()
@@ -488,9 +489,16 @@ class RejourneyModuleImpl(
488
489
  // Check if already active
489
490
  stateLock.withLock {
490
491
  val currentState = state
491
- if (currentState is SessionState.Active) {
492
- promise.resolve(createResultMap(true, currentState.sessionId))
493
- return@post
492
+ when (currentState) {
493
+ is SessionState.Active -> {
494
+ promise.resolve(createResultMap(true, currentState.sessionId))
495
+ return@post
496
+ }
497
+ is SessionState.Starting -> {
498
+ promise.resolve(createResultMap(true, currentState.sessionId))
499
+ return@post
500
+ }
501
+ else -> Unit
494
502
  }
495
503
  }
496
504
 
@@ -522,10 +530,10 @@ class RejourneyModuleImpl(
522
530
  DiagnosticLog.fault("[Rejourney] CRITICAL: No current activity available for capture!")
523
531
  }
524
532
 
525
- // Pre-generate session ID to ensure consistency between JS and native
526
- val sid = "session_${System.currentTimeMillis()}_${java.util.UUID.randomUUID().toString().replace("-", "").lowercase()}"
527
- ReplayOrchestrator.shared?.replayId = sid
528
- TelemetryPipeline.shared?.currentReplayId = sid
533
+ val pendingSessionId = "session_${System.currentTimeMillis()}_${java.util.UUID.randomUUID().toString().replace("-", "").lowercase()}"
534
+ stateLock.withLock {
535
+ state = SessionState.Starting(pendingSessionId, System.currentTimeMillis())
536
+ }
529
537
 
530
538
  // Begin replay
531
539
  ReplayOrchestrator.shared?.beginReplay(
@@ -539,6 +547,7 @@ class RejourneyModuleImpl(
539
547
 
540
548
  // Allow orchestrator time to spin up
541
549
  mainHandler.postDelayed({
550
+ val sid = ReplayOrchestrator.shared?.replayId ?: pendingSessionId
542
551
  stateLock.withLock {
543
552
  state = SessionState.Active(sid, System.currentTimeMillis())
544
553
  }
@@ -27,6 +27,7 @@ public final class RejourneyImpl: NSObject {
27
27
 
28
28
  private enum SessionState {
29
29
  case idle
30
+ case starting(sessionId: String, startTime: TimeInterval)
30
31
  case active(sessionId: String, startTime: TimeInterval)
31
32
  case paused(sessionId: String, startTime: TimeInterval)
32
33
  case terminated
@@ -353,12 +354,14 @@ public final class RejourneyImpl: NSObject {
353
354
  }
354
355
 
355
356
  self.stateLock.lock()
356
- if case .active(let sid, _) = self.state {
357
+ switch self.state {
358
+ case .active(let sid, _), .starting(let sid, _):
357
359
  self.stateLock.unlock()
358
360
  resolve(["success": true, "sessionId": sid])
359
361
  return
362
+ default:
363
+ self.stateLock.unlock()
360
364
  }
361
- self.stateLock.unlock()
362
365
 
363
366
  if !userId.isEmpty && userId != "anonymous" && !userId.hasPrefix("anon_") {
364
367
  self.currentUserIdentity = userId
@@ -376,11 +379,17 @@ public final class RejourneyImpl: NSObject {
376
379
  // Activate native network interception
377
380
  RejourneyURLProtocol.enable()
378
381
 
382
+ let pendingSessionId = "session_\(Int(Date().timeIntervalSince1970 * 1000))_\(UUID().uuidString.replacingOccurrences(of: "-", with: "").lowercased())"
383
+ let pendingStart = Date().timeIntervalSince1970
384
+ self.stateLock.lock()
385
+ self.state = .starting(sessionId: pendingSessionId, startTime: pendingStart)
386
+ self.stateLock.unlock()
387
+
379
388
  ReplayOrchestrator.shared.beginReplay(apiToken: publicKey, serverEndpoint: apiUrl, captureSettings: config)
380
389
 
381
390
  // Allow orchestrator time to spin up
382
391
  DispatchQueue.main.asyncAfter(deadline: .now() + 0.3) {
383
- let sid = ReplayOrchestrator.shared.replayId ?? UUID().uuidString
392
+ let sid = ReplayOrchestrator.shared.replayId ?? pendingSessionId
384
393
  let start = Date().timeIntervalSince1970
385
394
 
386
395
  self.stateLock.lock()
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rejourneyco/react-native",
3
- "version": "1.0.13",
3
+ "version": "1.0.14",
4
4
  "description": "Rejourney Session Recording SDK for React Native",
5
5
  "main": "lib/commonjs/index.js",
6
6
  "module": "lib/module/index.js",