useLocalPeer
The useLocalPeer hook allows you to interact with your own Peer object, which is how you are represented inside a Huddle01 room.
Name | Description | Return Type | Params |
---|---|---|---|
peerId | Your peerId. | string | null | |
metadata | The metadata associated with you. | unknown | |
permissions | Your peer permissions inside the room. | TPermissions | |
updateMetadata | Update the metadata associated with your peer object. | void | data: unknown |
role | Your peer role inside the room. | string | |
updateRole | Update the role associated with your peer object. | void | role: string |
const {
peerId,
role,
permissions,
metadata,
updateMetadata,
updateRole,
} = useLocalPeer<{name: string}>({
onMetadataUpdated(metadata) {},
onPermissionsUpdated(permissions) {},
onRoleUpdated(role) {},
});
// update your metadata
const updateMetadata = () => {
updateMetadata({ name: 'John Doe' });
};
// update your role
const updateRole = () => {
updateRole('coHost');
};
Props
The useLocalPeer hook accepts an object with the following fields as props.
onMetadataUpdated
OptionalAdvanced
Description | Return Type |
---|---|
This function will be called when the metadata associated with you is updated. | void |
Parameter Name | Type | Description | Required |
---|---|---|---|
metadata | unknown | The metadata associated with your peer object. | Yes |
Example Usage
const localPeer = useLocalPeer({ onMetadataUpdated: (metadata) => {
console.log("Your metadata was updated!");
console.log(metadata);
// your code here
}});
onPermissionsUpdated
OptionalAdvanced
Description | Return Type |
---|---|
This function will be called when your user permissions are updated. | void |
Parameter Name | Type | Description | Required |
---|---|---|---|
permissions | TPermissions | The permissions associated with your peer object. | Yes |
Example Usage
const localPeer = useLocalPeer({ onPermissionsUpdated: (permissions) => {
console.log("Your permissions were updated!");
console.log(permissions);
// your code here
}});
onRoleUpdated
OptionalAdvanced
Description | Return Type |
---|---|
This function will be called when your user role is updated. | void |
Parameter Name | Type | Description | Required |
---|---|---|---|
role | string | The role associated with your peer object. | Yes |
Example Usage
const localPeer = useLocalPeer({ onRoleUpdated: (role) => {
console.log("Your role was updated!");
console.log(role);
// your code here
}});