@poolse/sdk 2.11.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.d.cts CHANGED
@@ -1452,8 +1452,18 @@ declare class UsersResource {
1452
1452
  *
1453
1453
  * Deliberately narrow — only what {@link CallRoom} actually touches.
1454
1454
  */
1455
- /** A media track. Opaque here; the platform renderer consumes it. */
1456
- type LiveKitTrack = object;
1455
+ /**
1456
+ * A media track.
1457
+ *
1458
+ * Mostly opaque — the platform renderer consumes video. Audio is the
1459
+ * exception: {@link CallRoom} attaches it itself on the web, because
1460
+ * livekit-client does not play remote audio for you.
1461
+ */
1462
+ interface LiveKitTrack {
1463
+ kind?: string;
1464
+ attach?: () => HTMLMediaElement;
1465
+ detach?: (element?: HTMLMediaElement) => unknown;
1466
+ }
1457
1467
  interface LiveKitPublication {
1458
1468
  track?: LiveKitTrack | null | undefined;
1459
1469
  isMuted?: boolean;
@@ -1663,6 +1673,19 @@ declare class CallRoom {
1663
1673
  private readonly errorListeners;
1664
1674
  /** Bound once so `off()` in teardown removes the same references. */
1665
1675
  private readonly onRoomChange;
1676
+ /**
1677
+ * Hidden `<audio>` elements playing each remote audio track.
1678
+ *
1679
+ * livekit-client does NOT play remote audio for you on the web — that
1680
+ * is what `@livekit/components-react`'s `<RoomAudioRenderer />` exists
1681
+ * to do. Without this a call connects, the roster is right, video
1682
+ * flows, and nobody hears anything. The peer-to-peer mesh always did
1683
+ * this (see `webrtc-browser.ts`); the SFU path has to as well.
1684
+ *
1685
+ * Empty on React Native, where there is no DOM and LiveKit routes
1686
+ * audio through the native audio session instead.
1687
+ */
1688
+ private readonly audioSinks;
1666
1689
  constructor(opts: CallRoomOptions);
1667
1690
  getStatus(): CallRoomStatus;
1668
1691
  onStatus(fn: (status: CallRoomStatus) => void): Unsubscribe;
@@ -1693,6 +1716,16 @@ declare class CallRoom {
1693
1716
  isMicrophoneEnabled(): boolean;
1694
1717
  private withLocal;
1695
1718
  private bind;
1719
+ /**
1720
+ * Play a remote audio track through a hidden element.
1721
+ *
1722
+ * No-ops for video (the UI renders that) and on React Native, where
1723
+ * there is no `document` and the native audio session handles
1724
+ * playback.
1725
+ */
1726
+ private playAudio;
1727
+ /** Tear a sink down, so a departed peer stops holding an element. */
1728
+ private stopAudio;
1696
1729
  private toParticipant;
1697
1730
  private teardown;
1698
1731
  private setStatus;
@@ -1844,7 +1877,7 @@ declare class AuthError extends ApiError {
1844
1877
  declare function isWebRtcAvailable(): boolean;
1845
1878
  declare function createBrowserWebRtcAdapter(): WebRtcAdapter;
1846
1879
 
1847
- declare const version = "2.11.0";
1880
+ declare const version = "2.12.1";
1848
1881
 
1849
1882
  declare function safeUuid(): string;
1850
1883
 
package/dist/index.d.ts CHANGED
@@ -1452,8 +1452,18 @@ declare class UsersResource {
1452
1452
  *
1453
1453
  * Deliberately narrow — only what {@link CallRoom} actually touches.
1454
1454
  */
1455
- /** A media track. Opaque here; the platform renderer consumes it. */
1456
- type LiveKitTrack = object;
1455
+ /**
1456
+ * A media track.
1457
+ *
1458
+ * Mostly opaque — the platform renderer consumes video. Audio is the
1459
+ * exception: {@link CallRoom} attaches it itself on the web, because
1460
+ * livekit-client does not play remote audio for you.
1461
+ */
1462
+ interface LiveKitTrack {
1463
+ kind?: string;
1464
+ attach?: () => HTMLMediaElement;
1465
+ detach?: (element?: HTMLMediaElement) => unknown;
1466
+ }
1457
1467
  interface LiveKitPublication {
1458
1468
  track?: LiveKitTrack | null | undefined;
1459
1469
  isMuted?: boolean;
@@ -1663,6 +1673,19 @@ declare class CallRoom {
1663
1673
  private readonly errorListeners;
1664
1674
  /** Bound once so `off()` in teardown removes the same references. */
1665
1675
  private readonly onRoomChange;
1676
+ /**
1677
+ * Hidden `<audio>` elements playing each remote audio track.
1678
+ *
1679
+ * livekit-client does NOT play remote audio for you on the web — that
1680
+ * is what `@livekit/components-react`'s `<RoomAudioRenderer />` exists
1681
+ * to do. Without this a call connects, the roster is right, video
1682
+ * flows, and nobody hears anything. The peer-to-peer mesh always did
1683
+ * this (see `webrtc-browser.ts`); the SFU path has to as well.
1684
+ *
1685
+ * Empty on React Native, where there is no DOM and LiveKit routes
1686
+ * audio through the native audio session instead.
1687
+ */
1688
+ private readonly audioSinks;
1666
1689
  constructor(opts: CallRoomOptions);
1667
1690
  getStatus(): CallRoomStatus;
1668
1691
  onStatus(fn: (status: CallRoomStatus) => void): Unsubscribe;
@@ -1693,6 +1716,16 @@ declare class CallRoom {
1693
1716
  isMicrophoneEnabled(): boolean;
1694
1717
  private withLocal;
1695
1718
  private bind;
1719
+ /**
1720
+ * Play a remote audio track through a hidden element.
1721
+ *
1722
+ * No-ops for video (the UI renders that) and on React Native, where
1723
+ * there is no `document` and the native audio session handles
1724
+ * playback.
1725
+ */
1726
+ private playAudio;
1727
+ /** Tear a sink down, so a departed peer stops holding an element. */
1728
+ private stopAudio;
1696
1729
  private toParticipant;
1697
1730
  private teardown;
1698
1731
  private setStatus;
@@ -1844,7 +1877,7 @@ declare class AuthError extends ApiError {
1844
1877
  declare function isWebRtcAvailable(): boolean;
1845
1878
  declare function createBrowserWebRtcAdapter(): WebRtcAdapter;
1846
1879
 
1847
- declare const version = "2.11.0";
1880
+ declare const version = "2.12.1";
1848
1881
 
1849
1882
  declare function safeUuid(): string;
1850
1883
 
package/dist/index.js CHANGED
@@ -1675,6 +1675,19 @@ var CallRoom = class {
1675
1675
  errorListeners = /* @__PURE__ */ new Set();
1676
1676
  /** Bound once so `off()` in teardown removes the same references. */
1677
1677
  onRoomChange = () => this.emitParticipants();
1678
+ /**
1679
+ * Hidden `<audio>` elements playing each remote audio track.
1680
+ *
1681
+ * livekit-client does NOT play remote audio for you on the web — that
1682
+ * is what `@livekit/components-react`'s `<RoomAudioRenderer />` exists
1683
+ * to do. Without this a call connects, the roster is right, video
1684
+ * flows, and nobody hears anything. The peer-to-peer mesh always did
1685
+ * this (see `webrtc-browser.ts`); the SFU path has to as well.
1686
+ *
1687
+ * Empty on React Native, where there is no DOM and LiveKit routes
1688
+ * audio through the native audio session instead.
1689
+ */
1690
+ audioSinks = /* @__PURE__ */ new Map();
1678
1691
  constructor(opts) {
1679
1692
  this.livekit = opts.livekit;
1680
1693
  this.tokenProvider = opts.tokenProvider;
@@ -1819,6 +1832,14 @@ var CallRoom = class {
1819
1832
  ]) {
1820
1833
  if (event) room.on(event, this.onRoomChange);
1821
1834
  }
1835
+ const subscribed = RoomEvent["TrackSubscribed"];
1836
+ if (subscribed) {
1837
+ room.on(subscribed, ((track) => this.playAudio(track)));
1838
+ }
1839
+ const unsubscribed = RoomEvent["TrackUnsubscribed"];
1840
+ if (unsubscribed) {
1841
+ room.on(unsubscribed, ((track) => this.stopAudio(track)));
1842
+ }
1822
1843
  const disconnected = RoomEvent["Disconnected"];
1823
1844
  if (disconnected) {
1824
1845
  room.on(disconnected, () => {
@@ -1827,6 +1848,38 @@ var CallRoom = class {
1827
1848
  });
1828
1849
  }
1829
1850
  }
1851
+ /**
1852
+ * Play a remote audio track through a hidden element.
1853
+ *
1854
+ * No-ops for video (the UI renders that) and on React Native, where
1855
+ * there is no `document` and the native audio session handles
1856
+ * playback.
1857
+ */
1858
+ playAudio(track) {
1859
+ if (typeof document === "undefined") return;
1860
+ if (track?.kind !== "audio" || typeof track.attach !== "function") return;
1861
+ if (this.audioSinks.has(track)) return;
1862
+ try {
1863
+ const element = track.attach();
1864
+ element.autoplay = true;
1865
+ element.style.display = "none";
1866
+ document.body.appendChild(element);
1867
+ this.audioSinks.set(track, element);
1868
+ } catch (err) {
1869
+ this.emitError(new Error(`could not play remote audio: ${String(err)}`));
1870
+ }
1871
+ }
1872
+ /** Tear a sink down, so a departed peer stops holding an element. */
1873
+ stopAudio(track) {
1874
+ const element = this.audioSinks.get(track);
1875
+ if (!element) return;
1876
+ this.audioSinks.delete(track);
1877
+ try {
1878
+ track.detach?.(element);
1879
+ } catch {
1880
+ }
1881
+ element.remove();
1882
+ }
1830
1883
  toParticipant(participant, isSelf) {
1831
1884
  const cameraSource = this.livekit.Track.Source["Camera"] ?? "camera";
1832
1885
  const publication = participant.getTrackPublication(cameraSource);
@@ -1848,6 +1901,7 @@ var CallRoom = class {
1848
1901
  this.room = null;
1849
1902
  this.selfId = null;
1850
1903
  this.holders = 0;
1904
+ for (const track of [...this.audioSinks.keys()]) this.stopAudio(track);
1851
1905
  if (room) {
1852
1906
  try {
1853
1907
  await room.disconnect();
@@ -2205,7 +2259,7 @@ var Poolse = class {
2205
2259
  };
2206
2260
 
2207
2261
  // src/version.ts
2208
- var version = "2.11.0";
2262
+ var version = "2.12.1";
2209
2263
 
2210
2264
  export { ApiError, AttachmentHandle, AttachmentsResource, AuthError, CallRoom, CallTokensResource, CallsResource, ConversationChannel, ConversationHandle, ConversationMessages, ConversationsResource, DevicesResource, IceServersResource, MeResource, MessageHandle, MessagesResource, NetworkError, POOLSE_API_URL, Poolse, PoolseError, PoolseRealtime, RateLimitedError, UserChannel, UsersResource, VoiceRoom, createBrowserWebRtcAdapter, isWebRtcAvailable, safeUuid, version };
2211
2265
  //# sourceMappingURL=index.js.map