Methods returned by useRoom Hook - React Native
Every method that acts on the room returns a Promise. A method called before join() rejects with ERROR_ACTION_PERFORMED_BEFORE_ROOM_JOINED (3035). Some failures are reported only through the onError callback, so handle errors both where you call the method and in onError. To see all available error codes from SDK, refer to Error Codes.
Call these methods on what useRoom() returns. The room object has most of them too, but not the toggles, setAudioDevice(), the video processor methods, getActivePresenterId() or getActiveSpeakerId().
join()
- Joins the room.
- If
joinWithoutUserInteractionistrueon<RoomProvider>, the participant joins automatically. If it isfalse, calljoin()yourself.
Events associated with join():
- The local participant receives
onRoomJoinedonce joined. - Remote participants receive
onParticipantJoinedwith the newParticipant.
Participant having ask_join permission inside token
-
If the token has the
ask_joinpermission, the participant does not join directly. Participants with theallow_joinpermission receiveonEntryRequested, and answer with itsallow()/deny()functions or withrespondEntry(). -
Once someone decides,
onEntryRespondedreports the decision.
Participant having allow_join permission inside token
- If the token has the
allow_joinpermission, the participant joins directly.
Returns
Promise<void>
leave()
- Leaves the room. Only the local participant leaves.
Events associated with leave():
- The local participant receives
onRoomLeft. - Remote participants receive
onParticipantLeftwith theParticipantwho left.
Returns
Promise<void>
end()
- Ends the room for every participant.
Events associated with end():
- Every participant, including the local participant, receives
onRoomLeft.
Returns
Promise<void>
unmuteMic()
- Turns on the local participant's microphone.
- In
RECV_ONLYorSIGNALLING_ONLYmode, it rejects with3066ERROR_ACTION_NOT_SUPPORTED_IN_MODE.
Parameters
- customMicrophoneTrack (optional): a
CustomStreamTrackfromcreateMicrophoneAudioTrack(). If you do not pass one, the SDK opens the selected microphone.
Events associated with unmuteMic():
- Every participant receives
onStreamEnabled()ofuseParticipant()with theRTCStream.
Returns
Promise<void>
muteMic()
- Turns off the local participant's microphone.
Events associated with muteMic():
- Every participant receives
onStreamDisabled()ofuseParticipant()with theRTCStream.
Returns
Promise<void>
Example
const { isMicEnabled, muteMic, unmuteMic } = useRoom();
const onMicPress = () => (isMicEnabled ? muteMic() : unmuteMic());
toggleMic()
- Turns the local participant's microphone off when it is on, and on when it is off.
- In
RECV_ONLYorSIGNALLING_ONLYmode, turning it on rejects with3066ERROR_ACTION_NOT_SUPPORTED_IN_MODE.
Parameters
- customMicrophoneTrack (optional): a
CustomStreamTrackfromcreateMicrophoneAudioTrack(), used when the microphone turns on.
Events associated with toggleMic():
- Every participant receives
onStreamEnabled()when the microphone turns on, oronStreamDisabled()when it turns off.
Returns
Promise<void>
Example
const { toggleMic } = useRoom();
const onMicPress = async () => {
try {
await toggleMic();
} catch (error) {
console.log("toggleMic failed", error.code, error.message);
}
};
enableCam()
- Turns on the local participant's camera.
- In
RECV_ONLYorSIGNALLING_ONLYmode, it rejects with3066ERROR_ACTION_NOT_SUPPORTED_IN_MODE.
Parameters
- customCameraTrack (optional): a
CustomStreamTrackfromcreateCameraVideoTrack(). Pass the track you previewed to keep its picture. If you do not pass one, the SDK opens the selected camera.
Events associated with enableCam():
- Every participant receives
onStreamEnabled()ofuseParticipant()with theRTCStream.
Returns
Promise<void>
disableCam()
- Turns off the local participant's camera.
Events associated with disableCam():
- Every participant receives
onStreamDisabled()ofuseParticipant()with theRTCStream.
Returns
Promise<void>
Example
const { isCamEnabled, enableCam, disableCam } = useRoom();
const onCameraPress = () => (isCamEnabled ? disableCam() : enableCam());
toggleCam()
- Turns the local participant's camera off when it is on, and on when it is off.
- In
RECV_ONLYorSIGNALLING_ONLYmode, turning it on rejects with3066ERROR_ACTION_NOT_SUPPORTED_IN_MODE.
Parameters
- customCameraTrack (optional): a
CustomStreamTrackfromcreateCameraVideoTrack(), used when the camera turns on.
Events associated with toggleCam():
- Every participant receives
onStreamEnabled()when the camera turns on, oronStreamDisabled()when it turns off.
Returns
Promise<void>
Example
const { toggleCam } = useRoom();
const onCameraPress = async () => {
try {
await toggleCam();
} catch (error) {
console.log("toggleCam failed", error.code, error.message);
}
};
changeMic()
- Switches the microphone.
- Pass a
deviceIdfromgetMics(), or a track fromcreateMicrophoneAudioTrack(). If you pass nothing, the SDK switches to the next microphone in the list, and after the last one back to the first. - A
deviceIdthat matches no microphone rejects withERROR_NO_MICROPHONE_DEVICE_FOUND(3059).
Parameters
- deviceIdOrTrack (optional):
string|CustomStreamTrack
Returns
Promise<void>
changeCam()
- Switches the camera.
- Pass a
deviceIdfromgetCameras(), or a track fromcreateCameraVideoTrack(). If you pass nothing, the SDK switches to the next camera in the list, and after the last one back to the first. - A
deviceIdthat matches no camera rejects withERROR_NO_WEBCAM_DEVICE_FOUND(3051).
Parameters
- deviceIdOrTrack (optional):
string|CustomStreamTrack
Returns
Promise<void>
Example
import { useMediaDevice, useRoom } from "@videosdk.live/react-native-sdk";
const { changeCam } = useRoom();
const { getCameras } = useMediaDevice();
const switchToBackCamera = async () => {
const cameras = await getCameras();
const backCamera = cameras.find((camera) => camera.facingMode === "back");
if (backCamera) {
await changeCam(backCamera.deviceId);
}
};
setWebcamQuality()
- Sets the quality of the camera video you send.
Parameters
- quality:
"low"|"med"|"high", the values ofConstants.VideoQuality
Returns
Promise<void>
enableScreenShare()
- Starts sharing the local participant's screen.
- In
RECV_ONLYorSIGNALLING_ONLYmode, it rejects with3066ERROR_ACTION_NOT_SUPPORTED_IN_MODE. - It takes one optional argument: a track from
createScreenShareVideoTrack(). To choose the encoder profile, create the track withencoderConfig. - On Android, the screen capture consent dialog appears when you create the track. If you call
enableScreenShare()without a track, it shows the dialog itself and, on Android 10 and later, also shares the device audio mixed into your microphone track. To share without device audio, pass a track fromcreateScreenShareVideoTrack(). - On iOS,
enableScreenShare()shows the system broadcast sheet. Screen capture starts when the user taps Start Broadcast.
Parameters
- customScreenShareTrack (optional):
CustomStreamTrack
Events associated with enableScreenShare():
-
Every participant receives
onStreamEnabled()ofuseParticipant()with theshareRTCStream. This tells you that sharing has started. -
onPresenterChanged()receives the presenter's id.
Returns
Promise<void>
Example
import {
createScreenShareVideoTrack,
useRoom,
} from "@videosdk.live/react-native-sdk";
const { enableScreenShare } = useRoom();
const startScreenShare = async () => {
const screenShareTrack = await createScreenShareVideoTrack({
encoderConfig: "h720p_15fps",
});
await enableScreenShare(screenShareTrack);
};
For React Native iOS Screen Share feature, your app needs a Broadcast Upload Extension. Follow this guide to set it up: React Native iOS Screen Share
disableScreenShare()
- Stops sharing the local participant's screen.
Events associated with disableScreenShare():
-
Every participant receives
onStreamDisabled()ofuseParticipant()with theshareRTCStream. -
onPresenterChanged()receivesnull.
Returns
Promise<void>
toggleScreenShare()
- Starts the screen share when it is off and stops it when it is on.
- In
RECV_ONLYorSIGNALLING_ONLYmode, it rejects with3066ERROR_ACTION_NOT_SUPPORTED_IN_MODE. - It takes the same optional argument as
enableScreenShare(), used when sharing starts. - Only
useRoom()has it. Theroomobject does not.
Parameters
- customScreenShareTrack (optional):
CustomStreamTrack
Returns
Promise<void>
For React Native iOS Screen Share feature, your app needs a Broadcast Upload Extension. Follow this guide to set it up: React Native iOS Screen Share
setAudioDevice()
- Routes audio to a device from
getMics(), such as the speaker, earpiece or a Bluetooth headset. It does not change whether the microphone is muted. - Call it after
join().
Parameters
- device:
MicrophoneDeviceInfo|"SPEAKER_PHONE"|"EARPIECE"|"WIRED_HEADSET"|"BLUETOOTH"
Returns
Promise<void>
Example
import { useMediaDevice, useRoom } from "@videosdk.live/react-native-sdk";
const { setAudioDevice } = useRoom();
const { getMics } = useMediaDevice();
const useFirstDevice = async () => {
const devices = await getMics();
if (devices.length > 0) await setAudioDevice(devices[0]);
};
setVideoProcessor()
- Applies a video processor that your app registered natively under
name. See Video Processor. - Applying a name that has no registered processor rejects with
ERROR_INVALID_PARAMETER(3073).
Parameters
- name:
string
Returns
Promise<void>
removeVideoProcessor()
- Removes the video processor in use.
Returns
Promise<void>
startRecording()
-
Starts recording the room.
-
webhookUrlis called when the recording is complete and stored. Read more about webhooks here. -
awsDirPathis the folder in your own cloud storage where the recording is stored. To store recordings in your AWS S3, Azure Blob or GCP storage, set it up as described in Recording Storage Config. -
config.moderecords video and audio, or only audio. The default is video and audio. -
config.qualityapplies only to video-and-audio. -
transcriptionturns on a transcript of the recording, made after the recording ends.
Parameters
- webhookUrl (optional): String
- awsDirPath (optional): String
- config (optional):
- layout:
ConfigLayout- type: "GRID" | "SPOTLIGHT" | "SIDEBAR"
- priority: "SPEAKER" | "PIN"
- gridSize: Number
max 4
- theme: "DARK" | "LIGHT" | "DEFAULT"
- mode: "video-and-audio" | "audio"
- quality: "low" | "med" | "high"
- orientation: "landscape" | "portrait"
- layout:
- transcription (optional):
- enabled: Boolean
- summary: { enabled: Boolean, prompt: String }
- modelId: String
Events associated with startRecording():
- Every participant receives
onRecordingStarted(). - The returned Promise resolves once the request is sent, not when the recording has started. The recording has started when
onRecordingStateChanged()reportsRECORDING_STARTED.
Returns
Promise<void>
Example
const webhookUrl = "https://webhook.your-api-server.com";
const awsDirPath = "/room-recordings/";
const { startRecording } = useRoom();
startRecording(webhookUrl, awsDirPath, {
layout: {
type: "SPOTLIGHT",
priority: "PIN",
gridSize: 4,
},
theme: "DEFAULT",
mode: "video-and-audio",
quality: "high",
orientation: "landscape",
});
stopRecording()
- Stops the recording.
Events associated with stopRecording():
- Every participant receives
onRecordingStopped().
Returns
Promise<void>
startLivestream()
- Starts live streaming the room to platforms that support
RTMP, such as YouTube or Facebook.
Parameters
- outputs: Array<{ url: String, streamKey: String }>
- config (optional):
- layout:
ConfigLayout- type: "GRID" | "SPOTLIGHT" | "SIDEBAR"
- priority: "SPEAKER" | "PIN"
- gridSize: Number
max 4
- theme: "DARK" | "LIGHT" | "DEFAULT"
- recording: { enabled: Boolean }, whether the livestream is also recorded
- layout:
Events associated with startLivestream():
- Every participant receives
onLivestreamStarted().
Returns
Promise<void>
Example
const outputs = [
{
url: "rtmp://a.rtmp.youtube.com/live2",
streamKey: "<STREAM_KEY>",
},
{
url: "rtmps://",
streamKey: "<STREAM_KEY>",
},
];
const { startLivestream } = useRoom();
startLivestream(outputs, {
layout: {
type: "SPOTLIGHT",
priority: "PIN",
gridSize: 4,
},
theme: "DEFAULT",
});
stopLivestream()
- Stops the live stream.
Events associated with stopLivestream():
- Every participant receives
onLivestreamStopped().
Returns
Promise<void>
startHLS()
-
Starts HLS streaming of the room.
-
config.modestreams video and audio, or only audio. The default is video and audio. -
config.qualityapplies only to video-and-audio.
Parameters
- config (optional):
- layout:
ConfigLayout- type: "GRID" | "SPOTLIGHT" | "SIDEBAR"
- priority: "SPEAKER" | "PIN"
- gridSize: Number
max 25
- theme: "DARK" | "LIGHT" | "DEFAULT"
- mode: "video-and-audio" | "audio"
- quality: "low" | "med" | "high"
- orientation: "landscape" | "portrait"
- recording: { enabled: Boolean }, whether the HLS stream is also recorded
- layout:
- transcription (optional): the same as for
startRecording().
Events associated with startHLS():
- Every participant receives
onHlsStateChanged()as HLS starts. The HLS URLs arrive with theHLS_PLAYABLEstate.
Returns
Promise<void>
Example
const { startHLS } = useRoom();
startHLS({
layout: {
type: "SPOTLIGHT",
priority: "PIN",
gridSize: 9,
},
theme: "DEFAULT",
mode: "video-and-audio",
quality: "high",
orientation: "portrait",
});
stopHLS()
- Stops HLS streaming.
Events associated with stopHLS():
- Every participant receives
onHlsStateChanged()withHLS_STOPPING, thenHLS_STOPPED.
Returns
Promise<void>
changeMode()
Changes the local participant's mode.
-
The modes are:
-
SEND_AND_RECV: The participant sends and receives audio and video. -
SIGNALLING_ONLY: The participant neither sends nor receives audio and video, but stays in the room. -
RECV_ONLY: The participant receives audio and video but sends none.
-
Parameters
- mode: one of
Constants.Mode: "SEND_AND_RECV" | "SIGNALLING_ONLY" | "RECV_ONLY"
Events associated with changeMode():
- Every participant receives
onParticipantModeChanged().
Returns
Promise<void>
respondEntry()
- Answers an entry request from
onEntryRequested. The request's ownallow()anddeny()functions do the same. - Pass
"allowed"to let the participant in, or"denied"to refuse.
Parameters
- participantId: String, the
participantIdfrom the entry request - decision: "allowed" | "denied"
Events associated with respondEntry():
- The participant who asked to join, and the participants with the
allow_joinpermission, receiveonEntryResponded()with the decision.
Returns
Promise<void>
Example
const { respondEntry } = useRoom({
onEntryRequested: ({ participantId, name }) => {
console.log(`${name} requested to join the room.`);
// To let them in
respondEntry(participantId, "allowed");
// To refuse
// respondEntry(participantId, "denied");
},
});
send()
- Sends a message to every other participant over the room's data channel.
- The message can be a string, an
ArrayBufferor a typed array such asUint8Array. ABlobis not supported. - The Promise resolves once the message is sent. It does not confirm that the other participants received it. It rejects when the message did not go out.
Parameters
- message: String | ArrayBuffer | typed array
- reliable (optional):
boolean.true(the default) delivers every message in order.falsesends the message once, so it can be lost.
Events associated with send():
- Every other participant receives
onDataReceived()with the message.
Returns
Promise<void>
Example
const { send } = useRoom();
const sendGreeting = async () => {
await send("Hello everyone!");
};
const sendPosition = async () => {
await send(new Uint8Array([10, 20]), false);
};
pauseAllStreams()
Pauses the media streams you receive from the other participants.
Parameters
-
kind (optional): the kind of stream to pause. If you leave it out, every kind is paused.
- Type:
String- Possible values:
"audio": Pauses audio streams."video": Pauses video streams."share": Pauses screen-share video streams."shareAudio": Pauses screen-share audio streams."all": Pauses every kind.
- Type:
Events associated with pauseAllStreams():
onPausedAllStreams()is called with thekindthat was paused. If you omitkind, it is called once for each kind or once with"all", depending on the platform.
Returns
Promise<void>
resumeAllStreams()
Resumes the media streams you paused.
Parameters
- kind (optional): the kind of stream to resume. If you leave it out, every kind is resumed. Takes the same values as
pauseAllStreams().
Events associated with resumeAllStreams():
onResumedAllStreams()is called with thekindthat was resumed. If you omitkind, it is called once for each kind or once with"all", depending on the platform.
Returns
Promise<void>
enableAdaptiveSubscription()
- Turns on adaptive subscription. The quality of each video stream you receive then follows how large you show that participant and your network conditions.
- Report the size you show each participant at with
setViewPort()of theuseParticipant()hook.
Returns
Promise<void>
disableAdaptiveSubscription()
- Turns off adaptive subscription. Every video stream you receive then comes at the quality its publisher sends, whatever its size on screen or the network conditions.
Returns
Promise<void>
requestMediaRelay()
Starts relaying your media, such as camera video, microphone audio or screen share, from this room into another room.
Parameters
It takes one object with these fields:
-
destinationRoomId (String) – Required: ID of the room to relay into.
-
token (String) – Optional: Authentication token for the destination room.
-
kinds (Array of Strings) – Optional: The media to relay. Every kind is relayed when you leave it out.
- Possible values:
"audio": Relays audio streams."video": Relays video streams."share": Relays screen-share streams.
- Possible values:
Events associated with requestMediaRelay():
- The participants of the destination room receive
onMediaRelayRequestReceived(). - You receive
onMediaRelayRequestResponse()with their decision, andonMediaRelayStarted()when the relay starts.
Returns
Promise<void>
Example
const { requestMediaRelay } = useRoom();
const relayToRoom = async (destinationRoomId) => {
await requestMediaRelay({
destinationRoomId,
kinds: ["audio", "video"],
});
};
stopMediaRelay()
Stops relaying your media into one room.
Parameters
- destinationRoomId (String) – Required: ID of the room to stop relaying into.
Events associated with stopMediaRelay():
- You receive
onMediaRelayStopped().
Returns
Promise<void>
switchTo()
Moves you from this room into another room without leaving and joining again.
Parameters
-
roomId (String) – Required: ID of the room to switch to.
-
token (String) – Optional: Authentication token for the new room. Without it, the current token is used.
Events associated with switchTo():
- You receive
onRoomJoined()once you are in the new room.
Returns
Promise<void>
Example
const { switchTo } = useRoom();
const moveToRoom = async (roomId, token) => {
await switchTo(roomId, token);
};
getActivePresenterId()
- Returns the id of the participant sharing their screen, or
nullwhen nobody is. - Calling it while rendering re-renders the component when the presenter changes.
Returns
string | null
getActiveSpeakerId()
- Returns the id of the participant speaking, or
nullwhen nobody is. - Calling it while rendering re-renders the component when the speaker changes.
Returns
string | null
Example
const { getActiveSpeakerId, getActivePresenterId } = useRoom();
const speakerId = getActiveSpeakerId();
const presenterId = getActivePresenterId();
Transcription, translation and whiteboard
- To start and stop transcription, translation and the whiteboard, use the
useTranscription(),useTranslation()anduseWhiteboard()hooks.
Got a Question? Ask us on discord

