On / Off Camera - Python
Participants in the meeting have the ability to toggle their cameras on or off using the methods outlined below.
enable_webcam()
-
By using the
enable_webcam()
function, the local participant can publish their video to other participants. -
You can only call this method when the local participant is not broadcasting video to others.
-
You can also pass a customised video track in
enable_webcam()
by using Custom Video Track.
disable_webcam()
-
By using the
disable_webcam()
function, the local participant can stop publishing their video to other participants. -
You can only call this method when the local participant is broadcasting video to others.
Example
import asyncio
from videosdk import MeetingConfig, VideoSDK
VIDEOSDK_TOKEN = "<TOKEN>"
MEETING_ID = "<MEETING_ID>"
NAME = "<NAME>"
loop = asyncio.get_event_loop()
async def main():
meeting_config = MeetingConfig(
meeting_id=MEETING_ID,
name=NAME,
mic_enabled=True,
webcam_enabled=True,
token=VIDEOSDK_TOKEN,
)
meeting = VideoSDK.init_meeting(**meeting_config)
print("joining into meeting...")
await meeting.async_join()
await asyncio.sleep(5)
print("disable webcam...after 5 seconds...")
meeting.disable_webcam()
await asyncio.sleep(5)
print("enable webcam...after 5 seconds...")
meeting.enable_webcam()
print("done")
if __name__ == "__main__":
loop.run_until_complete(main())
loop.run_forever()
To learn, how to add custom video source in the meeting, follow this detailed guide.
Events associated with enable_webcam
- Every Participant will receive a callback on
on_stream_enabled()
with theStream
object. - Every Participant will receive a callback on
on_media_status_changed()
with the type of media and its status.
Events associated with disable_webcam
-
Every Participant will receive a callback on
on_stream_disabled()
with theStream
object. -
Every Participant will receive a callback on
on_media_status_changed()
with the type of media and its status.
from videosdk import ParticipantEventHandler, Stream
class MyParticipantEventHandler(ParticipantEventHandler):
def __init__(self, participant_id:str):
super().__init__()
self.participant_id = participant_id
def on_stream_enabled(self, stream: Stream):
print("paricipant :: stream enabled", self.participant_id, stream.kind)
def on_stream_disabled(self, stream: Stream):
print("paricipant :: stream disabled", self.participant_id, stream.kind)
def on_media_status_changed(self, data):
print("paricipant :: media status changed", self.participant_id, data)
def on_video_quality_changed(self, data):
print("paricipant :: video quality changed", self.participant_id, data)
Adding event listener for local participant.
meeting = VideoSDK.init_meeting(**meeting_config)
# add event listener for participant here
local_participant = meeting.local_participant
local_participant.add_event_listener(MyParticipantEventHandler(
participant_id=local_participant.id
))
await meeting.aync_join()
...
Output
Stuck anywhere? Check out this reference code on GitHub
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