Display Attendees Count - iOS
In this guide, we will see how you can display the number of attendees in realtime.
note
Before going forward in this guide, do make sure all the attendees join the live stream with mode as SIGNALLING_ONLY
- We will get all the
participantsexcept the local participant using theparticipantsproperty of theRoomclass. From these, we will count the participants who have joined asSIGNALLING_ONLYand display that count. The local participant is counted too when its mode isSIGNALLING_ONLY. - Count again whenever a participant joins, leaves or changes mode, so the number stays correct.
- Swift
class LiveStreamViewController: ObservableObject {
@Published var viewerParticipantCount: Int = 0
//...
func updateViewerParticipantCount() {
guard let room = room else { return }
// remote participants who joined as SIGNALLING_ONLY
let remoteViewers = room.participants.values.filter { $0.mode == .SIGNALLING_ONLY }.count
// count yourself too if you joined as SIGNALLING_ONLY
let localViewer = room.localParticipant.mode == .SIGNALLING_ONLY ? 1 : 0
viewerParticipantCount = remoteViewers + localViewer
}
}
extension LiveStreamViewController: RoomEventListener {
func onRoomJoined() {
//...
updateViewerParticipantCount()
}
func onParticipantJoined(_ participant: Participant) {
//...
updateViewerParticipantCount()
}
func onParticipantLeft(_ participant: Participant, reason: LeaveReason) {
//...
updateViewerParticipantCount()
}
func onParticipantModeChanged(participantId: String, mode: Mode) {
//...
updateViewerParticipantCount()
}
}
API Reference
The API references for all the methods utilized in this guide are provided below.
Got a Question? Ask us on discord

