@poolse/sdk 2.12.0 → 2.12.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
@@ -1677,6 +1677,19 @@ var CallRoom = class {
1677
1677
  errorListeners = /* @__PURE__ */ new Set();
1678
1678
  /** Bound once so `off()` in teardown removes the same references. */
1679
1679
  onRoomChange = () => this.emitParticipants();
1680
+ /**
1681
+ * Hidden `<audio>` elements playing each remote audio track.
1682
+ *
1683
+ * livekit-client does NOT play remote audio for you on the web — that
1684
+ * is what `@livekit/components-react`'s `<RoomAudioRenderer />` exists
1685
+ * to do. Without this a call connects, the roster is right, video
1686
+ * flows, and nobody hears anything. The peer-to-peer mesh always did
1687
+ * this (see `webrtc-browser.ts`); the SFU path has to as well.
1688
+ *
1689
+ * Empty on React Native, where there is no DOM and LiveKit routes
1690
+ * audio through the native audio session instead.
1691
+ */
1692
+ audioSinks = /* @__PURE__ */ new Map();
1680
1693
  constructor(opts) {
1681
1694
  this.livekit = opts.livekit;
1682
1695
  this.tokenProvider = opts.tokenProvider;
@@ -1821,6 +1834,14 @@ var CallRoom = class {
1821
1834
  ]) {
1822
1835
  if (event) room.on(event, this.onRoomChange);
1823
1836
  }
1837
+ const subscribed = RoomEvent["TrackSubscribed"];
1838
+ if (subscribed) {
1839
+ room.on(subscribed, ((track) => this.playAudio(track)));
1840
+ }
1841
+ const unsubscribed = RoomEvent["TrackUnsubscribed"];
1842
+ if (unsubscribed) {
1843
+ room.on(unsubscribed, ((track) => this.stopAudio(track)));
1844
+ }
1824
1845
  const disconnected = RoomEvent["Disconnected"];
1825
1846
  if (disconnected) {
1826
1847
  room.on(disconnected, () => {
@@ -1829,6 +1850,38 @@ var CallRoom = class {
1829
1850
  });
1830
1851
  }
1831
1852
  }
1853
+ /**
1854
+ * Play a remote audio track through a hidden element.
1855
+ *
1856
+ * No-ops for video (the UI renders that) and on React Native, where
1857
+ * there is no `document` and the native audio session handles
1858
+ * playback.
1859
+ */
1860
+ playAudio(track) {
1861
+ if (typeof document === "undefined") return;
1862
+ if (track?.kind !== "audio" || typeof track.attach !== "function") return;
1863
+ if (this.audioSinks.has(track)) return;
1864
+ try {
1865
+ const element = track.attach();
1866
+ element.autoplay = true;
1867
+ element.style.display = "none";
1868
+ document.body.appendChild(element);
1869
+ this.audioSinks.set(track, element);
1870
+ } catch (err) {
1871
+ this.emitError(new Error(`could not play remote audio: ${String(err)}`));
1872
+ }
1873
+ }
1874
+ /** Tear a sink down, so a departed peer stops holding an element. */
1875
+ stopAudio(track) {
1876
+ const element = this.audioSinks.get(track);
1877
+ if (!element) return;
1878
+ this.audioSinks.delete(track);
1879
+ try {
1880
+ track.detach?.(element);
1881
+ } catch {
1882
+ }
1883
+ element.remove();
1884
+ }
1832
1885
  toParticipant(participant, isSelf) {
1833
1886
  const cameraSource = this.livekit.Track.Source["Camera"] ?? "camera";
1834
1887
  const publication = participant.getTrackPublication(cameraSource);
@@ -1850,6 +1903,7 @@ var CallRoom = class {
1850
1903
  this.room = null;
1851
1904
  this.selfId = null;
1852
1905
  this.holders = 0;
1906
+ for (const track of [...this.audioSinks.keys()]) this.stopAudio(track);
1853
1907
  if (room) {
1854
1908
  try {
1855
1909
  await room.disconnect();
@@ -2207,7 +2261,7 @@ var Poolse = class {
2207
2261
  };
2208
2262
 
2209
2263
  // src/version.ts
2210
- var version = "2.12.0";
2264
+ var version = "2.12.1";
2211
2265
 
2212
2266
  exports.ApiError = ApiError;
2213
2267
  exports.AttachmentHandle = AttachmentHandle;