@stream-io/video-client 1.44.1-beta.0 → 1.44.1

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.cjs.js CHANGED
@@ -4303,7 +4303,7 @@ const isSfuEvent = (eventName) => {
4303
4303
  class Dispatcher {
4304
4304
  constructor() {
4305
4305
  this.logger = videoLoggerSystem.getLogger('Dispatcher');
4306
- this.subscribers = {};
4306
+ this.subscribers = new Map();
4307
4307
  /**
4308
4308
  * Dispatch an event to all subscribers.
4309
4309
  *
@@ -4316,12 +4316,14 @@ class Dispatcher {
4316
4316
  return;
4317
4317
  const payload = message.eventPayload[eventKind];
4318
4318
  this.logger.debug(`Dispatching ${eventKind}, tag=${tag}`, payload);
4319
- const handlers = this.subscribers[eventKind];
4319
+ const handlers = this.subscribers.get(eventKind);
4320
4320
  if (!handlers)
4321
4321
  return;
4322
- this.emit(payload, handlers[tag]);
4322
+ const { byTag, dynamic } = handlers;
4323
+ this.emit(payload, byTag.get(tag));
4323
4324
  if (tag !== '*')
4324
- this.emit(payload, handlers['*']);
4325
+ this.emit(payload, byTag.get('*'));
4326
+ this.emitDynamic(payload, tag, dynamic);
4325
4327
  };
4326
4328
  /**
4327
4329
  * Emit an event to a list of listeners.
@@ -4331,26 +4333,54 @@ class Dispatcher {
4331
4333
  */
4332
4334
  this.emit = (payload, listeners = []) => {
4333
4335
  for (const listener of listeners) {
4334
- try {
4335
- listener(payload);
4336
- }
4337
- catch (e) {
4338
- this.logger.warn('Listener failed with error', e);
4336
+ this.emitOne(payload, listener);
4337
+ }
4338
+ };
4339
+ /**
4340
+ * Emit an event to a list of listeners.
4341
+ *
4342
+ */
4343
+ this.emitDynamic = (payload, tag, dynamic) => {
4344
+ for (const { tagSelector, listener } of dynamic) {
4345
+ const dynamicTag = tagSelector();
4346
+ if (dynamicTag === tag || (tag !== '*' && dynamicTag === '*')) {
4347
+ this.emitOne(payload, listener);
4339
4348
  }
4340
4349
  }
4341
4350
  };
4351
+ /**
4352
+ * Emit an event to a single listener.
4353
+ * @param payload the event payload to emit.
4354
+ * @param listener the listener to emit the event to.
4355
+ */
4356
+ this.emitOne = (payload, listener) => {
4357
+ try {
4358
+ listener(payload);
4359
+ }
4360
+ catch (e) {
4361
+ this.logger.warn('Listener failed with error', e);
4362
+ }
4363
+ };
4342
4364
  /**
4343
4365
  * Subscribe to an event.
4344
4366
  *
4345
4367
  * @param eventName the name of the event to subscribe to.
4346
- * @param tag for scoping events to a specific tag. Use `*` dispatch to every tag.
4368
+ * @param tag for scoping events to a specific tag. Can be a static tag
4369
+ * string or a function that resolves the tag dynamically.
4347
4370
  * @param fn the callback function to invoke when the event is emitted.
4348
4371
  * @returns a function that can be called to unsubscribe from the event.
4349
4372
  */
4350
4373
  this.on = (eventName, tag, fn) => {
4351
- var _a;
4352
- const bucket = ((_a = this.subscribers)[eventName] ?? (_a[eventName] = {}));
4353
- (bucket[tag] ?? (bucket[tag] = [])).push(fn);
4374
+ const { byTag, dynamic } = this.getHandlers(eventName);
4375
+ const listener = fn;
4376
+ if (typeof tag === 'string') {
4377
+ const listeners = byTag.get(tag) ?? [];
4378
+ listeners.push(listener);
4379
+ byTag.set(tag, listeners);
4380
+ }
4381
+ else {
4382
+ dynamic.push({ tagSelector: tag, listener });
4383
+ }
4354
4384
  return () => {
4355
4385
  this.off(eventName, tag, fn);
4356
4386
  };
@@ -4359,15 +4389,35 @@ class Dispatcher {
4359
4389
  * Unsubscribe from an event.
4360
4390
  *
4361
4391
  * @param eventName the name of the event to unsubscribe from.
4362
- * @param tag for scoping events to a specific tag. Use `*` dispatch to every tag.
4392
+ * @param tag the original static/dynamic tag selector used during subscription.
4363
4393
  * @param fn the callback function to remove from the event listeners.
4364
4394
  */
4365
4395
  this.off = (eventName, tag, fn) => {
4366
- const bucket = this.subscribers[eventName];
4367
- const listeners = bucket?.[tag];
4368
- if (!listeners)
4396
+ const bucket = this.subscribers.get(eventName);
4397
+ if (!bucket)
4369
4398
  return;
4370
- bucket[tag] = listeners.filter((f) => f !== fn);
4399
+ const { byTag, dynamic } = bucket;
4400
+ if (typeof tag === 'string') {
4401
+ const listeners = byTag.get(tag) || [];
4402
+ const idx = listeners.indexOf(fn);
4403
+ if (idx >= 0)
4404
+ listeners.splice(idx, 1);
4405
+ }
4406
+ else {
4407
+ const idx = dynamic.findIndex(({ tagSelector, listener }) => {
4408
+ return tagSelector === tag && listener === fn;
4409
+ });
4410
+ if (idx >= 0)
4411
+ dynamic.splice(idx, 1);
4412
+ }
4413
+ };
4414
+ this.getHandlers = (eventName) => {
4415
+ const existing = this.subscribers.get(eventName);
4416
+ if (existing)
4417
+ return existing;
4418
+ const next = { byTag: new Map(), dynamic: [] };
4419
+ this.subscribers.set(eventName, next);
4420
+ return next;
4371
4421
  };
4372
4422
  }
4373
4423
  }
@@ -6251,7 +6301,7 @@ const getSdkVersion = (sdk) => {
6251
6301
  return sdk ? `${sdk.major}.${sdk.minor}.${sdk.patch}` : '0.0.0-development';
6252
6302
  };
6253
6303
 
6254
- const version = "1.44.1-beta.0";
6304
+ const version = "1.44.1";
6255
6305
  const [major, minor, patch] = version.split('.');
6256
6306
  let sdkInfo = {
6257
6307
  type: SdkType.PLAIN_JAVASCRIPT,
@@ -7318,7 +7368,8 @@ class BasePeerConnection {
7318
7368
  * Consecutive events are queued and executed one after the other.
7319
7369
  */
7320
7370
  this.on = (event, fn) => {
7321
- this.subscriptions.push(this.dispatcher.on(event, this.tag, (e) => {
7371
+ const getTag = () => this.tag;
7372
+ this.subscriptions.push(this.dispatcher.on(event, getTag, (e) => {
7322
7373
  const lockKey = `pc.${this.lock}.${event}`;
7323
7374
  withoutConcurrency(lockKey, async () => fn(e)).catch((err) => {
7324
7375
  if (this.isDisposed)
@@ -7351,6 +7402,7 @@ class BasePeerConnection {
7351
7402
  */
7352
7403
  this.setSfuClient = (sfuClient) => {
7353
7404
  this.sfuClient = sfuClient;
7405
+ this.tag = sfuClient.tag;
7354
7406
  };
7355
7407
  /**
7356
7408
  * Returns the result of the `RTCPeerConnection.getStats()` method
@@ -7541,6 +7593,7 @@ class BasePeerConnection {
7541
7593
  pc.removeEventListener('icegatheringstatechange', this.onIceGatherChange);
7542
7594
  this.unsubscribeIceTrickle?.();
7543
7595
  this.subscriptions.forEach((unsubscribe) => unsubscribe());
7596
+ this.subscriptions = [];
7544
7597
  }
7545
7598
  }
7546
7599
 
@@ -12964,8 +13017,7 @@ class Call {
12964
13017
  // const calls = useCalls().filter((c) => c.ringing);
12965
13018
  const calls = this.clientStore.calls.filter((c) => c.cid !== this.cid);
12966
13019
  this.clientStore.setCalls([this, ...calls]);
12967
- const skipSpeakerApply = isReactNative() && true;
12968
- await this.applyDeviceConfig(settings, false, skipSpeakerApply);
13020
+ await this.applyDeviceConfig(settings, false);
12969
13021
  };
12970
13022
  /**
12971
13023
  * Loads the information about the call.
@@ -12988,10 +13040,7 @@ class Call {
12988
13040
  this.watching = true;
12989
13041
  this.clientStore.registerOrUpdateCall(this);
12990
13042
  }
12991
- const skipSpeakerApply = isReactNative()
12992
- ? (params?.ring ?? this.ringing)
12993
- : false;
12994
- await this.applyDeviceConfig(response.call.settings, false, skipSpeakerApply);
13043
+ await this.applyDeviceConfig(response.call.settings, false);
12995
13044
  return response;
12996
13045
  };
12997
13046
  /**
@@ -13012,10 +13061,7 @@ class Call {
13012
13061
  this.watching = true;
13013
13062
  this.clientStore.registerOrUpdateCall(this);
13014
13063
  }
13015
- const skipSpeakerApply = isReactNative()
13016
- ? (data?.ring ?? this.ringing)
13017
- : false;
13018
- await this.applyDeviceConfig(response.call.settings, false, skipSpeakerApply);
13064
+ await this.applyDeviceConfig(response.call.settings, false);
13019
13065
  return response;
13020
13066
  };
13021
13067
  /**
@@ -14528,10 +14574,8 @@ class Call {
14528
14574
  *
14529
14575
  * @internal
14530
14576
  */
14531
- this.applyDeviceConfig = async (settings, publish, skipSpeakerApply = false) => {
14532
- if (!skipSpeakerApply) {
14533
- this.speaker.apply(settings);
14534
- }
14577
+ this.applyDeviceConfig = async (settings, publish) => {
14578
+ this.speaker.apply(settings);
14535
14579
  await this.camera.apply(settings.video, publish).catch((err) => {
14536
14580
  this.logger.warn('Camera init failed', err);
14537
14581
  });
@@ -15844,7 +15888,7 @@ class StreamClient {
15844
15888
  this.getUserAgent = () => {
15845
15889
  if (!this.cachedUserAgent) {
15846
15890
  const { clientAppIdentifier = {} } = this.options;
15847
- const { sdkName = 'js', sdkVersion = "1.44.1-beta.0", ...extras } = clientAppIdentifier;
15891
+ const { sdkName = 'js', sdkVersion = "1.44.1", ...extras } = clientAppIdentifier;
15848
15892
  this.cachedUserAgent = [
15849
15893
  `stream-video-${sdkName}-v${sdkVersion}`,
15850
15894
  ...Object.entries(extras).map(([key, value]) => `${key}=${value}`),