Call & Participant State

The call, participant and client states are reactive. Their value is updated on WebSocket events and API calls. We use the RxJS library for this, each state property is an Observable.

Let’s see an example, this is how you can subscribe to changes related to participants:

const { participants$ } = call.state;
const subscription = participants$.subscribe((participants) => {
  console.log(participants);
});

// dispose the subscription when you don't need it anymore
subscription.unsubscribe();

The console.log method will be called each time there is a change to the list of participants in the call.

This approach makes it possible to access the state and be notified about changes anywhere in your application without having to manually subscribe to WebSocket events.

Alternatively, you can also access the current value of each state variable:

const { participants } = call.state;
console.log(participants);

It’s useful when you need to know the current value, but you don’t need to be notified about future changes.

Call state

The call state can be accessed through call.state object as in the examples above. In this object, you’ll find properties that are reactive and static as well. The reactive/observable properties are suffixed with $ and the static ones are without the suffix.

For the best experience, please make sure that the call instance is loaded and connected to our backend: Load Call.

Otherwise, call.state observables will emit empty values and you won’t get real time updates.

Here is an excerpt of the call state properties:

Reactive valueStatic valueDescription
backstage$backstagetrue when the call runs in backstage mode
blockedUserIds$blockedUserIdsThe list of blocked user IDs.
callingState$callingStateProvides information about the call state. For example, RINGING, JOINED or RECONNECTING.
callStatsReport$callStatsReportWhen stats gathering is enabled, this observable will emit a new value at a regular (configurable) interval.
createdAt$createdAtThe time the call was created.
createdBy$createdByThe user who created the call.
custom$customCustom data attached to the call.
dominantSpeaker$dominantSpeakerThe participant that is the current dominant speaker of the call.
egress$egressThe egress data of the call (for broadcasting and livestreaming).
endedAt$endedAtThe time the call was ended.
endedBy$endedByThe user who ended the call.
hasOngoingScreenShare$hasOngoingScreenShareIt will return true if at least one participant is sharing their screen.
ingress$ingressThe ingress data of the call (for broadcasting and livestreaming).
members$membersThe list of call members
ownCapabilities$ownCapabilitiesThe capabilities of the local participant.
pinnedParticipants$pinnedParticipantsThe participants that are currently pinned.
recording$recordingThe recording state of the call.
session$sessionThe data for the current call session.
settings$settingsThe settings of the call.
startedAt$startedAtThe actual start time of the current call session.
startsAt$startsAtThe time the call is scheduled to start.
thumbnails$thumbnailsThe thumbnails of the call.
transcribing$transcribingThe transcribing state of the call.
updatedAt$updatedAtThe time the call was updated.

Your IDE of choice may help you to discover the other properties of the call state.

Participant state

If you want to display information about the joined participants of the call you can use the following properties in call.state:

Reactive valueStatic valueDescription
localParticipant$localParticipantThe local participant is the logged-in user.
remoteParticipants$remoteParticipantsAll participants except the local participant.
participants$participantsAll participants, including local and remote participants.
participantCount$participantCountThe approximate participant count of the active call. This includes the anonymous users as well, it is computed on the server-side.
anonymousParticipantCount$anonymousParticipantCountThe approximate participant count of anonymous users in the active call.

The StreamVideoParticipant object contains the following information:

NameDescription
audioLevelThe audio level of the participant (determined on the server).
audioStreamThe published audio MediaStream.
audioVolumeThe audio volume level of the participant (overridable local audioVolume level).
connectionQualityThe participant’s connection quality.
customThe participant’s custom data. Comes from the custom field of the user object.
imageThe image of the participant.
isDominantSpeakerIt’s true if the participant is the current dominant speaker in the call.
isLocalParticipantIt’s true if the participant is the local participant.
isSpeakingIt’s true if the participant is currently speaking.
joinedAtThe time the participant joined the call.
nameThe name of the participant.
pinHolds pinning information.
publishedTracksThe track types the participant is currently publishing
reactionThe last reaction this user has sent to this call.
rolesThe roles of the participant in this call.
sessionIdThe identifier of the participant within the existing call session
screenShareAudioStreamThe published screen share audio MediaStream.
screenShareStreamThe published screen share MediaStream.
userIdThe user ID of the participant.
videoStreamThe published video MediaStream.
viewportVisibilityStateThe viewport visibility state of the participant.

The SDK also provides a few utility functions that help you to work with participants:

import {
  Call,
  hasAudio,
  hasScreenShare,
  hasScreenShareAudio,
  hasVideo,
  isPinned,
} from "@stream-io/video-client";

let call: Call;

// example usage
const subscription = call.state.participants$.subscribe((participants) => {
  for (let participant of participants) {
    // check if the participant has audio, video, screen share or screen share audio
    const hasAudioOn = hasAudio(participant);
    const hasVideoOn = hasVideo(participant);
    const hasScreenShareOn = hasScreenShare(participant);
    const hasScreenShareAudioOn = hasScreenShareAudio(participant);
    const isPinnedOn = isPinned(participant);
  }

  // participants with a specific role
  const hosts = participants.filter((p) => p.roles.includes("host"));

  // participants that publish video and audio
  const videoParticipants = participants.filter(
    (p) => hasVideo(p) && hasAudio(p),
  );
});

subscription.unsubscribe();

In a call with many participants, the value of the participants$ call state observable is truncated to 250 participants. The participants who are publishing video, audio, or screen sharing have priority over the other participants in the list. This means, for example, that in a livestream with one host and many viewers, the host is guaranteed to be in the list.

Client state

The client state can be accessed by client.state.

Here is the list of client state properties:

Reactive valueStatic valueDescription
connectedUser$connectedUserReturns the connected user. Holds the server-side data of the connected user.
calls$callsA list of all tracked calls. These calls can be outgoing (I have called somebody) or incoming (somebody has called me). Loaded calls (call.get()) are also part of this list.

The connectedUser object contains the following properties:

NameDescription
created_atThe time the user was created.
customCustom user data.
deleted_atThe time the user was deleted.
devicesThe registered push notification devices of the user.
idThe id of the user.
imageThe profile image of the user.
nameThe name of the user.
roleThe role of the user.
teamsThe teams the user belongs to.
updated_atThe time when the user was updated.
© Getstream.io, Inc. All Rights Reserved.