@maravilla-labs/platform 0.1.27 → 0.1.28

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.ts CHANGED
@@ -1,3 +1,52 @@
1
+ import { LocalParticipant } from 'livekit-client';
2
+
3
+ /**
4
+ * Media service for video/audio room management.
5
+ *
6
+ * In production (Deno runtime) calls go through `Deno.core.ops`.
7
+ * In development they are proxied as HTTP requests to the dev-server.
8
+ */
9
+ interface MediaRoomInfo {
10
+ name: string;
11
+ numParticipants: number;
12
+ maxParticipants: number;
13
+ createdAt: number;
14
+ active: boolean;
15
+ }
16
+ interface MediaRoomInfoSettings {
17
+ maxParticipants?: number;
18
+ emptyTimeoutSecs?: number;
19
+ }
20
+ interface MediaParticipantInfo {
21
+ identity: string;
22
+ name: string;
23
+ canPublish?: boolean;
24
+ canSubscribe?: boolean;
25
+ canPublishData?: boolean;
26
+ }
27
+ interface MediaTokenResult {
28
+ token: string;
29
+ url: string;
30
+ }
31
+ interface MediaService {
32
+ createRoom(roomId: string, settings?: MediaRoomInfoSettings): Promise<MediaRoomInfo>;
33
+ deleteRoom(roomId: string): Promise<void>;
34
+ listRooms(): Promise<MediaRoomInfo[]>;
35
+ generateToken(roomId: string, participant: MediaParticipantInfo): Promise<MediaTokenResult>;
36
+ mediaUrl(): Promise<string | null>;
37
+ }
38
+ declare class RemoteMediaService implements MediaService {
39
+ private baseUrl;
40
+ private headers;
41
+ constructor(baseUrl: string, headers: Record<string, string>);
42
+ private fetch;
43
+ createRoom(roomId: string, settings?: MediaRoomInfoSettings): Promise<MediaRoomInfo>;
44
+ deleteRoom(roomId: string): Promise<void>;
45
+ listRooms(): Promise<MediaRoomInfo[]>;
46
+ generateToken(roomId: string, participant: MediaParticipantInfo): Promise<MediaTokenResult>;
47
+ mediaUrl(): Promise<string | null>;
48
+ }
49
+
1
50
  /**
2
51
  * Key-Value namespace interface for storing and retrieving data.
3
52
  * Similar to Cloudflare Workers KV API for familiar developer experience.
@@ -528,6 +577,8 @@ interface PlatformEnv {
528
577
  interface Platform {
529
578
  /** Environment containing all available platform services */
530
579
  env: PlatformEnv;
580
+ /** Media service for video/audio room management (optional — available when media is configured) */
581
+ media?: MediaService;
531
582
  }
532
583
 
