@observertc/observer-js 1.0.0-beta.10 → 1.0.0-beta.12

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
@@ -2250,7 +2250,8 @@ var ObservedClient = class extends import_events2.EventEmitter {
2250
2250
  // public totalNumberOfIssues = 0;
2251
2251
  mediaDevices = [];
2252
2252
  issues = [];
2253
- _injections = {};
2253
+ _pendingInjections = {};
2254
+ _activeSample;
2254
2255
  closeTimer;
2255
2256
  get numberOfPeerConnections() {
2256
2257
  return this.observedPeerConnections.size;
@@ -2260,11 +2261,8 @@ var ObservedClient = class extends import_events2.EventEmitter {
2260
2261
  }
2261
2262
  close() {
2262
2263
  if (this.closed) return;
2264
+ this._flushPendingInjections();
2263
2265
  this.closed = true;
2264
- this._injections.clientEvents?.forEach((clientEvent) => this._processClientEvent(clientEvent));
2265
- this._injections.clientIssues?.forEach((clientIssue) => this.addIssue(clientIssue));
2266
- this._injections.extensionStats?.forEach((extensionStat) => this.addExtensionStats(extensionStat));
2267
- this._injections.clientMetaItems?.forEach((clientMetaItem) => this.addMetadata(clientMetaItem));
2268
2266
  Array.from(this.observedPeerConnections.values()).forEach((peerConnection) => peerConnection.close());
2269
2267
  if (!this.leftAt) {
2270
2268
  this.leftAt = this.lastSampleTimestamp;
@@ -2287,7 +2285,6 @@ var ObservedClient = class extends import_events2.EventEmitter {
2287
2285
  logger2.warn("Attempted to accept a sample on a closed client %s", this.clientId);
2288
2286
  return;
2289
2287
  }
2290
- this.sink?.write(sample);
2291
2288
  if (this.closeTimer) {
2292
2289
  clearTimeout(this.closeTimer);
2293
2290
  this.closeTimer = void 0;
@@ -2327,7 +2324,8 @@ var ObservedClient = class extends import_events2.EventEmitter {
2327
2324
  this.usingTCP = false;
2328
2325
  this.currentMinRttInMs = void 0;
2329
2326
  this.currentMaxRttInMs = void 0;
2330
- this._mergeInjections(sample);
2327
+ this._mergePendingInjections(sample);
2328
+ this._activeSample = sample;
2331
2329
  const clientEventsPostBuffer = [];
2332
2330
  for (const clientEvent of sample.clientEvents ?? []) {
2333
2331
  this._processClientEvent(clientEvent, clientEventsPostBuffer);
@@ -2415,31 +2413,68 @@ var ObservedClient = class extends import_events2.EventEmitter {
2415
2413
  this.close();
2416
2414
  }, this.settings.closeClientIfIdleForMs);
2417
2415
  }
2416
+ this._activeSample = void 0;
2417
+ try {
2418
+ this.sink?.write(sample);
2419
+ } catch (err) {
2420
+ logger2.warn("ClientSampleSink.write failed for client %s: %o", this.clientId, err);
2421
+ }
2418
2422
  }
2419
2423
  injectMetaData(metaData) {
2420
2424
  if (this.closed) return;
2421
- if (!this._injections.clientMetaItems) this._injections.clientMetaItems = [];
2422
- this._injections.clientMetaItems.push(metaData);
2425
+ if (this._activeSample) {
2426
+ if (!this._activeSample.clientMetaItems) this._activeSample.clientMetaItems = [];
2427
+ this._activeSample.clientMetaItems.push(metaData);
2428
+ this.addMetadata(metaData);
2429
+ return;
2430
+ }
2431
+ if (!this._pendingInjections.clientMetaItems) this._pendingInjections.clientMetaItems = [];
2432
+ this._pendingInjections.clientMetaItems.push(metaData);
2423
2433
  }
2424
2434
  injectEvent(event) {
2425
2435
  if (this.closed) return;
2426
- if (!this._injections.clientEvents) this._injections.clientEvents = [];
2427
- this._injections.clientEvents.push(event);
2436
+ if (this._activeSample) {
2437
+ if (!this._activeSample.clientEvents) this._activeSample.clientEvents = [];
2438
+ this._activeSample.clientEvents.push(event);
2439
+ this._processClientEvent(event);
2440
+ return;
2441
+ }
2442
+ if (!this._pendingInjections.clientEvents) this._pendingInjections.clientEvents = [];
2443
+ this._pendingInjections.clientEvents.push(event);
2428
2444
  }
2429
2445
  injectIssue(issue) {
2430
2446
  if (this.closed) return;
2431
- if (!this._injections.clientIssues) this._injections.clientIssues = [];
2432
- this._injections.clientIssues.push(issue);
2447
+ if (this._activeSample) {
2448
+ if (!this._activeSample.clientIssues) this._activeSample.clientIssues = [];
2449
+ this._activeSample.clientIssues.push(issue);
2450
+ this.addIssue(issue);
2451
+ ++this.deltaNumberOfIssues;
2452
+ return;
2453
+ }
2454
+ if (!this._pendingInjections.clientIssues) this._pendingInjections.clientIssues = [];
2455
+ this._pendingInjections.clientIssues.push(issue);
2433
2456
  }
2434
2457
  injectExtensionStat(stat) {
2435
2458
  if (this.closed) return;
2436
- if (!this._injections.extensionStats) this._injections.extensionStats = [];
2437
- this._injections.extensionStats.push(stat);
2459
+ if (this._activeSample) {
2460
+ if (!this._activeSample.extensionStats) this._activeSample.extensionStats = [];
2461
+ this._activeSample.extensionStats.push(stat);
2462
+ this.addExtensionStats(stat);
2463
+ return;
2464
+ }
2465
+ if (!this._pendingInjections.extensionStats) this._pendingInjections.extensionStats = [];
2466
+ this._pendingInjections.extensionStats.push(stat);
2438
2467
  }
2439
- injectAttachment(key, value) {
2468
+ injectAttachment(attachments) {
2440
2469
  if (this.closed) return;
2441
- if (!this._injections.attachments) this._injections.attachments = {};
2442
- this._injections.attachments[key] = value;
2470
+ if (this._activeSample) {
2471
+ if (!this._activeSample.attachments) this._activeSample.attachments = {};
2472
+ Object.assign(this._activeSample.attachments, attachments);
2473
+ this.attachments = this._activeSample.attachments;
2474
+ return;
2475
+ }
2476
+ if (!this._pendingInjections.attachments) this._pendingInjections.attachments = {};
2477
+ Object.assign(this._pendingInjections.attachments, attachments);
2443
2478
  }
2444
2479
  addMetadata(metadata) {
2445
2480
  if (this.closed) return;
@@ -2701,35 +2736,53 @@ var ObservedClient = class extends import_events2.EventEmitter {
2701
2736
  observedPeerConnection.accept(sample, context);
2702
2737
  return observedPeerConnection;
2703
2738
  }
2704
- _mergeInjections(sample) {
2739
+ _mergePendingInjections(sample) {
2705
2740
  if (this.closed) return sample;
2706
- if (this._injections.clientEvents) {
2741
+ if (this._pendingInjections.clientEvents) {
2707
2742
  if (!sample.clientEvents) sample.clientEvents = [];
2708
- sample.clientEvents.push(...this._injections.clientEvents);
2709
- this._injections.clientEvents = void 0;
2743
+ sample.clientEvents.push(...this._pendingInjections.clientEvents);
2744
+ this._pendingInjections.clientEvents = void 0;
2710
2745
  }
2711
- if (this._injections.clientIssues) {
2746
+ if (this._pendingInjections.clientIssues) {
2712
2747
  if (!sample.clientIssues) sample.clientIssues = [];
2713
- sample.clientIssues.push(...this._injections.clientIssues);
2714
- this._injections.clientIssues = void 0;
2748
+ sample.clientIssues.push(...this._pendingInjections.clientIssues);
2749
+ this._pendingInjections.clientIssues = void 0;
2715
2750
  }
2716
- if (this._injections.extensionStats) {
2751
+ if (this._pendingInjections.extensionStats) {
2717
2752
  if (!sample.extensionStats) sample.extensionStats = [];
2718
- sample.extensionStats.push(...this._injections.extensionStats);
2719
- this._injections.extensionStats = void 0;
2753
+ sample.extensionStats.push(...this._pendingInjections.extensionStats);
2754
+ this._pendingInjections.extensionStats = void 0;
2720
2755
  }
2721
- if (this._injections.attachments) {
2756
+ if (this._pendingInjections.attachments) {
2722
2757
  if (!sample.attachments) sample.attachments = {};
2723
- Object.assign(sample.attachments, this._injections.attachments);
2724
- this._injections.attachments = void 0;
2758
+ Object.assign(sample.attachments, this._pendingInjections.attachments);
2759
+ this._pendingInjections.attachments = void 0;
2725
2760
  }
2726
- if (this._injections.clientMetaItems) {
2761
+ if (this._pendingInjections.clientMetaItems) {
2727
2762
  if (!sample.clientMetaItems) sample.clientMetaItems = [];
2728
- sample.clientMetaItems.push(...this._injections.clientMetaItems);
2729
- this._injections.clientMetaItems = void 0;
2763
+ sample.clientMetaItems.push(...this._pendingInjections.clientMetaItems);
2764
+ this._pendingInjections.clientMetaItems = void 0;
2730
2765
  }
2731
2766
  return sample;
2732
2767
  }
2768
+ _flushPendingInjections() {
2769
+ const hasPending = Boolean(
2770
+ this._pendingInjections.clientEvents || this._pendingInjections.clientIssues || this._pendingInjections.extensionStats || this._pendingInjections.clientMetaItems || this._pendingInjections.attachments
2771
+ );
2772
+ if (!hasPending) return;
2773
+ const finalSample = { timestamp: Date.now() };
2774
+ this._mergePendingInjections(finalSample);
2775
+ for (const clientEvent of finalSample.clientEvents ?? []) this._processClientEvent(clientEvent);
2776
+ for (const metaData of finalSample.clientMetaItems ?? []) this.addMetadata(metaData);
2777
+ for (const issue of finalSample.clientIssues ?? []) this.addIssue(issue);
2778
+ for (const extensionStat of finalSample.extensionStats ?? []) this.addExtensionStats(extensionStat);
2779
+ if (finalSample.attachments) this.attachments = { ...this.attachments, ...finalSample.attachments };
2780
+ try {
2781
+ this.sink?.write(finalSample);
2782
+ } catch (err) {
2783
+ logger2.warn("ClientSampleSink.write failed during injection flush for client %s: %o", this.clientId, err);
2784
+ }
2785
+ }
2733
2786
  /** Emit an Observer-bus event scoped to this client (or a peer connection under it). */
2734
2787
  _notify(type, ...args) {
2735
2788
  this.call.observer.emit(type, ...args);
@@ -3305,12 +3358,9 @@ var import_events5 = require("events");
3305
3358
  var logger6 = createLogger("ObservedMediasoupRouter");
3306
3359
  var ObservedMediasoupRouter = class extends import_events5.EventEmitter {
3307
3360
  router;
3308
- sample;
3309
3361
  appData;
3362
+ sample;
3310
3363
  webrtcTransportIds = /* @__PURE__ */ new Set();
3311
- get attachments() {
3312
- return this.sample.attachments;
3313
- }
3314
3364
  closed = false;
3315
3365
  constructor(settings) {
3316
3366
  super();
@@ -3331,6 +3381,15 @@ var ObservedMediasoupRouter = class extends import_events5.EventEmitter {
3331
3381
  get id() {
3332
3382
  return this.router.id;
3333
3383
  }
3384
+ get attachments() {
3385
+ return this.sample.attachments;
3386
+ }
3387
+ close() {
3388
+ if (this.closed) return;
3389
+ this.closed = true;
3390
+ if (this.sample.closedAt === void 0) this.sample.closedAt = Date.now();
3391
+ this.emit("close");
3392
+ }
3334
3393
  addTransport = (transport) => {
3335
3394
  let transportType = transport.type;
3336
3395
  if (!transportType) {
@@ -3363,35 +3422,17 @@ var ObservedMediasoupRouter = class extends import_events5.EventEmitter {
3363
3422
  history
3364
3423
  };
3365
3424
  this.sample.transports.push(transportSample);
3366
- const onIceStateChange = (iceState) => {
3367
- history.push({
3368
- type: `icestate-changed-to-${iceState}`,
3369
- timestamp: Date.now()
3370
- });
3371
- };
3425
+ this.webrtcTransportIds.add(transport.id);
3426
+ const onIceStateChange = (iceState) => history.push({ type: `icestate-changed-to-${iceState}`, timestamp: Date.now() });
3372
3427
  const onIceSelectedTupleChange = (tuple) => {
3373
3428
  transportSample.tuple = tuple;
3374
- history.push({
3375
- type: "iceselectedtuple-changed",
3376
- timestamp: Date.now(),
3377
- ...tuple
3378
- });
3429
+ history.push({ type: "iceselectedtuple-changed", timestamp: Date.now(), ...tuple });
3379
3430
  };
3380
3431
  const onDtlsStateChange = (dtlsState) => {
3381
- history.push({
3382
- type: `dtlsstate-changed-to-${dtlsState}`,
3383
- timestamp: Date.now()
3384
- });
3385
- if (dtlsState === "connected" && transportSample.connectedAt === void 0) {
3386
- transportSample.connectedAt = Date.now();
3387
- }
3388
- };
3389
- const onSctpStateChange = (sctpState) => {
3390
- history.push({
3391
- type: `sctpstate-changed-to-${sctpState}`,
3392
- timestamp: Date.now()
3393
- });
3432
+ history.push({ type: `dtlsstate-changed-to-${dtlsState}`, timestamp: Date.now() });
3433
+ if (dtlsState === "connected" && transportSample.connectedAt === void 0) transportSample.connectedAt = Date.now();
3394
3434
  };
3435
+ const onSctpStateChange = (sctpState) => history.push({ type: `sctpstate-changed-to-${sctpState}`, timestamp: Date.now() });
3395
3436
  this._attachTransportObserverListeners(transport, transportSample, () => {
3396
3437
  transport.observer.off("icestatechange", onIceStateChange);
3397
3438
  transport.observer.off("iceselectedtuplechange", onIceSelectedTupleChange);
@@ -3403,7 +3444,6 @@ var ObservedMediasoupRouter = class extends import_events5.EventEmitter {
3403
3444
  transport.observer.on("iceselectedtuplechange", onIceSelectedTupleChange);
3404
3445
  transport.observer.on("dtlsstatechange", onDtlsStateChange);
3405
3446
  transport.observer.on("sctpstatechange", onSctpStateChange);
3406
- this.webrtcTransportIds.add(transport.id);
3407
3447
  }
3408
3448
  addPlainTransport(transport) {
3409
3449
  const history = [];
@@ -3426,13 +3466,8 @@ var ObservedMediasoupRouter = class extends import_events5.EventEmitter {
3426
3466
  history.push({ type: "rtcptuple-changed", timestamp: Date.now(), ...rtcpTuple });
3427
3467
  };
3428
3468
  const onSctpStateChange = (sctpState) => {
3429
- if (sctpState === "connected" && transportSample.connectedAt === void 0) {
3430
- transportSample.connectedAt = Date.now();
3431
- }
3432
- history.push({
3433
- type: `sctpstate-changed-to-${sctpState}`,
3434
- timestamp: Date.now()
3435
- });
3469
+ if (sctpState === "connected" && transportSample.connectedAt === void 0) transportSample.connectedAt = Date.now();
3470
+ history.push({ type: `sctpstate-changed-to-${sctpState}`, timestamp: Date.now() });
3436
3471
  };
3437
3472
  this._attachTransportObserverListeners(transport, transportSample, () => {
3438
3473
  transport.observer.off("tuple", onTuple);
@@ -3454,13 +3489,8 @@ var ObservedMediasoupRouter = class extends import_events5.EventEmitter {
3454
3489
  };
3455
3490
  this.sample.transports.push(transportSample);
3456
3491
  const onSctpStateChange = (sctpState) => {
3457
- if (sctpState === "connected" && transportSample.connectedAt === void 0) {
3458
- transportSample.connectedAt = Date.now();
3459
- }
3460
- history.push({
3461
- type: `sctpstate-changed-to-${sctpState}`,
3462
- timestamp: Date.now()
3463
- });
3492
+ if (sctpState === "connected" && transportSample.connectedAt === void 0) transportSample.connectedAt = Date.now();
3493
+ history.push({ type: `sctpstate-changed-to-${sctpState}`, timestamp: Date.now() });
3464
3494
  };
3465
3495
  this._attachTransportObserverListeners(transport, transportSample, () => {
3466
3496
  transport.observer.off("sctpstatechange", onSctpStateChange);
@@ -3473,7 +3503,6 @@ var ObservedMediasoupRouter = class extends import_events5.EventEmitter {
3473
3503
  id: transport.id,
3474
3504
  type: "direct",
3475
3505
  createdAt: now,
3476
- // A DirectTransport has no network layer — it is connected the instant it exists.
3477
3506
  connectedAt: now,
3478
3507
  history: []
3479
3508
  };
@@ -3482,37 +3511,26 @@ var ObservedMediasoupRouter = class extends import_events5.EventEmitter {
3482
3511
  }
3483
3512
  addProducer(transport, producer) {
3484
3513
  const firstCodec = producer.rtpParameters.codecs[0];
3485
- const codecInfo = {
3486
- mimeType: firstCodec?.mimeType ?? "unknown/unknown",
3487
- payloadType: firstCodec?.payloadType ?? 0,
3488
- clockRate: firstCodec?.clockRate ?? 0,
3489
- channels: firstCodec?.channels,
3490
- parameters: firstCodec?.parameters,
3491
- rtcpFeedback: firstCodec?.rtcpFeedback
3492
- };
3493
3514
  const producerSample = {
3494
3515
  id: producer.id,
3516
+ transportId: transport.id,
3495
3517
  createdAt: Date.now(),
3496
3518
  kind: producer.kind,
3497
- codecInfo,
3498
- ssrcs: producer.rtpParameters.encodings?.map((encoding) => encoding.ssrc).filter((ssrc) => typeof ssrc === "number"),
3499
- rids: producer.rtpParameters.encodings?.map((encoding) => encoding.rid).filter((rid) => typeof rid === "string"),
3500
- history: [],
3501
- transportId: transport.id
3519
+ codecInfo: {
3520
+ mimeType: firstCodec?.mimeType ?? "unknown/unknown",
3521
+ payloadType: firstCodec?.payloadType ?? 0,
3522
+ clockRate: firstCodec?.clockRate ?? 0,
3523
+ channels: firstCodec?.channels,
3524
+ parameters: firstCodec?.parameters,
3525
+ rtcpFeedback: firstCodec?.rtcpFeedback
3526
+ },
3527
+ ssrcs: producer.rtpParameters.encodings?.map((e) => e.ssrc).filter((s) => typeof s === "number"),
3528
+ rids: producer.rtpParameters.encodings?.map((e) => e.rid).filter((r) => typeof r === "string"),
3529
+ history: []
3502
3530
  };
3503
3531
  this.sample.producers.push(producerSample);
3504
- const onPause = () => {
3505
- producerSample.history.push({
3506
- type: "pause",
3507
- timestamp: Date.now()
3508
- });
3509
- };
3510
- const onResume = () => {
3511
- producerSample.history.push({
3512
- type: "resume",
3513
- timestamp: Date.now()
3514
- });
3515
- };
3532
+ const onPause = () => producerSample.history.push({ type: "pause", timestamp: Date.now() });
3533
+ const onResume = () => producerSample.history.push({ type: "resume", timestamp: Date.now() });
3516
3534
  producer.observer.once("close", () => {
3517
3535
  producer.observer.off("pause", onPause);
3518
3536
  producer.observer.off("resume", onResume);
@@ -3531,30 +3549,10 @@ var ObservedMediasoupRouter = class extends import_events5.EventEmitter {
3531
3549
  history: []
3532
3550
  };
3533
3551
  this.sample.consumers.push(consumerSample);
3534
- const onPause = () => {
3535
- consumerSample.history.push({
3536
- type: "pause",
3537
- timestamp: Date.now()
3538
- });
3539
- };
3540
- const onResume = () => {
3541
- consumerSample.history.push({
3542
- type: "resume",
3543
- timestamp: Date.now()
3544
- });
3545
- };
3546
- const onProducerPause = () => {
3547
- consumerSample.history.push({
3548
- type: "producerPaused",
3549
- timestamp: Date.now()
3550
- });
3551
- };
3552
- const onProducerResume = () => {
3553
- consumerSample.history.push({
3554
- type: "producerResumed",
3555
- timestamp: Date.now()
3556
- });
3557
- };
3552
+ const onPause = () => consumerSample.history.push({ type: "pause", timestamp: Date.now() });
3553
+ const onResume = () => consumerSample.history.push({ type: "resume", timestamp: Date.now() });
3554
+ const onProducerPause = () => consumerSample.history.push({ type: "producerPaused", timestamp: Date.now() });
3555
+ const onProducerResume = () => consumerSample.history.push({ type: "producerResumed", timestamp: Date.now() });
3558
3556
  consumer.observer.once("close", () => {
3559
3557
  consumer.observer.off("pause", onPause);
3560
3558
  consumer.observer.off("resume", onResume);
@@ -3576,9 +3574,7 @@ var ObservedMediasoupRouter = class extends import_events5.EventEmitter {
3576
3574
  protocol: dataProducer.protocol
3577
3575
  };
3578
3576
  this.sample.dataProducers.push(dataProducerSample);
3579
- dataProducer.observer.once("close", () => {
3580
- dataProducerSample.closedAt = Date.now();
3581
- });
3577
+ dataProducer.observer.once("close", () => dataProducerSample.closedAt = Date.now());
3582
3578
  }
3583
3579
  addDataConsumer(transport, dataConsumer) {
3584
3580
  const dataConsumerSample = {
@@ -3590,14 +3586,7 @@ var ObservedMediasoupRouter = class extends import_events5.EventEmitter {
3590
3586
  protocol: dataConsumer.protocol
3591
3587
  };
3592
3588
  this.sample.dataConsumers.push(dataConsumerSample);
3593
- dataConsumer.observer.once("close", () => {
3594
- dataConsumerSample.closedAt = Date.now();
3595
- });
3596
- }
3597
- close() {
3598
- if (this.closed) return;
3599
- this.closed = true;
3600
- this.emit("close");
3589
+ dataConsumer.observer.once("close", () => dataConsumerSample.closedAt = Date.now());
3601
3590
  }
3602
3591
  attachRouterListeners() {
3603
3592
  this.router.observer.once("close", () => {
@@ -3608,18 +3597,10 @@ var ObservedMediasoupRouter = class extends import_events5.EventEmitter {
3608
3597
  this.router.observer.on("newtransport", this.addTransport);
3609
3598
  }
3610
3599
  _attachTransportObserverListeners(transport, transportSample, onClose) {
3611
- const onNewProducer = (producer) => {
3612
- this.addProducer(transport, producer);
3613
- };
3614
- const onNewConsumer = (consumer) => {
3615
- this.addConsumer(transport, consumer);
3616
- };
3617
- const onNewDataProducer = (dataProducer) => {
3618
- this.addDataProducer(transport, dataProducer);
3619
- };
3620
- const onNewDataConsumer = (dataConsumer) => {
3621
- this.addDataConsumer(transport, dataConsumer);
3622
- };
3600
+ const onNewProducer = (producer) => this.addProducer(transport, producer);
3601
+ const onNewConsumer = (consumer) => this.addConsumer(transport, consumer);
3602
+ const onNewDataProducer = (dataProducer) => this.addDataProducer(transport, dataProducer);
3603
+ const onNewDataConsumer = (dataConsumer) => this.addDataConsumer(transport, dataConsumer);
3623
3604
  transport.observer.once("close", () => {
3624
3605
  transport.observer.off("newproducer", onNewProducer);
3625
3606
  transport.observer.off("newconsumer", onNewConsumer);
@@ -3702,7 +3683,7 @@ var Observer = class extends import_events6.EventEmitter {
3702
3683
  appData: settings.appData ?? this.config.createCallAppData?.({ callId: settings.callId, observer: this })
3703
3684
  };
3704
3685
  const observedCall = new ObservedCall(callSettings, this);
3705
- observedCall.remoteTrackResolver = this.config.createTrackResolver?.(observedCall);
3686
+ observedCall.remoteTrackResolver = this.config.createRemoteTrackResolver?.(observedCall);
3706
3687
  observedCall.once("close", () => {
3707
3688
  this.observedCalls.delete(observedCall.callId);
3708
3689
  ++this.totalRemovedCall;
@@ -3729,17 +3710,19 @@ var Observer = class extends import_events6.EventEmitter {
3729
3710
  observedMediasoupRouter,
3730
3711
  observer: this
3731
3712
  };
3732
- const onPeerConnectionAdded = (observedPeerConnectionScope) => {
3733
- if (!observedMediasoupRouter.webrtcTransportIds.has(observedPeerConnectionScope.observedPeerConnection.peerConnectionId)) return;
3734
- this.emit("mediasoup-router-matched-with-peer-connection", {
3735
- ...observedMediasoupRouterScope,
3736
- ...observedPeerConnectionScope
3737
- });
3738
- };
3739
- const stopMatching = () => this.off("peer-connection-added", onPeerConnectionAdded);
3740
- this.on("peer-connection-added", onPeerConnectionAdded);
3741
- this.once("observer-closed", stopMatching);
3742
- observedMediasoupRouter.once("close", stopMatching);
3713
+ if (settings.matchPeerConnectionByWebRtcTransportId) {
3714
+ const onPeerConnectionAdded = (observedPeerConnectionScope) => {
3715
+ if (!observedMediasoupRouter.webrtcTransportIds.has(observedPeerConnectionScope.observedPeerConnection.peerConnectionId)) return;
3716
+ this.emit("mediasoup-router-matched-with-peer-connection", {
3717
+ ...observedMediasoupRouterScope,
3718
+ ...observedPeerConnectionScope
3719
+ });
3720
+ };
3721
+ const stopMatching = () => this.off("peer-connection-added", onPeerConnectionAdded);
3722
+ this.on("peer-connection-added", onPeerConnectionAdded);
3723
+ this.once("observer-closed", stopMatching);
3724
+ observedMediasoupRouter.once("close", stopMatching);
3725
+ }
3743
3726
  observedMediasoupRouter.once("close", () => {
3744
3727
  this.observedMediasoupRouters.delete(observedMediasoupRouter.id);
3745
3728
  this.emit("mediasoup-router-removed", observedMediasoupRouterScope);