@stream-io/video-client 0.0.1-alpha.80 → 0.0.1-alpha.82

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.
@@ -4606,6 +4606,25 @@ const registerEventHandlers = (call, store, dispatcher) => {
4606
4606
  watchDominantSpeakerChanged(dispatcher, store);
4607
4607
  };
4608
4608
 
4609
+ const sfuEventKinds = {
4610
+ subscriberOffer: undefined,
4611
+ publisherAnswer: undefined,
4612
+ connectionQualityChanged: undefined,
4613
+ audioLevelChanged: undefined,
4614
+ iceTrickle: undefined,
4615
+ changePublishQuality: undefined,
4616
+ participantJoined: undefined,
4617
+ participantLeft: undefined,
4618
+ dominantSpeakerChanged: undefined,
4619
+ joinResponse: undefined,
4620
+ healthCheckResponse: undefined,
4621
+ trackPublished: undefined,
4622
+ trackUnpublished: undefined,
4623
+ error: undefined,
4624
+ };
4625
+ const isSfuEvent = (eventName) => {
4626
+ return Object.prototype.hasOwnProperty.call(sfuEventKinds, eventName);
4627
+ };
4609
4628
  class Dispatcher {
4610
4629
  constructor() {
4611
4630
  this.subscribers = {};
@@ -5657,16 +5676,6 @@ class Call {
5657
5676
  this.dispatcher = new Dispatcher();
5658
5677
  this.trackSubscriptionsSubject = new Subject();
5659
5678
  this.joined$ = new BehaviorSubject(false);
5660
- /**
5661
- * You can subscribe to WebSocket events provided by the API. To remove a subscription, call the `off` method.
5662
- * Please note that subscribing to WebSocket events is an advanced use-case, for most use-cases it should be enough to watch for changes in the [reactive state store](./StreamVideoClient.md/#readonlystatestore).
5663
- * @param eventName
5664
- * @param fn
5665
- * @returns
5666
- */
5667
- this.on = (eventName, fn) => {
5668
- return this.dispatcher.on(eventName, fn);
5669
- };
5670
5679
  /**
5671
5680
  * Remove subscription for WebSocket events that were created by the `on` method.
5672
5681
  * @param eventName
@@ -6349,6 +6358,19 @@ class Call {
6349
6358
  (_a = this.sfuClient) === null || _a === void 0 ? void 0 : _a.updateSubscriptions(subscriptions);
6350
6359
  });
6351
6360
  }
6361
+ on(eventName, fn) {
6362
+ if (isSfuEvent(eventName)) {
6363
+ return this.dispatcher.on(eventName, fn);
6364
+ }
6365
+ else {
6366
+ const eventHandler = (event) => {
6367
+ if (event.call_cid && event.call_cid === this.cid) {
6368
+ fn(event);
6369
+ }
6370
+ };
6371
+ return this.streamClient.on(eventName, eventHandler);
6372
+ }
6373
+ }
6352
6374
  get data() {
6353
6375
  return this.state.getCurrentValue(this.state.metadata$);
6354
6376
  }
@@ -6361,6 +6383,9 @@ class Call {
6361
6383
  */
6362
6384
  const watchCallCreated = (store, streamClient) => {
6363
6385
  return function onCallCreated(event) {
6386
+ if (event.type !== 'call.created') {
6387
+ return;
6388
+ }
6364
6389
  const { call, members } = event;
6365
6390
  if (!call) {
6366
6391
  console.warn("Can't find call in CallCreatedEvent");
@@ -6391,6 +6416,9 @@ const watchCallCreated = (store, streamClient) => {
6391
6416
  */
6392
6417
  const watchCallAccepted = (store) => {
6393
6418
  return function onCallAccepted(event) {
6419
+ if (event.type !== 'call.accepted') {
6420
+ return;
6421
+ }
6394
6422
  const { call_cid } = event;
6395
6423
  if (!call_cid) {
6396
6424
  console.warn("Can't find call_cid in CallAcceptedEvent");
@@ -6429,6 +6457,9 @@ const watchCallAccepted = (store) => {
6429
6457
  */
6430
6458
  const watchCallRejected = (store) => {
6431
6459
  return function onCallRejected(event) {
6460
+ if (event.type !== 'call.rejected') {
6461
+ return;
6462
+ }
6432
6463
  const { call_cid } = event;
6433
6464
  if (!call_cid) {
6434
6465
  console.warn("Can't find call_cid in CallRejectedEvent");
@@ -6462,6 +6493,9 @@ const watchCallRejected = (store) => {
6462
6493
  */
6463
6494
  const watchCallCancelled = (store) => {
6464
6495
  return function onCallCancelled(event) {
6496
+ if (event.type !== 'call.ended') {
6497
+ return;
6498
+ }
6465
6499
  const { call_cid } = event;
6466
6500
  if (!call_cid) {
6467
6501
  console.log("Can't find call in CallEndedEvent");
@@ -6488,6 +6522,9 @@ const watchCallCancelled = (store) => {
6488
6522
  */
6489
6523
  const watchCallPermissionRequest = (store) => {
6490
6524
  return function onCallPermissionRequest(event) {
6525
+ if (event.type !== 'call.permission_request') {
6526
+ return;
6527
+ }
6491
6528
  const activeCall = store.getCurrentValue(store.activeCallSubject);
6492
6529
  if (!activeCall) {
6493
6530
  console.warn(`Ignoring "call.permission_request" as there is no active call`, event);
@@ -6512,6 +6549,9 @@ const watchCallPermissionRequest = (store) => {
6512
6549
  */
6513
6550
  const watchCallPermissionsUpdated = (store) => {
6514
6551
  return function onCallPermissionsUpdated(event) {
6552
+ if (event.type !== 'call.permissions_updated') {
6553
+ return;
6554
+ }
6515
6555
  const activeCall = store.getCurrentValue(store.activeCallSubject);
6516
6556
  if (!activeCall) {
6517
6557
  console.warn(`Ignoring "call.permissions_updated" as there is no active call`, event);
@@ -6539,6 +6579,9 @@ const watchCallPermissionsUpdated = (store) => {
6539
6579
  */
6540
6580
  const watchNewReactions = (store) => {
6541
6581
  return function onNewReactions(event) {
6582
+ if (event.type !== 'call.reaction_new') {
6583
+ return;
6584
+ }
6542
6585
  const { call_cid, reaction } = event;
6543
6586
  const activeCall = store.getCurrentValue(store.activeCallSubject);
6544
6587
  if (!activeCall || activeCall.cid !== call_cid) {
@@ -6571,6 +6614,9 @@ const watchNewReactions = (store) => {
6571
6614
  */
6572
6615
  const watchCallRecordingStarted = (store) => {
6573
6616
  return function onCallRecordingStarted(event) {
6617
+ if (event.type !== 'call.recording_started') {
6618
+ return;
6619
+ }
6574
6620
  const { call_cid } = event;
6575
6621
  const activeCall = store.getCurrentValue(store.activeCallSubject);
6576
6622
  if (!activeCall || activeCall.cid !== call_cid) {
@@ -6586,6 +6632,9 @@ const watchCallRecordingStarted = (store) => {
6586
6632
  */
6587
6633
  const watchCallRecordingStopped = (store) => {
6588
6634
  return function onCallRecordingStopped(event) {
6635
+ if (event.type !== 'call.recording_stopped') {
6636
+ return;
6637
+ }
6589
6638
  const { call_cid } = event;
6590
6639
  const activeCall = store.getCurrentValue(store.activeCallSubject);
6591
6640
  if (!activeCall || activeCall.cid !== call_cid) {
@@ -6603,6 +6652,9 @@ const watchCallRecordingStopped = (store) => {
6603
6652
  * `event.user_id` to the list
6604
6653
  */
6605
6654
  const watchBlockedUser = (store) => (event) => {
6655
+ if (event.type !== 'call.blocked_user') {
6656
+ return;
6657
+ }
6606
6658
  const activeCall = store.getCurrentValue(store.activeCallSubject);
6607
6659
  if (!activeCall || activeCall.cid !== event.call_cid) {
6608
6660
  console.warn(`Received "call.blocked_user" for an inactive or unknown call`, event);
@@ -6622,6 +6674,9 @@ const watchBlockedUser = (store) => (event) => {
6622
6674
  * removing `event.user_id` from the list
6623
6675
  */
6624
6676
  const watchUnblockedUser = (store) => (event) => {
6677
+ if (event.type !== 'call.unblocked_user') {
6678
+ return;
6679
+ }
6625
6680
  const activeCall = store.getCurrentValue(store.activeCallSubject);
6626
6681
  if (!activeCall || activeCall.cid !== event.call_cid) {
6627
6682
  console.warn(`Received "call.unblocked_user" for an inactive or unknown call`, event);
@@ -8263,15 +8318,14 @@ class StreamClient {
8263
8318
  this.resolveConnectionId = resolve;
8264
8319
  this.rejectConnectionId = reject;
8265
8320
  });
8266
- this.axiosInstance = axios.create(this.options);
8267
- // todo: replace 'https://chat.stream-io-api.com' with an actual video server URL
8268
- this.setBaseURL(this.options.baseURL || 'https://chat.stream-io-api.com');
8321
+ this.setBaseURL(this.options.baseURL || 'https://video.stream-io-api.com/video');
8269
8322
  if (typeof process !== 'undefined' && process.env.STREAM_LOCAL_TEST_RUN) {
8270
- this.setBaseURL('http://localhost:3030');
8323
+ this.setBaseURL('http://localhost:3030/video');
8271
8324
  }
8272
8325
  if (typeof process !== 'undefined' && process.env.STREAM_LOCAL_TEST_HOST) {
8273
- this.setBaseURL('http://' + process.env.STREAM_LOCAL_TEST_HOST);
8326
+ this.setBaseURL(`http://${process.env.STREAM_LOCAL_TEST_HOST}/video`);
8274
8327
  }
8328
+ this.axiosInstance = axios.create(Object.assign({ baseURL: this.baseURL }, this.options));
8275
8329
  // WS connection is initialized when setUser is called
8276
8330
  this.wsConnection = null;
8277
8331
  this.wsPromise = null;
@@ -8496,7 +8550,7 @@ class StreamClient {
8496
8550
  }
8497
8551
  getUserAgent() {
8498
8552
  return (this.userAgent ||
8499
- `stream-video-javascript-client-${this.node ? 'node' : 'browser'}-${"0.0.1-alpha.79"}`);
8553
+ `stream-video-javascript-client-${this.node ? 'node' : 'browser'}-${"0.0.1-alpha.81"}`);
8500
8554
  }
8501
8555
  setUserAgent(userAgent) {
8502
8556
  this.userAgent = userAgent;
@@ -8557,39 +8611,17 @@ class StreamVideoClient {
8557
8611
  // @ts-expect-error
8558
8612
  user, tokenOrProvider);
8559
8613
  this.callDropScheduler = new CallDropScheduler(this.writeableStateStore, this.callConfig);
8560
- this.on('call.created',
8561
- // @ts-expect-error until we sort out the types
8562
- watchCallCreated(this.writeableStateStore, this.streamClient));
8563
- this.on('call.accepted',
8564
- // @ts-expect-error until we sort out the types
8565
- watchCallAccepted(this.writeableStateStore));
8566
- this.on('call.rejected',
8567
- // @ts-expect-error until we sort out the types
8568
- watchCallRejected(this.writeableStateStore));
8569
- this.on('call.cancelled',
8570
- // @ts-expect-error until we sort out the types
8571
- watchCallCancelled(this.writeableStateStore));
8572
- this.on('call.permission_request',
8573
- // @ts-expect-error until we sort out the types
8574
- watchCallPermissionRequest(this.writeableStateStore));
8575
- this.on('call.permissions_updated',
8576
- // @ts-expect-error until we sort out the types
8577
- watchCallPermissionsUpdated(this.writeableStateStore));
8578
- this.on('call.blocked_user',
8579
- // @ts-expect-error until we sort out the types
8580
- watchBlockedUser(this.writeableStateStore));
8581
- this.on('call.unblocked_user',
8582
- // @ts-expect-error until we sort out the types
8583
- watchUnblockedUser(this.writeableStateStore));
8584
- this.on('call.recording_started',
8585
- // @ts-expect-error until we sort out the types
8586
- watchCallRecordingStarted(this.writeableStateStore));
8587
- this.on('call.recording_stopped',
8588
- // @ts-expect-error until we sort out the types
8589
- watchCallRecordingStopped(this.writeableStateStore));
8590
- this.on('call.reaction_new',
8591
- // @ts-expect-error until we sort out the types
8592
- watchNewReactions(this.writeableStateStore));
8614
+ this.on('call.created', watchCallCreated(this.writeableStateStore, this.streamClient));
8615
+ this.on('call.accepted', watchCallAccepted(this.writeableStateStore));
8616
+ this.on('call.rejected', watchCallRejected(this.writeableStateStore));
8617
+ this.on('call.ended', watchCallCancelled(this.writeableStateStore));
8618
+ this.on('call.permission_request', watchCallPermissionRequest(this.writeableStateStore));
8619
+ this.on('call.permissions_updated', watchCallPermissionsUpdated(this.writeableStateStore));
8620
+ this.on('call.blocked_user', watchBlockedUser(this.writeableStateStore));
8621
+ this.on('call.unblocked_user', watchUnblockedUser(this.writeableStateStore));
8622
+ this.on('call.recording_started', watchCallRecordingStarted(this.writeableStateStore));
8623
+ this.on('call.recording_stopped', watchCallRecordingStopped(this.writeableStateStore));
8624
+ this.on('call.reaction_new', watchNewReactions(this.writeableStateStore));
8593
8625
  this.writeableStateStore.setCurrentValue(this.writeableStateStore.connectedUserSubject, user);
8594
8626
  });
8595
8627
  /**
@@ -8677,7 +8709,7 @@ class StreamVideoClient {
8677
8709
  return this.streamClient.get(`/calltypes`);
8678
8710
  });
8679
8711
  this.callConfig = callConfig;
8680
- this.streamClient = new StreamClient(apiKey, Object.assign({ baseURL: 'https://video-edge-frankfurt-ce1.stream-io-api.com/video',
8712
+ this.streamClient = new StreamClient(apiKey, Object.assign({
8681
8713
  // FIXME: OL: fix SSR.
8682
8714
  browser: true, persistUserOnConnectionFailure: true }, opts));
8683
8715
  this.writeableStateStore = new StreamVideoWriteableStateStore();