@observertc/observer-js 1.0.0-beta.4 → 1.0.0-beta.5

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.mjs CHANGED
@@ -330,8 +330,7 @@ var ObservedOutboundRtp = class {
330
330
  return this._peerConnection.observedMediaSources.get(this.mediaSourceId ?? "");
331
331
  }
332
332
  getTrack() {
333
- var _a;
334
- return (_a = this.getMediaSource()) == null ? void 0 : _a.getTrack();
333
+ return this.getMediaSource()?.getTrack();
335
334
  }
336
335
  update(stats) {
337
336
  this._visited = true;
@@ -1114,16 +1113,14 @@ var ObservedInboundTrack = class {
1114
1113
  return this._mediaPlayout;
1115
1114
  }
1116
1115
  getRemoteOutboundTrack() {
1117
- var _a;
1118
- return (_a = this._peerConnection.client.call.remoteTrackResolver) == null ? void 0 : _a.resolveRemoteOutboundTrack(this);
1116
+ return this._peerConnection.client.call.remoteTrackResolver?.resolveRemoteOutboundTrack(this);
1119
1117
  }
1120
1118
  update(stats) {
1121
- var _a;
1122
1119
  this._visited = true;
1123
1120
  this.timestamp = stats.timestamp;
1124
1121
  this.calculatedScore.value = stats.score;
1125
1122
  this.attachments = stats.attachments;
1126
- const fl = (_a = this._inboundRtp) == null ? void 0 : _a.fractionLost;
1123
+ const fl = this._inboundRtp?.fractionLost;
1127
1124
  if (fl !== void 0) {
1128
1125
  if (fl < 0.01) this.report.fractionLostDistribution.lt001 += 1;
1129
1126
  else if (fl < 0.05) this.report.fractionLostDistribution.lt005 += 1;
@@ -1186,8 +1183,7 @@ var ObservedOutboundTrack = class {
1186
1183
  return this._mediaSource;
1187
1184
  }
1188
1185
  getRemoteInboundTracks() {
1189
- var _a;
1190
- return (_a = this._peerConnection.client.call.remoteTrackResolver) == null ? void 0 : _a.resolveRemoteInboundTracks(this);
1186
+ return this._peerConnection.client.call.remoteTrackResolver?.resolveRemoteInboundTracks(this);
1191
1187
  }
1192
1188
  update(stats) {
1193
1189
  this._visited = true;
@@ -1364,10 +1360,7 @@ var ObservedPeerConnection = class extends EventEmitter {
1364
1360
  }
1365
1361
  get selectedIceCandiadtePairForTurn() {
1366
1362
  return this.selectedIceCandidatePairs.filter(
1367
- (pair) => {
1368
- var _a, _b, _c;
1369
- return ((_a = pair.getLocalCandidate()) == null ? void 0 : _a.candidateType) === "relay" && ((_c = (_b = pair.getRemoteCandidate()) == null ? void 0 : _b.url) == null ? void 0 : _c.startsWith("turn:"));
1370
- }
1363
+ (pair) => pair.getLocalCandidate()?.candidateType === "relay" && pair.getRemoteCandidate()?.url?.startsWith("turn:")
1371
1364
  );
1372
1365
  }
1373
1366
  close() {
@@ -1415,7 +1408,6 @@ var ObservedPeerConnection = class extends EventEmitter {
1415
1408
  this._notify("peer-connection-closed", { ...this.eventScope });
1416
1409
  }
1417
1410
  accept(sample, context) {
1418
- var _a, _b, _c, _d, _e;
1419
1411
  if (this.closed) return;
1420
1412
  this._visited = true;
1421
1413
  if (context) this.appData = { ...this.appData, ...context };
@@ -1641,10 +1633,10 @@ var ObservedPeerConnection = class extends EventEmitter {
1641
1633
  this.usingTCP = false;
1642
1634
  this.usingTURN = false;
1643
1635
  for (const selectedCandidatePair of selectedIceCandidatePairs) {
1644
- if (((_a = selectedCandidatePair.getLocalCandidate()) == null ? void 0 : _a.protocol) === "tcp") {
1636
+ if (selectedCandidatePair.getLocalCandidate()?.protocol === "tcp") {
1645
1637
  this.usingTCP = true;
1646
1638
  }
1647
- if (((_b = selectedCandidatePair.getLocalCandidate()) == null ? void 0 : _b.candidateType) === "relay" && ((_d = (_c = selectedCandidatePair.getRemoteCandidate()) == null ? void 0 : _c.url) == null ? void 0 : _d.startsWith("turn:"))) {
1639
+ if (selectedCandidatePair.getLocalCandidate()?.candidateType === "relay" && selectedCandidatePair.getRemoteCandidate()?.url?.startsWith("turn:")) {
1648
1640
  selectedCandidatePairForTurn.push(selectedCandidatePair);
1649
1641
  this.usingTURN = true;
1650
1642
  }
@@ -1655,7 +1647,7 @@ var ObservedPeerConnection = class extends EventEmitter {
1655
1647
  if (!this.observedTurnServer) {
1656
1648
  this.observedTurnServer = this.client.call.observer.observedTURN.addPeerConnection(this);
1657
1649
  }
1658
- (_e = this.observedTurnServer) == null ? void 0 : _e.updateTurnUsage(...selectedCandidatePairForTurn);
1650
+ this.observedTurnServer?.updateTurnUsage(...selectedCandidatePairForTurn);
1659
1651
  } else if (wasUsingTURN) {
1660
1652
  if (!this.usingTURN) {
1661
1653
  this.client.call.observer.observedTURN.removePeerConnection(this);
@@ -1995,7 +1987,7 @@ var ObservedPeerConnection = class extends EventEmitter {
1995
1987
  );
1996
1988
  }
1997
1989
  const observedMediaSource = [...this.observedMediaSources.values()].find((mediaSource) => mediaSource.trackIdentifier === stats.id);
1998
- const outboundRtps = observedMediaSource ? [...this.observedOutboundRtps.values()].filter((outboundRtp) => outboundRtp.mediaSourceId === (observedMediaSource == null ? void 0 : observedMediaSource.id)) : void 0;
1990
+ const outboundRtps = observedMediaSource ? [...this.observedOutboundRtps.values()].filter((outboundRtp) => outboundRtp.mediaSourceId === observedMediaSource?.id) : void 0;
1999
1991
  observedOutboundTrack = new ObservedOutboundTrack(
2000
1992
  stats.timestamp,
2001
1993
  stats.id,
@@ -2142,12 +2134,11 @@ var ClientMetaTypes = /* @__PURE__ */ ((ClientMetaTypes2) => {
2142
2134
  var logger2 = createLogger("ObservedClient");
2143
2135
  var ObservedClient = class extends EventEmitter2 {
2144
2136
  constructor(settings, call) {
2145
- var _a, _b;
2146
2137
  super();
2147
2138
  this.call = call;
2148
2139
  this.setMaxListeners(Infinity);
2149
2140
  this.eventScope = { observer: call.observer, observedCall: call, observedClient: this };
2150
- this.sink = (_b = (_a = call.observer.config).createClientSink) == null ? void 0 : _b.call(_a, { clientId: settings.clientId, observedCall: call });
2141
+ this.sink = call.observer.config.createClientSink?.({ clientId: settings.clientId, observedCall: call });
2151
2142
  this.clientId = settings.clientId;
2152
2143
  this.appData = settings.appData ?? {};
2153
2144
  this.settings = {
@@ -2192,10 +2183,7 @@ var ObservedClient = class extends EventEmitter2 {
2192
2183
  };
2193
2184
  if (this.sink) {
2194
2185
  const onError = (err) => logger2.warn("ClientSampleSink error for client %s: %o", this.clientId, err);
2195
- this.sink.once("close", () => {
2196
- var _a2;
2197
- return (_a2 = this.sink) == null ? void 0 : _a2.off("error", onError);
2198
- });
2186
+ this.sink.once("close", () => this.sink?.off("error", onError));
2199
2187
  this.sink.on("error", onError);
2200
2188
  }
2201
2189
  }
@@ -2275,13 +2263,12 @@ var ObservedClient = class extends EventEmitter2 {
2275
2263
  return this.calculatedScore.value;
2276
2264
  }
2277
2265
  close() {
2278
- var _a, _b, _c, _d, _e;
2279
2266
  if (this.closed) return;
2280
2267
  this.closed = true;
2281
- (_a = this._injections.clientEvents) == null ? void 0 : _a.forEach((clientEvent) => this._processClientEvent(clientEvent));
2282
- (_b = this._injections.clientIssues) == null ? void 0 : _b.forEach((clientIssue) => this.addIssue(clientIssue));
2283
- (_c = this._injections.extensionStats) == null ? void 0 : _c.forEach((extensionStat) => this.addExtensionStats(extensionStat));
2284
- (_d = this._injections.clientMetaItems) == null ? void 0 : _d.forEach((clientMetaItem) => this.addMetadata(clientMetaItem));
2268
+ this._injections.clientEvents?.forEach((clientEvent) => this._processClientEvent(clientEvent));
2269
+ this._injections.clientIssues?.forEach((clientIssue) => this.addIssue(clientIssue));
2270
+ this._injections.extensionStats?.forEach((extensionStat) => this.addExtensionStats(extensionStat));
2271
+ this._injections.clientMetaItems?.forEach((clientMetaItem) => this.addMetadata(clientMetaItem));
2285
2272
  Array.from(this.observedPeerConnections.values()).forEach((peerConnection) => peerConnection.close());
2286
2273
  if (!this.leftAt) {
2287
2274
  this.leftAt = this.lastSampleTimestamp;
@@ -2294,18 +2281,17 @@ var ObservedClient = class extends EventEmitter2 {
2294
2281
  this.emit("close");
2295
2282
  this._notify("client-closed", { ...this.eventScope });
2296
2283
  try {
2297
- (_e = this.sink) == null ? void 0 : _e.end();
2284
+ this.sink?.end();
2298
2285
  } catch (err) {
2299
2286
  logger2.warn("ClientSampleSink.end failed for client %s: %o", this.clientId, err);
2300
2287
  }
2301
2288
  }
2302
2289
  accept(sample, context) {
2303
- var _a;
2304
2290
  if (this.closed) {
2305
2291
  logger2.warn("Attempted to accept a sample on a closed client %s", this.clientId);
2306
2292
  return;
2307
2293
  }
2308
- (_a = this.sink) == null ? void 0 : _a.write(sample);
2294
+ this.sink?.write(sample);
2309
2295
  if (this.closeTimer) {
2310
2296
  clearTimeout(this.closeTimer);
2311
2297
  this.closeTimer = void 0;
@@ -2548,7 +2534,7 @@ var ObservedClient = class extends EventEmitter2 {
2548
2534
  }
2549
2535
  case "PEER_CONNECTION_OPENED" /* PEER_CONNECTION_OPENED */: {
2550
2536
  const payload = parseJsonAs(event.payload);
2551
- if ((payload == null ? void 0 : payload.peerConnectionId) && typeof payload.peerConnectionId === "string") {
2537
+ if (payload?.peerConnectionId && typeof payload.peerConnectionId === "string") {
2552
2538
  const observedPeerConnection = this.observedPeerConnections.get(payload.peerConnectionId);
2553
2539
  if (observedPeerConnection) {
2554
2540
  observedPeerConnection.openedAt = event.timestamp;
@@ -2562,7 +2548,7 @@ var ObservedClient = class extends EventEmitter2 {
2562
2548
  }
2563
2549
  case "PEER_CONNECTION_CLOSED" /* PEER_CONNECTION_CLOSED */: {
2564
2550
  const payload = parseJsonAs(event.payload);
2565
- if ((payload == null ? void 0 : payload.peerConnectionId) && typeof payload.peerConnectionId === "string") {
2551
+ if (payload?.peerConnectionId && typeof payload.peerConnectionId === "string") {
2566
2552
  const observedPeerConnection = this.observedPeerConnections.get(payload.peerConnectionId);
2567
2553
  if (observedPeerConnection) {
2568
2554
  observedPeerConnection.closedAt = event.timestamp;
@@ -2576,9 +2562,9 @@ var ObservedClient = class extends EventEmitter2 {
2576
2562
  }
2577
2563
  case "MEDIA_TRACK_ADDED" /* MEDIA_TRACK_ADDED */: {
2578
2564
  const payload = parseJsonAs(event.payload);
2579
- if ((payload == null ? void 0 : payload.peerConnectionId) && typeof payload.peerConnectionId === "string" && (payload == null ? void 0 : payload.trackId) && typeof payload.trackId === "string") {
2565
+ if (payload?.peerConnectionId && typeof payload.peerConnectionId === "string" && payload?.trackId && typeof payload.trackId === "string") {
2580
2566
  const observedPeerConnection = this.observedPeerConnections.get(payload.peerConnectionId);
2581
- const observedTrack = (observedPeerConnection == null ? void 0 : observedPeerConnection.observedInboundTracks.get(payload.trackId)) ?? (observedPeerConnection == null ? void 0 : observedPeerConnection.observedOutboundTracks.get(payload.trackId));
2567
+ const observedTrack = observedPeerConnection?.observedInboundTracks.get(payload.trackId) ?? observedPeerConnection?.observedOutboundTracks.get(payload.trackId);
2582
2568
  if (observedTrack) {
2583
2569
  observedTrack.addedAt = event.timestamp;
2584
2570
  } else if (postBuffer) {
@@ -2591,9 +2577,9 @@ var ObservedClient = class extends EventEmitter2 {
2591
2577
  }
2592
2578
  case "MEDIA_TRACK_REMOVED" /* MEDIA_TRACK_REMOVED */: {
2593
2579
  const payload = parseJsonAs(event.payload);
2594
- if ((payload == null ? void 0 : payload.peerConnectionId) && typeof payload.peerConnectionId === "string" && (payload == null ? void 0 : payload.trackId) && typeof payload.trackId === "string") {
2580
+ if (payload?.peerConnectionId && typeof payload.peerConnectionId === "string" && payload?.trackId && typeof payload.trackId === "string") {
2595
2581
  const observedPeerConnection = this.observedPeerConnections.get(payload.peerConnectionId);
2596
- const observedTrack = (observedPeerConnection == null ? void 0 : observedPeerConnection.observedInboundTracks.get(payload.trackId)) ?? (observedPeerConnection == null ? void 0 : observedPeerConnection.observedOutboundTracks.get(payload.trackId));
2582
+ const observedTrack = observedPeerConnection?.observedInboundTracks.get(payload.trackId) ?? observedPeerConnection?.observedOutboundTracks.get(payload.trackId);
2597
2583
  if (observedTrack) {
2598
2584
  observedTrack.removedAt = event.timestamp;
2599
2585
  } else if (postBuffer) {
@@ -2606,9 +2592,9 @@ var ObservedClient = class extends EventEmitter2 {
2606
2592
  }
2607
2593
  case "DATA_CHANNEL_OPEN" /* DATA_CHANNEL_OPEN */: {
2608
2594
  const payload = parseJsonAs(event.payload);
2609
- if ((payload == null ? void 0 : payload.peerConnectionId) && typeof payload.peerConnectionId === "string" && (payload == null ? void 0 : payload.dataChannelId) && typeof payload.dataChannelId === "string") {
2595
+ if (payload?.peerConnectionId && typeof payload.peerConnectionId === "string" && payload?.dataChannelId && typeof payload.dataChannelId === "string") {
2610
2596
  const observedPeerConnection = this.observedPeerConnections.get(payload.peerConnectionId);
2611
- const observedDataChannel = observedPeerConnection == null ? void 0 : observedPeerConnection.observedDataChannels.get(payload.dataChannelId);
2597
+ const observedDataChannel = observedPeerConnection?.observedDataChannels.get(payload.dataChannelId);
2612
2598
  if (observedDataChannel) {
2613
2599
  observedDataChannel.addedAt = event.timestamp;
2614
2600
  } else if (postBuffer) {
@@ -2621,9 +2607,9 @@ var ObservedClient = class extends EventEmitter2 {
2621
2607
  }
2622
2608
  case "DATA_CHANNEL_CLOSED" /* DATA_CHANNEL_CLOSED */: {
2623
2609
  const payload = parseJsonAs(event.payload);
2624
- if ((payload == null ? void 0 : payload.peerConnectionId) && typeof payload.peerConnectionId === "string" && (payload == null ? void 0 : payload.dataChannelId) && typeof payload.dataChannelId === "string") {
2610
+ if (payload?.peerConnectionId && typeof payload.peerConnectionId === "string" && payload?.dataChannelId && typeof payload.dataChannelId === "string") {
2625
2611
  const observedPeerConnection = this.observedPeerConnections.get(payload.peerConnectionId);
2626
- const observedDataChannel = observedPeerConnection == null ? void 0 : observedPeerConnection.observedDataChannels.get(payload.dataChannelId);
2612
+ const observedDataChannel = observedPeerConnection?.observedDataChannels.get(payload.dataChannelId);
2627
2613
  if (observedDataChannel) {
2628
2614
  observedDataChannel.removedAt = event.timestamp;
2629
2615
  } else if (postBuffer) {
@@ -2636,10 +2622,10 @@ var ObservedClient = class extends EventEmitter2 {
2636
2622
  }
2637
2623
  case "MEDIA_TRACK_MUTED" /* MEDIA_TRACK_MUTED */: {
2638
2624
  const payload = parseJsonAs(event.payload);
2639
- if ((payload == null ? void 0 : payload.peerConnectionId) && typeof payload.peerConnectionId === "string" && (payload == null ? void 0 : payload.trackId) && typeof payload.trackId === "string") {
2625
+ if (payload?.peerConnectionId && typeof payload.peerConnectionId === "string" && payload?.trackId && typeof payload.trackId === "string") {
2640
2626
  const observedPeerConnection = this.observedPeerConnections.get(payload.peerConnectionId);
2641
- const observedInboundTrack = observedPeerConnection == null ? void 0 : observedPeerConnection.observedInboundTracks.get(payload.trackId);
2642
- const observedOutboundTrack = observedPeerConnection == null ? void 0 : observedPeerConnection.observedOutboundTracks.get(payload.trackId);
2627
+ const observedInboundTrack = observedPeerConnection?.observedInboundTracks.get(payload.trackId);
2628
+ const observedOutboundTrack = observedPeerConnection?.observedOutboundTracks.get(payload.trackId);
2643
2629
  if (observedPeerConnection) {
2644
2630
  if (observedInboundTrack) {
2645
2631
  observedInboundTrack.muted = true;
@@ -2658,10 +2644,10 @@ var ObservedClient = class extends EventEmitter2 {
2658
2644
  }
2659
2645
  case "MEDIA_TRACK_UNMUTED" /* MEDIA_TRACK_UNMUTED */: {
2660
2646
  const payload = parseJsonAs(event.payload);
2661
- if ((payload == null ? void 0 : payload.peerConnectionId) && typeof payload.peerConnectionId === "string" && (payload == null ? void 0 : payload.trackId) && typeof payload.trackId === "string") {
2647
+ if (payload?.peerConnectionId && typeof payload.peerConnectionId === "string" && payload?.trackId && typeof payload.trackId === "string") {
2662
2648
  const observedPeerConnection = this.observedPeerConnections.get(payload.peerConnectionId);
2663
- const observedInboundTrack = observedPeerConnection == null ? void 0 : observedPeerConnection.observedInboundTracks.get(payload.trackId);
2664
- const observedOutboundTrack = observedPeerConnection == null ? void 0 : observedPeerConnection.observedOutboundTracks.get(payload.trackId);
2649
+ const observedInboundTrack = observedPeerConnection?.observedInboundTracks.get(payload.trackId);
2650
+ const observedOutboundTrack = observedPeerConnection?.observedOutboundTracks.get(payload.trackId);
2665
2651
  if (observedPeerConnection) {
2666
2652
  if (observedInboundTrack) {
2667
2653
  observedInboundTrack.muted = false;
@@ -2680,7 +2666,7 @@ var ObservedClient = class extends EventEmitter2 {
2680
2666
  }
2681
2667
  case "ICE_CONNECTION_STATE_CHANGED" /* ICE_CONNECTION_STATE_CHANGED */: {
2682
2668
  const payload = parseJsonAs(event.payload);
2683
- if ((payload == null ? void 0 : payload.peerConnectionId) && typeof payload.peerConnectionId === "string" && (payload == null ? void 0 : payload.iceConnectionState) && typeof payload.iceConnectionState === "string") {
2669
+ if (payload?.peerConnectionId && typeof payload.peerConnectionId === "string" && payload?.iceConnectionState && typeof payload.iceConnectionState === "string") {
2684
2670
  const observedPeerConnection = this.observedPeerConnections.get(payload.peerConnectionId);
2685
2671
  if (observedPeerConnection) {
2686
2672
  observedPeerConnection.iceConnectionState = payload.iceConnectionState;
@@ -2695,7 +2681,7 @@ var ObservedClient = class extends EventEmitter2 {
2695
2681
  }
2696
2682
  case "ICE_GATHERING_STATE_CHANGED" /* ICE_GATHERING_STATE_CHANGED */: {
2697
2683
  const payload = parseJsonAs(event.payload);
2698
- if ((payload == null ? void 0 : payload.peerConnectionId) && typeof payload.peerConnectionId === "string" && (payload == null ? void 0 : payload.iceGatheringState) && typeof payload.iceGatheringState === "string") {
2684
+ if (payload?.peerConnectionId && typeof payload.peerConnectionId === "string" && payload?.iceGatheringState && typeof payload.iceGatheringState === "string") {
2699
2685
  const observedPeerConnection = this.observedPeerConnections.get(payload.peerConnectionId);
2700
2686
  if (observedPeerConnection) {
2701
2687
  observedPeerConnection.iceGatheringState = payload.iceGatheringState;
@@ -2710,7 +2696,7 @@ var ObservedClient = class extends EventEmitter2 {
2710
2696
  }
2711
2697
  case "PEER_CONNECTION_STATE_CHANGED" /* PEER_CONNECTION_STATE_CHANGED */: {
2712
2698
  const payload = parseJsonAs(event.payload);
2713
- if ((payload == null ? void 0 : payload.peerConnectionId) && typeof payload.peerConnectionId === "string" && (payload == null ? void 0 : payload.peerConnectionState) && typeof payload.peerConnectionState === "string") {
2699
+ if (payload?.peerConnectionId && typeof payload.peerConnectionId === "string" && payload?.peerConnectionState && typeof payload.peerConnectionState === "string") {
2714
2700
  const observedPeerConnection = this.observedPeerConnections.get(payload.peerConnectionId);
2715
2701
  if (observedPeerConnection) {
2716
2702
  observedPeerConnection.connectionState = payload.peerConnectionState;
@@ -2755,8 +2741,8 @@ var ObservedClient = class extends EventEmitter2 {
2755
2741
  });
2756
2742
  };
2757
2743
  newObservedPeerConnection.once("close", () => {
2758
- newObservedPeerConnection == null ? void 0 : newObservedPeerConnection.off("removed-inbound-track", onInboundTrackRemoved);
2759
- newObservedPeerConnection == null ? void 0 : newObservedPeerConnection.off("removed-outbound-track", onOutboundTrackRemoved);
2744
+ newObservedPeerConnection?.off("removed-inbound-track", onInboundTrackRemoved);
2745
+ newObservedPeerConnection?.off("removed-outbound-track", onOutboundTrackRemoved);
2760
2746
  this.observedPeerConnections.delete(sample.peerConnectionId);
2761
2747
  });
2762
2748
  newObservedPeerConnection.on("removed-inbound-track", onInboundTrackRemoved);
@@ -2934,7 +2920,7 @@ var Detectors = class {
2934
2920
  try {
2935
2921
  detector.update();
2936
2922
  } catch (err) {
2937
- logger3.warn(`Error updating detector ${detector == null ? void 0 : detector.name}`, err);
2923
+ logger3.warn(`Error updating detector ${detector?.name}`, err);
2938
2924
  }
2939
2925
  }
2940
2926
  }
@@ -3027,11 +3013,10 @@ var ObservedCall = class extends EventEmitter3 {
3027
3013
  this._notify("call-issue", { ...this.eventScope, issue });
3028
3014
  }
3029
3015
  close() {
3030
- var _a;
3031
3016
  if (this.closed) return;
3032
3017
  this.update();
3033
3018
  this.closed = true;
3034
- (_a = this.updater) == null ? void 0 : _a.close();
3019
+ this.updater?.close();
3035
3020
  let minSampleTimestamps;
3036
3021
  let maxSampleTimestamps;
3037
3022
  for (const client of this.observedClients.values()) {
@@ -3050,7 +3035,6 @@ var ObservedCall = class extends EventEmitter3 {
3050
3035
  return this.observedClients.get(clientId);
3051
3036
  }
3052
3037
  createObservedClient(settings) {
3053
- var _a, _b;
3054
3038
  if (this.closed) {
3055
3039
  logger4.warn("Attempted to create a client (clientId: %s) on a closed call %s", settings.clientId, this.callId);
3056
3040
  return void 0;
@@ -3063,7 +3047,7 @@ var ObservedCall = class extends EventEmitter3 {
3063
3047
  settings.closeClientIfIdleForMs = this.observer.config.closeClientIfIdleForMs;
3064
3048
  }
3065
3049
  if (settings.appData === void 0) {
3066
- settings.appData = (_b = (_a = this.observer.config).createClientAppData) == null ? void 0 : _b.call(_a, { clientId: settings.clientId, observedCall: this });
3050
+ settings.appData = this.observer.config.createClientAppData?.({ clientId: settings.clientId, observedCall: this });
3067
3051
  }
3068
3052
  const result = new ObservedClient(settings, this);
3069
3053
  const wasEmpty = this.observedClients.size === 0;
@@ -3241,16 +3225,12 @@ var ObservedTURN = class extends EventEmitter4 {
3241
3225
  this.numberOfClients = clientIds.size;
3242
3226
  }
3243
3227
  addPeerConnection(peerConnection) {
3244
- var _a;
3245
- const turnPairs = peerConnection.selectedIceCandidatePairs.filter((pair) => {
3246
- var _a2, _b, _c;
3247
- return ((_a2 = pair.getLocalCandidate()) == null ? void 0 : _a2.candidateType) === "relay" && ((_c = (_b = pair.getRemoteCandidate()) == null ? void 0 : _b.url) == null ? void 0 : _c.startsWith("turn:"));
3248
- });
3228
+ const turnPairs = peerConnection.selectedIceCandidatePairs.filter((pair) => pair.getLocalCandidate()?.candidateType === "relay" && pair.getRemoteCandidate()?.url?.startsWith("turn:"));
3249
3229
  if (turnPairs.length !== 1) {
3250
3230
  return logger5.warn(`Expected exactly one TURN pair, but found for peerconnection ${peerConnection.peerConnectionId}`, turnPairs.length), void 0;
3251
3231
  }
3252
3232
  const candidatePair = turnPairs[0];
3253
- const rawUrl = (_a = candidatePair.getRemoteCandidate()) == null ? void 0 : _a.url;
3233
+ const rawUrl = candidatePair.getRemoteCandidate()?.url;
3254
3234
  if (!rawUrl) {
3255
3235
  return logger5.warn(`No remote candidate URL found for peerconnection ${peerConnection.peerConnectionId}`), void 0;
3256
3236
  }
@@ -3473,7 +3453,7 @@ var Observer = class extends EventEmitter5 {
3473
3453
  this.config = config;
3474
3454
  this.setMaxListeners(Infinity);
3475
3455
  this.update = this.update.bind(this);
3476
- const currentUpdatePolicy = (config == null ? void 0 : config.updatePolicy) ?? "update-when-all-call-updated";
3456
+ const currentUpdatePolicy = config?.updatePolicy ?? "update-when-all-call-updated";
3477
3457
  switch (currentUpdatePolicy) {
3478
3458
  case "update-on-any-call-updated":
3479
3459
  this.updater = new OnAnyCallObserverUpdater(this);
@@ -3482,7 +3462,7 @@ var Observer = class extends EventEmitter5 {
3482
3462
  this.updater = new OnAllCallObserverUpdater(this);
3483
3463
  break;
3484
3464
  case "update-on-interval": {
3485
- const interval = config == null ? void 0 : config.updateIntervalInMs;
3465
+ const interval = config?.updateIntervalInMs;
3486
3466
  if (!interval) {
3487
3467
  logger6.warn('updateIntervalInMs must be set when updatePolicy is "update-on-interval"; falling back to "update-when-all-call-updated"');
3488
3468
  this.updater = new OnAllCallObserverUpdater(this);
@@ -3523,7 +3503,6 @@ var Observer = class extends EventEmitter5 {
3523
3503
  return this.observedCalls.get(callId);
3524
3504
  }
3525
3505
  createObservedCall(settings) {
3526
- var _a, _b;
3527
3506
  if (this.closed) {
3528
3507
  logger6.warn("Attempted to create a call (callId: %s) on a closed observer", settings.callId);
3529
3508
  return void 0;
@@ -3537,7 +3516,7 @@ var Observer = class extends EventEmitter5 {
3537
3516
  updatePolicy: settings.updatePolicy ?? this.config.defaultCallUpdatePolicy,
3538
3517
  updateIntervalInMs: settings.updateIntervalInMs ?? this.config.defaultCallUpdateIntervalInMs,
3539
3518
  closeCallIfEmptyForMs: settings.closeCallIfEmptyForMs ?? this.config.closeCallIfEmptyForMs,
3540
- appData: settings.appData ?? ((_b = (_a = this.config).createCallAppData) == null ? void 0 : _b.call(_a, { callId: settings.callId, observer: this }))
3519
+ appData: settings.appData ?? this.config.createCallAppData?.({ callId: settings.callId, observer: this })
3541
3520
  };
3542
3521
  const observedCall = new ObservedCall(callSettings, this);
3543
3522
  if (callSettings.remoteTrackResolvePolicy === "mediasoup-sfu") {
@@ -3566,7 +3545,6 @@ var Observer = class extends EventEmitter5 {
3566
3545
  this._notify("observer-closed", { ...this.eventScope });
3567
3546
  }
3568
3547
  accept(sample, context) {
3569
- var _a, _b, _c, _d;
3570
3548
  if (this.closed) {
3571
3549
  this._notify("sample-rejected", { ...this.eventScope, reason: "observer-closed", sample });
3572
3550
  return;
@@ -3583,7 +3561,7 @@ var Observer = class extends EventEmitter5 {
3583
3561
  if (!call) {
3584
3562
  call = this.createObservedCall({
3585
3563
  callId: sample.callId,
3586
- appData: (_b = (_a = this.config).createCallAppData) == null ? void 0 : _b.call(_a, { callId: sample.callId, observer: this })
3564
+ appData: this.config.createCallAppData?.({ callId: sample.callId, observer: this })
3587
3565
  });
3588
3566
  }
3589
3567
  if (!call) return;
@@ -3591,7 +3569,7 @@ var Observer = class extends EventEmitter5 {
3591
3569
  if (!client) {
3592
3570
  client = call.createObservedClient({
3593
3571
  clientId: sample.clientId,
3594
- appData: (_d = (_c = this.config).createClientAppData) == null ? void 0 : _d.call(_c, { clientId: sample.clientId, observedCall: call })
3572
+ appData: this.config.createClientAppData?.({ clientId: sample.clientId, observedCall: call })
3595
3573
  });
3596
3574
  }
3597
3575
  if (!client) return;
@@ -3633,11 +3611,14 @@ var ClientSampleSink = class extends EventEmitter6 {
3633
3611
  import * as fs from "fs";
3634
3612
  import * as path from "path";
3635
3613
  var JsonlFileSink = class extends ClientSampleSink {
3614
+ /** The file this sink writes to. Read it (e.g. in a `close` handler) to upload/move the file. */
3615
+ path;
3636
3616
  _stream;
3637
3617
  _serializeSample;
3638
3618
  constructor(options) {
3639
3619
  super();
3640
- this._stream = fs.createWriteStream(options.path, { flags: "a" });
3620
+ this.path = options.path;
3621
+ this._stream = fs.createWriteStream(this.path, { flags: "a" });
3641
3622
  this._stream.on("close", () => this.emit("close"));
3642
3623
  this._stream.on("finish", () => this.emit("finish"));
3643
3624
  this._stream.on("drain", () => this.emit("drain"));
@@ -3657,8 +3638,7 @@ function createJsonlFileSink(options) {
3657
3638
  }
3658
3639
  function createJsonlFileSinkFactory(options) {
3659
3640
  return ({ clientId, observedCall }) => {
3660
- var _a;
3661
- const filename = ((_a = options.getFileName) == null ? void 0 : _a.call(options, { callId: observedCall.callId, clientId })) ?? `${observedCall.callId}__${clientId}.jsonl`;
3641
+ const filename = options.getFileName?.({ callId: observedCall.callId, clientId }) ?? `${observedCall.callId}__${clientId}.jsonl`;
3662
3642
  return createJsonlFileSink({
3663
3643
  path: path.join(options.directory, filename),
3664
3644
  serializeSample: options.serializeSample