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

    Class HiyveStoreRN

    Framework-agnostic state store for Hiyve React Native WebRTC applications.

    HiyveStoreRN manages all real-time communication state -- connection, room, participants, media, chat, recording, streaming, transcription, waiting room, hand raises, layout, and AI chat -- in a single store with per-slice subscriptions for efficient rendering.

    This is the React Native counterpart to HiyveStore from @hiyve/core. The API surface is nearly identical, with these React Native-specific differences:

    • switchCamera is available for toggling front/back cameras
    • leaveRoom and destroy return Promise<void> (the underlying RN client uses async disconnect)
    • The localMedia slice includes a localStream field for the native camera MediaStream
    • No screen-sharing methods (not supported on mobile)
    • No device enumeration methods (use switchCamera instead)

    The store follows a subscribe/getSnapshot contract, making it compatible with React Native's useSyncExternalStore or any callback-based subscription model.

    import { HiyveStoreRN } from '@hiyve/rn-core';

    const store = new HiyveStoreRN({
    generateRoomToken: async () => {
    const res = await fetch('https://your-api.com/token');
    return res.json();
    },
    onError: (err) => Alert.alert('Error', err.message),
    });

    // Subscribe to connection changes
    const unsub = store.subscribeToSlice('connection', () => {
    const conn = store.getSlice('connection');
    console.log('Connected:', conn.isConnected);
    });

    // Create a room
    await store.createRoom('my-room', 'user123');

    // Toggle camera
    await store.switchCamera();

    // Clean up
    unsub();
    await store.destroy();
    Index

    Constructors

    Methods

    • Admit a user from the waiting room into the active room.

      The user is removed from waitingRoom.waitingUsers immediately. Only effective when called by the room owner; does nothing otherwise.

      Parameters

      • userId: string

        The identifier of the waiting user to admit

      Returns Promise<void>

    • Clear the recording.error field, resetting it to null.

      Call this after displaying or handling a recording error so the UI can return to a clean state.

      Returns void

    • Clear the streaming.error field, resetting it to null.

      Call this after displaying or handling a streaming error so the UI can return to a clean state.

      Returns void

    • Reset the unread message counter to zero.

      Typically called when the user opens or focuses the chat panel, indicating they have seen the new messages.

      Returns void

    • Create a new room and join as the owner/host.

      Initializes the client, creates the room on the server, connects media transports, and loads any existing chat history. After this resolves, the room, connection, and participants slices are populated and media is flowing.

      Parameters

      • roomName: string

        Display name for the room

      • userId: string

        Your user identifier (alphanumeric and underscores only; other characters are stripped automatically)

      • Optionaloptions: CreateRoomOptions

        Optional room configuration (e.g., waiting room)

      Returns Promise<void>

      Re-throws the underlying error after updating the connection slice with the error message and invoking HiyveStoreRNOptions.onError

      await store.createRoom('standup', 'alice', {
      requireWaitingRoom: true,
      });
    • Destroy the store and release all resources.

      Disconnects the client, stops any polling intervals, and clears all subscription listeners. After calling destroy(), the store instance should not be reused -- create a new HiyveStoreRN instead.

      Returns Promise<void>

      Unlike the web HiyveStore.destroy() which is synchronous, this method returns Promise<void> because the React Native client requires an async disconnect.

    • Enrich recent transcription entries with mood and sentiment data.

      Applies the provided mood analysis to the user's transcription entries from the last 30 seconds that have not yet been enriched. Each matched entry receives sentiment, emotion, engagement, and confidence fields.

      Parameters

      • userId: string

        The participant whose transcriptions to enrich

      • moodData: TranscriptionMoodData

        Mood/sentiment analysis results to attach

      Returns void

    • Get the underlying React Native WebRTC client instance.

      Returns null before createRoom or joinRoom is called, or after destroy.

      Returns Client | null

      The Client instance, or null if not connected

      This is an escape hatch for advanced scenarios where you need to call methods on the client directly. Prefer the store's public action methods for most use cases, as they keep the state in sync automatically.

    • Get a specific state slice as an immutable snapshot.

      Use with subscribeToSlice for efficient per-slice rendering.

      Type Parameters

      Parameters

      • slice: K

        The name of the state slice to retrieve

      Returns HiyveStoreRNState[K]

      The current value of the requested slice

      const recording = store.getSlice('recording');
      if (recording.isRecording) { ... }
    • Join an existing room as a participant.

      Initializes the client, joins the room on the server, connects media transports, and loads chat history. If the room has a waiting room enabled, the waitingRoom.isWaitingForAdmission flag is set to true and media will not connect until the host admits you.

      Any active recording, streaming, or transcription session in the room is automatically reflected in the corresponding state slices.

      Parameters

      • roomName: string

        The name of the room to join

      • userId: string

        Your user identifier (alphanumeric and underscores only; other characters are stripped automatically)

      Returns Promise<void>

      Re-throws the underlying error after updating the connection slice with the error message and invoking HiyveStoreRNOptions.onError

      await store.joinRoom('standup', 'bob');
      
    • Join a room using a join token from an invite link.

      Similar to joinRoom, but uses a token+region pair instead of a room name. The token encodes the room identity and the region routes the connection to the correct media server.

      Parameters

      Returns Promise<void>

      Re-throws the underlying error after updating the connection slice with the error message and invoking HiyveStoreRNOptions.onError

    • Leave the current room and disconnect from the server.

      Removes all event listeners, closes the connection, and resets the entire state tree back to its initial values. All subscribers are notified of the reset.

      Returns Promise<void>

      Unlike the web HiyveStore.leaveRoom() which is synchronous, this method returns Promise<void> because the React Native client requires an async disconnect.

    • Load older chat messages from the server.

      Messages are prepended to the chat.messages array in chronological order. Use the returned hasMore flag to drive "load more" pagination.

      Parameters

      • Optionalcursor: string | null

        Pagination cursor from a previous call. Pass null or omit to load the most recent page.

      Returns Promise<{ hasMore: boolean }>

      An object with hasMore: boolean indicating whether additional older messages are available on the server.

    • Lower all raised hands in the room at once.

      Broadcasts a "lower all" signal to every participant and clears the handRaise.raisedHands map. Only effective when called by the room owner/host; does nothing otherwise.

      Returns Promise<void>

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

      Sends a server command to mute/unmute the target participant's speaker output. The participants slice is updated optimistically. Does nothing if not connected or if the local user is not the room owner.

      Parameters

      • userId: string

        The participant whose output to mute/unmute

      • muted: boolean

        true to mute, false to unmute

      Returns Promise<void>

    • Reject a user from the waiting room, denying them entry.

      The user is removed from waitingRoom.waitingUsers immediately and notified of the rejection. Only effective when called by the room owner; does nothing otherwise.

      Parameters

      • userId: string

        The identifier of the waiting user to reject

      Returns Promise<void>

    • Remotely mute or unmute a participant's microphone (owner only).

      Sends a server command to mute/unmute the target participant's audio. The participants slice is updated optimistically. Does nothing if not connected or if the local user is not the room owner.

      Parameters

      • userId: string

        The participant to mute/unmute

      • muted: boolean

        true to mute, false to unmute

      Returns Promise<void>

    • Remotely mute or unmute a participant's camera (owner only).

      Sends a server command to mute/unmute the target participant's video. The participants slice is updated optimistically. Does nothing if not connected or if the local user is not the room owner.

      Parameters

      • userId: string

        The participant to mute/unmute

      • muted: boolean

        true to mute, false to unmute

      Returns Promise<void>

    • Send an arbitrary data message to all participants in the room.

      Use this for custom signaling -- the payload is delivered as-is to every connected client's DATA_MESSAGE event handler. Does nothing if not connected.

      Parameters

      • data: unknown

        Any JSON-serializable value to broadcast

      Returns void

    • Send a text chat message to all participants in the room.

      The message is immediately added to the local chat.messages array with isLocal: true and broadcast to remote participants. Does nothing if not connected.

      Parameters

      • content: string

        The message text to send

      Returns void

    • Replace the entire AI chat message list.

      Typically called by the AI cloud provider to synchronize its conversation state with the store. Updates the aiChat.messages slice, notifying all subscribers.

      Parameters

      • messages: AiChatMessage[]

        The full array of AI chat messages to set

      Returns void

    • Set (or clear) the dominant/pinned speaker for video grid layouts.

      Broadcasts the change to all participants and updates layout.dominantSpeaker. Only effective when called by the room owner; does nothing otherwise.

      Parameters

      • userId: string | null

        The user to pin as dominant, or null to clear

      Returns void

    • Start cloud recording of the current room.

      Sets recording.isRecordingStarting to true while the request is in progress. On success the server will emit a recording-started event that updates the recording slice. On failure, the error is stored in recording.error.

      Parameters

      • Optionaloptions: RecordingOptions

        Optional recording configuration (auto-compose, transcription, context, post-meeting summary)

      Returns Promise<boolean>

      true if the API call succeeded, false if it failed or the client is not connected

    • Start a cloud live stream of the current room.

      Sets streaming.isStreamingStarting to true while the request is in progress. The streaming slice is updated once the server confirms the stream has started. On failure, the error is stored in streaming.error and the promise is rejected.

      Parameters

      • Optionaloptions: StreamingOptions

        Optional streaming configuration (RTMP URL, mode, MP4 creation)

      Returns Promise<void>

      Rethrows the underlying error after updating the streaming slice with the error message

    • Start real-time speech-to-text transcription for the room.

      Sets transcription.isTranscriptionStarting to true while the request is in progress. Incoming transcription entries are appended to the transcription.transcriptions array as they arrive.

      Returns Promise<boolean>

      true if the API call succeeded, false if it failed or the client is not connected

    • Stop the current cloud recording.

      The recording slice is reset to its idle state once the server confirms the recording has stopped. Does nothing if not connected.

      Returns Promise<void>

    • Stop the current live stream.

      The streaming slice is reset to its idle state once the server confirms the stream has stopped. Does nothing if not connected.

      Returns Promise<void>

    • Stop real-time transcription.

      The transcription slice flags are reset once the server confirms the transcription session has ended. Existing transcription entries are preserved. Does nothing if not connected.

      Returns Promise<void>

    • Subscribe to all state changes across every slice.

      The listener is called whenever any part of the state tree changes. For more targeted updates, prefer subscribeToSlice.

      Compatible with React Native's useSyncExternalStore:

      const state = useSyncExternalStore(store.subscribe, store.getState);
      

      Parameters

      • listener: () => void

        Callback invoked on every state change

      Returns () => void

      An unsubscribe function. Call it to stop receiving updates.

    • Subscribe to changes in a specific state slice.

      Only fires when the targeted slice produces a new reference, which avoids unnecessary re-renders in components that only depend on one area of state (e.g., chat, recording, or participants).

      Parameters

      • slice: keyof HiyveStoreRNState

        The name of the state slice to watch

      • listener: () => void

        Callback invoked when the slice changes

      Returns () => void

      An unsubscribe function. Call it to stop receiving updates.

      const unsub = store.subscribeToSlice('chat', () => {
      const chat = store.getSlice('chat');
      console.log('Messages:', chat.messages.length);
      });
    • Switch between the front-facing and rear-facing camera.

      Cycles to the next available camera each time it is called. Does nothing if not connected.

      Returns Promise<void>

      This method is React Native-only and has no equivalent in the web HiyveStore. On web, use setVideoDevice(deviceId) instead.

    • Toggle the local microphone between muted and unmuted.

      The new mute state is reflected in the localMedia.isAudioMuted field once the server acknowledges the change. Does nothing if not connected.

      Returns Promise<void>

    • Toggle the local user's "hand raised" state.

      Broadcasts the new state to all participants and updates the handRaise.raisedHands map. If the hand is currently raised it will be lowered, and vice versa. Does nothing if not connected.

      Returns Promise<void>

    • Toggle speaker/output mute on the local device.

      When muted, audio from remote participants is silenced locally. The new state is reflected in localMedia.isOutputMuted once the server acknowledges the change. Does nothing if not connected.

      Returns Promise<void>

    • Toggle the local camera between on and off.

      The new mute state is reflected in the localMedia.isVideoMuted field once the server acknowledges the change. Does nothing if not connected.

      Returns Promise<void>