Skip to main content
Version: Version 2.0

useVideo

The useVideo hook provides access to video conferencing functionalities, such as joining, leaving, and managing participants.

Usage

Example:

const videoHook = useVideo({
onParticipantJoined: (participant) => console.log('Component: Participant joined', participant),
onParticipantLeft: (participant) => console.log('Component: Participant left', participant),
});

Callbacks

onHostChanged

Triggered when the host changes.

Example:

const videoHook = useVideo({
onHostChanged: (host) => console.log('Component: Host changed', host)
});

On the callback function, you will receive the following argument:

TypeDescription
ParticipantParticipant that now is the host.

onParticipantJoined

Triggered when a participant joins the meeting.

Example:

const videoHook = useVideo({
onParticipantJoined: (participant) => console.log('Component: Participant joined', participant)
});

On the callback function, you will receive the following argument:

TypeDescription
ParticipantParticipant that joined the meeting.

onMeetingStateUpdate

Triggered when the meeting state updates. The Video Conference operates through a series of distinct states to ensure the meeting experience. This callback enables you to monitor and react to these state transitions.

Example:

const videoHook = useVideo({
onMeetingStateUpdate: (state) => console.log('Component: Meeting state updated', state),
});

On the callback function, you will receive the following argument:

TypeDescription
MeetingStateMeeting state.

onParticipantLeft

Triggered when a participant leaves the meeting.

Example:

const videoHook = useVideo({
onParticipantLeft: (participant) => console.log('Component: Participant left', participant),
});

On the callback function, you will receive the following argument:

TypeDescription
ParticipantParticipant that left the meeting.

onParticipantListUpdate

Triggered when there is any change in the participant list (e.g., a participant joins or leaves).

Example:

const videoHook = useVideo({
onParticipantListUpdate: (participants) => console.log('Component: Participant list updated', participants)
});

On the callback function, you will receive the following argument:

TypeDescription
Record<string, Participant>
list of participants in the meeting.

onParticipantKicked

Triggered when a participant is kicked from the meeting.

Example:

const videoHook = useVideo({
onParticipantKicked: (participant) => console.log('Component: Participant kicked', participant)
});

On the callback function, you will receive the following argument:

TypeDescription
ParticipantParticipant that was kicked.

Type Definitions

Participant

Type: object

An object describing the participant information, like name and avatar.

NameTypeDescription
idstringIdentifier of the participant who is entering the room. Usually, this ID matches the internal ID of your users. Minimum length of 2 characters and maximum of 64.

Accepted pattern: [-_&@+=,()\{\}\\[\\]\/«».:|'"#a-zA-Z0-9À-ÿ\s]*
activeComponentsComponentNames[]List of active components that the participant has entered.
namestringThe name of the participant who will enter the room.

Example:

{
"id": "USER_ID",
"name": "USER_NAME",
"activeComponents": [],
"slot": {
"index": 2,
"color": "#878291",
"textColor": "#fff",
"colorName": "gray",
"timestamp": 1736161104631
}
}

MeetingState

Type: enum

Represents the current state of the Video Conference meeting. This value reflects one of the possible states indicating the operational status of the meeting component. You can utilize this information in your callback function to respond to and manage the meeting's dynamic behavior based on its state.

Here are the possible states and their meanings:

StateValue
MEETING_FAILED-1Indicates a failure in the meeting, requiring attention or troubleshooting.
MEETING_DISCONNECTED0Indicates a state where the meeting is not connected.
MEETING_INITIALIZING1Signifies the meeting is in the process of initialization.
MEETING_READY_TO_JOIN2Confirms that the meeting was prepared for participants to join, indicating that device permissions have been granted and everything is ready for participants to join.
MEETING_CONNECTING3Indicates an ongoing connection process that happens after the participant joins the meeting.
MEETING_CONNECTED4Confirms that the meeting is successfully connected.
MEETING_RECONNECT5Occurs when the meeting reconnects after a disruption.
FRAME_INITIALIZING6Indicates the initialization of the meeting iframe.
FRAME_INITIALIZED7Indicates a successfully initialized meeting iframe.
FRAME_UNINITIALIZED8Represents an uninitialized meeting iframe.