@stream-io/video-client 0.0.30 → 0.0.31

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
@@ -8185,38 +8185,45 @@ const watchCallMemberUpdated = (state) => {
8185
8185
  /**
8186
8186
  * An event responder which handles the `participantJoined` event.
8187
8187
  */
8188
- const watchParticipantJoined = (dispatcher, state) => {
8189
- return dispatcher.on('participantJoined', (e) => {
8188
+ const watchParticipantJoined = (state) => {
8189
+ return function onParticipantJoined(e) {
8190
8190
  if (e.eventPayload.oneofKind !== 'participantJoined')
8191
8191
  return;
8192
8192
  const { participant } = e.eventPayload.participantJoined;
8193
8193
  if (!participant)
8194
8194
  return;
8195
- state.setParticipants((participants) => [
8196
- ...participants,
8197
- Object.assign(Object.assign({}, participant), { viewportVisibilityState: exports.VisibilityState.UNKNOWN }),
8198
- ]);
8199
- });
8195
+ // `state.updateOrAddParticipant` acts as a safeguard against
8196
+ // potential duplicate events from the SFU.
8197
+ //
8198
+ // Although the SFU should not send duplicate events, we have seen
8199
+ // some race conditions in the past during the `join-flow` where
8200
+ // the SFU would send participant info as part of the `join`
8201
+ // response and then follow up with a `participantJoined` event for
8202
+ // already announced participants.
8203
+ state.updateOrAddParticipant(participant.sessionId, Object.assign(participant, {
8204
+ viewportVisibilityState: exports.VisibilityState.UNKNOWN,
8205
+ }));
8206
+ };
8200
8207
  };
8201
8208
  /**
8202
8209
  * An event responder which handles the `participantLeft` event.
8203
8210
  */
8204
- const watchParticipantLeft = (dispatcher, state) => {
8205
- return dispatcher.on('participantLeft', (e) => {
8211
+ const watchParticipantLeft = (state) => {
8212
+ return function onParticipantLeft(e) {
8206
8213
  if (e.eventPayload.oneofKind !== 'participantLeft')
8207
8214
  return;
8208
8215
  const { participant } = e.eventPayload.participantLeft;
8209
8216
  if (!participant)
8210
8217
  return;
8211
8218
  state.setParticipants((participants) => participants.filter((p) => p.sessionId !== participant.sessionId));
8212
- });
8219
+ };
8213
8220
  };
8214
8221
  /**
8215
8222
  * An event responder which handles the `trackPublished` event.
8216
8223
  * The SFU will send this event when a participant publishes a track.
8217
8224
  */
8218
- const watchTrackPublished = (dispatcher, state) => {
8219
- return dispatcher.on('trackPublished', (e) => {
8225
+ const watchTrackPublished = (state) => {
8226
+ return function onTrackPublished(e) {
8220
8227
  if (e.eventPayload.oneofKind !== 'trackPublished')
8221
8228
  return;
8222
8229
  const { trackPublished: { type, sessionId, participant }, } = e.eventPayload;
@@ -8225,34 +8232,34 @@ const watchTrackPublished = (dispatcher, state) => {
8225
8232
  // events, and instead, it would only provide the participant's information
8226
8233
  // once they start publishing a track.
8227
8234
  if (participant) {
8228
- state.updateOrAddParticipant(participant.sessionId, participant);
8235
+ state.updateOrAddParticipant(sessionId, participant);
8229
8236
  }
8230
8237
  else {
8231
8238
  state.updateParticipant(sessionId, (p) => ({
8232
8239
  publishedTracks: [...p.publishedTracks, type].filter(unique),
8233
8240
  }));
8234
8241
  }
8235
- });
8242
+ };
8236
8243
  };
8237
8244
  /**
8238
8245
  * An event responder which handles the `trackUnpublished` event.
8239
8246
  * The SFU will send this event when a participant unpublishes a track.
8240
8247
  */
8241
- const watchTrackUnpublished = (dispatcher, state) => {
8242
- return dispatcher.on('trackUnpublished', (e) => {
8248
+ const watchTrackUnpublished = (state) => {
8249
+ return function onTrackUnpublished(e) {
8243
8250
  if (e.eventPayload.oneofKind !== 'trackUnpublished')
8244
8251
  return;
8245
8252
  const { trackUnpublished: { type, sessionId, participant }, } = e.eventPayload;
8246
8253
  // An optimization for large calls. See `watchTrackPublished`.
8247
8254
  if (participant) {
8248
- state.updateOrAddParticipant(participant.sessionId, participant);
8255
+ state.updateOrAddParticipant(sessionId, participant);
8249
8256
  }
8250
8257
  else {
8251
8258
  state.updateParticipant(sessionId, (p) => ({
8252
8259
  publishedTracks: p.publishedTracks.filter((t) => t !== type),
8253
8260
  }));
8254
8261
  }
8255
- });
8262
+ };
8256
8263
  };
8257
8264
  const unique = (v, i, arr) => arr.indexOf(v) === i;
8258
8265
 
@@ -8500,10 +8507,10 @@ const registerEventHandlers = (call, state, dispatcher) => {
8500
8507
  watchChangePublishQuality(dispatcher, call),
8501
8508
  watchConnectionQualityChanged(dispatcher, state),
8502
8509
  watchParticipantCountChanged(dispatcher, state),
8503
- watchParticipantJoined(dispatcher, state),
8504
- watchParticipantLeft(dispatcher, state),
8505
- watchTrackPublished(dispatcher, state),
8506
- watchTrackUnpublished(dispatcher, state),
8510
+ call.on('participantJoined', watchParticipantJoined(state)),
8511
+ call.on('participantLeft', watchParticipantLeft(state)),
8512
+ call.on('trackPublished', watchTrackPublished(state)),
8513
+ call.on('trackUnpublished', watchTrackUnpublished(state)),
8507
8514
  watchAudioLevelChanged(dispatcher, state),
8508
8515
  watchDominantSpeakerChanged(dispatcher, state),
8509
8516
  call.on('callGrantsUpdated', watchCallGrantsUpdated(state)),
@@ -11895,7 +11902,7 @@ class StreamClient {
11895
11902
  }
11896
11903
  getUserAgent() {
11897
11904
  return (this.userAgent ||
11898
- `stream-video-javascript-client-${this.node ? 'node' : 'browser'}-${"0.0.29"}`);
11905
+ `stream-video-javascript-client-${this.node ? 'node' : 'browser'}-${"0.0.30"}`);
11899
11906
  }
11900
11907
  setUserAgent(userAgent) {
11901
11908
  this.userAgent = userAgent;