Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions examples/room_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,12 @@

async def main():
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)
room = rtc.Room()

@room.on("participant_connected")
def on_participant_connected(participant: rtc.RemoteParticipant):
logging.info(
logger.info(
"participant connected: %s %s", participant.sid, participant.identity
)

Expand All @@ -30,15 +31,15 @@ def on_track_subscribed(
publication: rtc.RemoteTrackPublication,
participant: rtc.RemoteParticipant,
):
logging.info("track subscribed: %s", publication.sid)
logger.info("track subscribed: %s", publication.sid)
if track.kind == rtc.TrackKind.KIND_VIDEO:
video_stream = rtc.VideoStream(track)
asyncio.ensure_future(receive_frames(video_stream))

# By default, autosubscribe is enabled. The participant will be subscribed to
# all published tracks in the room
await room.connect(URL, TOKEN)
logging.info("connected to room %s", room.name)
logger.info("connected to room %s", room.name)

for identity, participant in room.remote_participants.items():
print(f"identity: {identity}")
Expand All @@ -48,8 +49,10 @@ def on_track_subscribed(
print(f"participant identity: {participant.identity}")
print(f"participant name: {participant.name}")
print(f"participant kind: {participant.kind}")
print(f"participant track publications: {
participant.track_publications}")
print(
f"participant track publications: {
participant.track_publications}"
)
for tid, publication in participant.track_publications.items():
print(f"\ttrack id: {tid}")
print(f"\t\ttrack publication: {publication}")
Expand Down
28 changes: 28 additions & 0 deletions livekit-rtc/livekit/rtc/track.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,20 @@ def create_audio_track(name: str, source: "AudioSource") -> "LocalAudioTrack":
resp = FfiClient.instance.request(req)
return LocalAudioTrack(resp.create_audio_track.track)

def mute(self):
req = proto_ffi.FfiRequest()
req.local_track_mute.track_handle = self._ffi_handle.handle
req.local_track_mute.mute = True
FfiClient.instance.request(req)
self._info.muted = True

def unmute(self):
req = proto_ffi.FfiRequest()
req.local_track_mute.track_handle = self._ffi_handle.handle
req.local_track_mute.mute = False
FfiClient.instance.request(req)
self._info.muted = False

def __repr__(self) -> str:
return f"rtc.LocalAudioTrack(sid={self.sid}, name={self.name})"

Expand All @@ -97,6 +111,20 @@ def create_video_track(name: str, source: "VideoSource") -> "LocalVideoTrack":
resp = FfiClient.instance.request(req)
return LocalVideoTrack(resp.create_video_track.track)

def mute(self):
req = proto_ffi.FfiRequest()
req.local_track_mute.track_handle = self._ffi_handle.handle
req.local_track_mute.mute = True
FfiClient.instance.request(req)
self._info.muted = True

def unmute(self):
req = proto_ffi.FfiRequest()
req.local_track_mute.track_handle = self._ffi_handle.handle
req.local_track_mute.mute = False
FfiClient.instance.request(req)
self._info.muted = False

def __repr__(self) -> str:
return f"rtc.LocalVideoTrack(sid={self.sid}, name={self.name})"

Expand Down
Loading