useRemotePeer
The useRemotePeer hook allows you to interact with another user's Peer object, which is how they are represented inside a Huddle01 room.
| Name | Description | Return Type | Params | 
|---|---|---|---|
| peerId | The peerId of the remote peer. | void | |
| role | The role you want to be associated with your peer object. | string | |
| metadata | The metadata you want to be associated with your peer object. | unknown | |
| updateRole | A function that allows you to update the role associated with your peer object. | void | role: string | 
Example Usage
import { useRemotePeer } from "@huddle01/react/hooks";
 
const {
    peerId,
    role,
    metadata,
    updateRole,
  } = useRemotePeer({
    peerId: "remote-peer-id",
    onMetadataUpdate(data) {},
  });
 
const updateRemotePeerRole = () => {
  updateRole("speaker");
}Props
The useRemotePeer hook accepts an object with the following fields as props.
peerId
Required
| Description | Type | 
|---|---|
| The peerId of the remote peer. | string | 
Example Usage
const remotePeer = useRemotePeer({ peerId: "remote-peer-id" });onMetadataUpdated
OptionalAdvanced
| Description | Return Type | 
|---|---|
| This function will be called when the metadata associated with the remote peer is updated. | void | 
| Parameter Name | Type | Description | Required | 
|---|---|---|---|
| data | { metadata: unknown } | An object containing the metadata associated with the remote peer object. | Yes | 
Example Usage
const remotePeer = useRemotePeer({ peerId: "remote-peer-id", onMetadataUpdated: (data) => {
	console.log("Remote peer's metadata was updated!");
	console.log(data.metadata);
    // your code here
}});