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

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

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. Here’s how you iterate over the participants:

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

// Notice that we pass create argument as true - this will create the call if it doesn't already 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

    // Iterate over participant tracks. They can be either of type `StreamVideoTrack` or `StreamAudioTrack`
    foreach (var track in participant.GetTracks())
    {

    }

    // Subscribe to `TrackAdded` event in order to get notified about new tracks added later
    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.

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. This method can be used in conjunction with the TrackAdded event to manage tracks.
© Getstream.io, Inc. All Rights Reserved.