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: true or call.get() to receive call events.
  • Use the on method'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:

NameDescription
connection.okFired when the authentication process finished successfully
connection.errorFired when the WS connection fails
health.checkFired periodically as a heartbeat to keep the connection alive
user.updatedFired 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:

  1. Call the queryCalls method with the watch option set to true:
import { StreamVideoClient } from "@stream-io/video-react-sdk";

let client: StreamVideoClient;

await client.queryCalls({
  // ...
  watch: true,
});
  1. Join a call:
import { StreamVideoClient } from "@stream-io/video-react-sdk";

let client: StreamVideoClient;

await client.call("default", "test-call").join();
  1. 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:

NameDescriptionDelivered to
call.acceptedA user accepts a notification to join a callAll call members
call.blocked_userA user is blocked from the callCall watchers
call.closed_captionA new closed caption is availableCall watchers
call.closed_captions_failedClosed captions failed to start or runCall watchers
call.closed_captions_startedClosed captions were startedCall watchers
call.closed_captions_stoppedClosed captions were stoppedCall watchers
call.createdThe call was createdAll call members
call.deletedThe call was deletedAll call members
call.endedThe call was endedAll call members
call.frame_recording_failedA frame recording (screenshot capture) failedCall watchers
call.frame_recording_readyA frame recording is readyCall watchers
call.frame_recording_startedA frame recording was startedCall watchers
call.frame_recording_stoppedA frame recording was stoppedCall watchers
call.hls_broadcasting_failedThe call failed to broadcastCall watchers
call.hls_broadcasting_startedThe call started to broadcastCall watchers
call.hls_broadcasting_stoppedThe call stopped broadcastingCall watchers
call.kicked_userA user was kicked from the callCall watchers
call.live_startedThe call left backstage modeCall watchers
call.member_addedOne or more members were added to the callAll call members
call.member_removedOne or more members were removed from the callAll call members
call.member_updatedOne or more members were updatedAll call members
call.member_updated_permissionOne or more members' role was updatedAll call members
call.missedA ringing call was missed by the userAll call members
call.moderation_blurA moderation blur action was appliedCall watchers
call.moderation_warningA moderation warning was issuedCall watchers
call.notificationA user is calling all call membersAll call members
call.permission_requestA user is requesting permissionsCall watchers
call.permissions_updatedA member's permissions were updatedCall watchers
call.reaction_newA new reaction was sentCall watchers
call.recording_failedA recording failedCall watchers
call.recording_readyA recording is readyCall watchers
call.recording_startedA recording has been startedCall watchers
call.recording_stoppedThe recording was stoppedCall watchers
call.rejectedA user declined to join the callAll call members
call.ringA user is calling all call membersAll call members
call.rtmp_broadcast_failedAn RTMP broadcast failedCall watchers
call.rtmp_broadcast_startedAn RTMP broadcast was startedCall watchers
call.rtmp_broadcast_stoppedAn RTMP broadcast was stoppedCall watchers
call.session_endedA call session ended (all participants have left the call)Call watchers
call.session_participant_count_updatedThe participant counts for the session were updatedCall watchers
call.session_participant_joinedA participant joined the call sessionCall watchers
call.session_participant_leftA participant left a call sessionCall watchers
call.session_startedA call session started (the first participant joined the call)Call watchers
call.stats_report_readyA call stats report is readyCall watchers
call.transcription_failedA transcription failed to start or runCall watchers
call.transcription_readyA transcription is readyCall watchers
call.transcription_startedA transcription was startedCall watchers
call.transcription_stoppedA transcription was stoppedCall watchers
call.unblocked_userA user is unblockedCall watchers
call.updatedThe call was updatedCall watchers
call.user_feedback_submittedA user submitted call feedbackCall watchers
call.user_mutedA user was muted by another userCall watchers
customA custom event sent via sendCustomEventAll 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);
  }
});