@stream-io/video-client 0.0.7 → 0.0.9

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
@@ -5696,6 +5696,19 @@ class Publisher {
5696
5696
  return this.notifyTrackMuteStateChanged(undefined, transceiver.sender.track, trackType, true);
5697
5697
  }
5698
5698
  });
5699
+ /**
5700
+ * Returns true if the given track type is currently being published to the SFU.
5701
+ *
5702
+ * @param trackType the track type to check.
5703
+ */
5704
+ this.isPublishing = (trackType) => {
5705
+ const transceiverForTrackType = this.transceiverRegistry[trackType];
5706
+ if (transceiverForTrackType && transceiverForTrackType.sender) {
5707
+ const sender = transceiverForTrackType.sender;
5708
+ return !!sender.track && sender.track.readyState === 'live';
5709
+ }
5710
+ return false;
5711
+ };
5699
5712
  this.notifyTrackMuteStateChanged = (mediaStream, track, trackType, isMuted) => __awaiter(this, void 0, void 0, function* () {
5700
5713
  yield this.sfuClient.updateMuteState(trackType, isMuted);
5701
5714
  const audioOrVideoOrScreenShareStream = trackTypeToParticipantStreamKey(trackType);
@@ -5973,13 +5986,13 @@ const createWebSocketSignalChannel = (opts) => {
5973
5986
  const ws = new WebSocket(endpoint);
5974
5987
  ws.binaryType = 'arraybuffer'; // do we need this?
5975
5988
  ws.addEventListener('error', (e) => {
5976
- console.error('Error', e);
5989
+ console.log('Signaling WS channel error', e);
5977
5990
  });
5978
5991
  ws.addEventListener('close', (e) => {
5979
- console.warn('Signalling channel is closed', e);
5992
+ console.log('Signaling WS channel is closed', e);
5980
5993
  });
5981
5994
  ws.addEventListener('open', (e) => {
5982
- console.log('Signalling channel is open', e);
5995
+ console.log('Signaling WS channel is open', e);
5983
5996
  });
5984
5997
  if (onMessage) {
5985
5998
  ws.addEventListener('message', (e) => {
@@ -8322,6 +8335,13 @@ const getSdkInfo = () => {
8322
8335
  * An object representation of a `Call`.
8323
8336
  */
8324
8337
  class Call {
8338
+ /**
8339
+ * A promise that exposes the reconnection logic
8340
+ * The use-case is for the react-native platform where online/offline events are not available in the window
8341
+ */
8342
+ get rejoin() {
8343
+ return this.rejoinPromise;
8344
+ }
8325
8345
  /**
8326
8346
  * Constructs a new `Call` instance.
8327
8347
  *
@@ -8367,6 +8387,7 @@ class Call {
8367
8387
  if (callingState === exports.CallingState.LEFT) {
8368
8388
  throw new Error('Cannot leave call that has already been left.');
8369
8389
  }
8390
+ this.rejoinPromise = undefined;
8370
8391
  if (this.ringing) {
8371
8392
  // I'm the one who started the call, so I should cancel it.
8372
8393
  const hasOtherParticipants = this.state.remoteParticipants.length > 0;
@@ -8559,7 +8580,7 @@ class Call {
8559
8580
  yield sleep(retryInterval(this.reconnectAttempts));
8560
8581
  yield this.join(data);
8561
8582
  console.log(`Rejoin: ${this.reconnectAttempts} successful!`);
8562
- if (localParticipant) {
8583
+ if (localParticipant && !isReactNative()) {
8563
8584
  const { audioStream, videoStream, screenShareStream: screenShare, } = localParticipant;
8564
8585
  // restore previous publishing state
8565
8586
  if (audioStream)
@@ -8571,6 +8592,7 @@ class Call {
8571
8592
  }
8572
8593
  console.log(`Rejoin: state restored ${this.reconnectAttempts}`);
8573
8594
  });
8595
+ this.rejoinPromise = rejoin;
8574
8596
  // reconnect if the connection was closed unexpectedly. example:
8575
8597
  // - SFU crash or restart
8576
8598
  // - network change
@@ -8583,6 +8605,9 @@ class Call {
8583
8605
  // e.g., the user has been blocked by an admin or moderator
8584
8606
  if (e.code === KnownCodes.WS_POLICY_VIOLATION)
8585
8607
  return;
8608
+ // do nothing for react-native as its handled by SDK
8609
+ if (isReactNative())
8610
+ return;
8586
8611
  if (this.reconnectAttempts < this.maxReconnectAttempts) {
8587
8612
  rejoin().catch(() => {
8588
8613
  console.log(`Rejoin failed for ${this.reconnectAttempts} times. Giving up.`);
@@ -9283,20 +9308,22 @@ class Call {
9283
9308
  createSubscription(this.state.ownCapabilities$, (ownCapabilities) => {
9284
9309
  // update the permission context.
9285
9310
  this.permissionsContext.setPermissions(ownCapabilities);
9311
+ if (!this.publisher)
9312
+ return;
9286
9313
  // check if the user still has publishing permissions and stop publishing if not.
9287
9314
  const permissionToTrackType = {
9288
9315
  [OwnCapability.SEND_AUDIO]: TrackType.AUDIO,
9289
9316
  [OwnCapability.SEND_VIDEO]: TrackType.VIDEO,
9290
9317
  [OwnCapability.SCREENSHARE]: TrackType.SCREEN_SHARE,
9291
9318
  };
9292
- Object.entries(permissionToTrackType).forEach(([permission, type]) => {
9319
+ for (const [permission, trackType] of Object.entries(permissionToTrackType)) {
9293
9320
  const hasPermission = this.permissionsContext.hasPermission(permission);
9294
- if (!hasPermission) {
9295
- this.stopPublish(type).catch((err) => {
9296
- console.error('Error stopping publish', type, err);
9321
+ if (!hasPermission && this.publisher.isPublishing(trackType)) {
9322
+ this.stopPublish(trackType).catch((err) => {
9323
+ console.error('Error stopping publish', trackType, err);
9297
9324
  });
9298
9325
  }
9299
- });
9326
+ }
9300
9327
  }),
9301
9328
  // handles the case when the user is blocked by the call owner.
9302
9329
  createSubscription(this.state.metadata$, (metadata) => __awaiter(this, void 0, void 0, function* () {
@@ -10998,7 +11025,7 @@ class StreamClient {
10998
11025
  }
10999
11026
  getUserAgent() {
11000
11027
  return (this.userAgent ||
11001
- `stream-video-javascript-client-${this.node ? 'node' : 'browser'}-${"0.0.6"}`);
11028
+ `stream-video-javascript-client-${this.node ? 'node' : 'browser'}-${"0.0.8"}`);
11002
11029
  }
11003
11030
  setUserAgent(userAgent) {
11004
11031
  this.userAgent = userAgent;