Shinigami Hooks
useRemoteAudio

useRemoteAudio

The useRemoteAudio hook exposes primitives to interact with audio streams coming from other peers in the room.

const {
    state,
    track,
    stream,
  } = useRemoteAudio({
    peerId: "remote-peer-id",
    onPlayable(data) {},
    onClose() {},
  });

Props

The useRemoteAudio hook accepts an object with the following fields as props.

1. peerIdRequired
DescriptionType
The peerId of the peer whose audio stream you want to consume.string
Example Usage
const remoteAudio = useRemoteAudio({ peerId: "remote-peer-id" });
2. onPlayableOptionalAdvanced
DescriptionReturn Type
This function will be called when the other peer has enabled their audio stream and it can now be played on your end.void
Parameter NameTypeDescriptionRequired
data{track: MediaStreamTrack; stream: MediaStream; label: 'audio';}The data object containing the audio stream and audio stream track that can be played.Yes
Example Usage
const remoteAudio = useRemoteAudio({ peerId: "remote-peer-id", onPlayable: (data) => {
	console.log("Ready to play remote peer's audio stream!");
    // your code here
}});
3. onCloseOptionalAdvanced
DescriptionReturn Type
This function will be called when the other peer disabled their microphone's audio stream.void
Example Usage
const remoteAudio = useRemoteAudio({ peerId: "remote-peer-id", onClose: () => {
	console.log("Remote audio stream has been closed!");
    // your code here
}});

Returns

The useRemoteAudio hook returns an object with the following fields.

1. streamObject
DescriptionType
Remote peer's audio stream. null if not enabled yet.MediaStream | null
2. trackObject
DescriptionType
Remote peer's audio stream track. null if not enabled yet.MediaStreamTrack | null
3. stateObject
DescriptionType
State of the remote peer's audio stream."playable" | "unavailable" | "stopped" | "paused" | "available"
Audio/Video Infrastructure designed for the developers to empower them ship simple yet powerful Audio/Video Apps.
support
company
Copyright © 2022 Graphene 01, Inc. All Rights Reserved.