@defcomm/meetingsdk 0.3.2 → 0.3.3

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.mjs CHANGED
@@ -512,6 +512,9 @@ var SFUClient = class {
512
512
  getScreenStream() {
513
513
  return this.screenStream;
514
514
  }
515
+ getRemoteScreenStream(participantId) {
516
+ return this.remoteScreenStreams.get(participantId) || null;
517
+ }
515
518
  setLocalStream(stream) {
516
519
  this.localStream = stream;
517
520
  }
@@ -931,19 +934,7 @@ var SFUClient = class {
931
934
  }
932
935
  case "screen_share_stopped": {
933
936
  const participantId = payload.participant_id;
934
- const screenStream = participantId ? this.remoteScreenStreams.get(participantId) : null;
935
937
  const trackId = payload.track_id;
936
- if (screenStream) {
937
- for (const track of screenStream.getVideoTracks()) {
938
- if (!trackId || this.normalizeRemoteTrackId(track.id) === String(trackId)) {
939
- screenStream.removeTrack(track);
940
- track.stop();
941
- }
942
- }
943
- if (screenStream.getTracks().length === 0 && participantId) {
944
- this.remoteScreenStreams.delete(participantId);
945
- }
946
- }
947
938
  this.onScreenShareStopped(participantId, trackId);
948
939
  break;
949
940
  }
@@ -2330,11 +2321,11 @@ var VideoSDKCore = class {
2330
2321
  // SCREEN SHARE
2331
2322
  onScreenShareStarted: (participantId, _track) => {
2332
2323
  console.log("[SFU] Screen share started", participantId);
2333
- if (participantId === this.myId && !this.screenStream) {
2334
- this.screenStream = this.sfuClient?.getScreenStream() ?? null;
2335
- }
2336
- this.state.setPresenterId(participantId);
2337
2324
  if (participantId === this.myId) {
2325
+ if (!this.screenStream) {
2326
+ this.screenStream = this.sfuClient?.getScreenStream() ?? null;
2327
+ }
2328
+ this.state.setPresenterId(participantId);
2338
2329
  this.state.updateLocalParticipant({
2339
2330
  media: {
2340
2331
  isScreenSharing: true,
@@ -2344,11 +2335,25 @@ var VideoSDKCore = class {
2344
2335
  });
2345
2336
  return;
2346
2337
  }
2338
+ this.state.setPresenterId(participantId);
2339
+ const existingRemoteScreen = this.sfuClient?.getRemoteScreenStream(participantId) ?? this.remoteScreenStreams.get(participantId) ?? null;
2340
+ if (existingRemoteScreen) {
2341
+ this.remoteScreenStreams.set(participantId, existingRemoteScreen);
2342
+ const screenTrack = existingRemoteScreen.getVideoTracks()[0];
2343
+ this.state.updateParticipantMedia(participantId, {
2344
+ isScreenSharing: true,
2345
+ screenStream: existingRemoteScreen,
2346
+ screenTrack
2347
+ });
2348
+ this.events.onScreenShareStarted?.(participantId, existingRemoteScreen);
2349
+ return;
2350
+ }
2347
2351
  const current = this.state.getParticipant(participantId);
2348
2352
  if (current) {
2349
2353
  this.state.updateParticipantMedia(participantId, {
2350
2354
  isScreenSharing: true,
2351
- screenStream: current.media?.screenStream ?? null
2355
+ screenStream: current.media?.screenStream ?? null,
2356
+ screenTrack: current.media?.screenTrack
2352
2357
  });
2353
2358
  }
2354
2359
  },
@@ -2366,13 +2371,8 @@ var VideoSDKCore = class {
2366
2371
  });
2367
2372
  return;
2368
2373
  }
2369
- const screen = this.remoteScreenStreams.get(participantId);
2370
- screen?.getTracks().forEach((track) => track.stop());
2371
- this.remoteScreenStreams.delete(participantId);
2372
2374
  this.state.updateParticipantMedia(participantId, {
2373
- isScreenSharing: false,
2374
- screenStream: null,
2375
- screenTrack: void 0
2375
+ isScreenSharing: false
2376
2376
  });
2377
2377
  this.events.onScreenShareStopped?.(participantId);
2378
2378
  },