@defcomm/meetingsdk 0.2.8 → 0.2.9

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,32 +1425,19 @@ 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
- }
1431
- if (!this.screenTransceiver || !this.screenSender) {
1430
+ if (!this.screenTransceiver || !this.screenSender)
1432
1431
  throw new Error("Screen transceiver is not initialized");
1433
- }
1432
+ const existing = this.screenStream;
1434
1433
  const existingTrack = this.screenSender.track;
1435
- if (this.screenStream && existingTrack && existingTrack.readyState === "live") {
1436
- return this.screenStream;
1434
+ if (existing || existingTrack && existingTrack.readyState === "live") {
1435
+ return existing;
1437
1436
  }
1438
- const generation = ++this.screenShareGeneration;
1439
1437
  try {
1440
1438
  await this.screenSender.replaceTrack(null);
1441
- } catch (err) {
1442
- console.warn("[SFU] Failed to clear previous screen track", err);
1443
- }
1444
- if (this.screenStream) {
1445
- for (const track of this.screenStream.getTracks()) {
1446
- try {
1447
- track.onended = null;
1448
- track.stop();
1449
- } catch {
1450
- }
1451
- }
1439
+ } catch {
1452
1440
  }
1453
- this.screenStream = null;
1454
1441
  this.screenTransceiver.direction = "inactive";
1455
1442
  const screenStream = await navigator.mediaDevices.getDisplayMedia({
1456
1443
  video: true,
@@ -1461,58 +1448,34 @@ var SFUClient = class {
1461
1448
  screenStream.getTracks().forEach((track) => track.stop());
1462
1449
  throw new Error("Screen share returned no video track");
1463
1450
  }
1451
+ const generation = ++this.screenShareGeneration;
1464
1452
  this.screenStream = screenStream;
1465
1453
  try {
1466
1454
  await this.screenSender.replaceTrack(screenTrack);
1467
1455
  this.screenTransceiver.direction = "sendonly";
1468
- this.send({
1469
- type: "start_screen_share"
1470
- });
1471
- await new Promise((resolve) => {
1472
- queueMicrotask(resolve);
1473
- });
1456
+ this.send({ type: "start_screen_share" });
1474
1457
  const offer = await this.publisher.createOffer();
1475
1458
  await this.publisher.setLocalDescription(offer);
1476
- const localDescription = this.publisher.localDescription;
1477
- if (!localDescription?.sdp) {
1478
- throw new Error("Publisher did not produce a valid screen-share SDP");
1479
- }
1480
- const revision = ++this.publisherRevision;
1481
1459
  this.send({
1482
1460
  type: "publish_offer",
1483
- payload: {
1484
- revision,
1485
- sdp: localDescription.sdp
1486
- }
1461
+ payload: { revision: ++this.publisherRevision, sdp: offer.sdp }
1487
1462
  });
1488
1463
  screenTrack.onended = () => {
1489
- if (generation !== this.screenShareGeneration) {
1490
- return;
1491
- }
1464
+ if (generation !== this.screenShareGeneration) return;
1492
1465
  void this.stopScreenShare();
1493
1466
  };
1494
- return screenStream;
1467
+ return this.screenStream;
1495
1468
  } catch (error) {
1496
- if (generation === this.screenShareGeneration) {
1497
- try {
1498
- await this.screenSender.replaceTrack(null);
1499
- } catch {
1500
- }
1501
- this.screenTransceiver.direction = "inactive";
1502
- screenTrack.onended = null;
1503
- screenStream.getTracks().forEach((track) => {
1504
- try {
1505
- track.stop();
1506
- } catch {
1507
- }
1508
- });
1509
- this.screenStream = null;
1510
- try {
1511
- this.send({
1512
- type: "stop_screen_share"
1513
- });
1514
- } catch {
1515
- }
1469
+ try {
1470
+ await this.screenSender.replaceTrack(null);
1471
+ } catch {
1472
+ }
1473
+ this.screenTransceiver.direction = "inactive";
1474
+ screenStream.getTracks().forEach((track) => track.stop());
1475
+ this.screenStream = null;
1476
+ try {
1477
+ this.send({ type: "stop_screen_share" });
1478
+ } catch {
1516
1479
  }
1517
1480
  throw error;
1518
1481
  }
@@ -1651,7 +1614,9 @@ var SFUClient = class {
1651
1614
  sendReaction(reaction) {
1652
1615
  this.send({
1653
1616
  type: "send_reaction",
1654
- reaction
1617
+ payload: {
1618
+ reaction
1619
+ }
1655
1620
  });
1656
1621
  }
1657
1622
  removeRemoteParticipant(participantId) {