Toggle Remote Participant Media - iOS
When hosting a room, the host can ask a participant to turn on their mic or camera, and can turn them off.
The participant who controls other participants' mic and camera needs the allow_mod permission in their token. To know more about permissions visit here.
Before we discuss the methods and events associated with this functionality, here is how the flow looks.

Methods
enableMic()
-
If you wish to turn on the microphone of a participant, you will be calling the
enableMic()from theParticipantclass. -
When this method is called, the participant whose microphone is requested will receive the
onMicRequestedevent with theparticipantIdof the participant who requested it and two callback functionsacceptandrejectwhich should be called based on decision made by the user. -
Example: A room is running with Participant A and Participant B. Now Participant A wants to Enable Mic of Participant B, so Participant A will use
enableMic()function to request Participant B, after that Participant B receives theonMicRequestedevent, from there user can either accept or reject the incoming request.
enableCam()
-
If you wish to turn on the camera of a participant, you will be calling the
enableCam()from theParticipantclass. -
When this method is called, the participant whose camera is requested will receive the
onWebcamRequestedevent with theparticipantIdof the participant who requested it and two callback functionsacceptandrejectwhich should be called based on decision made by the user. -
Example: A room is running with Participant A and Participant B. Now Participant A wants to Enable Camera of Participant B, so Participant A will use
enableCam()function to request Participant B, after that Participant B receives theonWebcamRequestedevent, from there user can either accept or reject the incoming request.
disableMic()
- If you wish to turn off the microphone of a participant, you will be calling the
disableMic()from theParticipantclass. - This will disable the microphone of the participant.
disableCam()
- If you wish to turn off the camera of a participant, you will be calling the
disableCam()from theParticipantclass. - This will disable the camera of the participant.
All four methods are async throws, so call them with try await inside a Task. They throw a VideoSDKError if the call fails, for example ERROR_ACTION_PERFORMED_BEFORE_ROOM_JOINED when you call them before joining the room.
Example
- Swift
extension RoomViewController {
//Button when tapped will toggle participant's mic
@IBAction func micButtonTapped(_ sender: Any) {
let participant = room?.participants["<participantId>"]
Task {
do {
//micenabled is a user defined status for participant's mic
if !micenabled {
try await participant?.enableMic()
} else {
try await participant?.disableMic()
}
} catch {
print("Could not change the mic: \(error)")
}
}
}
//Button when tapped will toggle participant's video
@IBAction func cameraButtonTapped(_ sender: Any) {
let participant = room?.participants["<participantId>"]
Task {
do {
//videoenabled is a user defined status for participant's video
if !videoenabled {
try await participant?.enableCam()
} else {
try await participant?.disableCam()
}
} catch {
print("Could not change the camera: \(error)")
}
}
}
}
Events
onWebcamRequested
This event will be emitted to the Participant B when any other Participant A requests to enable webcam of that participant (Participant B). This event handler will receive the following arguments:
participantId- ParticipantId of the requesting participantaccept- Call this closure to accept the request and turn on the webcamreject- Call this closure to reject the request
onMicRequested
This event will be emitted to the Participant B when any other Participant A requests to enable mic of that participant (Participant B). This event handler will receive the following arguments:
participantId- ParticipantId of the requesting participantaccept- Call this closure to accept the request and turn on the micreject- Call this closure to reject the request
Usage
- Swift
extension RoomViewController: RoomEventListener {
/// Called when host requests to turn on the mic/audio
func onMicRequested(participantId: String?, accept: @escaping () -> Void, reject: @escaping () -> Void) {
// Ask the user, then call only one of the callbacks
// callback to accept the request
accept()
// or, callback to reject the request
// reject()
}
/// Called when host requests to turn on the camera/video
func onWebcamRequested(participantId: String?, accept: @escaping () -> Void, reject: @escaping () -> Void) {
// Ask the user, then call only one of the callbacks
// callback to accept the request
accept()
// or, callback to reject the request
// reject()
}
}
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

