Call & Participant State

Stateful models

Stream's Video SDK for Unity contains several stateful models that automatically receive events from the Stream Server and update their inner state. Thanks to this you can always rely on them having the most up-to-date state.

Stateful models:

  • IStreamCall - represents a call object
  • IStreamVideoUser - represents a user
  • IStreamVideoCallParticipant - represents a user that is participating in a call. Note that a single user could join from several devices and show up as multiple participants

Call State

Here's an example of how you can access the call state:

var callType = StreamCallType.Default; // Call type affects default permissions
var callId = "my-call-id";

// Get call or create if it doesn't exist
var streamCall = await _client.GetOrCreateCallAsync(callType, callId);

Here's an outline of the IStreamCall object:

Events

EventDescription
ParticipantJoinedFired when a new participant joins the call
ParticipantLeftFired when a participant leaves the call
ParticipantTrackAddedFired when a track is added for a participant in the call
DominantSpeakerChangedFired when the most actively speaking participant in the call changes
ReactionAddedFired when a call participant adds a reaction to the call
PinnedParticipantsUpdatedFired when the PinnedParticipants collection is updated
RecordingStartedFired when recording of the call starts
RecordingStoppedFired when recording of the call stops
SortedParticipantsUpdatedFired when the SortedParticipants collection is updated
EventReceivedFired when a custom event is received. Provides a CallEvent object.
UpdatedFired when the call state is updated.

Properties

PropertyDescription
ParticipantsUsers that are currently in the call. The complete list of users associated with the call can be obtained via Members.
DominantSpeakerThe participant that is currently the most actively speaking. Changes in the dominant speaker trigger the DominantSpeakerChanged event. The PreviousDominantSpeaker can also be obtained.
PreviousDominantSpeakerThe participant who was the last dominant speaker before the current one.
PinnedParticipantsParticipants that are pinned to this call, sorted by the time they were pinned. Locally pinned participants are listed first, followed by those pinned remotely. Updates to this collection trigger the PinnedParticipantsUpdated event.
SortedParticipantsParticipants sorted by pin status, screen-sharing status, dominant speaker, video participants, and audio-only participants. Any update to this collection triggers the SortedParticipantsUpdated event.
OwnCapabilitiesA list of actions the user has permission to perform in the call.
IdThe identifier of the call.
CidThe unique identifier for the call, combining Type and Id.
TypeThe type of call, which determines the permissions schema used. Types can be predefined or custom-created via the dashboard.
IsLocalUserOwnerIndicates whether the local user is the owner of the call.
MembersUsers permanently associated with the call, including those who haven't joined. This includes all invited participants, regardless of whether they have joined the call.
RecordingIndicates whether the call is currently being recorded.
BlockedUsersA list of users that are blocked in this call.
SettingsThe settings configured for this call.
BackstageIndicates whether the call is in backstage mode.
CreatedAtThe date and time when the call was created.
UpdatedAtThe date and time of the last update to the call.
StartsAtThe scheduled start time of the call.
EndedAtThe date and time when the call ended.
TeamThe team that the call is restricted to.
CreatedByThe user who created the call.
IngressIndicates if there is an active ingress session to this call (e.g., sending RTMP into the call).

Methods

MethodDescription
LeaveAsyncLeave the call
EndAsyncEnd the call
GoLiveAsyncStart the live stream of the call
StopLiveAsyncStop the live stream of the call
StartRecordingAsyncStart recording the call
StopRecordingAsyncStop recording the call
MuteAllUsersAsyncMute all users in the call
BlockUserAsyncBlock a user from the call
UnblockUserAsyncUnblock a user from the call
HasPermissionsCheck if you currently have a certain permission
RequestPermissionAsyncRequest a permission from the call host
RequestPermissionsAsyncRequest multiple permissions from the call host
GrantPermissionsAsyncGrant permissions to a user in this call
RevokePermissionsAsyncRevoke permissions from a user in this call
AcceptAsyncMark an incoming call as accepted
RejectAsyncMark an incoming call as rejected
StartHLSStart HTTP Live Streaming
StopHLSStop HTTP Live Streaming
RemoveMembersAsyncRemove members from the call
MuteUsersAsyncMute specific users in the call
QueryMembersAsyncQuery members in the call
SendReactionAsyncSend a reaction in the call
SendCustomEventAsyncSend a custom event in the call
PinLocallyPin a participant locally
UnpinLocallyUnpin a participant locally
IsPinnedLocallyCheck if a participant is pinned locally
IsPinnedRemotelyCheck if a participant is pinned remotely
IsPinnedCheck if a participant is pinned
GetLocalParticipantGet the local user's participant object
MuteSelfMute the local user's audio, video, or screen share
MuteOthersMute all other participants' audio, video, or screen share

