Toggle Remote Participant Media - Python
When hosting a meeting, it's essential for the host to have the capability to request that someone's microphone or camera be turned on, or to turn them off as needed. This guide focuses on this very aspect of controlling other participant's media.
The Participant with the capability to control other participant's media should have permission allow_mod
passed in the token. To know more about permissions visit here.
Before delving into the methods and events associated with this functionality, explore how the flow would unfold.
Methods
enable_mic()
-
If the host wishes to activate a participant's microphone, the
enable_mic()
method from theparticipant
object should be employed. -
Upon invoking this method, the participant whose microphone is requested for, will receive the
on_mic_requested
event. This event contains theparticipantId
of the host making the request, along with two callback functions—accept
andreject
. The participant can decide to accept or reject the incoming request. -
For instance, if a meeting involves Participant A and Participant B, and the host (Participant A) desires to enable the microphone of Participant B, the host will utilize the
enable_mic()
function to send a request to Participant B. Subsequently, Participant B will receive theon_mic_requested
event and can choose to either accept or reject the incoming request.
enable_webcam()
-
If the host wishes to activate a participant's camera, the
enable_webcam()
method from theparticipant
object should be employed. -
Upon invoking this method, the participant whose camera is requested for, will receive the
on_webcam_requested
event. This event contains theparticipantId
of the host making the request, along with two callback functions—accept
andreject
. The participant can decide to accept or reject the incoming request. -
For instance, if a meeting involves Participant A and Participant B, and the host (Participant A) desires to enable the camera of Participant B, the host will utilize the
enable_webcam()
function to send a request to Participant B. Subsequently, Participant B will receive theon_mic_requested
event and can choose to either accept or reject the incoming request.
disbale_mic()
-
If the host wishes to deactivate a participant's microphone, the
disbale_mic()
method from theparticipant
object should be employed. -
This will automatically disable the microphone of the participant.
disable_webcam()
-
If the host wishes to deactivate a participant's camera, the
disable_webcam()
method from theParticipant
object should be employed. -
This will automatically disable the camera of the participant.
Example 1
In this example, we have covered participant.disable_webcam()
& participant.disable_mic()
whenever stream enabled.
class ParticipantEventHandler(ParticipantEventHandler):
def __init__(self, participant: Participant):
super().__init__()
self.participant = participant
def on_stream_enabled(self, stream: Stream):
print(
self.participant.id,
"stream enabled ====",
stream.kind,
)
if stream.kind == "audio":
self.participant.disable_mic()
if stream.kind == "video":
self.participant.disable_webcam()
class MyMeetingEventHandler(MeetingEventHandler):
def __init__(self):
super().__init__()
def on_participant_joined(self, participant: Participant)
participant.add_event_listener(
ParticipantEventHandler(participant=participant)
)
Example 2
In this example, we have covered participant.enable_webcam()
& participant.enable_mic()
whenever new participant joined.
class MyMeetingEventHandler(MeetingEventHandler):
def __init__(self):
super().__init__()
def on_participant_joined(self, participant):
participant.enable_mic()
participant.enable_webcam()
Events
on_webcam_requested()
This event is triggered for a participant (Participant B
) when the host (Participant A
), requests to enable their webcam. The event handler for this event will receive the following three arguments:
accept()
- Callback function to accept the request.reject()
- Callback function to reject the request.participantId
- ParticipantId of the requesting participant.
on_mic_requested()
This event is triggered for a participant (Participant B
) when the host (Participant A
), requests to enable their microphone. The event handler for this event will receive the following three arguments:
accept()
- Callback function to accept the request.reject()
- Callback function to reject the request.participantId
- ParticipantId of the requesting participant.
Usage
class MyMeetingEventHandler(MeetingEventHandler):
def __init__(self):
super().__init__()
def on_webcam_requested(self, data):
wanted_to_accept = True
if wanted_to_accept:
accept = data["accept"]
accept()
else:
reject = data["reject"]
reject()
def on_mic_requested(self, data):
wanted_to_accept = True
if wanted_to_accept:
accept = data["accept"]
accept()
else:
reject = data["reject"]
reject()
API Reference
The API references for all the methods and events utilized in this guide are provided below.
Got a Question? Ask us on discord