@poolse/sdk 2.12.0 → 2.13.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.
package/dist/index.d.cts CHANGED
@@ -1452,12 +1452,41 @@ 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;
1460
1470
  isSubscribed?: boolean;
1471
+ /**
1472
+ * The same track typed as video, when it is one.
1473
+ *
1474
+ * Separate from `track` because only this side carries
1475
+ * `restartTrack`, which is how the camera is flipped: LiveKit
1476
+ * re-acquires the capture device under the existing publication, so
1477
+ * the far side sees the picture change without a renegotiation and
1478
+ * without the tile blanking.
1479
+ */
1480
+ videoTrack?: LiveKitLocalVideoTrack | null | undefined;
1481
+ }
1482
+ /** Which camera a video track is capturing from. */
1483
+ type CameraFacing = 'user' | 'environment';
1484
+ /** The slice of LiveKit's `LocalVideoTrack` used to flip the camera. */
1485
+ interface LiveKitLocalVideoTrack {
1486
+ restartTrack?(constraints?: {
1487
+ facingMode?: CameraFacing;
1488
+ deviceId?: string;
1489
+ }): Promise<unknown>;
1461
1490
  }
1462
1491
  interface LiveKitParticipant {
1463
1492
  /** The poolse user id — we mint tokens with `sub` set to it. */
@@ -1469,7 +1498,14 @@ interface LiveKitParticipant {
1469
1498
  getTrackPublication(source: string): LiveKitPublication | undefined;
1470
1499
  }
1471
1500
  interface LiveKitLocalParticipant extends LiveKitParticipant {
1472
- setCameraEnabled(enabled: boolean): Promise<unknown>;
1501
+ /**
1502
+ * `options` carries the capture constraints. It is how the call opens
1503
+ * on the front camera rather than whatever the OS picks by default,
1504
+ * which on Android is routinely the rear one.
1505
+ */
1506
+ setCameraEnabled(enabled: boolean, options?: {
1507
+ facingMode?: CameraFacing;
1508
+ }): Promise<unknown>;
1473
1509
  setMicrophoneEnabled(enabled: boolean): Promise<unknown>;
1474
1510
  }
1475
1511
  interface LiveKitRoomHandle {
@@ -1591,6 +1627,22 @@ interface CallRoomOptions {
1591
1627
  video?: boolean;
1592
1628
  /** Start muted. */
1593
1629
  muted?: boolean;
1630
+ /**
1631
+ * Which camera to open with. Defaults to the front one — a call is a
1632
+ * conversation, so the selfie camera is what anyone expects.
1633
+ */
1634
+ facing?: CameraFacing;
1635
+ /**
1636
+ * How long the last participant may sit alone before the call is
1637
+ * declared over, in milliseconds. Defaults to 1500. Pass `0` to
1638
+ * disable and keep the call open indefinitely.
1639
+ *
1640
+ * The delay is not cosmetic. Two people hanging up within a frame of
1641
+ * each other, or an SFU reconnect that briefly empties the roster,
1642
+ * would both otherwise trip an immediate check — and a call that ends
1643
+ * itself during a half-second blip is worse than one that lingers.
1644
+ */
1645
+ aloneGraceMs?: number;
1594
1646
  }
1595
1647
 
1596
1648
  /**
@@ -1654,20 +1706,62 @@ declare class CallRoom {
1654
1706
  private readonly tokenProvider;
1655
1707
  private readonly startWithVideo;
1656
1708
  private readonly startMuted;
1709
+ private readonly aloneGraceMs;
1710
+ private facing;
1657
1711
  private room;
1658
1712
  private status;
1659
1713
  private selfId;
1660
1714
  private holders;
1715
+ /**
1716
+ * Whether anyone else has ever been on this call.
1717
+ *
1718
+ * The whole point of the alone check is to end a call the other side
1719
+ * has vanished from, and "vanished" is only meaningful once they were
1720
+ * here. Without this flag the caller who connects first — alone, by
1721
+ * definition, for as long as it takes the callee to join — would end
1722
+ * their own call before it ever started.
1723
+ */
1724
+ private hasSeenPeer;
1725
+ /** Pending alone verdict, cleared the moment anyone shows up. */
1726
+ private aloneTimer;
1661
1727
  private readonly statusListeners;
1662
1728
  private readonly participantListeners;
1663
1729
  private readonly errorListeners;
1730
+ private readonly aloneListeners;
1664
1731
  /** Bound once so `off()` in teardown removes the same references. */
1665
1732
  private readonly onRoomChange;
1733
+ /**
1734
+ * Hidden `<audio>` elements playing each remote audio track.
1735
+ *
1736
+ * livekit-client does NOT play remote audio for you on the web — that
1737
+ * is what `@livekit/components-react`'s `<RoomAudioRenderer />` exists
1738
+ * to do. Without this a call connects, the roster is right, video
1739
+ * flows, and nobody hears anything. The peer-to-peer mesh always did
1740
+ * this (see `webrtc-browser.ts`); the SFU path has to as well.
1741
+ *
1742
+ * Empty on React Native, where there is no DOM and LiveKit routes
1743
+ * audio through the native audio session instead.
1744
+ */
1745
+ private readonly audioSinks;
1666
1746
  constructor(opts: CallRoomOptions);
1667
1747
  getStatus(): CallRoomStatus;
1668
1748
  onStatus(fn: (status: CallRoomStatus) => void): Unsubscribe;
1669
1749
  onParticipants(fn: (participants: CallParticipant[]) => void): Unsubscribe;
1670
1750
  onError(fn: (error: Error) => void): Unsubscribe;
1751
+ /**
1752
+ * Everyone else has left and is not coming back.
1753
+ *
1754
+ * A call whose other participants hang up cleanly ends by signal:
1755
+ * `call:hangup` travels over poolse's own channel and the far side
1756
+ * closes its screen. This covers the case where no signal is ever
1757
+ * sent — the app was killed, the phone lost its network, the tab was
1758
+ * closed — where the only evidence is that the SFU roster emptied.
1759
+ *
1760
+ * Media is NOT torn down here. Whoever handles this owns hanging up,
1761
+ * because ending a call also means telling poolse about it, which is
1762
+ * a layer this class deliberately knows nothing about.
1763
+ */
1764
+ onAlone(fn: () => void): Unsubscribe;
1671
1765
  getParticipants(): CallParticipant[];
1672
1766
  /**
1673
1767
  * Connect to the SFU.
@@ -1687,16 +1781,53 @@ declare class CallRoom {
1687
1781
  * renegotiates underneath.
1688
1782
  */
1689
1783
  setCameraEnabled(enabled: boolean): Promise<void>;
1784
+ /**
1785
+ * Swap between the front and rear cameras.
1786
+ *
1787
+ * `restartTrack` re-acquires the capture device under the *existing*
1788
+ * publication, so the far side's tile keeps rendering throughout.
1789
+ * Unpublishing and republishing instead would blank their view and
1790
+ * force a renegotiation for what is, to them, the same camera.
1791
+ *
1792
+ * No-ops when the camera is off — there is nothing to restart, and
1793
+ * the next `setCameraEnabled(true)` will open whichever lens is
1794
+ * selected anyway.
1795
+ */
1796
+ switchCamera(): Promise<void>;
1797
+ /** Which camera the local video track is capturing from. */
1798
+ getFacingMode(): CameraFacing;
1690
1799
  /** Mute or unmute the microphone. */
1691
1800
  setMicrophoneEnabled(enabled: boolean): Promise<void>;
1692
1801
  isCameraEnabled(): boolean;
1693
1802
  isMicrophoneEnabled(): boolean;
1694
1803
  private withLocal;
1695
1804
  private bind;
1805
+ /**
1806
+ * Play a remote audio track through a hidden element.
1807
+ *
1808
+ * No-ops for video (the UI renders that) and on React Native, where
1809
+ * there is no `document` and the native audio session handles
1810
+ * playback.
1811
+ */
1812
+ private playAudio;
1813
+ /** Tear a sink down, so a departed peer stops holding an element. */
1814
+ private stopAudio;
1696
1815
  private toParticipant;
1697
1816
  private teardown;
1698
1817
  private setStatus;
1699
1818
  private emitParticipants;
1819
+ /**
1820
+ * Decide whether this client is the last one standing.
1821
+ *
1822
+ * Runs on every roster change. Three things have to be true before a
1823
+ * call is declared over: it is actually connected, somebody else was
1824
+ * here at some point, and nobody is here now — and even then the
1825
+ * verdict waits out {@link CallRoomOptions.aloneGraceMs}, so a
1826
+ * simultaneous hang-up or a momentary SFU reconnect does not read as
1827
+ * abandonment.
1828
+ */
1829
+ private checkAlone;
1830
+ private clearAloneTimer;
1700
1831
  private emitError;
1701
1832
  /** The local participant's poolse user id, once connected. */
1702
1833
  getSelfId(): string | null;
@@ -1844,8 +1975,8 @@ declare class AuthError extends ApiError {
1844
1975
  declare function isWebRtcAvailable(): boolean;
1845
1976
  declare function createBrowserWebRtcAdapter(): WebRtcAdapter;
1846
1977
 
1847
- declare const version = "2.12.0";
1978
+ declare const version = "2.13.0";
1848
1979
 
1849
1980
  declare function safeUuid(): string;
1850
1981
 
1851
- export { type AddMemberOptions, ApiError, type Attachment, type AttachmentDownloadResponse, AttachmentHandle, type AttachmentOptions, type AttachmentProgressEvent, type AttachmentStatus, type AttachmentUploadInput, type AttachmentUploadRequest, type AttachmentUploadResponse, AttachmentsResource, AuthError, type CallAccepted, type CallBusy, type CallCancelled, type CallConnection, type CallDeclined, type CallEnded, type CallMedia, type CallParticipant, CallRoom, type CallRoomOptions, type CallRoomStatus, CallTokensResource, CallsResource, type CheckedLiveKitModule, type Conversation, ConversationChannel, type ConversationCreateRequest, type ConversationCreatedEvent, ConversationHandle, type ConversationList, ConversationMessages, type ConversationType, type ConversationUpdateRequest, type ConversationUpdatedEvent, ConversationsResource, type Device, type DeviceEnvironment, type DevicePlatform, DevicesResource, type ErrorEnvelope, type IceServerResponse, IceServersResource, type IncomingCall, type IsoDateTime, type LiveKitModule, type LiveKitParticipant, type LiveKitPublication, type LiveKitRoomHandle, type LiveKitTrack, type LiveKitTrackReference, type Me, MeResource, type MemberReadEvent, type MemberRole, type Membership, type MembershipCreateRequest, type MembershipList, type MentionEvent, type Message, type MessageCreateRequest, type MessageDeletedEvent, MessageHandle, type MessageList, type MessageNewEvent, type MessageType, type MessageUpdateRequest, type MessageUpdatedEvent, MessagesResource, NetworkError, type OutgoingCall, POOLSE_API_URL, Poolse, type PoolseConfig, PoolseError, PoolseRealtime, type PoolseUserProfile, type PresenceSnapshot, type QuotedMessagePreview, RateLimitedError, type ReactionEvent, type ReactionRequest, type ReadRequest, type RealtimeStatus, type RegisterDeviceRequest, type TypingEvent, type Unsubscribe$1 as Unsubscribe, UserChannel, UsersResource, type Uuid, type VoiceCandidate, type VoiceDescription, type VoiceIceServer, type VoiceParticipant, type VoicePeerConnection, VoiceRoom, type VoiceRoomOptions, type VoiceStatus, type VoiceStream, type VoiceTrack, type WebRtcAdapter, createBrowserWebRtcAdapter, isWebRtcAvailable, safeUuid, version };
1982
+ export { type AddMemberOptions, ApiError, type Attachment, type AttachmentDownloadResponse, AttachmentHandle, type AttachmentOptions, type AttachmentProgressEvent, type AttachmentStatus, type AttachmentUploadInput, type AttachmentUploadRequest, type AttachmentUploadResponse, AttachmentsResource, AuthError, type CallAccepted, type CallBusy, type CallCancelled, type CallConnection, type CallDeclined, type CallEnded, type CallMedia, type CallParticipant, CallRoom, type CallRoomOptions, type CallRoomStatus, CallTokensResource, CallsResource, type CameraFacing, type CheckedLiveKitModule, type Conversation, ConversationChannel, type ConversationCreateRequest, type ConversationCreatedEvent, ConversationHandle, type ConversationList, ConversationMessages, type ConversationType, type ConversationUpdateRequest, type ConversationUpdatedEvent, ConversationsResource, type Device, type DeviceEnvironment, type DevicePlatform, DevicesResource, type ErrorEnvelope, type IceServerResponse, IceServersResource, type IncomingCall, type IsoDateTime, type LiveKitLocalVideoTrack, type LiveKitModule, type LiveKitParticipant, type LiveKitPublication, type LiveKitRoomHandle, type LiveKitTrack, type LiveKitTrackReference, type Me, MeResource, type MemberReadEvent, type MemberRole, type Membership, type MembershipCreateRequest, type MembershipList, type MentionEvent, type Message, type MessageCreateRequest, type MessageDeletedEvent, MessageHandle, type MessageList, type MessageNewEvent, type MessageType, type MessageUpdateRequest, type MessageUpdatedEvent, MessagesResource, NetworkError, type OutgoingCall, POOLSE_API_URL, Poolse, type PoolseConfig, PoolseError, PoolseRealtime, type PoolseUserProfile, type PresenceSnapshot, type QuotedMessagePreview, RateLimitedError, type ReactionEvent, type ReactionRequest, type ReadRequest, type RealtimeStatus, type RegisterDeviceRequest, type TypingEvent, type Unsubscribe$1 as Unsubscribe, UserChannel, UsersResource, type Uuid, type VoiceCandidate, type VoiceDescription, type VoiceIceServer, type VoiceParticipant, type VoicePeerConnection, VoiceRoom, type VoiceRoomOptions, type VoiceStatus, type VoiceStream, type VoiceTrack, type WebRtcAdapter, createBrowserWebRtcAdapter, isWebRtcAvailable, safeUuid, version };
package/dist/index.d.ts CHANGED
@@ -1452,12 +1452,41 @@ 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;
1460
1470
  isSubscribed?: boolean;
1471
+ /**
1472
+ * The same track typed as video, when it is one.
1473
+ *
1474
+ * Separate from `track` because only this side carries
1475
+ * `restartTrack`, which is how the camera is flipped: LiveKit
1476
+ * re-acquires the capture device under the existing publication, so
1477
+ * the far side sees the picture change without a renegotiation and
1478
+ * without the tile blanking.
1479
+ */
1480
+ videoTrack?: LiveKitLocalVideoTrack | null | undefined;
1481
+ }
1482
+ /** Which camera a video track is capturing from. */
1483
+ type CameraFacing = 'user' | 'environment';
1484
+ /** The slice of LiveKit's `LocalVideoTrack` used to flip the camera. */
1485
+ interface LiveKitLocalVideoTrack {
1486
+ restartTrack?(constraints?: {
1487
+ facingMode?: CameraFacing;
1488
+ deviceId?: string;
1489
+ }): Promise<unknown>;
1461
1490
  }
1462
1491
  interface LiveKitParticipant {
1463
1492
  /** The poolse user id — we mint tokens with `sub` set to it. */
@@ -1469,7 +1498,14 @@ interface LiveKitParticipant {
1469
1498
  getTrackPublication(source: string): LiveKitPublication | undefined;
1470
1499
  }
1471
1500
  interface LiveKitLocalParticipant extends LiveKitParticipant {
1472
- setCameraEnabled(enabled: boolean): Promise<unknown>;
1501
+ /**
1502
+ * `options` carries the capture constraints. It is how the call opens
1503
+ * on the front camera rather than whatever the OS picks by default,
1504
+ * which on Android is routinely the rear one.
1505
+ */
1506
+ setCameraEnabled(enabled: boolean, options?: {
1507
+ facingMode?: CameraFacing;
1508
+ }): Promise<unknown>;
1473
1509
  setMicrophoneEnabled(enabled: boolean): Promise<unknown>;
1474
1510
  }
1475
1511
  interface LiveKitRoomHandle {
@@ -1591,6 +1627,22 @@ interface CallRoomOptions {
1591
1627
  video?: boolean;
1592
1628
  /** Start muted. */
1593
1629
  muted?: boolean;
1630
+ /**
1631
+ * Which camera to open with. Defaults to the front one — a call is a
1632
+ * conversation, so the selfie camera is what anyone expects.
1633
+ */
1634
+ facing?: CameraFacing;
1635
+ /**
1636
+ * How long the last participant may sit alone before the call is
1637
+ * declared over, in milliseconds. Defaults to 1500. Pass `0` to
1638
+ * disable and keep the call open indefinitely.
1639
+ *
1640
+ * The delay is not cosmetic. Two people hanging up within a frame of
1641
+ * each other, or an SFU reconnect that briefly empties the roster,
1642
+ * would both otherwise trip an immediate check — and a call that ends
1643
+ * itself during a half-second blip is worse than one that lingers.
1644
+ */
1645
+ aloneGraceMs?: number;
1594
1646
  }
1595
1647
 
1596
1648
  /**
@@ -1654,20 +1706,62 @@ declare class CallRoom {
1654
1706
  private readonly tokenProvider;
1655
1707
  private readonly startWithVideo;
1656
1708
  private readonly startMuted;
1709
+ private readonly aloneGraceMs;
1710
+ private facing;
1657
1711
  private room;
1658
1712
  private status;
1659
1713
  private selfId;
1660
1714
  private holders;
1715
+ /**
1716
+ * Whether anyone else has ever been on this call.
1717
+ *
1718
+ * The whole point of the alone check is to end a call the other side
1719
+ * has vanished from, and "vanished" is only meaningful once they were
1720
+ * here. Without this flag the caller who connects first — alone, by
1721
+ * definition, for as long as it takes the callee to join — would end
1722
+ * their own call before it ever started.
1723
+ */
1724
+ private hasSeenPeer;
1725
+ /** Pending alone verdict, cleared the moment anyone shows up. */
1726
+ private aloneTimer;
1661
1727
  private readonly statusListeners;
1662
1728
  private readonly participantListeners;
1663
1729
  private readonly errorListeners;
1730
+ private readonly aloneListeners;
1664
1731
  /** Bound once so `off()` in teardown removes the same references. */
1665
1732
  private readonly onRoomChange;
1733
+ /**
1734
+ * Hidden `<audio>` elements playing each remote audio track.
1735
+ *
1736
+ * livekit-client does NOT play remote audio for you on the web — that
1737
+ * is what `@livekit/components-react`'s `<RoomAudioRenderer />` exists
1738
+ * to do. Without this a call connects, the roster is right, video
1739
+ * flows, and nobody hears anything. The peer-to-peer mesh always did
1740
+ * this (see `webrtc-browser.ts`); the SFU path has to as well.
1741
+ *
1742
+ * Empty on React Native, where there is no DOM and LiveKit routes
1743
+ * audio through the native audio session instead.
1744
+ */
1745
+ private readonly audioSinks;
1666
1746
  constructor(opts: CallRoomOptions);
1667
1747
  getStatus(): CallRoomStatus;
1668
1748
  onStatus(fn: (status: CallRoomStatus) => void): Unsubscribe;
1669
1749
  onParticipants(fn: (participants: CallParticipant[]) => void): Unsubscribe;
1670
1750
  onError(fn: (error: Error) => void): Unsubscribe;
1751
+ /**
1752
+ * Everyone else has left and is not coming back.
1753
+ *
1754
+ * A call whose other participants hang up cleanly ends by signal:
1755
+ * `call:hangup` travels over poolse's own channel and the far side
1756
+ * closes its screen. This covers the case where no signal is ever
1757
+ * sent — the app was killed, the phone lost its network, the tab was
1758
+ * closed — where the only evidence is that the SFU roster emptied.
1759
+ *
1760
+ * Media is NOT torn down here. Whoever handles this owns hanging up,
1761
+ * because ending a call also means telling poolse about it, which is
1762
+ * a layer this class deliberately knows nothing about.
1763
+ */
1764
+ onAlone(fn: () => void): Unsubscribe;
1671
1765
  getParticipants(): CallParticipant[];
1672
1766
  /**
1673
1767
  * Connect to the SFU.
@@ -1687,16 +1781,53 @@ declare class CallRoom {
1687
1781
  * renegotiates underneath.
1688
1782
  */
1689
1783
  setCameraEnabled(enabled: boolean): Promise<void>;
1784
+ /**
1785
+ * Swap between the front and rear cameras.
1786
+ *
1787
+ * `restartTrack` re-acquires the capture device under the *existing*
1788
+ * publication, so the far side's tile keeps rendering throughout.
1789
+ * Unpublishing and republishing instead would blank their view and
1790
+ * force a renegotiation for what is, to them, the same camera.
1791
+ *
1792
+ * No-ops when the camera is off — there is nothing to restart, and
1793
+ * the next `setCameraEnabled(true)` will open whichever lens is
1794
+ * selected anyway.
1795
+ */
1796
+ switchCamera(): Promise<void>;
1797
+ /** Which camera the local video track is capturing from. */
1798
+ getFacingMode(): CameraFacing;
1690
1799
  /** Mute or unmute the microphone. */
1691
1800
  setMicrophoneEnabled(enabled: boolean): Promise<void>;
1692
1801
  isCameraEnabled(): boolean;
1693
1802
  isMicrophoneEnabled(): boolean;
1694
1803
  private withLocal;
1695
1804
  private bind;
1805
+ /**
1806
+ * Play a remote audio track through a hidden element.
1807
+ *
1808
+ * No-ops for video (the UI renders that) and on React Native, where
1809
+ * there is no `document` and the native audio session handles
1810
+ * playback.
1811
+ */
1812
+ private playAudio;
1813
+ /** Tear a sink down, so a departed peer stops holding an element. */
1814
+ private stopAudio;
1696
1815
  private toParticipant;
1697
1816
  private teardown;
1698
1817
  private setStatus;
1699
1818
  private emitParticipants;
1819
+ /**
1820
+ * Decide whether this client is the last one standing.
1821
+ *
1822
+ * Runs on every roster change. Three things have to be true before a
1823
+ * call is declared over: it is actually connected, somebody else was
1824
+ * here at some point, and nobody is here now — and even then the
1825
+ * verdict waits out {@link CallRoomOptions.aloneGraceMs}, so a
1826
+ * simultaneous hang-up or a momentary SFU reconnect does not read as
1827
+ * abandonment.
1828
+ */
1829
+ private checkAlone;
1830
+ private clearAloneTimer;
1700
1831
  private emitError;
1701
1832
  /** The local participant's poolse user id, once connected. */
1702
1833
  getSelfId(): string | null;
@@ -1844,8 +1975,8 @@ declare class AuthError extends ApiError {
1844
1975
  declare function isWebRtcAvailable(): boolean;
1845
1976
  declare function createBrowserWebRtcAdapter(): WebRtcAdapter;
1846
1977
 
1847
- declare const version = "2.12.0";
1978
+ declare const version = "2.13.0";
1848
1979
 
1849
1980
  declare function safeUuid(): string;
1850
1981
 
1851
- export { type AddMemberOptions, ApiError, type Attachment, type AttachmentDownloadResponse, AttachmentHandle, type AttachmentOptions, type AttachmentProgressEvent, type AttachmentStatus, type AttachmentUploadInput, type AttachmentUploadRequest, type AttachmentUploadResponse, AttachmentsResource, AuthError, type CallAccepted, type CallBusy, type CallCancelled, type CallConnection, type CallDeclined, type CallEnded, type CallMedia, type CallParticipant, CallRoom, type CallRoomOptions, type CallRoomStatus, CallTokensResource, CallsResource, type CheckedLiveKitModule, type Conversation, ConversationChannel, type ConversationCreateRequest, type ConversationCreatedEvent, ConversationHandle, type ConversationList, ConversationMessages, type ConversationType, type ConversationUpdateRequest, type ConversationUpdatedEvent, ConversationsResource, type Device, type DeviceEnvironment, type DevicePlatform, DevicesResource, type ErrorEnvelope, type IceServerResponse, IceServersResource, type IncomingCall, type IsoDateTime, type LiveKitModule, type LiveKitParticipant, type LiveKitPublication, type LiveKitRoomHandle, type LiveKitTrack, type LiveKitTrackReference, type Me, MeResource, type MemberReadEvent, type MemberRole, type Membership, type MembershipCreateRequest, type MembershipList, type MentionEvent, type Message, type MessageCreateRequest, type MessageDeletedEvent, MessageHandle, type MessageList, type MessageNewEvent, type MessageType, type MessageUpdateRequest, type MessageUpdatedEvent, MessagesResource, NetworkError, type OutgoingCall, POOLSE_API_URL, Poolse, type PoolseConfig, PoolseError, PoolseRealtime, type PoolseUserProfile, type PresenceSnapshot, type QuotedMessagePreview, RateLimitedError, type ReactionEvent, type ReactionRequest, type ReadRequest, type RealtimeStatus, type RegisterDeviceRequest, type TypingEvent, type Unsubscribe$1 as Unsubscribe, UserChannel, UsersResource, type Uuid, type VoiceCandidate, type VoiceDescription, type VoiceIceServer, type VoiceParticipant, type VoicePeerConnection, VoiceRoom, type VoiceRoomOptions, type VoiceStatus, type VoiceStream, type VoiceTrack, type WebRtcAdapter, createBrowserWebRtcAdapter, isWebRtcAvailable, safeUuid, version };
1982
+ export { type AddMemberOptions, ApiError, type Attachment, type AttachmentDownloadResponse, AttachmentHandle, type AttachmentOptions, type AttachmentProgressEvent, type AttachmentStatus, type AttachmentUploadInput, type AttachmentUploadRequest, type AttachmentUploadResponse, AttachmentsResource, AuthError, type CallAccepted, type CallBusy, type CallCancelled, type CallConnection, type CallDeclined, type CallEnded, type CallMedia, type CallParticipant, CallRoom, type CallRoomOptions, type CallRoomStatus, CallTokensResource, CallsResource, type CameraFacing, type CheckedLiveKitModule, type Conversation, ConversationChannel, type ConversationCreateRequest, type ConversationCreatedEvent, ConversationHandle, type ConversationList, ConversationMessages, type ConversationType, type ConversationUpdateRequest, type ConversationUpdatedEvent, ConversationsResource, type Device, type DeviceEnvironment, type DevicePlatform, DevicesResource, type ErrorEnvelope, type IceServerResponse, IceServersResource, type IncomingCall, type IsoDateTime, type LiveKitLocalVideoTrack, type LiveKitModule, type LiveKitParticipant, type LiveKitPublication, type LiveKitRoomHandle, type LiveKitTrack, type LiveKitTrackReference, type Me, MeResource, type MemberReadEvent, type MemberRole, type Membership, type MembershipCreateRequest, type MembershipList, type MentionEvent, type Message, type MessageCreateRequest, type MessageDeletedEvent, MessageHandle, type MessageList, type MessageNewEvent, type MessageType, type MessageUpdateRequest, type MessageUpdatedEvent, MessagesResource, NetworkError, type OutgoingCall, POOLSE_API_URL, Poolse, type PoolseConfig, PoolseError, PoolseRealtime, type PoolseUserProfile, type PresenceSnapshot, type QuotedMessagePreview, RateLimitedError, type ReactionEvent, type ReactionRequest, type ReadRequest, type RealtimeStatus, type RegisterDeviceRequest, type TypingEvent, type Unsubscribe$1 as Unsubscribe, UserChannel, UsersResource, type Uuid, type VoiceCandidate, type VoiceDescription, type VoiceIceServer, type VoiceParticipant, type VoicePeerConnection, VoiceRoom, type VoiceRoomOptions, type VoiceStatus, type VoiceStream, type VoiceTrack, type WebRtcAdapter, createBrowserWebRtcAdapter, isWebRtcAvailable, safeUuid, version };
package/dist/index.js CHANGED
@@ -1663,6 +1663,8 @@ var CallRoom = class {
1663
1663
  tokenProvider;
1664
1664
  startWithVideo;
1665
1665
  startMuted;
1666
+ aloneGraceMs;
1667
+ facing;
1666
1668
  room = null;
1667
1669
  status = "idle";
1668
1670
  selfId = null;
@@ -1670,16 +1672,44 @@ var CallRoom = class {
1670
1672
  // both hold the same call, and the second holder must not open a
1671
1673
  // second SFU connection or tear the first one down on leaving.
1672
1674
  holders = 0;
1675
+ /**
1676
+ * Whether anyone else has ever been on this call.
1677
+ *
1678
+ * The whole point of the alone check is to end a call the other side
1679
+ * has vanished from, and "vanished" is only meaningful once they were
1680
+ * here. Without this flag the caller who connects first — alone, by
1681
+ * definition, for as long as it takes the callee to join — would end
1682
+ * their own call before it ever started.
1683
+ */
1684
+ hasSeenPeer = false;
1685
+ /** Pending alone verdict, cleared the moment anyone shows up. */
1686
+ aloneTimer = null;
1673
1687
  statusListeners = /* @__PURE__ */ new Set();
1674
1688
  participantListeners = /* @__PURE__ */ new Set();
1675
1689
  errorListeners = /* @__PURE__ */ new Set();
1690
+ aloneListeners = /* @__PURE__ */ new Set();
1676
1691
  /** Bound once so `off()` in teardown removes the same references. */
1677
1692
  onRoomChange = () => this.emitParticipants();
1693
+ /**
1694
+ * Hidden `<audio>` elements playing each remote audio track.
1695
+ *
1696
+ * livekit-client does NOT play remote audio for you on the web — that
1697
+ * is what `@livekit/components-react`'s `<RoomAudioRenderer />` exists
1698
+ * to do. Without this a call connects, the roster is right, video
1699
+ * flows, and nobody hears anything. The peer-to-peer mesh always did
1700
+ * this (see `webrtc-browser.ts`); the SFU path has to as well.
1701
+ *
1702
+ * Empty on React Native, where there is no DOM and LiveKit routes
1703
+ * audio through the native audio session instead.
1704
+ */
1705
+ audioSinks = /* @__PURE__ */ new Map();
1678
1706
  constructor(opts) {
1679
1707
  this.livekit = opts.livekit;
1680
1708
  this.tokenProvider = opts.tokenProvider;
1681
1709
  this.startWithVideo = opts.video ?? false;
1682
1710
  this.startMuted = opts.muted ?? false;
1711
+ this.facing = opts.facing ?? "user";
1712
+ this.aloneGraceMs = opts.aloneGraceMs ?? 1500;
1683
1713
  }
1684
1714
  // ── observation ─────────────────────────────────────────────────────
1685
1715
  getStatus() {
@@ -1697,6 +1727,23 @@ var CallRoom = class {
1697
1727
  this.errorListeners.add(fn);
1698
1728
  return () => this.errorListeners.delete(fn);
1699
1729
  }
1730
+ /**
1731
+ * Everyone else has left and is not coming back.
1732
+ *
1733
+ * A call whose other participants hang up cleanly ends by signal:
1734
+ * `call:hangup` travels over poolse's own channel and the far side
1735
+ * closes its screen. This covers the case where no signal is ever
1736
+ * sent — the app was killed, the phone lost its network, the tab was
1737
+ * closed — where the only evidence is that the SFU roster emptied.
1738
+ *
1739
+ * Media is NOT torn down here. Whoever handles this owns hanging up,
1740
+ * because ending a call also means telling poolse about it, which is
1741
+ * a layer this class deliberately knows nothing about.
1742
+ */
1743
+ onAlone(fn) {
1744
+ this.aloneListeners.add(fn);
1745
+ return () => this.aloneListeners.delete(fn);
1746
+ }
1700
1747
  getParticipants() {
1701
1748
  if (!this.room) return [];
1702
1749
  const self = this.toParticipant(this.room.localParticipant, true);
@@ -1748,7 +1795,9 @@ var CallRoom = class {
1748
1795
  await room.connect(connection.url, connection.token);
1749
1796
  this.selfId = room.localParticipant.identity;
1750
1797
  await room.localParticipant.setMicrophoneEnabled(!this.startMuted);
1751
- if (this.startWithVideo) await room.localParticipant.setCameraEnabled(true);
1798
+ if (this.startWithVideo) {
1799
+ await room.localParticipant.setCameraEnabled(true, { facingMode: this.facing });
1800
+ }
1752
1801
  try {
1753
1802
  await room.startAudio?.();
1754
1803
  } catch {
@@ -1780,7 +1829,41 @@ var CallRoom = class {
1780
1829
  * renegotiates underneath.
1781
1830
  */
1782
1831
  async setCameraEnabled(enabled) {
1783
- await this.withLocal((local) => local.setCameraEnabled(enabled), "camera");
1832
+ await this.withLocal(
1833
+ (local) => enabled ? local.setCameraEnabled(true, { facingMode: this.facing }) : local.setCameraEnabled(false),
1834
+ "camera"
1835
+ );
1836
+ }
1837
+ /**
1838
+ * Swap between the front and rear cameras.
1839
+ *
1840
+ * `restartTrack` re-acquires the capture device under the *existing*
1841
+ * publication, so the far side's tile keeps rendering throughout.
1842
+ * Unpublishing and republishing instead would blank their view and
1843
+ * force a renegotiation for what is, to them, the same camera.
1844
+ *
1845
+ * No-ops when the camera is off — there is nothing to restart, and
1846
+ * the next `setCameraEnabled(true)` will open whichever lens is
1847
+ * selected anyway.
1848
+ */
1849
+ async switchCamera() {
1850
+ const room = this.room;
1851
+ if (!room) return;
1852
+ const source = this.livekit.Track.Source["Camera"] ?? "camera";
1853
+ const track = room.localParticipant.getTrackPublication(source)?.videoTrack;
1854
+ if (!track?.restartTrack) return;
1855
+ const next = this.facing === "user" ? "environment" : "user";
1856
+ try {
1857
+ await track.restartTrack({ facingMode: next });
1858
+ this.facing = next;
1859
+ this.emitParticipants();
1860
+ } catch (err) {
1861
+ this.emitError(new Error(`could not switch camera: ${String(err)}`));
1862
+ }
1863
+ }
1864
+ /** Which camera the local video track is capturing from. */
1865
+ getFacingMode() {
1866
+ return this.facing;
1784
1867
  }
1785
1868
  /** Mute or unmute the microphone. */
1786
1869
  async setMicrophoneEnabled(enabled) {
@@ -1819,6 +1902,14 @@ var CallRoom = class {
1819
1902
  ]) {
1820
1903
  if (event) room.on(event, this.onRoomChange);
1821
1904
  }
1905
+ const subscribed = RoomEvent["TrackSubscribed"];
1906
+ if (subscribed) {
1907
+ room.on(subscribed, ((track) => this.playAudio(track)));
1908
+ }
1909
+ const unsubscribed = RoomEvent["TrackUnsubscribed"];
1910
+ if (unsubscribed) {
1911
+ room.on(unsubscribed, ((track) => this.stopAudio(track)));
1912
+ }
1822
1913
  const disconnected = RoomEvent["Disconnected"];
1823
1914
  if (disconnected) {
1824
1915
  room.on(disconnected, () => {
@@ -1827,6 +1918,38 @@ var CallRoom = class {
1827
1918
  });
1828
1919
  }
1829
1920
  }
1921
+ /**
1922
+ * Play a remote audio track through a hidden element.
1923
+ *
1924
+ * No-ops for video (the UI renders that) and on React Native, where
1925
+ * there is no `document` and the native audio session handles
1926
+ * playback.
1927
+ */
1928
+ playAudio(track) {
1929
+ if (typeof document === "undefined") return;
1930
+ if (track?.kind !== "audio" || typeof track.attach !== "function") return;
1931
+ if (this.audioSinks.has(track)) return;
1932
+ try {
1933
+ const element = track.attach();
1934
+ element.autoplay = true;
1935
+ element.style.display = "none";
1936
+ document.body.appendChild(element);
1937
+ this.audioSinks.set(track, element);
1938
+ } catch (err) {
1939
+ this.emitError(new Error(`could not play remote audio: ${String(err)}`));
1940
+ }
1941
+ }
1942
+ /** Tear a sink down, so a departed peer stops holding an element. */
1943
+ stopAudio(track) {
1944
+ const element = this.audioSinks.get(track);
1945
+ if (!element) return;
1946
+ this.audioSinks.delete(track);
1947
+ try {
1948
+ track.detach?.(element);
1949
+ } catch {
1950
+ }
1951
+ element.remove();
1952
+ }
1830
1953
  toParticipant(participant, isSelf) {
1831
1954
  const cameraSource = this.livekit.Track.Source["Camera"] ?? "camera";
1832
1955
  const publication = participant.getTrackPublication(cameraSource);
@@ -1848,6 +1971,9 @@ var CallRoom = class {
1848
1971
  this.room = null;
1849
1972
  this.selfId = null;
1850
1973
  this.holders = 0;
1974
+ this.hasSeenPeer = false;
1975
+ this.clearAloneTimer();
1976
+ for (const track of [...this.audioSinks.keys()]) this.stopAudio(track);
1851
1977
  if (room) {
1852
1978
  try {
1853
1979
  await room.disconnect();
@@ -1865,6 +1991,39 @@ var CallRoom = class {
1865
1991
  emitParticipants() {
1866
1992
  const participants = this.getParticipants();
1867
1993
  for (const fn of this.participantListeners) fn(participants);
1994
+ this.checkAlone();
1995
+ }
1996
+ /**
1997
+ * Decide whether this client is the last one standing.
1998
+ *
1999
+ * Runs on every roster change. Three things have to be true before a
2000
+ * call is declared over: it is actually connected, somebody else was
2001
+ * here at some point, and nobody is here now — and even then the
2002
+ * verdict waits out {@link CallRoomOptions.aloneGraceMs}, so a
2003
+ * simultaneous hang-up or a momentary SFU reconnect does not read as
2004
+ * abandonment.
2005
+ */
2006
+ checkAlone() {
2007
+ if (this.aloneGraceMs <= 0) return;
2008
+ const others = this.room?.remoteParticipants.size ?? 0;
2009
+ if (others > 0) {
2010
+ this.hasSeenPeer = true;
2011
+ this.clearAloneTimer();
2012
+ return;
2013
+ }
2014
+ if (!this.hasSeenPeer || this.status !== "connected") return;
2015
+ if (this.aloneTimer) return;
2016
+ this.aloneTimer = setTimeout(() => {
2017
+ this.aloneTimer = null;
2018
+ if ((this.room?.remoteParticipants.size ?? 0) > 0) return;
2019
+ if (this.status !== "connected") return;
2020
+ for (const fn of this.aloneListeners) fn();
2021
+ }, this.aloneGraceMs);
2022
+ }
2023
+ clearAloneTimer() {
2024
+ if (!this.aloneTimer) return;
2025
+ clearTimeout(this.aloneTimer);
2026
+ this.aloneTimer = null;
1868
2027
  }
1869
2028
  emitError(error) {
1870
2029
  for (const fn of this.errorListeners) fn(error);
@@ -2205,7 +2364,7 @@ var Poolse = class {
2205
2364
  };
2206
2365
 
2207
2366
  // src/version.ts
2208
- var version = "2.12.0";
2367
+ var version = "2.13.0";
2209
2368
 
2210
2369
  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
2370
  //# sourceMappingURL=index.js.map