useRoom

Acess the following methods & states joinRoom(), leaveRoom(), isLoading, isLobbyJoined, error, lobbyPeers .

NameTypeDescription
joinRoom()Functionmoves user from lobby to actual room with other peers
leaveRoom()Functionremoves user from room, back to the lobby
isLoadingbooleanloading state
isRoomJoinedbooleanstate whether the room is joined or not
errorstringgives the error message
roomIdstringgives the current joined room id
endRoom()FunctionEnds the room for all, only `host` has the ability to call this function
lobbyPeersObjectgives the list of peers waiting in the lobby to join the room

Sample Code

 
  import { useRoom } from '@huddle01/react/hooks';
 
  const App = () => {
    const { joinRoom, leaveRoom, isLoading, isRoomJoined, lobbyPeers, error, endRoom } = useRoom();
 
    if(isLoading) return (<div>...loading</div>)
  
    return (
      <div> 
        <button disabled={!joinRoom.isCallable} onClick={joinRoom}>
          JOIN_ROOM 
        </button>
 
        {isRoomJoined ? "room joined": error} 
 
        <div>lobbyPeers: {JSON.stringify(lobbyPeers)}</div>
 
        <button disabled={!leaveRoom.isCallable} onClick={leaveRoom}>
          LEAVE_ROOM 
        </button>
 
        <button disabled={!endRoom.isCallable} onClick={endRoom}>
          END_ROOM 
        </button>
      </div>
    );
  };
 
Audio/Video Infrastructure designed for the developers to empower them ship simple yet powerful Audio/Video Apps.
support
company
Copyright © 2022 Graphene 01, Inc. All Rights Reserved.