Hiyve Components - v1.0.0
    Preparing search index...

    Class HiyveStore

    Framework-agnostic state store for Hiyve WebRTC client.

    Exposes subscribe/getSnapshot for universal framework integration:

    • React: useSyncExternalStore
    • Vue: watch + ref
    • Svelte: readable store
    • Vanilla: direct subscribe
    Index

    Constructors

    Methods

    • Admit a user from the waiting room (owner only).

      Parameters

      • userId: string

      Returns Promise<void>

    • Attach a broadcast transport. The store routes dominant + hand-raised through it (publish + subscribe). Replaces any previously attached transport. Pass null to detach.

      Parameters

      Returns void

    • Connect to the active rooms SSE stream for real-time room discovery. The stream delivers snapshot, room-added, room-removed, and room-updated events.

      Parameters

      • streamUrl: string

        Full SSE endpoint URL (obtained from cloudClient.getActiveRoomsStreamUrl())

      Returns void

    • Connect to the user-files SSE stream for real-time file updates. Delivers snapshot, file-added, file-updated, file-removed, and resync events.

      Parameters

      • streamUrl: string

        Full SSE endpoint URL (obtained from cloudClient.getUserFilesStreamUrl())

      Returns void

    • Create a no-video (offline/signaling-only) room as the owner. Connects via signaling for chat, files, whiteboard, etc. — no WebRTC media.

      Parameters

      • roomName: string
      • userId: string

      Returns Promise<void>

    • Create a new folder at the given location.

      Parameters

      • location: string
      • OptionalroomName: string

      Returns Promise<void>

    • Delete a stored room by roomName.

      Parameters

      • roomName: string
      • userId: string

      Returns Promise<boolean>

    • Delete a user file by ID.

      Parameters

      • fileId: string

      Returns Promise<void>

    • Delete a folder at the given location.

      Parameters

      • location: string

      Returns Promise<void>

    • Fetch active rooms (one-shot query for late joiners).

      Parameters

      • cloudClient: { getActiveRooms(userId?: string): Promise<ActiveRoom[]> }
      • OptionaluserId: string

      Returns Promise<ActiveRoom[]>

    • Fetch all stored rooms for a user.

      Parameters

      • userId: string
      • Optionaloptions: { consumerOnly?: boolean; enabledOnly?: boolean; offlineOnly?: boolean }

      Returns Promise<StoredRoom[]>

    • Fetch all files across all rooms for a user (room owners only).

      Honors the share-patch guard window two ways:

      1. For any file whose ACL was optimistically patched in the last USER_FILES_SHARE_PATCH_GUARD_MS AND that the server still returns, the server's sharedWith / sharing fields are dropped from the fetched record and the local optimistic ACL is kept.
      2. For any guarded file that the server does NOT return, the prior local entry is preserved (re-added after the merge). This covers the recipient flow: when a teacher shares with a student, the student's LessonRoomShell broadcast handler calls upsertUserFileLocal to add the file locally; the student's next fetchUserFiles might race the cloud read replica which hasn't propagated the share yet — without (2) the file would be DROPPED from the student's slice and they'd have to force-refresh to see it. (2) also covers the unshared-and-removed-locally case: removeUserFileLocal sets a guard too, but the file is gone from prev.files so there's no prior to re-add — the guard there just stops a lagged server view from briefly resurrecting the file.

      Without this, the cloud's read replica (which lags the primary write by enough to routinely return the pre-share view) would clobber a fresh share/unshare any time a refetch ran inside the guard window — e.g. the periodic 30s safety-net refetch in lesson rooms, an explicit onRefresh call, or a remount-driven re-fetch. Other fields on the file (rename, move, content updates) are still merged through normally.

      Parameters

      • userId: string

      Returns Promise<UserFile[]>

    • Get the streaming URLs for the current stream.

      Returns Promise<string | null>

    • Get a presigned URL for a file.

      Parameters

      • fileId: string

        File identifier.

      • Optionaloptions: { stream?: boolean }
        • Optionalstream?: boolean

          When true, returns an inline-streamable URL (no Content-Disposition: attachment header) suitable for <video>, <img>, <iframe>, etc. Default (false) returns a download URL.

      Returns Promise<string>

    • Join an existing no-video (offline/signaling-only) room as a participant. Connects via signaling for chat, files, whiteboard, etc. — no WebRTC media.

      Parameters

      • roomName: string
      • userId: string

      Returns Promise<void>

    • Join an existing room as a participant.

      Parameters

      • roomName: string
      • userId: string

      Returns Promise<void>

    • Load chat history from the server.

      Parameters

      • Optionalcursor: string | null

      Returns Promise<{ hasMore: boolean }>

    • Move a user file to a new location/folder.

      Parameters

      • fileId: string
      • newLocation: string

      Returns Promise<void>

    • Mute/unmute a remote participant's audio output locally (owner only).

      Parameters

      • userId: string
      • muted: boolean

      Returns Promise<void>

    • Reject a user from the waiting room (owner only).

      Parameters

      • userId: string

      Returns Promise<void>

    • Remotely mute/unmute a participant's audio (owner only).

      Parameters

      • userId: string
      • muted: boolean

      Returns Promise<void>

    • Remotely mute/unmute a participant's video (owner only).

      Parameters

      • userId: string
      • muted: boolean

      Returns Promise<void>

    • Remove an advertised room from discovery (owner action).

      Parameters

      • cloudClient: { removeAdvertisedRoom(roomName: string): Promise<void> }
      • roomName: string

      Returns Promise<void>

    • Remove a file from the local userFiles slice without going to the server. Companion to upsertUserFileLocal for unshare-style broadcasts: when a peer learns a file is no longer shared with them, they can drop it from local state instantly.

      Parameters

      • fileId: string

      Returns void

    • Rename a user file.

      Parameters

      • fileId: string
      • newFilename: string

      Returns Promise<void>

    • Invalidate the cached lightweight client so the next API call generates a fresh room token for the new user. Call this on user change / logout to prevent stale-token data leaks.

      Returns void

    • Switch the active room name for file operations on an existing no-video connection. Avoids tearing down and re-establishing the signaling connection.

      Parameters

      • roomName: string

      Returns void

    • Switch to a different microphone.

      Parameters

      • deviceId: string

      Returns Promise<void>

    • Switch to a different speaker.

      Parameters

      • deviceId: string

      Returns Promise<void>

    • Set the dominant speaker for video grid layouts (owner only).

      Parameters

      • userId: string | null

      Returns void

    • Switch to a different camera.

      Parameters

      • deviceId: string

      Returns Promise<void>

    • Share a user file with other users.

      Patches the local cache in place rather than refetching the full user-files list. The previous "POST /upload/files/all on every share" pattern hit the cloud's per-IP file-ops rate limit (50/min) in cascade-share scenarios — e.g. an assignment with several embedded files, or a clip-composition fanning out to N clip media files. Each individual share triggered a list refetch, easily burning 20+ list-fetches per save.

      When the SSE stream is connected the server's file-updated event arrives shortly and reconciles the cache against server canon. When it isn't (degraded session, before initial connect), we fall back to the full refetch so the cache doesn't drift indefinitely.

      Parameters

      • fileId: string
      • userIds: string[]
      • OptionalsharedRoom: string

      Returns Promise<void>

    • Start real-time transcription. Returns true if API call succeeded.

      Returns Promise<boolean>

    • Subscribe to all state changes. Returns unsubscribe function.

      Parameters

      • listener: () => void

      Returns () => void

    • Switch the featured user in the stream.

      Parameters

      • userId: string

      Returns Promise<void>

    • Trigger post-recording transcription and analysis on a completed recording. Unlike real-time transcription, this processes an existing recording asynchronously. Poll transcription status to track progress.

      Parameters

      • recordingId: string

      Returns Promise<boolean>

    • Update an advertised room's metadata (owner action).

      Parameters

      • cloudClient: {
            updateAdvertisedRoom(
                roomName: string,
                updates: Partial<AdvertiseRoomOptions>,
            ): Promise<void>;
        }
      • roomName: string
      • updates: Partial<AdvertiseRoomOptions>

      Returns Promise<void>

    • Update coaching data from the coaching endpoint response.

      Parameters

      • data: {
            currentTopic?: string;
            hints?: CoachingHint[];
            talkRatio?: { listening: number; speaking: number };
            topicShifts?: TopicShift[];
        }

      Returns void

    • Update application-specific metadata for a file without re-uploading content. Skips the full-list refetch (which would re-sort and lose selection) and patches the matching entry in the local userFiles cache in place, so subscribers see the new appData immediately. Callers can still call fetchUserFiles to force a full refresh when they need server canon.

      Parameters

      • fileId: string
      • appData: Record<string, unknown>

      Returns Promise<void>

    • Upload a file to the user's file storage.

      Parameters

      • file: File
      • location: string
      • OptionalresourceType: string

      Returns Promise<{ fileId: string }>

    • Apply a file to the local userFiles slice without going to the server. Used by peers that learn about a file change via a relay broadcast (or any other side-channel) and want to reflect it immediately instead of refetching — the cloud's read replica routinely lags the primary by long enough that the refetch returns the pre-mutation state, producing visible "the change didn't take" symptoms.

      If a file with the same fileId exists locally, its fields are shallow-merged with the incoming payload. Otherwise the file is prepended. Also marks the file as recently-patched so the SSE file-updated handler's guard window protects this update from being clobbered by an SSE event carrying a replica-lagged view.

      Parameters

      Returns void