useAcl
useAcl hook allows you to manage access control of peers.
Supported Roles: host
, coHost
, speaker
, listener
, peer
Please follow this hierarchy when changing peer roles: host -> coHost -> speaker -> listener
Name | Type | |
---|---|---|
changePeerRole(peerId: string, role: string) | Function | Change peer role of given peerId to given role |
changeRoomControls(type: string, value: boolean) | Function | Handle room controls such as `muteEveryone`, `audioLocked`, and `videoLocked` |
kickPeer(peerId: string) | Function | Kicks out peer from the room |
admitPeer(peerIds: string[]) | Function | Admit peers to the room |
denyPeer(peerIds: string[]) | Function | Deny peers from the room |
Example
import { useAcl } from '@huddle01/react/hooks';
const { changePeerRole, changeRoomControls } = useAcl();
const handleMuteEveryone = () => {
changeRoomControls('muteEveryone', true);
}
const changeRoleToHost = () => {
// This will change peer role of given peerId to host
changePeerRole(PEER_ID, 'host');
}
const changeRoleToCoHost = () => {
// This will change peer role of given peerId to coHost
changePeerRole(PEER_ID, 'coHost');
}
const changeRoleToSpeaker = () => {
// This will change peer role of given peerId to speaker
changePeerRole(PEER_ID, 'speaker');
}
const changeRoleToListener = () => {
// This will change peer role of given peerId to listener
changePeerRole(PEER_ID, 'listener');
}
const lockRoom = () => {
// This will lock the room
changeRoomControls('roomLocked', true);
}
const unlockRoom = () => {
// This will unlock the room
changeRoomControls('roomLocked', false);
}
const muteEveryone = () => {
// This will mute everyone in the room
changeRoomControls('muteEveryone', true);
}
const removePeer = () => {
// This will remove peer from the room
kickPeer(PEER_ID);
}
const admitPeers = () => {
// This will admit peers to the room
admitPeer([PEER_ID]);
}
const denyPeers = () => {
// This will deny peers from the room
denyPeer([PEER_ID]);
}
const admitAll = () => {
// This will admit all peers to the room
admitPeer(lobbyPeers.map(({peerId}) => peerId));
}
const denyAll = () => {
// This will deny all peers from the room
denyPeer(lobbyPeers.map(({peerId}) => peerId));
}