@stream-io/video-client 0.0.6 → 0.0.8

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
@@ -5973,13 +5973,13 @@ const createWebSocketSignalChannel = (opts) => {
5973
5973
  const ws = new WebSocket(endpoint);
5974
5974
  ws.binaryType = 'arraybuffer'; // do we need this?
5975
5975
  ws.addEventListener('error', (e) => {
5976
- console.error('Error', e);
5976
+ console.log('Signaling WS channel error', e);
5977
5977
  });
5978
5978
  ws.addEventListener('close', (e) => {
5979
- console.warn('Signalling channel is closed', e);
5979
+ console.log('Signaling WS channel is closed', e);
5980
5980
  });
5981
5981
  ws.addEventListener('open', (e) => {
5982
- console.log('Signalling channel is open', e);
5982
+ console.log('Signaling WS channel is open', e);
5983
5983
  });
5984
5984
  if (onMessage) {
5985
5985
  ws.addEventListener('message', (e) => {
@@ -8322,6 +8322,13 @@ const getSdkInfo = () => {
8322
8322
  * An object representation of a `Call`.
8323
8323
  */
8324
8324
  class Call {
8325
+ /**
8326
+ * A promise that exposes the reconnection logic
8327
+ * The use-case is for the react-native platform where online/offline events are not available in the window
8328
+ */
8329
+ get rejoin() {
8330
+ return this.rejoinPromise;
8331
+ }
8325
8332
  /**
8326
8333
  * Constructs a new `Call` instance.
8327
8334
  *
@@ -8367,6 +8374,7 @@ class Call {
8367
8374
  if (callingState === exports.CallingState.LEFT) {
8368
8375
  throw new Error('Cannot leave call that has already been left.');
8369
8376
  }
8377
+ this.rejoinPromise = undefined;
8370
8378
  if (this.ringing) {
8371
8379
  // I'm the one who started the call, so I should cancel it.
8372
8380
  const hasOtherParticipants = this.state.remoteParticipants.length > 0;
@@ -8559,7 +8567,7 @@ class Call {
8559
8567
  yield sleep(retryInterval(this.reconnectAttempts));
8560
8568
  yield this.join(data);
8561
8569
  console.log(`Rejoin: ${this.reconnectAttempts} successful!`);
8562
- if (localParticipant) {
8570
+ if (localParticipant && !isReactNative()) {
8563
8571
  const { audioStream, videoStream, screenShareStream: screenShare, } = localParticipant;
8564
8572
  // restore previous publishing state
8565
8573
  if (audioStream)
@@ -8571,6 +8579,7 @@ class Call {
8571
8579
  }
8572
8580
  console.log(`Rejoin: state restored ${this.reconnectAttempts}`);
8573
8581
  });
8582
+ this.rejoinPromise = rejoin;
8574
8583
  // reconnect if the connection was closed unexpectedly. example:
8575
8584
  // - SFU crash or restart
8576
8585
  // - network change
@@ -8583,6 +8592,9 @@ class Call {
8583
8592
  // e.g., the user has been blocked by an admin or moderator
8584
8593
  if (e.code === KnownCodes.WS_POLICY_VIOLATION)
8585
8594
  return;
8595
+ // do nothing for react-native as its handled by SDK
8596
+ if (isReactNative())
8597
+ return;
8586
8598
  if (this.reconnectAttempts < this.maxReconnectAttempts) {
8587
8599
  rejoin().catch(() => {
8588
8600
  console.log(`Rejoin failed for ${this.reconnectAttempts} times. Giving up.`);
@@ -10998,7 +11010,7 @@ class StreamClient {
10998
11010
  }
10999
11011
  getUserAgent() {
11000
11012
  return (this.userAgent ||
11001
- `stream-video-javascript-client-${this.node ? 'node' : 'browser'}-${"0.0.5"}`);
11013
+ `stream-video-javascript-client-${this.node ? 'node' : 'browser'}-${"0.0.7"}`);
11002
11014
  }
11003
11015
  setUserAgent(userAgent) {
11004
11016
  this.userAgent = userAgent;
@@ -11080,9 +11092,17 @@ class StreamVideoClient {
11080
11092
  * @param tokenOrProvider a token or a function that returns a token.
11081
11093
  */
11082
11094
  this.connectUser = (user, tokenOrProvider) => __awaiter(this, void 0, void 0, function* () {
11083
- const connectUserResponse = yield this.streamClient.connectUser(
11084
- // @ts-expect-error
11085
- user, tokenOrProvider);
11095
+ var _a;
11096
+ const connectUser = () => {
11097
+ return this.streamClient.connectUser(
11098
+ // @ts-expect-error
11099
+ user, tokenOrProvider);
11100
+ };
11101
+ this.connectionPromise = this.disconnectionPromise
11102
+ ? this.disconnectionPromise.then(() => connectUser())
11103
+ : connectUser();
11104
+ (_a = this.connectionPromise) === null || _a === void 0 ? void 0 : _a.finally(() => (this.connectionPromise = undefined));
11105
+ const connectUserResponse = yield this.connectionPromise;
11086
11106
  this.writeableStateStore.setConnectedUser(user);
11087
11107
  this.eventHandlersToUnregister.push(this.on('connection.changed', (e) => {
11088
11108
  const event = e;
@@ -11156,8 +11176,14 @@ class StreamVideoClient {
11156
11176
  * @param tokenOrProvider a token or a function that returns a token.
11157
11177
  */
11158
11178
  this.connectAnonymousUser = (user, tokenOrProvider) => __awaiter(this, void 0, void 0, function* () {
11179
+ const connectAnonymousUser = () =>
11159
11180
  // @ts-expect-error
11160
- return this.streamClient.connectAnonymousUser(user, tokenOrProvider);
11181
+ this.streamClient.connectAnonymousUser(user, tokenOrProvider);
11182
+ this.connectionPromise = this.disconnectionPromise
11183
+ ? this.disconnectionPromise.then(() => connectAnonymousUser())
11184
+ : connectAnonymousUser();
11185
+ this.connectionPromise.finally(() => (this.connectionPromise = undefined));
11186
+ return this.connectionPromise;
11161
11187
  });
11162
11188
  /**
11163
11189
  * Disconnects the currently connected user from the client.
@@ -11168,7 +11194,12 @@ class StreamVideoClient {
11168
11194
  * https://developer.mozilla.org/en-US/docs/Web/API/CloseEvent
11169
11195
  */
11170
11196
  this.disconnectUser = (timeout) => __awaiter(this, void 0, void 0, function* () {
11171
- yield this.streamClient.disconnectUser(timeout);
11197
+ const disconnectUser = () => this.streamClient.disconnectUser(timeout);
11198
+ this.disconnectionPromise = this.connectionPromise
11199
+ ? this.connectionPromise.then(() => disconnectUser())
11200
+ : disconnectUser();
11201
+ this.disconnectionPromise.finally(() => (this.disconnectionPromise = undefined));
11202
+ yield this.disconnectionPromise;
11172
11203
  this.eventHandlersToUnregister.forEach((unregister) => unregister());
11173
11204
  this.eventHandlersToUnregister = [];
11174
11205
  this.writeableStateStore.setConnectedUser(undefined);