import { StreamVideoClient } from "@stream-io/video-react-sdk";
let client: StreamVideoClient;
await client.queryCalls({
// ...
watch: true,
});Events
Use the reactive state store for most cases. For advanced use cases, subscribe to WebSocket events directly.
Best Practices
- Use state hooks when possible - events are for advanced cases.
- Always unsubscribe when components unmount to prevent memory leaks.
- Watch calls with
watch: trueorcall.get()to receive call events. - Use the
onmethod's return value for cleanup.
List of events
Client events
Client events are always delivered if a user is connected to the client using the connectUser method.
The list of client events:
| Name | Description |
|---|---|
connection.ok | Fired when the authentication process finished successfully |
connection.error | Fired when the WS connection fails |
health.check | Fired periodically as a heartbeat to keep the connection alive |
user.updated | Fired when the connected user's data is updated |
Call events
These events are related to a specific call. Some of these events are only delivered to clients that are watching the specific call. There are 3 ways to watch a call:
- Call the
queryCallsmethod with thewatchoption set totrue:
- Join a call:
import { StreamVideoClient } from "@stream-io/video-react-sdk";
let client: StreamVideoClient;
await client.call("default", "test-call").join();- Watch a call:
import { StreamVideoClient } from "@stream-io/video-react-sdk";
let client: StreamVideoClient;
await client.call("default", "test-call").getOrCreate();
// or
await client.call("default", "test-call").get();The list of call events:
| Name | Description | Delivered to |
|---|---|---|
call.accepted | A user accepts a notification to join a call | All call members |
call.blocked_user | A user is blocked from the call | Call watchers |
call.closed_caption | A new closed caption is available | Call watchers |
call.closed_captions_failed | Closed captions failed to start or run | Call watchers |
call.closed_captions_started | Closed captions were started | Call watchers |
call.closed_captions_stopped | Closed captions were stopped | Call watchers |
call.created | The call was created | All call members |
call.deleted | The call was deleted | All call members |
call.ended | The call was ended | All call members |
call.frame_recording_failed | A frame recording (screenshot capture) failed | Call watchers |
call.frame_recording_ready | A frame recording is ready | Call watchers |
call.frame_recording_started | A frame recording was started | Call watchers |
call.frame_recording_stopped | A frame recording was stopped | Call watchers |
call.hls_broadcasting_failed | The call failed to broadcast | Call watchers |
call.hls_broadcasting_started | The call started to broadcast | Call watchers |
call.hls_broadcasting_stopped | The call stopped broadcasting | Call watchers |
call.kicked_user | A user was kicked from the call | Call watchers |
call.live_started | The call left backstage mode | Call watchers |
call.member_added | One or more members were added to the call | All call members |
call.member_removed | One or more members were removed from the call | All call members |
call.member_updated | One or more members were updated | All call members |
call.member_updated_permission | One or more members' role was updated | All call members |
call.missed | A ringing call was missed by the user | All call members |
call.moderation_blur | A moderation blur action was applied | Call watchers |
call.moderation_warning | A moderation warning was issued | Call watchers |
call.notification | A user is calling all call members | All call members |
call.permission_request | A user is requesting permissions | Call watchers |
call.permissions_updated | A member's permissions were updated | Call watchers |
call.reaction_new | A new reaction was sent | Call watchers |
call.recording_failed | A recording failed | Call watchers |
call.recording_ready | A recording is ready | Call watchers |
call.recording_started | A recording has been started | Call watchers |
call.recording_stopped | The recording was stopped | Call watchers |
call.rejected | A user declined to join the call | All call members |
call.ring | A user is calling all call members | All call members |
call.rtmp_broadcast_failed | An RTMP broadcast failed | Call watchers |
call.rtmp_broadcast_started | An RTMP broadcast was started | Call watchers |
call.rtmp_broadcast_stopped | An RTMP broadcast was stopped | Call watchers |
call.session_ended | A call session ended (all participants have left the call) | Call watchers |
call.session_participant_count_updated | The participant counts for the session were updated | Call watchers |
call.session_participant_joined | A participant joined the call session | Call watchers |
call.session_participant_left | A participant left a call session | Call watchers |
call.session_started | A call session started (the first participant joined the call) | Call watchers |
call.stats_report_ready | A call stats report is ready | Call watchers |
call.transcription_failed | A transcription failed to start or run | Call watchers |
call.transcription_ready | A transcription is ready | Call watchers |
call.transcription_started | A transcription was started | Call watchers |
call.transcription_stopped | A transcription was stopped | Call watchers |
call.unblocked_user | A user is unblocked | Call watchers |
call.updated | The call was updated | Call watchers |
call.user_feedback_submitted | A user submitted call feedback | Call watchers |
call.user_muted | A user was muted by another user | Call watchers |
custom | A custom event sent via sendCustomEvent | All call members |
Listening to client and call events
You can use the on method of the StreamVideoClient instance to subscribe to client and call WebSocket events.
The on method takes the type of the event you want to subscribe to or the 'all' keyword indicating that you want to be notified about all events.
The event handler will receive an object with type StreamVideoEvent that has a type attribute that tells the type of the event. The available event types are described by the EventTypes type.
The on method returns a method that can be called to unsubscribe from WebSocket events.
Subscribing to all events:
import {
StreamVideoClient,
StreamVideoEvent,
} from "@stream-io/video-react-sdk";
let client: StreamVideoClient;
// Subscribe to all events
const unsubscribe = client.on("all", (event: StreamVideoEvent) => {
console.log(event);
});
// Unsubscribe
unsubscribe();Subscribing to call.created events:
import {
StreamVideoClient,
StreamVideoEvent,
} from "@stream-io/video-react-sdk";
let client: StreamVideoClient;
// Subscribe to all events
const unsubscribe = client.on("call.created", (event: StreamVideoEvent) => {
if (event.type === "call.created") {
console.log(`Call created: ${event.call_cid}`);
}
});
// Unsubscribe
unsubscribe();Listening to call events
You can use the on method of the call instance to subscribe to WebSocket events belonging to a specific call.
The call.on method takes the type of the event you want to subscribe to.
The event handler will receive an object with type StreamCallEvent that has a type attribute that tells the type of the event.
The available event types are described by the CallEventTypes type.
The call.on method returns a method that can be called to unsubscribe from WebSocket events.
Example: Subscribing to call.reaction_new event:
import { Call, StreamVideoEvent } from "@stream-io/video-react-sdk";
let call: Call;
// Subscribe to new reactions event
const unsubscribe = call.on("call.reaction_new", (event: StreamVideoEvent) => {
if (event.type === "call.reaction_new") {
console.log(`New reaction: ${event.reaction}`);
}
});
// Unsubscribe
unsubscribe();Custom events
You can send custom events between the call participants using the sendCustomEvent method of the call instance.
Note that the payload for these events is limited to 5KB in size.
import {
Call,
CustomVideoEvent,
StreamVideoEvent,
} from "@stream-io/video-react-sdk";
let call: Call;
// sending a custom event
await call.sendCustomEvent({
type: "my-event-type",
payload: {
foo: "bar",
},
});
// receiving a custom event
call.on("custom", (event: StreamVideoEvent) => {
const customEvent = event as CustomVideoEvent;
const payload = customEvent.custom;
if (payload.type === "my-event-type") {
console.log(payload.foo);
}
});