@furious.luke/argus-js 0.5.0 → 0.5.1

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.cjs CHANGED
@@ -180,10 +180,11 @@ var Publisher = class {
180
180
  // may later reuse any compatible inactive transceiver, not necessarily the one
181
181
  // that previously carried the same logical type.
182
182
  typeSenders = /* @__PURE__ */ new Map();
183
- // intentionalTrackEnds holds physical track ids removed by publish/unpublish
184
- // whose server-side `media_track_ended` has not yet arrived. Correlating by id
185
- // keeps a delayed end for an old screen track from being mistaken for failure
186
- // of a newly-published screen track.
183
+ // intentionalTrackEnds holds the browser track ids removed by publish/unpublish
184
+ // whose server-side `media_track_ended` has not yet arrived. Correlating by the
185
+ // track id (the generation identity the server echoes in track_id) keeps a
186
+ // delayed end for an old screen track from being mistaken for failure of a
187
+ // newly-published screen track.
187
188
  intentionalTrackEnds = /* @__PURE__ */ new Map();
188
189
  // negotiationChain serializes every offer/answer exchange, including recovery.
189
190
  // User operations do not resolve until their answer is applied, so no caller
@@ -1124,7 +1125,7 @@ var Publisher = class {
1124
1125
  sdp: local.sdp,
1125
1126
  sdp_type: "offer",
1126
1127
  negotiation_id: id,
1127
- tracks: change?.labels ?? this.buildTrackLabels(),
1128
+ tracks: change?.labels?.() ?? this.buildTrackLabels(),
1128
1129
  speech_enabled: this.speechEnabled || this.speechPending || void 0
1129
1130
  });
1130
1131
  this.releaseLocalCandidateBatch();
@@ -1533,7 +1534,7 @@ var Publisher = class {
1533
1534
  this.typeSenders.set(type, addedSender);
1534
1535
  }
1535
1536
  return {
1536
- labels: this.labelsReplacingType(type, track),
1537
+ labels: () => this.labelsReplacingType(type, track),
1537
1538
  commit: () => {
1538
1539
  for (const { track: oldTrack } of previous) {
1539
1540
  this.unwatchTrack(oldTrack);
@@ -1597,18 +1598,34 @@ var Publisher = class {
1597
1598
  buildTrackLabels() {
1598
1599
  const labels = [];
1599
1600
  for (const [track, type] of this.published) {
1600
- labels.push({ id: track.id, type });
1601
+ const mid = this.midForTrack(track);
1602
+ if (mid !== null) labels.push({ mid, id: track.id, type });
1601
1603
  }
1602
1604
  return labels;
1603
1605
  }
1604
1606
  labelsReplacingType(type, replacement) {
1605
1607
  const labels = [];
1606
1608
  for (const [track, publishedType] of this.published) {
1607
- if (publishedType !== type) labels.push({ id: track.id, type: publishedType });
1609
+ if (publishedType === type) continue;
1610
+ const mid = this.midForTrack(track);
1611
+ if (mid !== null) labels.push({ mid, id: track.id, type: publishedType });
1612
+ }
1613
+ if (replacement) {
1614
+ const mid = this.midForTrack(replacement);
1615
+ if (mid !== null) labels.push({ mid, id: replacement.id, type });
1608
1616
  }
1609
- if (replacement) labels.push({ id: replacement.id, type });
1610
1617
  return labels;
1611
1618
  }
1619
+ /**
1620
+ * The negotiated mid of the transceiver currently sending `track`, or null if
1621
+ * none is found or it has not been negotiated yet. The mid is the identifier
1622
+ * both peers agree on; it is assigned once setLocalDescription runs, which the
1623
+ * publisher always does before sending an offer's labels.
1624
+ */
1625
+ midForTrack(track) {
1626
+ const transceiver = this.pc?.getTransceivers().find((candidate) => candidate.sender.track === track);
1627
+ return transceiver?.mid ?? null;
1628
+ }
1612
1629
  async stagePublish(track, stream, type) {
1613
1630
  const pc = this.pc;
1614
1631
  if (!pc) throw new Error("publisher not started");
@@ -1639,7 +1656,7 @@ var Publisher = class {
1639
1656
  this.typeSenders.set(type, addedSender);
1640
1657
  }
1641
1658
  return {
1642
- labels: this.labelsReplacingType(type, track),
1659
+ labels: () => this.labelsReplacingType(type, track),
1643
1660
  commit: () => {
1644
1661
  this.cancelMediaRecovery(type);
1645
1662
  this.recoveryState(type).required = false;
@@ -1687,7 +1704,7 @@ var Publisher = class {
1687
1704
  for (const { track } of previous) this.expectIntentionalTrackEnd(track.id, type);
1688
1705
  pc.removeTrack(typeSender);
1689
1706
  return {
1690
- labels: this.labelsReplacingType(type),
1707
+ labels: () => this.labelsReplacingType(type),
1691
1708
  commit: () => {
1692
1709
  this.cancelMediaRecovery(type);
1693
1710
  this.recoveryState(type).required = false;