Participant State

The Call Participant State represented by a IStreamVideoCallParticipant object is the most essential component used to render a participant in a call. It contains all of the information to render a participant, such as audio & video renderers, availabilities of audio & video, the screen sharing session, reactions, and etc.

You must subscribe to each participant's tracks and bind them to Unity components to receive their audio and video. Call SetAudioSourceTarget on each StreamAudioTrack and SetRenderTarget on each StreamVideoTrack. Without this, you will not hear or see other participants. See the Quickstart for a complete example.

Here's how you iterate over the participants:

var callType = StreamCallType.Default; // Call type affects default permissions
var callId = "my-call-id";

// Passing create: true will create the call if it doesn't exist
var streamCall = await _client.JoinCallAsync(callType, callId, create: true, ring: false, notify: false);

foreach (var participant in streamCall.Participants)
{
    // Handle call participant. For example: spawn a prefab that will contain RawImage to show the video and an AudioSource to play the audio

    // Subscribe to TrackAdded event - it will be called for both existing and future tracks
    // Tracks can be either of type `StreamVideoTrack` or `StreamAudioTrack`
    participant.TrackAdded += OnParticipantTrackAdded;
}

// Subscribe to `ParticipantJoined` and `ParticipantLeft` to get notified when a new participant joins the call or a participant left the call
streamCall.ParticipantJoined += OnParticipantJoined;
streamCall.ParticipantLeft += OnParticipantLeft;

Here's an outline of the IStreamVideoCallParticipant object:

Events

EventDescription
TrackAddedFired when a track is added for this participant. Tracks represent streams of video and audio.
TrackIsEnabledChangedFired when a track's enabled state changes (e.g., participant mutes or unmutes).
AudioLevelChangedFired when the participant's audio level changes. Provides a float value.
IsSpeakingChangedFired when the participant starts or stops speaking. Provides a bool value.

Properties

PropertyDescription
IsPinnedIndicates if this participant is "pinned" in the call, giving them precedence in the IStreamCall.SortedParticipants list
IsScreenSharingIndicates if this participant is currently streaming a screen share track
IsVideoEnabledIndicates if this participant is currently streaming a video track
IsAudioEnabledIndicates if this participant is currently streaming an audio track
IsDominantSpeakerIndicates if this participant is currently the most actively speaking participant
UserIdThe user ID of the participant
SessionIdA unique identifier for a participant in a call, allowing for multiple instances of the same user through different devices
TrackLookupPrefixA prefix used for track lookup
NameThe name of the participant
IsLocalParticipantIndicates if this is the participant from the local device
UserThe IStreamVideoUser associated with the participant
VideoTrackThe video track of the participant
AudioTrackThe audio track of the participant
ScreenShareTrackThe screen share track of the participant
JoinedAtThe date and time when the participant joined the call
AudioLevelThe audio level of the participant
IsSpeakingIndicates if the participant is currently speaking
ConnectionQualityThe quality of the connection for the participant

Methods

MethodDescription
GetTracksRetrieves all tracks associated with this participant. Note: subscribing to the TrackAdded event is sufficient to handle all tracks, as it is called for both existing and future tracks.
SetIncomingVideoEnabledControls whether video from this participant is received. By default, video is auto-subscribed for up to 5 participants. Use this to manually enable video for additional participants in larger calls, or to disable video for participants not currently visible on screen.
SetIncomingAudioEnabledControls whether audio from this participant is received. Audio is auto-subscribed by default with no limit.
UpdateRequestedVideoResolutionSets the preferred video resolution to receive for this participant. See Video Optimization for details.