@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.es.js CHANGED
@@ -4284,7 +4284,7 @@ const isSfuEvent = (eventName) => {
4284
4284
  class Dispatcher {
4285
4285
  constructor() {
4286
4286
  this.logger = videoLoggerSystem.getLogger('Dispatcher');
4287
- this.subscribers = {};
4287
+ this.subscribers = new Map();
4288
4288
  /**
4289
4289
  * Dispatch an event to all subscribers.
4290
4290
  *
@@ -4297,12 +4297,14 @@ class Dispatcher {
4297
4297
  return;
4298
4298
  const payload = message.eventPayload[eventKind];
4299
4299
  this.logger.debug(`Dispatching ${eventKind}, tag=${tag}`, payload);
4300
- const handlers = this.subscribers[eventKind];
4300
+ const handlers = this.subscribers.get(eventKind);
4301
4301
  if (!handlers)
4302
4302
  return;
4303
- this.emit(payload, handlers[tag]);
4303
+ const { byTag, dynamic } = handlers;
4304
+ this.emit(payload, byTag.get(tag));
4304
4305
  if (tag !== '*')
4305
- this.emit(payload, handlers['*']);
4306
+ this.emit(payload, byTag.get('*'));
4307
+ this.emitDynamic(payload, tag, dynamic);
4306
4308
  };
4307
4309
  /**
4308
4310
  * Emit an event to a list of listeners.
@@ -4312,26 +4314,54 @@ class Dispatcher {
4312
4314
  */
4313
4315
  this.emit = (payload, listeners = []) => {
4314
4316
  for (const listener of listeners) {
4315
- try {
4316
- listener(payload);
4317
- }
4318
- catch (e) {
4319
- this.logger.warn('Listener failed with error', e);
4317
+ this.emitOne(payload, listener);
4318
+ }
4319
+ };
4320
+ /**
4321
+ * Emit an event to a list of listeners.
4322
+ *
4323
+ */
4324
+ this.emitDynamic = (payload, tag, dynamic) => {
4325
+ for (const { tagSelector, listener } of dynamic) {
4326
+ const dynamicTag = tagSelector();
4327
+ if (dynamicTag === tag || (tag !== '*' && dynamicTag === '*')) {
4328
+ this.emitOne(payload, listener);
4320
4329
  }
4321
4330
  }
4322
4331
  };
4332
+ /**
4333
+ * Emit an event to a single listener.
4334
+ * @param payload the event payload to emit.
4335
+ * @param listener the listener to emit the event to.
4336
+ */
4337
+ this.emitOne = (payload, listener) => {
4338
+ try {
4339
+ listener(payload);
4340
+ }
4341
+ catch (e) {
4342
+ this.logger.warn('Listener failed with error', e);
4343
+ }
4344
+ };
4323
4345
  /**
4324
4346
  * Subscribe to an event.
4325
4347
  *
4326
4348
  * @param eventName the name of the event to subscribe to.
4327
- * @param tag for scoping events to a specific tag. Use `*` dispatch to every tag.
4349
+ * @param tag for scoping events to a specific tag. Can be a static tag
4350
+ * string or a function that resolves the tag dynamically.
4328
4351
  * @param fn the callback function to invoke when the event is emitted.
4329
4352
  * @returns a function that can be called to unsubscribe from the event.
4330
4353
  */
4331
4354
  this.on = (eventName, tag, fn) => {
4332
- var _a;
4333
- const bucket = ((_a = this.subscribers)[eventName] ?? (_a[eventName] = {}));
4334
- (bucket[tag] ?? (bucket[tag] = [])).push(fn);
4355
+ const { byTag, dynamic } = this.getHandlers(eventName);
4356
+ const listener = fn;
4357
+ if (typeof tag === 'string') {
4358
+ const listeners = byTag.get(tag) ?? [];
4359
+ listeners.push(listener);
4360
+ byTag.set(tag, listeners);
4361
+ }
4362
+ else {
4363
+ dynamic.push({ tagSelector: tag, listener });
4364
+ }
4335
4365
  return () => {
4336
4366
  this.off(eventName, tag, fn);
4337
4367
  };
@@ -4340,15 +4370,35 @@ class Dispatcher {
4340
4370
  * Unsubscribe from an event.
4341
4371
  *
4342
4372
  * @param eventName the name of the event to unsubscribe from.
4343
- * @param tag for scoping events to a specific tag. Use `*` dispatch to every tag.
4373
+ * @param tag the original static/dynamic tag selector used during subscription.
4344
4374
  * @param fn the callback function to remove from the event listeners.
4345
4375
  */
4346
4376
  this.off = (eventName, tag, fn) => {
4347
- const bucket = this.subscribers[eventName];
4348
- const listeners = bucket?.[tag];
4349
- if (!listeners)
4377
+ const bucket = this.subscribers.get(eventName);
4378
+ if (!bucket)
4350
4379
  return;
4351
- bucket[tag] = listeners.filter((f) => f !== fn);
4380
+ const { byTag, dynamic } = bucket;
4381
+ if (typeof tag === 'string') {
4382
+ const listeners = byTag.get(tag) || [];
4383
+ const idx = listeners.indexOf(fn);
4384
+ if (idx >= 0)
4385
+ listeners.splice(idx, 1);
4386
+ }
4387
+ else {
4388
+ const idx = dynamic.findIndex(({ tagSelector, listener }) => {
4389
+ return tagSelector === tag && listener === fn;
4390
+ });
4391
+ if (idx >= 0)
4392
+ dynamic.splice(idx, 1);
4393
+ }
4394
+ };
4395
+ this.getHandlers = (eventName) => {
4396
+ const existing = this.subscribers.get(eventName);
4397
+ if (existing)
4398
+ return existing;
4399
+ const next = { byTag: new Map(), dynamic: [] };
4400
+ this.subscribers.set(eventName, next);
4401
+ return next;
4352
4402
  };
4353
4403
  }
4354
4404
  }
@@ -6232,7 +6282,7 @@ const getSdkVersion = (sdk) => {
6232
6282
  return sdk ? `${sdk.major}.${sdk.minor}.${sdk.patch}` : '0.0.0-development';
6233
6283
  };
6234
6284
 
6235
- const version = "1.44.1-beta.0";
6285
+ const version = "1.44.1";
6236
6286
  const [major, minor, patch] = version.split('.');
6237
6287
  let sdkInfo = {
6238
6288
  type: SdkType.PLAIN_JAVASCRIPT,
@@ -7299,7 +7349,8 @@ class BasePeerConnection {
7299
7349
  * Consecutive events are queued and executed one after the other.
7300
7350
  */
7301
7351
  this.on = (event, fn) => {
7302
- this.subscriptions.push(this.dispatcher.on(event, this.tag, (e) => {
7352
+ const getTag = () => this.tag;
7353
+ this.subscriptions.push(this.dispatcher.on(event, getTag, (e) => {
7303
7354
  const lockKey = `pc.${this.lock}.${event}`;
7304
7355
  withoutConcurrency(lockKey, async () => fn(e)).catch((err) => {
7305
7356
  if (this.isDisposed)
@@ -7332,6 +7383,7 @@ class BasePeerConnection {
7332
7383
  */
7333
7384
  this.setSfuClient = (sfuClient) => {
7334
7385
  this.sfuClient = sfuClient;
7386
+ this.tag = sfuClient.tag;
7335
7387
  };
7336
7388
  /**
7337
7389
  * Returns the result of the `RTCPeerConnection.getStats()` method
@@ -7522,6 +7574,7 @@ class BasePeerConnection {
7522
7574
  pc.removeEventListener('icegatheringstatechange', this.onIceGatherChange);
7523
7575
  this.unsubscribeIceTrickle?.();
7524
7576
  this.subscriptions.forEach((unsubscribe) => unsubscribe());
7577
+ this.subscriptions = [];
7525
7578
  }
7526
7579
  }
7527
7580
 
@@ -12945,8 +12998,7 @@ class Call {
12945
12998
  // const calls = useCalls().filter((c) => c.ringing);
12946
12999
  const calls = this.clientStore.calls.filter((c) => c.cid !== this.cid);
12947
13000
  this.clientStore.setCalls([this, ...calls]);
12948
- const skipSpeakerApply = isReactNative() && true;
12949
- await this.applyDeviceConfig(settings, false, skipSpeakerApply);
13001
+ await this.applyDeviceConfig(settings, false);
12950
13002
  };
12951
13003
  /**
12952
13004
  * Loads the information about the call.
@@ -12969,10 +13021,7 @@ class Call {
12969
13021
  this.watching = true;
12970
13022
  this.clientStore.registerOrUpdateCall(this);
12971
13023
  }
12972
- const skipSpeakerApply = isReactNative()
12973
- ? (params?.ring ?? this.ringing)
12974
- : false;
12975
- await this.applyDeviceConfig(response.call.settings, false, skipSpeakerApply);
13024
+ await this.applyDeviceConfig(response.call.settings, false);
12976
13025
  return response;
12977
13026
  };
12978
13027
  /**
@@ -12993,10 +13042,7 @@ class Call {
12993
13042
  this.watching = true;
12994
13043
  this.clientStore.registerOrUpdateCall(this);
12995
13044
  }
12996
- const skipSpeakerApply = isReactNative()
12997
- ? (data?.ring ?? this.ringing)
12998
- : false;
12999
- await this.applyDeviceConfig(response.call.settings, false, skipSpeakerApply);
13045
+ await this.applyDeviceConfig(response.call.settings, false);
13000
13046
  return response;
13001
13047
  };
13002
13048
  /**
@@ -14509,10 +14555,8 @@ class Call {
14509
14555
  *
14510
14556
  * @internal
14511
14557
  */
14512
- this.applyDeviceConfig = async (settings, publish, skipSpeakerApply = false) => {
14513
- if (!skipSpeakerApply) {
14514
- this.speaker.apply(settings);
14515
- }
14558
+ this.applyDeviceConfig = async (settings, publish) => {
14559
+ this.speaker.apply(settings);
14516
14560
  await this.camera.apply(settings.video, publish).catch((err) => {
14517
14561
  this.logger.warn('Camera init failed', err);
14518
14562
  });
@@ -15825,7 +15869,7 @@ class StreamClient {
15825
15869
  this.getUserAgent = () => {
15826
15870
  if (!this.cachedUserAgent) {
15827
15871
  const { clientAppIdentifier = {} } = this.options;
15828
- const { sdkName = 'js', sdkVersion = "1.44.1-beta.0", ...extras } = clientAppIdentifier;
15872
+ const { sdkName = 'js', sdkVersion = "1.44.1", ...extras } = clientAppIdentifier;
15829
15873
  this.cachedUserAgent = [
15830
15874
  `stream-video-${sdkName}-v${sdkVersion}`,
15831
15875
  ...Object.entries(extras).map(([key, value]) => `${key}=${value}`),