@cloudflare/realtimekit 1.5.2-staging.7 → 1.5.2-staging.9

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.d.ts CHANGED
@@ -3690,7 +3690,9 @@ declare class MediaNodeClient {
3690
3690
  constructor(context: Context<ContextState>, options: MediaNodeClientOptions);
3691
3691
  get mediaJoined(): boolean;
3692
3692
  set mediaJoined(joined: boolean);
3693
- reset(): void;
3693
+ reset({ resetTransportQueue }: {
3694
+ resetTransportQueue: boolean;
3695
+ }): void;
3694
3696
  joinRoom(displayName: string, roomUuid: string, rejoining?: boolean, permissions?: MediaPermissions): Promise<{
3695
3697
  roomJoined: boolean;
3696
3698
  error?: Error;
package/dist/index.es.js CHANGED
@@ -18456,7 +18456,7 @@ const Af = (Sg = class {
18456
18456
  this.waitingRoomRequestHandler.bind(this)
18457
18457
  ), this.context.getValue("peerSessionStore").on(b.SOCKET_PEERS, (s) => {
18458
18458
  const t = this.participants.joined.size > 0;
18459
- this.participants.joined.clear(), this.participants.videoSubscribed.clear(), this.participants.audioSubscribed.clear(), this.participants.pinned.clear(), this.participants.currentPage = 0, this.participants.viewMode = "ACTIVE_GRID", t && this.participants.emit("viewModeChanged", {
18459
+ this.participants.videoSubscribed.clear(), this.participants.audioSubscribed.clear(), this.participants.pinned.clear(), this.participants.joined.clear(), this.participants.currentPage = 0, this.participants.viewMode = "ACTIVE_GRID", t && this.participants.emit("viewModeChanged", {
18460
18460
  viewMode: "ACTIVE_GRID",
18461
18461
  currentPage: this.participants.currentPage,
18462
18462
  pageCount: this.participants.pageCount
@@ -23425,12 +23425,29 @@ class aD extends iD {
23425
23425
  * sending close messages would fail since the SFU doesn't know
23426
23426
  * about these producers anymore.
23427
23427
  *
23428
- * Fire-and-forget is safe: Producer.close(REASON_TRANSPORT_CLOSED)
23429
- * skips the async SDP renegotiation path (stopSending + safeEmitAsPromise)
23430
- * and only performs synchronous local cleanup.
23428
+ * Also deactivates the underlying RTCRtpTransceivers as a
23429
+ * best-effort cleanup to stop unnecessary RTP from flowing
23430
+ * to the SFU on the still-alive send transport.
23431
23431
  */
23432
23432
  closeAllProducersLocally() {
23433
- Array.from(a(this, Ir).values()).forEach((e) => e.close(mo));
23433
+ return u(this, null, function* () {
23434
+ var r;
23435
+ const e = (r = this.sendTransport) == null ? void 0 : r.handler;
23436
+ yield Promise.all(Array.from(a(this, Ir).values()).map((i) => u(this, null, function* () {
23437
+ try {
23438
+ if (e) {
23439
+ const n = e.midTransceiverMap.get(i.localId);
23440
+ n && (yield n.sender.replaceTrack(null), n.direction = "inactive");
23441
+ }
23442
+ } catch (n) {
23443
+ this.logger.warn("closeAllProducersLocally: failed to deactivate transceiver", {
23444
+ producer: { id: i.id, kind: i.kind, appData: i.appData },
23445
+ error: n
23446
+ });
23447
+ }
23448
+ yield i.close(mo);
23449
+ })));
23450
+ });
23434
23451
  }
23435
23452
  createConsumer(e) {
23436
23453
  return this.createConsumers([e]);
@@ -23910,8 +23927,8 @@ class ne {
23910
23927
  set mediaJoined(t) {
23911
23928
  a(this, Js, Xr).mediaJoined = t;
23912
23929
  }
23913
- reset() {
23914
- a(this, G).closeAllProducers(), a(this, G).closeAllConsumers(), a(this, tt).clear(), a(this, _s).clear(), S(this, At, null), a(this, xi).stop(), a(this, G).stopAllTransports(), a(this, G).reset(), S(this, xi, new Ru());
23930
+ reset({ resetTransportQueue: t }) {
23931
+ this.logger.info(`Resetting media node client: closing all transports, producers, consumers, and queues(resetTransportQueue: ${t}).`), a(this, G).closeAllProducers(), a(this, G).closeAllConsumers(), a(this, tt).clear(), a(this, _s).clear(), S(this, At, null), t && a(this, xi).stop(), a(this, G).stopAllTransports(), a(this, G).reset(), t && S(this, xi, new Ru());
23915
23932
  }
23916
23933
  joinRoom(n, o) {
23917
23934
  return u(this, arguments, function* (t, e, r = !1, i = {}) {
@@ -24466,7 +24483,7 @@ lc = new WeakMap(), uc = new WeakMap(), et = new WeakMap(), G = new WeakMap(), t
24466
24483
  let n = !1;
24467
24484
  if (r) {
24468
24485
  const { recv: c, send: d } = (o = a(this, Js, Xr).mediaState) != null ? o : {};
24469
- (d == null ? void 0 : d.state) === Hr.CONNECTED && (c == null ? void 0 : c.state) === Hr.CONNECTED ? (this.logger.info("MediaNodeClient.joinRoom: transports healthy — partial reset (producers only)"), a(this, G).closeAllProducersLocally(), a(this, tt).clear(), a(this, _s).clear(), S(this, At, null), n = !0) : (this.logger.info("MediaNodeClient.joinRoom: transports unhealthy — full reset"), this.reset());
24486
+ (d == null ? void 0 : d.state) === Hr.CONNECTED && (c == null ? void 0 : c.state) === Hr.CONNECTED ? (this.logger.info("MediaNodeClient.joinRoom: transports healthy — partial reset (producers only)"), yield a(this, G).closeAllProducersLocally(), a(this, tt).clear(), a(this, _s).clear(), S(this, At, null), n = !0) : (this.logger.info("MediaNodeClient.joinRoom: transports unhealthy — full reset"), this.reset({ resetTransportQueue: !1 }));
24470
24487
  }
24471
24488
  try {
24472
24489
  a(this, At) ? yield a(this, At) : yield V(this, pc, Lu).call(this, t, e, r, i, n), V(this, il, eS).call(this, e);
@@ -24851,7 +24868,7 @@ const oS = (Tg = class {
24851
24868
  }
24852
24869
  resetSelf(s) {
24853
24870
  return u(this, null, function* () {
24854
- a(this, ee).getValue("callstats").callEnded(), s ? yield this.joinRoom(s) : a(this, ft, $t).reset();
24871
+ a(this, ee).getValue("callstats").callEnded(), s ? (this.logger.info("Resetting Self post reconnect. Peer has earlier tried joining the meeting. State cleanup will be done during room rejoin."), yield this.joinRoom(s)) : (this.logger.info("Resetting Self post reconnect. User never joined the room so doing full reset."), a(this, ft, $t).reset({ resetTransportQueue: !0 }));
24855
24872
  });
24856
24873
  }
24857
24874
  setupEvents() {
@@ -24862,7 +24879,7 @@ const oS = (Tg = class {
24862
24879
  }), a(this, ee).getValue("peerSessionStore").on(b.ROOM_NODE_DISCONNECTED, () => {
24863
24880
  this.self.roomState !== "disconnected" && (this.self.roomState = "disconnected", this.self.emit("roomLeft", { state: "disconnected" }));
24864
24881
  }), a(this, ee).getValue("peerSessionStore").on(b.ROOM_NODE_FAILED, () => {
24865
- this.self.roomState = "failed", this.self.emit("roomLeft", { state: "failed" });
24882
+ this.logger.error("Room node failed. SDK re-initialization is required."), this.self.roomState = "failed", this.self.emit("roomLeft", { state: "failed" });
24866
24883
  }), a(this, ee).getValue("peerSessionStore").on(b.SOCKET_SERVICE_RECONNECTED, ({ wasJoinAttempted: s }) => {
24867
24884
  s === !1 && (this.self.roomState = "init"), this.resetSelf(s);
24868
24885
  }), a(this, ee).getValue("peerSessionStore").on(b.SOCKET_SERVICE_DISCONNECTED, ({ joinAttempted: s }) => {
@@ -24871,7 +24888,7 @@ const oS = (Tg = class {
24871
24888
  const { peerId: t } = this;
24872
24889
  a(this, ha).updateURL(t), a(this, ee).getValue("telemetry").resetPeerId(t), vt().setHeader("tracing-id", t), $r.remapContext(t, a(this, ee)), this.self.roomState = "disconnected", this.self.emit("roomLeft", { state: "disconnected" });
24873
24890
  }), a(this, ee).getValue("peerSessionStore").on(b.SOCKET_SERVICE_FAILED, () => {
24874
- this.self.roomState = "failed", this.self.emit("roomLeft", { state: "failed" });
24891
+ this.logger.error("Socket reconnection failed after exhausting all attempts. SDK re-initialization is required."), this.self.roomState = "failed", this.self.emit("roomLeft", { state: "failed" });
24875
24892
  }), a(this, cs).on(x.waitingRoomRequestAccepted, () => {
24876
24893
  this.waitlistAcceptHandler();
24877
24894
  }), a(this, cs).on(Wc.updateUserPreset, (s) => {
@@ -24917,20 +24934,21 @@ const oS = (Tg = class {
24917
24934
  joinRoom(s = !1) {
24918
24935
  return u(this, null, function* () {
24919
24936
  try {
24937
+ this.logger.info("Joining socket room.");
24920
24938
  const { peer: t } = yield a(this, cs).joinRoom(
24921
24939
  this.self
24922
24940
  );
24923
- a(this, cs).socket.flush();
24941
+ this.logger.info("Joined socket room."), a(this, cs).socket.flush();
24924
24942
  const e = lh(t.stageType);
24925
24943
  if (a(this, ee).setValue("stageStatus", e, !1), t.waitlisted) {
24926
- this.waitlistedHandler();
24944
+ this.logger.info("Peer was waitlisted. Skipped joining media room."), this.waitlistedHandler();
24927
24945
  return;
24928
24946
  }
24929
24947
  } catch (t) {
24930
24948
  throw this.logger.error("SelfController.joinRoom: socket join failed", { error: t }), new A("Check the network and try again.", "0002");
24931
24949
  }
24932
24950
  try {
24933
- yield this.joinMediaRoom(s), a(this, ee).notify("stageStatus");
24951
+ this.logger.info("Joining media room."), yield this.joinMediaRoom(s), this.logger.info("Joined media room."), a(this, ee).notify("stageStatus");
24934
24952
  } catch (t) {
24935
24953
  throw this.logger.error("SelfController.joinRoom: media room join failed", { error: t }), t instanceof fr && t.message === "ice connection failed" ? new A(
24936
24954
  "A firewall or network restriction may be blocking the connection.",
@@ -24981,7 +24999,7 @@ const oS = (Tg = class {
24981
24999
  )) != null ? o : {};
24982
25000
  if (!h)
24983
25001
  throw g != null ? g : new Error("Could not connect to media server");
24984
- i === "ON_STAGE" && (yield this.shareMediaTracks()), this.self.roomState = "joined", this.self.emit("roomJoined", { reconnected: s });
25002
+ this.logger.info(i === "ON_STAGE" ? "Peer is on stage. Sharing media tracks" : "Peer is not on stage. Not sharing media tracks"), i === "ON_STAGE" && (yield this.shareMediaTracks()), this.logger.info(i === "ON_STAGE" ? "Peer is on stage. Shared media tracks" : "Peer is not on stage. Did not share media tracks"), this.self.roomState = "joined", this.self.emit("roomJoined", { reconnected: s });
24985
25003
  } catch (c) {
24986
25004
  throw this.logger.error("SelfController.mediaRoomJoin", { error: c }), c;
24987
25005
  }
@@ -26392,12 +26410,30 @@ const _S = (yg = class {
26392
26410
  S(this, Ee, new UD(a(this, Nr), {
26393
26411
  autoReconnect: !0,
26394
26412
  disconnectOnPingTimeout: n,
26395
- queueOnDisconnect: !0,
26413
+ queueOnDisconnect: !1,
26396
26414
  flushOnReconnect: !1,
26397
26415
  logger: this.logger,
26398
26416
  clientInitiatedPings: !n,
26399
- clientInitiatedPingInterval: 3e4
26400
- // 30 seconds
26417
+ /**
26418
+ * NOTE(ravindra-cloudflare):
26419
+ *
26420
+ * After exhausting maxReconnectionAttempts, socket will go in failed state,
26421
+ * never to connect again.
26422
+ *
26423
+ * Sockrates uses https://aws.amazon.com/blogs/architecture/exponential-backoff-and-jitter/ for exponential backoffs.
26424
+ * Full Jitter: random(0, min(cap, base * 2^attempt)), base=1s, cap=10s.
26425
+ * Default maxReconnectionAttempts - 10.
26426
+ * Avg occurs when internet is down (connection fails instantly).
26427
+ * Max occurs when internet or backend is slow (each attempt hits 5s connection timeout).
26428
+ * Attempt - Avg timing - Max timing
26429
+ * 10 ~42s ~2 min 14s
26430
+ * 20 ~1 min 32s ~4 min 44s
26431
+ * 30 ~2 min 22s ~7 min 14s
26432
+ * 50 ~4 min 2s ~12 min 14s
26433
+ */
26434
+ maxReconnectionAttempts: 50,
26435
+ clientInitiatedPingInterval: 15e3
26436
+ // 15 seconds
26401
26437
  })), this.handleSocketConnectionEvents();
26402
26438
  }
26403
26439
  get joinAttempted() {
@@ -27497,7 +27533,7 @@ let Fr = (Pg = class {
27497
27533
  video: !0
27498
27534
  };
27499
27535
  return n.setValue("options", e), n.setValue("peerId", t), n.setValue("modules", o), n.setValue("sdkName", "web-core"), n.setValue("meetingId", r), n.setValue("apiBase", i.apiBase), n.setValue("baseURI", i.baseURI), n.setValue("userId", i.participantId), n.setValue("organizationId", i.orgId), n.setValue("authToken", e.authToken), n.setValue("overrides", (d = e.overrides) != null ? d : {}), n.setValue("env", yC({ baseURI: i.baseURI })), n.setValue("defaults", c), n.setValue("onError", e.onError || (() => {
27500
- })), n.setValue("cachedUserDetails", Cs(e.cachedUserDetails)), n.setValue("sdkVersion", "1.5.2-staging.7"), (l = e.modules) != null && l.experimentalAudioPlayback && n.setValue("audioPlayback", new ZD()), n;
27536
+ })), n.setValue("cachedUserDetails", Cs(e.cachedUserDetails)), n.setValue("sdkVersion", "1.5.2-staging.9"), (l = e.modules) != null && l.experimentalAudioPlayback && n.setValue("audioPlayback", new ZD()), n;
27501
27537
  }
27502
27538
  join() {
27503
27539
  return u(this, null, function* () {
package/dist/index.es5.js CHANGED
@@ -18627,7 +18627,7 @@ var AM = Object.defineProperty, IM = Object.getOwnPropertyDescriptor, Ls = funct
18627
18627
  var e = this;
18628
18628
  this.roomSocketHandler.on(Y.getWaitingRoomRequests, this.waitingRoomRequestHandler.bind(this)), this.context.getValue("peerSessionStore").on(F.SOCKET_PEERS, function(r) {
18629
18629
  var n = e.participants.joined.size > 0;
18630
- e.participants.joined.clear(), e.participants.videoSubscribed.clear(), e.participants.audioSubscribed.clear(), e.participants.pinned.clear(), e.participants.currentPage = 0, e.participants.viewMode = "ACTIVE_GRID", n && e.participants.emit("viewModeChanged", { viewMode: "ACTIVE_GRID", currentPage: e.participants.currentPage, pageCount: e.participants.pageCount }), r == null || r.forEach(function(i) {
18630
+ e.participants.videoSubscribed.clear(), e.participants.audioSubscribed.clear(), e.participants.pinned.clear(), e.participants.joined.clear(), e.participants.currentPage = 0, e.participants.viewMode = "ACTIVE_GRID", n && e.participants.emit("viewModeChanged", { viewMode: "ACTIVE_GRID", currentPage: e.participants.currentPage, pageCount: e.participants.pageCount }), r == null || r.forEach(function(i) {
18631
18631
  i.waitlisted || e.onParticipantSocketJoined(e.createParticipantObjFromSocketPeer(i));
18632
18632
  });
18633
18633
  }), this.roomSocketHandler.on(this.events.peerJoinedBroadcast, function(r) {
@@ -24393,15 +24393,63 @@ var Ml = /* @__PURE__ */ E("context"), Gr = /* @__PURE__ */ E("logger"), b_ = /*
24393
24393
  * sending close messages would fail since the SFU doesn't know
24394
24394
  * about these producers anymore.
24395
24395
  *
24396
- * Fire-and-forget is safe: Producer.close(REASON_TRANSPORT_CLOSED)
24397
- * skips the async SDP renegotiation path (stopSending + safeEmitAsPromise)
24398
- * and only performs synchronous local cleanup.
24396
+ * Also deactivates the underlying RTCRtpTransceivers as a
24397
+ * best-effort cleanup to stop unnecessary RTP from flowing
24398
+ * to the SFU on the still-alive send transport.
24399
24399
  */
24400
24400
  }, { key: "closeAllProducersLocally", value: function() {
24401
- Array.from(c(this, gn)[gn].values()).forEach(function(r) {
24402
- return r.close(Lu);
24403
- });
24404
- } }, { key: "createConsumer", value: function(r) {
24401
+ var e = m(/* @__PURE__ */ h().mark(function n() {
24402
+ var i, a = this, o;
24403
+ return h().wrap(function(l) {
24404
+ for (; ; )
24405
+ switch (l.prev = l.next) {
24406
+ case 0:
24407
+ return o = (i = this.sendTransport) === null || i === void 0 ? void 0 : i.handler, l.next = 3, Promise.all(Array.from(c(this, gn)[gn].values()).map(/* @__PURE__ */ function() {
24408
+ var d = m(/* @__PURE__ */ h().mark(function p(v) {
24409
+ var f;
24410
+ return h().wrap(function(k) {
24411
+ for (; ; )
24412
+ switch (k.prev = k.next) {
24413
+ case 0:
24414
+ if (k.prev = 0, !o) {
24415
+ k.next = 7;
24416
+ break;
24417
+ }
24418
+ if (f = o.midTransceiverMap.get(v.localId), !f) {
24419
+ k.next = 7;
24420
+ break;
24421
+ }
24422
+ return k.next = 6, f.sender.replaceTrack(null);
24423
+ case 6:
24424
+ f.direction = "inactive";
24425
+ case 7:
24426
+ k.next = 12;
24427
+ break;
24428
+ case 9:
24429
+ k.prev = 9, k.t0 = k.catch(0), a.logger.warn("closeAllProducersLocally: failed to deactivate transceiver", { producer: { id: v.id, kind: v.kind, appData: v.appData }, error: k.t0 });
24430
+ case 12:
24431
+ return k.next = 14, v.close(Lu);
24432
+ case 14:
24433
+ case "end":
24434
+ return k.stop();
24435
+ }
24436
+ }, p, null, [[0, 9]]);
24437
+ }));
24438
+ return function(p) {
24439
+ return d.apply(this, arguments);
24440
+ };
24441
+ }()));
24442
+ case 3:
24443
+ case "end":
24444
+ return l.stop();
24445
+ }
24446
+ }, n, this);
24447
+ }));
24448
+ function r() {
24449
+ return e.apply(this, arguments);
24450
+ }
24451
+ return r;
24452
+ }() }, { key: "createConsumer", value: function(r) {
24405
24453
  return this.createConsumers([r]);
24406
24454
  } }, { key: "createConsumers", value: function() {
24407
24455
  var e = m(/* @__PURE__ */ h().mark(function n(i) {
@@ -24882,8 +24930,9 @@ var j_ = Object.defineProperty, F_ = Object.getOwnPropertyDescriptor, Ze = funct
24882
24930
  return c(this, Nt)[Nt].mediaJoined;
24883
24931
  }, set: function(e) {
24884
24932
  c(this, Nt)[Nt].mediaJoined = e;
24885
- } }, { key: "reset", value: function() {
24886
- c(this, W)[W].closeAllProducers(), c(this, W)[W].closeAllConsumers(), c(this, tr)[tr].clear(), c(this, ut)[ut].clear(), c(this, Lr)[Lr] = null, c(this, ui)[ui].stop(), c(this, W)[W].stopAllTransports(), c(this, W)[W].reset(), c(this, ui)[ui] = new vd();
24933
+ } }, { key: "reset", value: function(e) {
24934
+ var r = e.resetTransportQueue;
24935
+ this.logger.info("Resetting media node client: closing all transports, producers, consumers, and queues(resetTransportQueue: ".concat(r, ").")), c(this, W)[W].closeAllProducers(), c(this, W)[W].closeAllConsumers(), c(this, tr)[tr].clear(), c(this, ut)[ut].clear(), c(this, Lr)[Lr] = null, r && c(this, ui)[ui].stop(), c(this, W)[W].stopAllTransports(), c(this, W)[W].reset(), r && (c(this, ui)[ui] = new vd());
24887
24936
  } }, { key: "joinRoom", value: function() {
24888
24937
  var t = m(/* @__PURE__ */ h().mark(function r(n, i) {
24889
24938
  var a = this, o, u, l, d = arguments;
@@ -25764,29 +25813,44 @@ function jd() {
25764
25813
  for (; ; )
25765
25814
  switch (k.prev = k.next) {
25766
25815
  case 0:
25767
- if (c(this, ku)[ku] = t, i = !1, r && (o = (a = c(this, Nt)[Nt].mediaState) !== null && a !== void 0 ? a : {}, u = o.recv, l = o.send, d = (l == null ? void 0 : l.state) === ha.CONNECTED && (u == null ? void 0 : u.state) === ha.CONNECTED, d ? (this.logger.info("MediaNodeClient.joinRoom: transports healthy — partial reset (producers only)"), c(this, W)[W].closeAllProducersLocally(), c(this, tr)[tr].clear(), c(this, ut)[ut].clear(), c(this, Lr)[Lr] = null, i = !0) : (this.logger.info("MediaNodeClient.joinRoom: transports unhealthy — full reset"), this.reset())), k.prev = 3, !c(this, Lr)[Lr]) {
25768
- k.next = 9;
25816
+ if (c(this, ku)[ku] = t, i = !1, !r) {
25817
+ k.next = 17;
25769
25818
  break;
25770
25819
  }
25771
- return k.next = 7, c(this, Lr)[Lr];
25772
- case 7:
25773
- k.next = 11;
25774
- break;
25820
+ if (o = (a = c(this, Nt)[Nt].mediaState) !== null && a !== void 0 ? a : {}, u = o.recv, l = o.send, d = (l == null ? void 0 : l.state) === ha.CONNECTED && (u == null ? void 0 : u.state) === ha.CONNECTED, !d) {
25821
+ k.next = 15;
25822
+ break;
25823
+ }
25824
+ return this.logger.info("MediaNodeClient.joinRoom: transports healthy — partial reset (producers only)"), k.next = 9, c(this, W)[W].closeAllProducersLocally();
25775
25825
  case 9:
25776
- return k.next = 11, c(this, bu)[bu](t, e, r, n, i);
25777
- case 11:
25778
- return c(this, Nd)[Nd](e), k.next = 14, c(this, Ld)[Ld]();
25779
- case 14:
25826
+ c(this, tr)[tr].clear(), c(this, ut)[ut].clear(), c(this, Lr)[Lr] = null, i = !0, k.next = 17;
25827
+ break;
25828
+ case 15:
25829
+ this.logger.info("MediaNodeClient.joinRoom: transports unhealthy — full reset"), this.reset({ resetTransportQueue: !1 });
25830
+ case 17:
25831
+ if (k.prev = 17, !c(this, Lr)[Lr]) {
25832
+ k.next = 23;
25833
+ break;
25834
+ }
25835
+ return k.next = 21, c(this, Lr)[Lr];
25836
+ case 21:
25837
+ k.next = 25;
25838
+ break;
25839
+ case 23:
25840
+ return k.next = 25, c(this, bu)[bu](t, e, r, n, i);
25841
+ case 25:
25842
+ return c(this, Nd)[Nd](e), k.next = 28, c(this, Ld)[Ld]();
25843
+ case 28:
25780
25844
  return p = k.sent, v = p.joined, f = p.error, k.abrupt("return", { roomJoined: v, error: f });
25781
- case 20:
25782
- return k.prev = 20, k.t0 = k.catch(3), this.logger.error("Failed to complete room join", { error: k.t0 }), k.abrupt("return", { roomJoined: !1, error: k.t0 });
25783
- case 24:
25784
- return k.prev = 24, c(this, Lr)[Lr] = null, k.finish(24);
25785
- case 27:
25845
+ case 34:
25846
+ return k.prev = 34, k.t0 = k.catch(17), this.logger.error("Failed to complete room join", { error: k.t0 }), k.abrupt("return", { roomJoined: !1, error: k.t0 });
25847
+ case 38:
25848
+ return k.prev = 38, c(this, Lr)[Lr] = null, k.finish(38);
25849
+ case 41:
25786
25850
  case "end":
25787
25851
  return k.stop();
25788
25852
  }
25789
- }, s, this, [[3, 20, 24, 27]]);
25853
+ }, s, this, [[17, 34, 38, 41]]);
25790
25854
  })), jd.apply(this, arguments);
25791
25855
  }
25792
25856
  function q_() {
@@ -26119,16 +26183,16 @@ var eO = Object.defineProperty, rO = Object.getOwnPropertyDescriptor, Ns = funct
26119
26183
  switch (a.prev = a.next) {
26120
26184
  case 0:
26121
26185
  if (c(this, X)[X].getValue("callstats").callEnded(), !n) {
26122
- a.next = 6;
26186
+ a.next = 7;
26123
26187
  break;
26124
26188
  }
26125
- return a.next = 4, this.joinRoom(n);
26126
- case 4:
26127
- a.next = 7;
26189
+ return this.logger.info("Resetting Self post reconnect. Peer has earlier tried joining the meeting. State cleanup will be done during room rejoin."), a.next = 5, this.joinRoom(n);
26190
+ case 5:
26191
+ a.next = 9;
26128
26192
  break;
26129
- case 6:
26130
- c(this, yr)[yr].reset();
26131
26193
  case 7:
26194
+ this.logger.info("Resetting Self post reconnect. User never joined the room so doing full reset."), c(this, yr)[yr].reset({ resetTransportQueue: !0 });
26195
+ case 9:
26132
26196
  case "end":
26133
26197
  return a.stop();
26134
26198
  }
@@ -26162,7 +26226,7 @@ var eO = Object.defineProperty, rO = Object.getOwnPropertyDescriptor, Ns = funct
26162
26226
  }), c(this, X)[X].getValue("peerSessionStore").on(F.ROOM_NODE_DISCONNECTED, function() {
26163
26227
  e.self.roomState !== "disconnected" && (e.self.roomState = "disconnected", e.self.emit("roomLeft", { state: "disconnected" }));
26164
26228
  }), c(this, X)[X].getValue("peerSessionStore").on(F.ROOM_NODE_FAILED, function() {
26165
- e.self.roomState = "failed", e.self.emit("roomLeft", { state: "failed" });
26229
+ e.logger.error("Room node failed. SDK re-initialization is required."), e.self.roomState = "failed", e.self.emit("roomLeft", { state: "failed" });
26166
26230
  }), c(this, X)[X].getValue("peerSessionStore").on(F.SOCKET_SERVICE_RECONNECTED, function(r) {
26167
26231
  var n = r.wasJoinAttempted;
26168
26232
  n === !1 && (e.self.roomState = "init"), e.resetSelf(n);
@@ -26177,7 +26241,7 @@ var eO = Object.defineProperty, rO = Object.getOwnPropertyDescriptor, Ns = funct
26177
26241
  o.setHeader("tracing-id", i), la.remapContext(i, c(e, X)[X]), e.self.roomState = "disconnected", e.self.emit("roomLeft", { state: "disconnected" });
26178
26242
  }
26179
26243
  }), c(this, X)[X].getValue("peerSessionStore").on(F.SOCKET_SERVICE_FAILED, function() {
26180
- e.self.roomState = "failed", e.self.emit("roomLeft", { state: "failed" });
26244
+ e.logger.error("Socket reconnection failed after exhausting all attempts. SDK re-initialization is required."), e.self.roomState = "failed", e.self.emit("roomLeft", { state: "failed" });
26181
26245
  }), c(this, Jr)[Jr].on(Y.waitingRoomRequestAccepted, function() {
26182
26246
  e.waitlistAcceptHandler();
26183
26247
  }), c(this, Jr)[Jr].on(hc.updateUserPreset, function(r) {
@@ -26235,36 +26299,36 @@ var eO = Object.defineProperty, rO = Object.getOwnPropertyDescriptor, Ns = funct
26235
26299
  for (; ; )
26236
26300
  switch (d.prev = d.next) {
26237
26301
  case 0:
26238
- return n = u.length > 0 && u[0] !== void 0 ? u[0] : !1, d.prev = 1, d.next = 4, c(this, Jr)[Jr].joinRoom(this.self);
26239
- case 4:
26240
- if (i = d.sent, a = i.peer, c(this, Jr)[Jr].socket.flush(), o = kp(a.stageType), c(this, X)[X].setValue("stageStatus", o, !1), !a.waitlisted) {
26241
- d.next = 12;
26302
+ return n = u.length > 0 && u[0] !== void 0 ? u[0] : !1, d.prev = 1, this.logger.info("Joining socket room."), d.next = 5, c(this, Jr)[Jr].joinRoom(this.self);
26303
+ case 5:
26304
+ if (i = d.sent, a = i.peer, this.logger.info("Joined socket room."), c(this, Jr)[Jr].socket.flush(), o = kp(a.stageType), c(this, X)[X].setValue("stageStatus", o, !1), !a.waitlisted) {
26305
+ d.next = 15;
26242
26306
  break;
26243
26307
  }
26244
- return this.waitlistedHandler(), d.abrupt("return");
26245
- case 12:
26246
- d.next = 18;
26308
+ return this.logger.info("Peer was waitlisted. Skipped joining media room."), this.waitlistedHandler(), d.abrupt("return");
26309
+ case 15:
26310
+ d.next = 21;
26247
26311
  break;
26248
- case 14:
26249
- throw d.prev = 14, d.t0 = d.catch(1), this.logger.error("SelfController.joinRoom: socket join failed", { error: d.t0 }), new B("Check the network and try again.", "0002");
26250
- case 18:
26251
- return d.prev = 18, d.next = 21, this.joinMediaRoom(n);
26312
+ case 17:
26313
+ throw d.prev = 17, d.t0 = d.catch(1), this.logger.error("SelfController.joinRoom: socket join failed", { error: d.t0 }), new B("Check the network and try again.", "0002");
26252
26314
  case 21:
26253
- c(this, X)[X].notify("stageStatus"), d.next = 30;
26315
+ return d.prev = 21, this.logger.info("Joining media room."), d.next = 25, this.joinMediaRoom(n);
26316
+ case 25:
26317
+ this.logger.info("Joined media room."), c(this, X)[X].notify("stageStatus"), d.next = 35;
26254
26318
  break;
26255
- case 24:
26256
- if (d.prev = 24, d.t1 = d.catch(18), this.logger.error("SelfController.joinRoom: media room join failed", { error: d.t1 }), !(d.t1 instanceof pa && d.t1.message === "ice connection failed")) {
26257
- d.next = 29;
26319
+ case 29:
26320
+ if (d.prev = 29, d.t1 = d.catch(21), this.logger.error("SelfController.joinRoom: media room join failed", { error: d.t1 }), !(d.t1 instanceof pa && d.t1.message === "ice connection failed")) {
26321
+ d.next = 34;
26258
26322
  break;
26259
26323
  }
26260
26324
  throw new B("A firewall or network restriction may be blocking the connection.", "0014");
26261
- case 29:
26325
+ case 34:
26262
26326
  throw new B("Check the network and try again.", "0014");
26263
- case 30:
26327
+ case 35:
26264
26328
  case "end":
26265
26329
  return d.stop();
26266
26330
  }
26267
- }, r, this, [[1, 14], [18, 24]]);
26331
+ }, r, this, [[1, 17], [21, 29]]);
26268
26332
  }));
26269
26333
  function e() {
26270
26334
  return t.apply(this, arguments);
@@ -26338,21 +26402,21 @@ var eO = Object.defineProperty, rO = Object.getOwnPropertyDescriptor, Ns = funct
26338
26402
  }
26339
26403
  throw T != null ? T : new Error("Could not connect to media server");
26340
26404
  case 26:
26341
- if (l !== "ON_STAGE") {
26342
- M.next = 29;
26405
+ if (this.logger.info(l === "ON_STAGE" ? "Peer is on stage. Sharing media tracks" : "Peer is not on stage. Not sharing media tracks"), l !== "ON_STAGE") {
26406
+ M.next = 30;
26343
26407
  break;
26344
26408
  }
26345
- return M.next = 29, this.shareMediaTracks();
26346
- case 29:
26347
- this.self.roomState = "joined", this.self.emit("roomJoined", { reconnected: n }), M.next = 37;
26409
+ return M.next = 30, this.shareMediaTracks();
26410
+ case 30:
26411
+ this.logger.info(l === "ON_STAGE" ? "Peer is on stage. Shared media tracks" : "Peer is not on stage. Did not share media tracks"), this.self.roomState = "joined", this.self.emit("roomJoined", { reconnected: n }), M.next = 39;
26348
26412
  break;
26349
- case 33:
26350
- throw M.prev = 33, M.t3 = M.catch(2), this.logger.error("SelfController.mediaRoomJoin", { error: M.t3 }), M.t3;
26351
- case 37:
26413
+ case 35:
26414
+ throw M.prev = 35, M.t3 = M.catch(2), this.logger.error("SelfController.mediaRoomJoin", { error: M.t3 }), M.t3;
26415
+ case 39:
26352
26416
  case "end":
26353
26417
  return M.stop();
26354
26418
  }
26355
- }, r, this, [[2, 33]]);
26419
+ }, r, this, [[2, 35]]);
26356
26420
  }));
26357
26421
  function e() {
26358
26422
  return t.apply(this, arguments);
@@ -27955,12 +28019,30 @@ var RO = Object.defineProperty, AO = Object.getOwnPropertyDescriptor, rl = funct
27955
28019
  c(this, ye)[ye] = new CO(c(this, Yt)[Yt], {
27956
28020
  autoReconnect: !0,
27957
28021
  disconnectOnPingTimeout: o,
27958
- queueOnDisconnect: !0,
28022
+ queueOnDisconnect: !1,
27959
28023
  flushOnReconnect: !1,
27960
28024
  logger: this.logger,
27961
28025
  clientInitiatedPings: !o,
27962
- clientInitiatedPingInterval: 3e4
27963
- // 30 seconds
28026
+ /**
28027
+ * NOTE(ravindra-cloudflare):
28028
+ *
28029
+ * After exhausting maxReconnectionAttempts, socket will go in failed state,
28030
+ * never to connect again.
28031
+ *
28032
+ * Sockrates uses https://aws.amazon.com/blogs/architecture/exponential-backoff-and-jitter/ for exponential backoffs.
28033
+ * Full Jitter: random(0, min(cap, base * 2^attempt)), base=1s, cap=10s.
28034
+ * Default maxReconnectionAttempts - 10.
28035
+ * Avg occurs when internet is down (connection fails instantly).
28036
+ * Max occurs when internet or backend is slow (each attempt hits 5s connection timeout).
28037
+ * Attempt - Avg timing - Max timing
28038
+ * 10 ~42s ~2 min 14s
28039
+ * 20 ~1 min 32s ~4 min 44s
28040
+ * 30 ~2 min 22s ~7 min 14s
28041
+ * 50 ~4 min 2s ~12 min 14s
28042
+ */
28043
+ maxReconnectionAttempts: 50,
28044
+ clientInitiatedPingInterval: 15e3
28045
+ // 15 seconds
27964
28046
  }), this.handleSocketConnectionEvents();
27965
28047
  }
27966
28048
  return S(s, [{ key: "joinAttempted", get: function() {