useRoomControls
The useRoomControls hook allows you to read and update the room's controls.
Name | Description | Return Type | Params |
---|---|---|---|
roomControls | Object containing the current room controls. | Object | |
updateControls | Function to update the room controls. | void | data: NewRoomControls |
Example Usage
import { useRoomControls } from '@huddle01/react/hooks';
type NewRoomControls = {
value: boolean;
type: 'roomLocked' | 'allowProduce' | 'allowConsume' | 'allowSendData';
} | {
value: {
cam: boolean;
mic: boolean;
screen: boolean;
};
type: 'allowProduceSources';
};
const {
roomControls,
updateControls,
} = useRoomControls({
onRoomControlsUpdated(data: NewRoomControls) ();
onRoomLeave(data: {
reason: 'LEFT' | 'CLOSED' | 'KICKED' | 'DENIED';
message?: string;
}) ();
});
const lockRoom = () => {
updateControls({
type: 'roomLocked',
value: true,
});
};
// your code here
Props
The useRoomControls hook accepts an object with the following fields as props.
onRoomControlsUpdated
OptionalAdvanced
Description | Return Type |
---|---|
This function will be called when the room controls have been updated. | void |
Parameter Name | Type | Description | Required |
---|---|---|---|
data | NewRoomControls | Object containing the new room controls. | Yes |
Example Usage
const roomControls = useRoomControls({ onRoomControlsUpdated: (data) => {
console.log("Room controls updated!");
console.log(data);
// your code here
}});
onRoomLeave
OptionalAdvanced
Description | Return Type |
---|---|
This room controls will be updated when the peer leaves the room | void |
Parameter Name | Type | Description | Required |
---|---|---|---|
data | {reason: 'LEFT' | 'CLOSED' | 'KICKED' | 'DENIED'; message?: string;} | Object containing the new room controls. | Yes |
Example Usage
const roomControls = useRoomControls({ onRoomLeave: (data) => {
console.log("Room controls updated!");
console.log(data);
// your code here
}});