useRoomControls

useRoomControls

The useRoomControls hook allows you to read and update the room's controls.

NameDescriptionReturn TypeParams
roomControlsObject containing the current room controls.Object
updateControlsFunction to update the room controls.voiddata: 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
DescriptionReturn Type
This function will be called when the room controls have been updated.void
Parameter NameTypeDescriptionRequired
dataNewRoomControlsObject 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
DescriptionReturn Type
This room controls will be updated when the peer leaves the roomvoid
Parameter NameTypeDescriptionRequired
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
}});
Audio/Video Infrastructure designed for the developers to empower them ship simple yet powerful Audio/Video Apps.
support
company
Copyright © 2024 Graphene 01, Inc. All Rights Reserved.