Skip to main content
Version: 4.x.x

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.

note

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.

img1

Methods​

enableMic()​

  • If you wish to turn on the microphone of a participant, you will be calling the enableMic() from the Participant class.

  • When this method is called, the participant whose microphone is requested will receive the onMicRequested event with the participantId of the participant who requested it and two callback functions accept and reject which 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 the onMicRequested event, 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 the Participant class.

  • When this method is called, the participant whose camera is requested will receive the onWebcamRequested event with the participantId of the participant who requested it and two callback functions accept and reject which 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 the onWebcamRequested event, 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 the Participant class.
  • 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 the Participant class.
  • 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​

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 participant
  • accept - Call this closure to accept the request and turn on the webcam
  • reject - 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 participant
  • accept - Call this closure to accept the request and turn on the mic
  • reject - Call this closure to reject the request
Usage​
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