@defcomm/meetingsdk 0.2.8 → 0.3.0

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.d.mts CHANGED
@@ -219,8 +219,8 @@ declare class VideoSDKCore {
219
219
  rejectJoinRequest(requestId: string, reason?: string): Promise<void>;
220
220
  toggleMic(): void;
221
221
  toggleCam(): void;
222
- startScreenShare(): Promise<MediaStream>;
223
- stopScreenShare(): void;
222
+ startScreenShare(): Promise<MediaStream | null>;
223
+ stopScreenShare(): Promise<void>;
224
224
  startRecording(): Promise<void>;
225
225
  stopRecording(): Promise<void>;
226
226
  getRecordingStatus(): Promise<{
@@ -436,7 +436,7 @@ declare class SFUClient {
436
436
  video?: boolean | undefined;
437
437
  }): Promise<MediaStream>;
438
438
  private publishExistingTracks;
439
- shareScreen(): Promise<MediaStream>;
439
+ shareScreen(): Promise<MediaStream | null>;
440
440
  stopScreenShare(): Promise<void>;
441
441
  muteAudio(muted: boolean): void;
442
442
  muteVideo(muted: boolean): void;
@@ -479,7 +479,7 @@ type MeetingContextValue = {
479
479
  deleteRoom: (roomCode: string) => Promise<any>;
480
480
  toggleMic: () => void;
481
481
  toggleCam: () => void;
482
- startScreenShare: () => Promise<MediaStream>;
482
+ startScreenShare: () => Promise<MediaStream | null>;
483
483
  stopScreenShare: () => void;
484
484
  sendMessage: (input: ChatInput) => void;
485
485
  sendReaction: (emoji: string) => void;
@@ -537,7 +537,7 @@ declare const useMeeting: (handlers?: {
537
537
  deleteRoom: (roomCode: string) => Promise<any>;
538
538
  toggleMic: () => void;
539
539
  toggleCam: () => void;
540
- startScreenShare: () => Promise<MediaStream>;
540
+ startScreenShare: () => Promise<MediaStream | null>;
541
541
  stopScreenShare: () => void;
542
542
  sendMessage: (input: ChatInput) => void;
543
543
  sendReaction: (emoji: string) => void;
package/dist/index.d.ts CHANGED
@@ -219,8 +219,8 @@ declare class VideoSDKCore {
219
219
  rejectJoinRequest(requestId: string, reason?: string): Promise<void>;
220
220
  toggleMic(): void;
221
221
  toggleCam(): void;
222
- startScreenShare(): Promise<MediaStream>;
223
- stopScreenShare(): void;
222
+ startScreenShare(): Promise<MediaStream | null>;
223
+ stopScreenShare(): Promise<void>;
224
224
  startRecording(): Promise<void>;
225
225
  stopRecording(): Promise<void>;
226
226
  getRecordingStatus(): Promise<{
@@ -436,7 +436,7 @@ declare class SFUClient {
436
436
  video?: boolean | undefined;
437
437
  }): Promise<MediaStream>;
438
438
  private publishExistingTracks;
439
- shareScreen(): Promise<MediaStream>;
439
+ shareScreen(): Promise<MediaStream | null>;
440
440
  stopScreenShare(): Promise<void>;
441
441
  muteAudio(muted: boolean): void;
442
442
  muteVideo(muted: boolean): void;
@@ -479,7 +479,7 @@ type MeetingContextValue = {
479
479
  deleteRoom: (roomCode: string) => Promise<any>;
480
480
  toggleMic: () => void;
481
481
  toggleCam: () => void;
482
- startScreenShare: () => Promise<MediaStream>;
482
+ startScreenShare: () => Promise<MediaStream | null>;
483
483
  stopScreenShare: () => void;
484
484
  sendMessage: (input: ChatInput) => void;
485
485
  sendReaction: (emoji: string) => void;
@@ -537,7 +537,7 @@ declare const useMeeting: (handlers?: {
537
537
  deleteRoom: (roomCode: string) => Promise<any>;
538
538
  toggleMic: () => void;
539
539
  toggleCam: () => void;
540
- startScreenShare: () => Promise<MediaStream>;
540
+ startScreenShare: () => Promise<MediaStream | null>;
541
541
  stopScreenShare: () => void;
542
542
  sendMessage: (input: ChatInput) => void;
543
543
  sendReaction: (emoji: string) => void;
package/dist/index.js CHANGED
@@ -1467,26 +1467,15 @@ var SFUClient = class {
1467
1467
  if (!this.screenTransceiver || !this.screenSender) {
1468
1468
  throw new Error("Screen transceiver is not initialized");
1469
1469
  }
1470
+ const existing = this.screenStream;
1470
1471
  const existingTrack = this.screenSender.track;
1471
- if (this.screenStream && existingTrack && existingTrack.readyState === "live") {
1472
- return this.screenStream;
1472
+ if (existing || existingTrack && existingTrack.readyState === "live") {
1473
+ return existing;
1473
1474
  }
1474
- const generation = ++this.screenShareGeneration;
1475
1475
  try {
1476
1476
  await this.screenSender.replaceTrack(null);
1477
- } catch (err) {
1478
- console.warn("[SFU] Failed to clear previous screen track", err);
1479
- }
1480
- if (this.screenStream) {
1481
- for (const track of this.screenStream.getTracks()) {
1482
- try {
1483
- track.onended = null;
1484
- track.stop();
1485
- } catch {
1486
- }
1487
- }
1477
+ } catch {
1488
1478
  }
1489
- this.screenStream = null;
1490
1479
  this.screenTransceiver.direction = "inactive";
1491
1480
  const screenStream = await navigator.mediaDevices.getDisplayMedia({
1492
1481
  video: true,
@@ -1497,6 +1486,7 @@ var SFUClient = class {
1497
1486
  screenStream.getTracks().forEach((track) => track.stop());
1498
1487
  throw new Error("Screen share returned no video track");
1499
1488
  }
1489
+ const generation = ++this.screenShareGeneration;
1500
1490
  this.screenStream = screenStream;
1501
1491
  try {
1502
1492
  await this.screenSender.replaceTrack(screenTrack);
@@ -1504,20 +1494,16 @@ var SFUClient = class {
1504
1494
  this.send({
1505
1495
  type: "start_screen_share"
1506
1496
  });
1507
- await new Promise((resolve) => {
1508
- queueMicrotask(resolve);
1509
- });
1510
1497
  const offer = await this.publisher.createOffer();
1511
1498
  await this.publisher.setLocalDescription(offer);
1512
1499
  const localDescription = this.publisher.localDescription;
1513
1500
  if (!localDescription?.sdp) {
1514
1501
  throw new Error("Publisher did not produce a valid screen-share SDP");
1515
1502
  }
1516
- const revision = ++this.publisherRevision;
1517
1503
  this.send({
1518
1504
  type: "publish_offer",
1519
1505
  payload: {
1520
- revision,
1506
+ revision: ++this.publisherRevision,
1521
1507
  sdp: localDescription.sdp
1522
1508
  }
1523
1509
  });
@@ -1527,28 +1513,26 @@ var SFUClient = class {
1527
1513
  }
1528
1514
  void this.stopScreenShare();
1529
1515
  };
1530
- return screenStream;
1516
+ return this.screenStream;
1531
1517
  } catch (error) {
1532
- if (generation === this.screenShareGeneration) {
1518
+ try {
1519
+ await this.screenSender.replaceTrack(null);
1520
+ } catch {
1521
+ }
1522
+ this.screenTransceiver.direction = "inactive";
1523
+ screenTrack.onended = null;
1524
+ screenStream.getTracks().forEach((track) => {
1533
1525
  try {
1534
- await this.screenSender.replaceTrack(null);
1526
+ track.stop();
1535
1527
  } catch {
1536
1528
  }
1537
- this.screenTransceiver.direction = "inactive";
1538
- screenTrack.onended = null;
1539
- screenStream.getTracks().forEach((track) => {
1540
- try {
1541
- track.stop();
1542
- } catch {
1543
- }
1529
+ });
1530
+ this.screenStream = null;
1531
+ try {
1532
+ this.send({
1533
+ type: "stop_screen_share"
1544
1534
  });
1545
- this.screenStream = null;
1546
- try {
1547
- this.send({
1548
- type: "stop_screen_share"
1549
- });
1550
- } catch {
1551
- }
1535
+ } catch {
1552
1536
  }
1553
1537
  throw error;
1554
1538
  }
@@ -1556,32 +1540,52 @@ var SFUClient = class {
1556
1540
  async stopScreenShare() {
1557
1541
  const stream = this.screenStream;
1558
1542
  const senderTrack = this.screenSender?.track || null;
1559
- if (!stream && !senderTrack) return;
1543
+ if (!stream && !senderTrack) {
1544
+ return;
1545
+ }
1560
1546
  ++this.screenShareGeneration;
1561
- if (senderTrack) senderTrack.onended = null;
1547
+ if (senderTrack) {
1548
+ senderTrack.onended = null;
1549
+ }
1562
1550
  try {
1563
1551
  await this.screenSender?.replaceTrack(null);
1564
1552
  } catch (error) {
1565
1553
  this.onError(error);
1566
1554
  }
1567
- if (this.screenTransceiver) this.screenTransceiver.direction = "inactive";
1555
+ if (this.screenTransceiver) {
1556
+ this.screenTransceiver.direction = "inactive";
1557
+ }
1568
1558
  try {
1569
- const offer = await this.publisher?.createOffer();
1570
- if (offer && this.publisher) {
1559
+ if (this.publisher) {
1560
+ const offer = await this.publisher.createOffer();
1571
1561
  await this.publisher.setLocalDescription(offer);
1572
- this.send({
1573
- type: "publish_offer",
1574
- payload: { revision: ++this.publisherRevision, sdp: offer.sdp }
1575
- });
1562
+ const localDescription = this.publisher.localDescription;
1563
+ if (localDescription?.sdp) {
1564
+ this.send({
1565
+ type: "publish_offer",
1566
+ payload: {
1567
+ revision: ++this.publisherRevision,
1568
+ sdp: localDescription.sdp
1569
+ }
1570
+ });
1571
+ }
1576
1572
  }
1577
1573
  } catch (error) {
1578
1574
  this.onError(error);
1579
1575
  }
1580
- this.send({ type: "stop_screen_share" });
1581
- stream?.getTracks().forEach((track) => track.stop());
1576
+ this.send({
1577
+ type: "stop_screen_share"
1578
+ });
1579
+ stream?.getTracks().forEach((track) => {
1580
+ try {
1581
+ track.stop();
1582
+ } catch {
1583
+ }
1584
+ });
1582
1585
  this.screenStream = null;
1583
- if (this.currentParticipantId)
1586
+ if (this.currentParticipantId) {
1584
1587
  this.onScreenShareStopped(this.currentParticipantId);
1588
+ }
1585
1589
  }
1586
1590
  muteAudio(muted) {
1587
1591
  this.desiredAudioMuted = muted;
@@ -1687,7 +1691,9 @@ var SFUClient = class {
1687
1691
  sendReaction(reaction) {
1688
1692
  this.send({
1689
1693
  type: "send_reaction",
1690
- reaction
1694
+ payload: {
1695
+ emoji: reaction
1696
+ }
1691
1697
  });
1692
1698
  }
1693
1699
  removeRemoteParticipant(participantId) {
@@ -2581,21 +2587,23 @@ var VideoSDKCore = class {
2581
2587
  throw err;
2582
2588
  }
2583
2589
  }
2584
- stopScreenShare() {
2585
- if (!this.screenStream) {
2590
+ async stopScreenShare() {
2591
+ if (!this.sfuClient) {
2586
2592
  return;
2587
2593
  }
2588
- void this.sfuClient?.stopScreenShare();
2589
- this.screenStream.getTracks().forEach((track) => track.stop());
2590
- this.screenStream = null;
2591
- this.isScreenSharing = false;
2592
- this.state.updateLocalParticipant({
2593
- media: {
2594
- isScreenSharing: false,
2595
- screenStream: null,
2596
- screenTrack: void 0
2597
- }
2598
- });
2594
+ try {
2595
+ await this.sfuClient.stopScreenShare();
2596
+ } finally {
2597
+ this.screenStream = null;
2598
+ this.isScreenSharing = false;
2599
+ this.state.updateLocalParticipant({
2600
+ media: {
2601
+ isScreenSharing: false,
2602
+ screenStream: null,
2603
+ screenTrack: void 0
2604
+ }
2605
+ });
2606
+ }
2599
2607
  }
2600
2608
  // RECORDING
2601
2609
  async startRecording() {