533
584
  interface RenEvent {
@@ -538,6 +589,9 @@ interface RenEvent {
538
589
  ts?: number;
539
590
  src?: string;
540
591
  ns?: string;
592
+ ch?: string;
593
+ data?: any;
594
+ uid?: string;
541
595
  [extra: string]: any;
542
596
  }
543
597
  interface RenClientOptions {
@@ -574,6 +628,192 @@ declare function renFetch(input: string | URL | Request, init?: RequestInit, cli
574
628
  declare function storageUpload(path: string, file: Blob | File, clientId?: string): Promise<any>;
575
629
  declare function storageDelete(path: string, clientId?: string): Promise<any>;
576
630
 
631
+ interface RealtimeEvent {
632
+ event: string;
633
+ channel: string;
634
+ data?: any;
635
+ from?: string;
636
+ userId?: string;
637
+ ts?: number;
638
+ metadata?: any;
639
+ }
640
+ interface PresenceMember {
641
+ userId: string;
642
+ metadata?: any;
643
+ lastSeen?: number;
644
+ }
645
+ interface RealtimeClientOptions {
646
+ /** WebSocket endpoint (default: auto-detect) */
647
+ wsEndpoint?: string;
648
+ /** Client ID (persistent across sessions) */
649
+ clientId?: string;
650
+ /** Auto-reconnect on disconnect (default: true) */
651
+ autoReconnect?: boolean;
652
+ /** Max reconnect backoff in ms (default: 15000) */
653
+ maxBackoffMs?: number;
654
+ /** Enable debug logging (default: false) */
655
+ debug?: boolean;
656
+ }
657
+ type EventCallback$1 = (event: RealtimeEvent) => void;
658
+ type Unsubscribe = () => void;
659
+ declare class RealtimeClient {
660
+ private wsEndpoint;
661
+ private clientId;
662
+ private ws;
663
+ private closed;
664
+ private attempt;
665
+ private autoReconnect;
666
+ private maxBackoff;
667
+ private debug;
668
+ private channelListeners;
669
+ private globalListeners;
670
+ private presenceListeners;
671
+ private subscribedChannels;
672
+ private pendingMessages;
673
+ constructor(opts?: RealtimeClientOptions);
674
+ private detectEndpoint;
675
+ private log;
676
+ /** Connect to the realtime WebSocket server */
677
+ connect(): void;
678
+ private scheduleReconnect;
679
+ private sendRaw;
680
+ private dispatch;
681
+ /** Subscribe to messages on a channel */
682
+ subscribe(channel: string, callback: EventCallback$1, options?: {
683
+ token?: string;
684
+ }): Unsubscribe;
685
+ /** Listen to all events across all channels */
686
+ onAny(callback: EventCallback$1): Unsubscribe;
687
+ /** Publish a message to a channel */
688
+ publish(channel: string, data: any, options?: {
689
+ userId?: string;
690
+ }): void;
691
+ /** Get a presence handle for a channel */
692
+ presence(channel: string): {
693
+ /** Join the channel with presence */
694
+ join: (userId: string, metadata?: any) => void;
695
+ /** Leave the channel */
696
+ leave: () => void;
697
+ /** Listen for users joining */
698
+ onJoin: (callback: (member: PresenceMember) => void) => Unsubscribe;
699
+ /** Listen for users leaving */
700
+ onLeave: (callback: (member: PresenceMember) => void) => Unsubscribe;
701
+ };
702
+ /** Get current client ID */
703
+ getClientId(): string;
704
+ /** Check if connected */
705
+ isConnected(): boolean;
706
+ /** Disconnect and stop reconnecting */
707
+ disconnect(): void;
708
+ }
709
+
710
+ declare enum MediaRoomEvent {
711
+ Connected = "connected",
712
+ Reconnecting = "reconnecting",
713
+ Reconnected = "reconnected",
714
+ Disconnected = "disconnected",
715
+ ParticipantJoined = "participantJoined",
716
+ ParticipantLeft = "participantLeft",
717
+ TrackSubscribed = "trackSubscribed",
718
+ TrackUnsubscribed = "trackUnsubscribed",
719
+ TrackMuted = "trackMuted",
720
+ TrackUnmuted = "trackUnmuted",
721
+ ActiveSpeakersChanged = "activeSpeakersChanged",
722
+ DataReceived = "dataReceived",
723
+ RecordingStatusChanged = "recordingStatusChanged",
724
+ MediaDevicesChanged = "mediaDevicesChanged"
725
+ }
726
+ type TrackSource = 'camera' | 'microphone' | 'screen_share' | 'screen_share_audio';
727
+ type TrackKind = 'audio' | 'video';
728
+ interface MediaTrackPublication {
729
+ trackSid: string;
730
+ source: TrackSource;
731
+ kind: TrackKind;
732
+ muted: boolean;
733
+ track?: MediaStreamTrack;
734
+ }
735
+ interface MediaParticipant {
736
+ identity: string;
737
+ name?: string;
738
+ metadata?: string;
739
+ isSpeaking: boolean;
740
+ audioLevel: number;
741
+ tracks: MediaTrackPublication[];
742
+ }
743
+ interface VideoResolution {
744
+ width: number;
745
+ height: number;
746
+ frameRate?: number;
747
+ }
748
+ interface MediaRoomOptions {
749
+ autoSubscribe?: boolean;
750
+ adaptiveStream?: boolean;
751
+ dynacast?: boolean;
752
+ }
753
+ /** Attach a media track to a video or audio element */
754
+ declare function attachTrack(track: MediaStreamTrack, element: HTMLVideoElement | HTMLAudioElement): void;
755
+ /** Detach media from an element */
756
+ declare function detachTrack(element: HTMLVideoElement | HTMLAudioElement): void;
757
+ declare class MediaLocalParticipant implements MediaParticipant {
758
+ private lp;
759
+ /** @internal */
760
+ constructor(lp: LocalParticipant);
761
+ get identity(): string;
762
+ get name(): string | undefined;
763
+ get metadata(): string | undefined;
764
+ get isSpeaking(): boolean;
765
+ get audioLevel(): number;
766
+ get tracks(): MediaTrackPublication[];
767
+ get isCameraEnabled(): boolean;
768
+ enableCamera(options?: {
769
+ deviceId?: string;
770
+ resolution?: VideoResolution;
771
+ }): Promise<void>;
772
+ disableCamera(): Promise<void>;
773
+ get isMicrophoneEnabled(): boolean;
774
+ enableMicrophone(options?: {
775
+ deviceId?: string;
776
+ }): Promise<void>;
777
+ disableMicrophone(): Promise<void>;
778
+ get isScreenShareEnabled(): boolean;
779
+ enableScreenShare(options?: {
780
+ audio?: boolean;
781
+ }): Promise<void>;
782
+ disableScreenShare(): Promise<void>;
783
+ setName(name: string): Promise<void>;
784
+ setMetadata(metadata: string): Promise<void>;
785
+ sendData(data: Uint8Array, options?: {
786
+ reliable?: boolean;
787
+ }): Promise<void>;
788
+ }
789
+ type EventCallback = (...args: any[]) => void;
790
+ declare class MediaRoom {
791
+ private room;
792
+ private listeners;
793
+ private _localParticipant;
794
+ constructor();
795
+ connect(url: string, token: string, options?: MediaRoomOptions): Promise<void>;
796
+ disconnect(): Promise<void>;
797
+ get state(): 'disconnected' | 'connecting' | 'connected' | 'reconnecting';
798
+ get localParticipant(): MediaLocalParticipant;
799
+ get participants(): Map<string, MediaParticipant>;
800
+ get activeSpeakers(): MediaParticipant[];
801
+ get name(): string;
802
+ get numParticipants(): number;
803
+ get isRecording(): boolean;
804
+ on(event: MediaRoomEvent, callback: EventCallback): this;
805
+ off(event: MediaRoomEvent, callback: EventCallback): this;
806
+ private emit;
807
+ switchCamera(deviceId: string): Promise<void>;
808
+ switchMicrophone(deviceId: string): Promise<void>;
809
+ switchSpeaker(deviceId: string): Promise<void>;
810
+ static getDevices(): Promise<MediaDeviceInfo[]>;
811
+ static getCameras(): Promise<MediaDeviceInfo[]>;
812
+ static getMicrophones(): Promise<MediaDeviceInfo[]>;
813
+ static getSpeakers(): Promise<MediaDeviceInfo[]>;
814
+ private wireEvents;
815
+ }
816
+
577
817
  /**
578
818
  * @fileoverview Maravilla Platform SDK
579
819
  *
@@ -694,4 +934,4 @@ declare function getPlatform(options?: {
694
934
  */
695
935
  declare function clearPlatformCache(): void;
696
936
 
697
- export { type Database, type DbFindOptions, type KvListResult, type KvNamespace, type Platform, type PlatformEnv, RenClient, type RenClientOptions, type RenEvent, type Storage$1 as Storage, type StoragePutStreamSource, clearPlatformCache, getOrCreateClientId, getPlatform, renFetch, storageDelete, storageUpload };
937
+ export { type Database, type DbFindOptions, type KvListResult, type KvNamespace, MediaLocalParticipant, type MediaParticipant, type MediaParticipantInfo, MediaRoom, MediaRoomEvent, type MediaRoomInfo, type MediaRoomInfoSettings, type MediaRoomOptions, type MediaService, type MediaTokenResult, type MediaTrackPublication, type Platform, type PlatformEnv, type PresenceMember, RealtimeClient, type RealtimeClientOptions, type RealtimeEvent, RemoteMediaService, RenClient, type RenClientOptions, type RenEvent, type Storage$1 as Storage, type StoragePutStreamSource, type TrackKind, type TrackSource, type VideoResolution, attachTrack, clearPlatformCache, detachTrack, getOrCreateClientId, getPlatform, renFetch, storageDelete, storageUpload };