@observertc/observer-js 1.0.0-beta.17 → 1.0.0-beta.18

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
@@ -4355,7 +4355,7 @@ var ObservedCall = class extends EventEmitter3 {
4355
4355
  if (this.closed || !this.observedClients.has(clientId)) return;
4356
4356
  return this.observedClients.get(clientId);
4357
4357
  }
4358
- createObservedClient(settings) {
4358
+ createObservedClient(settings, acceptCtx) {
4359
4359
  if (this.closed) {
4360
4360
  logger4.warn("Attempted to create a client (clientId: %s) on a closed call %s", settings.clientId, this.callId);
4361
4361
  return void 0;
@@ -4364,15 +4364,18 @@ var ObservedCall = class extends EventEmitter3 {
4364
4364
  logger4.warn("Client with id %s already exists in call %s; returning the existing instance", settings.clientId, this.callId);
4365
4365
  return this.observedClients.get(settings.clientId);
4366
4366
  }
4367
- if (!settings.closeClientIfIdleForMs) {
4368
- settings.closeClientIfIdleForMs = this.observer.config.closeClientIfIdleForMs;
4369
- }
4370
- if (settings.appData === void 0) {
4371
- settings.appData = this.observer.config.createClientAppData?.({ clientId: settings.clientId, observedCall: this });
4372
- }
4367
+ const clientSettings = {
4368
+ ...settings,
4369
+ closeClientIfIdleForMs: settings.closeClientIfIdleForMs || this.observer.config.closeClientIfIdleForMs,
4370
+ appData: settings.appData ?? this.observer.config.createClientAppData?.({
4371
+ clientId: settings.clientId,
4372
+ observedCall: this,
4373
+ acceptCtx
4374
+ })
4375
+ };
4373
4376
  const observedClientIssueRegistry = new ObservedClientIssueRegistry(this.activeIssuesRegistry);
4374
4377
  const result = new ObservedClient(
4375
- settings,
4378
+ clientSettings,
4376
4379
  this,
4377
4380
  observedClientIssueRegistry
4378
4381
  );
@@ -4419,8 +4422,8 @@ var ObservedCall = class extends EventEmitter3 {
4419
4422
  }
4420
4423
  return result;
4421
4424
  }
4422
- getOrCreateObservedClient(settings) {
4423
- return this.getObservedClient(settings.clientId) ?? this.createObservedClient(settings);
4425
+ getOrCreateObservedClient(settings, acceptCtx) {
4426
+ return this.getObservedClient(settings.clientId) ?? this.createObservedClient(settings, acceptCtx);
4424
4427
  }
4425
4428
  update(context) {
4426
4429
  if (this.closed) return;
@@ -6668,7 +6671,12 @@ var Observer = class extends EventEmitter6 {
6668
6671
  if (this.closed || !this.observedCalls.has(callId)) return;
6669
6672
  return this.observedCalls.get(callId);
6670
6673
  }
6671
- createObservedCall(settings) {
6674
+ /**
6675
+ * @param acceptCtx the `accept()` context, when this call is being created to receive a sample.
6676
+ * Passed on to `ObserverConfig.createCallAppData`, so the factory can read whatever the caller (or
6677
+ * an accept middleware) put there — a tenant, a region, a trace id.
6678
+ */
6679
+ createObservedCall(settings, acceptCtx) {
6672
6680
  if (this.closed) {
6673
6681
  logger9.warn("Attempted to create a call (callId: %s) on a closed observer", settings.callId);
6674
6682
  return void 0;
@@ -6680,7 +6688,7 @@ var Observer = class extends EventEmitter6 {
6680
6688
  const callSettings = {
6681
6689
  ...settings,
6682
6690
  closeCallIfEmptyForMs: settings.closeCallIfEmptyForMs ?? this.config.closeCallIfEmptyForMs,
6683
- appData: settings.appData ?? this.config.createCallAppData?.({ callId: settings.callId, observer: this })
6691
+ appData: settings.appData ?? this.config.createCallAppData?.({ callId: settings.callId, observer: this, acceptCtx })
6684
6692
  };
6685
6693
  const callActiveIssuesRegistry = new ActiveIssuesRegistry(this.activeIssuesRegistry);
6686
6694
  const observedCall = new ObservedCall(
@@ -6707,8 +6715,8 @@ var Observer = class extends EventEmitter6 {
6707
6715
  this._notify("call-added", { ...this.eventScope, observedCall });
6708
6716
  return observedCall;
6709
6717
  }
6710
- getOrCreateObservedCall(settings) {
6711
- return this.getObservedCall(settings.callId) ?? this.createObservedCall(settings);
6718
+ getOrCreateObservedCall(settings, acceptCtx) {
6719
+ return this.getObservedCall(settings.callId) ?? this.createObservedCall(settings, acceptCtx);
6712
6720
  }
6713
6721
  createObservedMediasoupRouter(settings) {
6714
6722
  if (this.closed) {
@@ -6775,21 +6783,9 @@ var Observer = class extends EventEmitter6 {
6775
6783
  this._notify("sample-rejected", { ...this.eventScope, reason: "missing-clientId", sample });
6776
6784
  return;
6777
6785
  }
6778
- let call = this.getObservedCall(sample.callId);
6779
- if (!call) {
6780
- call = this.createObservedCall({
6781
- callId: sample.callId,
6782
- appData: this.config.createCallAppData?.({ callId: sample.callId, observer: this })
6783
- });
6784
- }
6786
+ const call = this.getOrCreateObservedCall({ callId: sample.callId }, context);
6785
6787
  if (!call) return;
6786
- let client = call.getObservedClient(sample.clientId);
6787
- if (!client) {
6788
- client = call.createObservedClient({
6789
- clientId: sample.clientId,
6790
- appData: this.config.createClientAppData?.({ clientId: sample.clientId, observedCall: call })
6791
- });
6792
- }
6788
+ const client = call.getOrCreateObservedClient({ clientId: sample.clientId }, context);
6793
6789
  if (!client) return;
6794
6790
  client.accept(sample, context);
6795
6791
  }