Skip to content

Latest commit

 

History

History
125 lines (94 loc) · 15.5 KB

useroomconnection.md

File metadata and controls

125 lines (94 loc) · 15.5 KB
layout
title description tableOfContents outline pagination
visible
true
visible
visible
true
visible
true
visible
true

useRoomConnection

The useRoomConnection hook provides the ability to connect participants in a given room, subscribe to state updates, and perform actions on the connection like toggling the camera or microphone.

useRoomConnection(roomUrl: string, roomConnectionOptions: RoomConnectionOptions): Object | null

ParameterRequiredTypeDescription
roomUrlstringThe URL of the Whereby room. Refer to our REST api reference to learn how to create these.
roomConnectionOptionsRoomConnectionOptionsAdditional options for the room connection

Return type

The hook returns a RoomConnectionReference object with the following properties.

PropertyTypeDescription
stateRoomConnectionStateObject representing the state of the room
actionsRoomConnectionActionsObject representing the available actions in the room
eventsRoomConnectionEventsEvent emitter that emits in-room events as they are happening

state

The current state of the room. Use this state to render your custom video experience.

Property Type Description
chatMessages ChatMessage[] The chat messages which have been sent in the room since connecting.
cloudRecording CloudRecordingState Indicates whether cloud recording is active in the room.
connectionStatus RoomConnectionStatus Overall status of the room connection
localScreenshareStatus LocalScreenshareStatus? Status of your local screen share
localParticipant LocalParticipant? A representation of the local participant in the call (you)
remoteParticipants RemoteParticipant[] A list of the remote participants in the room
screenshares Screenshare[] List of active screenshares in the room
liveStream LiveStreamState? Set if live stream is enabled for the room
waitingParticipants WaitingParticipant[] A list of participants waiting to enter a locked room.
spotlightedParticipants ClientView[] A list of spotlighted participants
breakout Breakout The breakout group state of the room

actions

The actions property contains a map of functions which can be invoked to perform an action in the room. All these functions are sync and return void, and you should rely on the state to render the effect of their invocation.

PropertyTypeDescription
joinRoom() => void

Join the room configured in the useRoomConnection config.

knock() => voidLet the room host know that the local participant is waiting and wants to join
setDisplayName(displayName: string) => voidChange your display name
sendChatMessage(text: string) => voidSend a chat message to the room
toggleCamera(enabled?: boolean) => voidChange the state of your camera
toggleMicrophone(enabled?: boolean) => voidChange the state of your microphone
toggleLowDataMode(enabled?: boolean) => voidChange the state of low data mode
toggleRaiseHand(enabled?: boolean) => voidToggle raising and lowering your hand in the meeting. Any host in the meeting can acknowledge your request with the askToSpeak host action.
acceptWaitingParticipant(participantId: string) => voidAccept waiting participant
rejectWaitingParticipant(participantId: string) => voidReject waiting participant
startScreenshare() => voidStart screen share
stopScreenshare() => voidStop screen share
leaveRoom() => voidLeave the room
joinBreakoutGroup(group: string) ⇒ voidJoin a breakout group.
joinBreakoutMainRoom() ⇒ voidJoin the main room in a breakout session.

Host-only actions

When a participant provides a valid "host" roomKey in the RoomConnectionOptions when the useRoomConnection hook was created, they will have access to a number of addition host-only actions in rooms:

PropertyTypeDescription
lockRoom(locked: boolean) => void[Host only] Lock (true) or unlock (false) the current room
muteParticipants(participantIds: string[]) => void[Host only] Mute the specified remote participants
askToSpeak(participantId: string) => void

[Host only] Ask the specified remote participant to unmute their microphone and speak in the meeting.

This is typically useful in response to a toggleRaiseHand request from a participant in the meeting.

kickParticipant(participantId: string) => void[Host only] Remove the specified remote participant from the meeting
endMeeting(stayBehind?: boolean) => void

[Host only] End the meeting for all remote participants.

If stayBehind is not provided or is not true, then the local participant will also leave the room

spotlightParticipant(participantId: string) => void[Host only] Put a spotlight on a participant.

When used in combination with the video grid, the spotlighted participant will move to the presentation stage, and their video cell will be bigger.
removeSpotlight(participantId: string) => void[Host only] Remove spotlight on a participant.

events

Event emitter which emits notification events as they are happening inside of the room.

It's possible to subscribe and unsubscribe to events using the events.on and events.off methods.

Event Payload Description
* NotificationEvent Listen for all events
requestAudioEnable NotificationEvent<RequestAudioEvent>

A host is asking for the local participant to speak in the meeting.

The local participant should be notified when this event is received and prompted to trigger actions.toggleMicrophone(true) if or when they are ready to speak

requestAudioDisable NotificationEvent<RequestAudioEvent> A host has forcibly muted your microphone
signalTrouble NotificationEvent<SignalStatusEvent> There is a problem with the internet connection and a connection to our signal server can not be established
signalOk NotificationEvent<SignalStatusEvent> Internet connectivity is present or it has been restored after signalTrouble
chatMessageReceived NotificationEvent<ChatMessageEvent> A chat message was sent by a remote participant

Host-only events

When a participant provides a valid "host" roomKey in the RoomConnectionOptions when the useRoomConnection hook was created, they will have access to a number of addition host-only events in rooms:

Event Payload Description
remoteHandRaised NotificationEvent<StickyReactionEvent>

A remote participant has raised their hand to request to speak in the meeting.

The local host participant should be notified when this event is received and prompted to trigger actions.askToSpeak(participantId) if or when they want to invite the remote participant to speak in the meeting.

remoteHandLowered NotificationEvent<StickyReactionEvent>

A remote participant who previously had their hand raised has now lowered their hand.

Any previous raised hand notifications shown for this remote participant should be cancelled and no further action is needed from the local host participant.

Usage

import * as React from "react";
import { useRoomConnection, VideoView } from "@whereby.com/browser-sdk/react";

function MyCallUX( { roomUrl, localStream }) {
    const { state, actions, events } = useRoomConnection(
        "<room_url>"
        {
            localMediaOptions: {
                audio: true,
                video: true,
            }
        }
    );

    const { connectionState, remoteParticipants } = state;
    const { joinRoom, leaveRoom, toggleCamera, toggleMicrophone } = actions;
    
    React.useEffect(() => {
        joinRoom();
        return () => leaveRoom();
    }, []);

    // listen to all notification events on mount and unlisten on unmount
    React.useEffect(() => {
        if(!events) return;
        const handleEvents = (e) => console.log(e);
        events.on("*", handleEvents);
        return () => events && events.off("*", handleEvents);
    }, []);

    return <div className="videoGrid">
        { /* Render any UI, making use of state */ }
        { remoteParticipants.map((p) => (
            <VideoView key={p.id} stream={p.stream} />
        )) }
    </div>;
}