useLobby
The useLobby hook allows you to interact with peers in the lobby, i.e. who are waiting to join a locked room. As an admin, you can choose to admit these peers into the room or deny them from joining the room.
Name | Description | Return Type | Params |
---|---|---|---|
lobbyPeers | List of peerIds in lobby who are waiting to join a locked room | string[] | |
admitPeer | Admit a peer into the room. | void | peerId: string |
denyPeer | Deny a peer from joining the room. | void | peerId: string |
getLobbyPeerMetadata | Returns the metadata of lobby peer. | void | peerId: string |
Example Usage
import { useLobby } from '@huddle01/react/hooks';
const {
lobbyPeers,
admitPeer,
denyPeer,
getLobbyPeerMetadata
} = useLobby({
onLobbyPeersUpdated(lobbyPeers: string[]) ();
});
// admit a peer into the room
const admitPeer = (peerId: string) => {
admitPeer(peerId);
}
// deny a peer from joining the room
const denyPeer = (peerId: string) => {
denyPeer(peerId);
}
// get metadata of a lobby peer
const getLobbyPeerMetadata = (peerId: string) => {
getLobbyPeerMetadata(peerId);
}
Props
The useLobby hook accepts an object with the following fields as props.
onLobbyPeersUpdated
Optional
Description | Return Type |
---|---|
This function will be called when the peers waiting in lobby are updated. | void |
Parameter Name | Type | Description | Required |
---|---|---|---|
lobbyPeers | string[] | Array of peerIds of peers waiting in lobby | Yes |
Example Usage
const lobby = useLobby({ onLobbyPeersUpdated: (lobbyPeers) => {
console.log("Peers in lobby who are waiting to join updated!");
console.log(lobbyPeers);
// your code here
}});