Manage Participants - iOS
1. Local Participant (self)
Local participant is used to consume your video & audio streams. it contains information about local participant such as displayName, id, quality and streams Map.
You can acces localParticipant from the meeting object.
Participant object properties
Property Name | Type | Description |
---|---|---|
id | string | Unique id of the participant. |
displayName | string | The name you define during the meeting initialization. |
local | boolean | Indicates the participant is local or not. |
quality | string | Indicates the participant streams quality. |
Streams | Map of Stream | Returns Video & Audio Streams. |
Stream Object properties
Property Name | Type | Description |
---|---|---|
id | string | Unique id |
codec | string | Video/Audio codec. |
kind | string | Stream Kind. |
track | string | MediaStreamTrack |
2. Other Participants (Except You)
Other participants Map is used to get all the participants (except you) in the meeting at any given time.
Other participants Map contains same properties as LocalParticipant.
Local And Other Participants
// get local participant
let localParticipant = self.meeting?.localParticipant;
// get other participants
let otherParticipants = self.meeting?.participants;
3. Participant Related Events
-
participant-joined - Whenever any new participant join the meeting,
participant-joined
event will trigger. For example, the meeting is running with Alice and Bob, then Eve join that meeting, after thatparticipant-joined
event trigger and return the participant object. -
participant-left - Whenever any participant leave/exit the meeting,
participant-left
event will trigger.For example, the meeting is running with Alice and Bob, then Bob leave that meeting, after thatparticipant-left
event trigger and return the participant object -
presenter-changed - Whenever any participant present/screenshare their screen/window in meeting,
presenter-changed
event will trigger and return the presenterparticipantId
. -
stream-enabled - Whenever any participant enabled mic/webcam in meeting,
stream-enabled
event will trigger and return Stream Map. -
stream-disabled - Whenever any participant disabled mic/webcam in meeting,
stream-disabled
event will trigger and return Stream Map.
/// keep track of video participants including self to show in UI
// ex. we can show participants as grid in collectionView.
private var participants: [Participant] = []
/// keep track of mic
private var micEnabled = true
/// keep track of video
private var videoEnabled = true
/// keep track of screenshare
private var screenShareEnabled = false
// MARK: - MeetingEventListener
extension MeetingViewController: MeetingEventListener {
/// Meeting started
func onMeetingJoined() {
// handle for local participant
if let localParticipant = self.meeting?.localParticipant {
// event listener for self
localParticipant.addEventListener(self)
// add to list
participants.append(localParticipant)
// show in ui
// ex. add to collecionView
// addParticipantToGridView()
}
}
/// A new participant joined
func onParticipantJoined(_ participant: Participant) {
// add new participant to list
participants.append(participant)
// add listener
participant.addEventListener(self)
// show in ui
// ex. add to collectionView
// addParticipantToGridView()
}
/// A participant left from the meeting
/// - Parameter participant: participant object
func onParticipantLeft(_ participant: Participant) {
// remove listener
participant.removeEventListener(self)
// remove from list and update ui
guard let index = self.participants.firstIndex(where: { $0.id == participant.id }) else {
return
}
// remove participant from list
participants.remove(at: index)
// hide from ui
// ex. remove from collectionview
// removeParticipantFromGridView(at: index)
}
}
// MARK: - ParticipantEventListener
extension MeetingViewController: ParticipantEventListener {
/// Participant has enabled mic, video or screenshare
/// - Parameters:
/// - stream: enabled stream object
/// - participant: participant object
func onStreamEnabled(_ stream: MediaStream, forParticipant participant: Participant) {
switch stream.kind {
case .audio:
// update ui to show that participant's mic is enabled
// ex. update collectionView cell
if participant.isLocal {
// update mic flag for local participant
micEnabled = true
}
case .video:
// show track in videoView: RTCMTLVideoView
if let track = stream.track as? RTCVideoTrack {
track.add(videoView)
}
if participant.isLocal {
// update video flag for local participant
videoEnabled = true
}
case .share:
// show track in screenShareView: RTCMTLVideoView
if let track = stream.track as? RTCVideoTrack {
track.add(screenShareView)
}
if participant.isLocal {
// update screenShare flag for local participant
screenShareEnabled = true
}
}
}
/// Participant has disabled mic, video or screenshare
/// - Parameters:
/// - stream: disabled stream object
/// - participant: participant object
func onStreamDisabled(_ stream: MediaStream, forParticipant participant: Participant) {
switch stream.kind {
case .audio:
// update ui to show that participant's mic is disabled
// ex. update collectionView cell
if participant.isLocal {
// update mic flag for local participant
micEnabled = false
}
case .video:
// remove track from videoView: RTCMTLVideoView
if let track = stream.track as? RTCVideoTrack {
track.remove(videoView)
}
if participant.isLocal {
// update video flag for local participant
videoEnabled = false
}
case .share:
// remove track from screenShareView: RTCMTLVideoView
if let track = stream.track as? RTCVideoTrack {
track.remove(screenShareView)
}
if participant.isLocal {
// update screenShare flag for local participant
screenShareEnabled = false
}
}
}
}
API Reference
The API references for all the methods and events utilised in this guide are provided below.
Got a Question? Ask us on discord