@defcomm/meetingsdk 0.2.9 → 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.mjs CHANGED
@@ -1425,10 +1425,12 @@ var SFUClient = class {
1425
1425
  }
1426
1426
  }
1427
1427
  async shareScreen() {
1428
- if (!this.publisher)
1428
+ if (!this.publisher) {
1429
1429
  throw new Error("Publisher PeerConnection is not initialized");
1430
- if (!this.screenTransceiver || !this.screenSender)
1430
+ }
1431
+ if (!this.screenTransceiver || !this.screenSender) {
1431
1432
  throw new Error("Screen transceiver is not initialized");
1433
+ }
1432
1434
  const existing = this.screenStream;
1433
1435
  const existingTrack = this.screenSender.track;
1434
1436
  if (existing || existingTrack && existingTrack.readyState === "live") {
@@ -1453,15 +1455,26 @@ var SFUClient = class {
1453
1455
  try {
1454
1456
  await this.screenSender.replaceTrack(screenTrack);
1455
1457
  this.screenTransceiver.direction = "sendonly";
1456
- this.send({ type: "start_screen_share" });
1458
+ this.send({
1459
+ type: "start_screen_share"
1460
+ });
1457
1461
  const offer = await this.publisher.createOffer();
1458
1462
  await this.publisher.setLocalDescription(offer);
1463
+ const localDescription = this.publisher.localDescription;
1464
+ if (!localDescription?.sdp) {
1465
+ throw new Error("Publisher did not produce a valid screen-share SDP");
1466
+ }
1459
1467
  this.send({
1460
1468
  type: "publish_offer",
1461
- payload: { revision: ++this.publisherRevision, sdp: offer.sdp }
1469
+ payload: {
1470
+ revision: ++this.publisherRevision,
1471
+ sdp: localDescription.sdp
1472
+ }
1462
1473
  });
1463
1474
  screenTrack.onended = () => {
1464
- if (generation !== this.screenShareGeneration) return;
1475
+ if (generation !== this.screenShareGeneration) {
1476
+ return;
1477
+ }
1465
1478
  void this.stopScreenShare();
1466
1479
  };
1467
1480
  return this.screenStream;
@@ -1471,10 +1484,18 @@ var SFUClient = class {
1471
1484
  } catch {
1472
1485
  }
1473
1486
  this.screenTransceiver.direction = "inactive";
1474
- screenStream.getTracks().forEach((track) => track.stop());
1487
+ screenTrack.onended = null;
1488
+ screenStream.getTracks().forEach((track) => {
1489
+ try {
1490
+ track.stop();
1491
+ } catch {
1492
+ }
1493
+ });
1475
1494
  this.screenStream = null;
1476
1495
  try {
1477
- this.send({ type: "stop_screen_share" });
1496
+ this.send({
1497
+ type: "stop_screen_share"
1498
+ });
1478
1499
  } catch {
1479
1500
  }
1480
1501
  throw error;
@@ -1483,32 +1504,52 @@ var SFUClient = class {
1483
1504
  async stopScreenShare() {
1484
1505
  const stream = this.screenStream;
1485
1506
  const senderTrack = this.screenSender?.track || null;
1486
- if (!stream && !senderTrack) return;
1507
+ if (!stream && !senderTrack) {
1508
+ return;
1509
+ }
1487
1510
  ++this.screenShareGeneration;
1488
- if (senderTrack) senderTrack.onended = null;
1511
+ if (senderTrack) {
1512
+ senderTrack.onended = null;
1513
+ }
1489
1514
  try {
1490
1515
  await this.screenSender?.replaceTrack(null);
1491
1516
  } catch (error) {
1492
1517
  this.onError(error);
1493
1518
  }
1494
- if (this.screenTransceiver) this.screenTransceiver.direction = "inactive";
1519
+ if (this.screenTransceiver) {
1520
+ this.screenTransceiver.direction = "inactive";
1521
+ }
1495
1522
  try {
1496
- const offer = await this.publisher?.createOffer();
1497
- if (offer && this.publisher) {
1523
+ if (this.publisher) {
1524
+ const offer = await this.publisher.createOffer();
1498
1525
  await this.publisher.setLocalDescription(offer);
1499
- this.send({
1500
- type: "publish_offer",
1501
- payload: { revision: ++this.publisherRevision, sdp: offer.sdp }
1502
- });
1526
+ const localDescription = this.publisher.localDescription;
1527
+ if (localDescription?.sdp) {
1528
+ this.send({
1529
+ type: "publish_offer",
1530
+ payload: {
1531
+ revision: ++this.publisherRevision,
1532
+ sdp: localDescription.sdp
1533
+ }
1534
+ });
1535
+ }
1503
1536
  }
1504
1537
  } catch (error) {
1505
1538
  this.onError(error);
1506
1539
  }
1507
- this.send({ type: "stop_screen_share" });
1508
- stream?.getTracks().forEach((track) => track.stop());
1540
+ this.send({
1541
+ type: "stop_screen_share"
1542
+ });
1543
+ stream?.getTracks().forEach((track) => {
1544
+ try {
1545
+ track.stop();
1546
+ } catch {
1547
+ }
1548
+ });
1509
1549
  this.screenStream = null;
1510
- if (this.currentParticipantId)
1550
+ if (this.currentParticipantId) {
1511
1551
  this.onScreenShareStopped(this.currentParticipantId);
1552
+ }
1512
1553
  }
1513
1554
  muteAudio(muted) {
1514
1555
  this.desiredAudioMuted = muted;
@@ -1615,7 +1656,7 @@ var SFUClient = class {
1615
1656
  this.send({
1616
1657
  type: "send_reaction",
1617
1658
  payload: {
1618
- reaction
1659
+ emoji: reaction
1619
1660
  }
1620
1661
  });
1621
1662
  }
@@ -2510,21 +2551,23 @@ var VideoSDKCore = class {
2510
2551
  throw err;
2511
2552
  }
2512
2553
  }
2513
- stopScreenShare() {
2514
- if (!this.screenStream) {
2554
+ async stopScreenShare() {
2555
+ if (!this.sfuClient) {
2515
2556
  return;
2516
2557
  }
2517
- void this.sfuClient?.stopScreenShare();
2518
- this.screenStream.getTracks().forEach((track) => track.stop());
2519
- this.screenStream = null;
2520
- this.isScreenSharing = false;
2521
- this.state.updateLocalParticipant({
2522
- media: {
2523
- isScreenSharing: false,
2524
- screenStream: null,
2525
- screenTrack: void 0
2526
- }
2527
- });
2558
+ try {
2559
+ await this.sfuClient.stopScreenShare();
2560
+ } finally {
2561
+ this.screenStream = null;
2562
+ this.isScreenSharing = false;
2563
+ this.state.updateLocalParticipant({
2564
+ media: {
2565
+ isScreenSharing: false,
2566
+ screenStream: null,
2567
+ screenTrack: void 0
2568
+ }
2569
+ });
2570
+ }
2528
2571
  }
2529
2572
  // RECORDING
2530
2573
  async startRecording() {