useRoom
The useRoom hook exposes primitives to interact with a Huddle01 room, like joining, leaving, closing the room.
const {
room,
state,
joinRoom,
leaveRoom,
closeRoom,
} = useRoom({
onJoin(data) {},
onClose() {},
onLeave() {},
});
Props
The useRoom hook accepts an object with the following fields as props.
1. onJoinOptional
Description | Return Type |
---|---|
This function will be called when you successfully join a room. | void |
Parameter Name | Type | Description | Required |
---|---|---|---|
data | { room: Room } | Object containing data about the room. | Yes |
Example Usage
const room = useRoom({ onJoin: (data) => {
console.log("Successfully joined the room!");
console.log(data.room);
// your code here
}});
2. onLeaveOptional
Description | Return Type |
---|---|
This function will be called when you successfully leave a room. | void |
Example Usage
const room = useRoom({ onLeave: () => {
console.log("Successfully left the room!");
// your code here
}});
3. onCloseOptional
Description | Return Type |
---|---|
This function will be called when the room has been closed. | void |
Example Usage
const room = useRoom({ onClose: () => {
console.log("The room was closed!");
// your code here
}});
Description | Return Type |
---|---|
This function will be called when the room controls have been updated. | void |
Parameter Name | Type | Description | Required |
---|---|---|---|
data | TNewRoomControls | Object containing the new room controls. | Yes |
Example Usage
const room = useRoom({ onJoin: (data) => {
console.log("Room controls updated!");
console.log(data);
// your code here
}});
Returns
The useRoom hook returns an object with the following fields.
1. roomObject
Description | Type |
---|---|
The currently joined room object. | Room |
2. stateObject
Description | Type |
---|---|
The state of the currently joined room. | RoomStates |
3. joinRoomFunction
Description | Return Type |
---|---|
Join the room. | Promise<Room> |
Parameter Name | Type | Description | Required |
---|---|---|---|
data | { roomId: string; token: string } | Object containing the roomId to be joined and the user’s access token. | Yes |
4. leaveRoomFunction
Description | Return Type |
---|---|
Leave the room. | void |
5. closeRoomFunction
Description | Return Type |
---|---|
Close the room. | void |