useLocalPeer

useLocalPeer

The useLocalPeer hook allows you to interact with your own Peer object, which is how you are represented inside a Huddle01 room.

NameDescriptionReturn TypeParams
peerIdYour peerId.string | null
metadataThe metadata associated with you.unknown
permissionsYour peer permissions inside the room.TPermissions
updateMetadataUpdate the metadata associated with your peer object.voiddata: unknown
roleYour peer role inside the room.string
updateRoleUpdate the role associated with your peer object.voidrole: 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
DescriptionReturn Type
This function will be called when the metadata associated with you is updated.void
Parameter NameTypeDescriptionRequired
metadataunknownThe 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
DescriptionReturn Type
This function will be called when your user permissions are updated.void
Parameter NameTypeDescriptionRequired
permissionsTPermissionsThe 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
DescriptionReturn Type
This function will be called when your user role is updated.void
Parameter NameTypeDescriptionRequired
rolestringThe 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
}});
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.