@fishjam-cloud/webrtc-client 0.27.0-rc.0 → 0.28.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.
Files changed (2) hide show
  1. package/dist/index.mjs +39 -16
  2. package/package.json +3 -4
package/dist/index.mjs CHANGED
@@ -1441,7 +1441,7 @@ var CommandsQueue = class {
1441
1441
  connection.getConnection().addEventListener("signalingstatechange", onSignalingStateChange);
1442
1442
  };
1443
1443
  commandsQueue = [];
1444
- commandResolutionNotifier = null;
1444
+ commandResolutionNotifiers = [];
1445
1445
  pushCommand = (command) => {
1446
1446
  this.commandsQueue.push(command);
1447
1447
  this.processNextCommand();
@@ -1449,35 +1449,53 @@ var CommandsQueue = class {
1449
1449
  processNextCommand = () => {
1450
1450
  if (this.localTrackManager.isNegotiationInProgress()) return;
1451
1451
  if (this.connection?.isConnectionUnstable()) return;
1452
- this.resolvePreviousCommand();
1452
+ this.resolvePreviousCommands();
1453
1453
  const command = this.commandsQueue.shift();
1454
1454
  if (!command) return;
1455
- this.commandResolutionNotifier = command.resolutionNotifier;
1455
+ this.commandResolutionNotifiers.push(command.resolutionNotifier);
1456
1456
  this.handleCommand(command);
1457
1457
  };
1458
+ /**
1459
+ * Drains queued batchable commands into the in-flight negotiation (called from `onOfferData`,
1460
+ * before the offer is created). Ignores `isNegotiationInProgress` by design; stops at the first
1461
+ * non-batchable command to preserve ordering.
1462
+ */
1463
+ processBatchedCommands = () => {
1464
+ if (this.connection?.isConnectionUnstable()) return;
1465
+ while (this.commandsQueue[0]?.batchable) {
1466
+ const command = this.commandsQueue.shift();
1467
+ this.commandResolutionNotifiers.push(command.resolutionNotifier);
1468
+ this.handleCommand(command);
1469
+ }
1470
+ };
1458
1471
  handleCommand = async (command) => {
1459
1472
  try {
1460
1473
  command.parse?.();
1461
- const promise = command.handler();
1474
+ await command.handler();
1462
1475
  if (command.resolve === "on-handler-resolve") {
1463
- await promise;
1464
- this.resolvePreviousCommand();
1476
+ this.resolveCommand(command.resolutionNotifier);
1465
1477
  this.processNextCommand();
1466
1478
  }
1467
1479
  } catch (error) {
1468
- this.commandResolutionNotifier?.reject(error);
1469
- this.commandResolutionNotifier = null;
1480
+ this.rejectCommand(command.resolutionNotifier, error);
1470
1481
  this.processNextCommand();
1471
1482
  }
1472
1483
  };
1473
- resolvePreviousCommand = () => {
1474
- if (!this.commandResolutionNotifier) return;
1475
- this.commandResolutionNotifier.resolve();
1476
- this.commandResolutionNotifier = null;
1484
+ resolvePreviousCommands = () => {
1485
+ this.commandResolutionNotifiers.forEach((notifier) => notifier.resolve());
1486
+ this.commandResolutionNotifiers = [];
1487
+ };
1488
+ resolveCommand = (notifier) => {
1489
+ notifier.resolve();
1490
+ this.commandResolutionNotifiers = this.commandResolutionNotifiers.filter((current) => current !== notifier);
1491
+ };
1492
+ rejectCommand = (notifier, error) => {
1493
+ notifier.reject(error);
1494
+ this.commandResolutionNotifiers = this.commandResolutionNotifiers.filter((current) => current !== notifier);
1477
1495
  };
1478
1496
  cleanUp = () => {
1479
- this.commandResolutionNotifier?.reject("Disconnected");
1480
- this.commandResolutionNotifier = null;
1497
+ this.commandResolutionNotifiers.forEach((notifier) => notifier.reject("Disconnected"));
1498
+ this.commandResolutionNotifiers = [];
1481
1499
  this.commandsQueue = [];
1482
1500
  this.clearConnectionCallbacks?.();
1483
1501
  };
@@ -4520,6 +4538,7 @@ var LocalTrackManager = class {
4520
4538
  }
4521
4539
  };
4522
4540
  addTrackHandler = (trackId, track, stream, trackMetadata, simulcastConfig, maxBandwidth) => {
4541
+ const isRenegotiationAlreadyPending = this.ongoingRenegotiation;
4523
4542
  this.ongoingRenegotiation = true;
4524
4543
  const trackManager = this.local.addTrack(
4525
4544
  this.connection,
@@ -4533,7 +4552,9 @@ var LocalTrackManager = class {
4533
4552
  if (this.connection) {
4534
4553
  trackManager.addTrackToConnection();
4535
4554
  }
4536
- this.sendMediaEvent({ renegotiateTracks: MediaEvent_RenegotiateTracks.create() });
4555
+ if (!isRenegotiationAlreadyPending) {
4556
+ this.sendMediaEvent({ renegotiateTracks: MediaEvent_RenegotiateTracks.create() });
4557
+ }
4537
4558
  };
4538
4559
  removeTrackHandler = (trackId) => {
4539
4560
  if (!this.connection) throw new Error(`There is no active RTCPeerConnection`);
@@ -5073,7 +5094,8 @@ var WebRTCEndpoint = class extends EventEmitter3 {
5073
5094
  ),
5074
5095
  parse: () => this.localTrackManager.parseAddTrack(track, simulcastConfig, resolvedMaxBandwidth),
5075
5096
  resolve: "after-renegotiation",
5076
- resolutionNotifier
5097
+ resolutionNotifier,
5098
+ batchable: true
5077
5099
  });
5078
5100
  } catch (error) {
5079
5101
  resolutionNotifier.reject(error);
@@ -5386,6 +5408,7 @@ var WebRTCEndpoint = class extends EventEmitter3 {
5386
5408
  if (offerData.tracksTypes) {
5387
5409
  connectionManager.addTransceiversIfNeeded(offerData.tracksTypes);
5388
5410
  }
5411
+ this.commandsQueue.processBatchedCommands();
5389
5412
  await this.createAndSendOffer();
5390
5413
  };
5391
5414
  setupConnectionListeners = (connection) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fishjam-cloud/webrtc-client",
3
- "version": "0.27.0-rc.0",
3
+ "version": "0.28.0",
4
4
  "description": "Typescript client library for ExWebRTC/WebRTC endpoint in Membrane RTC Engine",
5
5
  "license": "Apache-2.0",
6
6
  "author": "Fishjam Team",
@@ -50,7 +50,7 @@
50
50
  },
51
51
  "devDependencies": {
52
52
  "@faker-js/faker": "^9.6.0",
53
- "@fishjam-cloud/protobufs": "0.27.0-rc.0",
53
+ "@fishjam-cloud/protobufs": "0.28.0",
54
54
  "@playwright/test": "^1.51.1",
55
55
  "@types/events": "^3.0.3",
56
56
  "@types/node": "^22.14.0",
@@ -75,6 +75,5 @@
75
75
  "*.(js|ts|tsx)": [
76
76
  "yarn lint"
77
77
  ]
78
- },
79
- "stableVersion": "0.26.3"
78
+ }
80
79
  }