|
3 | 3 | from signal import SIGINT, SIGTERM
|
4 | 4 | from typing import Union
|
5 | 5 |
|
6 |
| -import livekit |
| 6 | +from livekit import rtc |
7 | 7 |
|
8 | 8 | URL = 'ws://localhost:7880'
|
9 | 9 | TOKEN = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE5MDY2MTMyODgsImlzcyI6IkFQSVRzRWZpZFpqclFvWSIsIm5hbWUiOiJuYXRpdmUiLCJuYmYiOjE2NzI2MTMyODgsInN1YiI6Im5hdGl2ZSIsInZpZGVvIjp7InJvb20iOiJ0ZXN0Iiwicm9vbUFkbWluIjp0cnVlLCJyb29tQ3JlYXRlIjp0cnVlLCJyb29tSm9pbiI6dHJ1ZSwicm9vbUxpc3QiOnRydWV9fQ.uSNIangMRu8jZD5mnRYoCHjcsQWCrJXgHCs0aNIgBFY' # noqa
|
10 | 10 |
|
11 | 11 |
|
12 |
| -async def main(room: livekit.Room) -> None: |
| 12 | +async def main(room: rtc.Room) -> None: |
13 | 13 |
|
14 | 14 | @room.listens_to("participant_connected")
|
15 |
| - def on_participant_connected(participant: livekit.RemoteParticipant) -> None: |
| 15 | + def on_participant_connected(participant: rtc.RemoteParticipant) -> None: |
16 | 16 | logging.info(
|
17 | 17 | "participant connected: %s %s", participant.sid, participant.identity)
|
18 | 18 |
|
19 | 19 | @room.listens_to("participant_disconnected")
|
20 |
| - def on_participant_disconnected(participant: livekit.RemoteParticipant): |
| 20 | + def on_participant_disconnected(participant: rtc.RemoteParticipant): |
21 | 21 | logging.info("participant disconnected: %s %s",
|
22 | 22 | participant.sid, participant.identity)
|
23 | 23 |
|
24 | 24 | @room.listens_to("local_track_published")
|
25 |
| - def on_local_track_published(publication: livekit.LocalTrackPublication, |
26 |
| - track: Union[livekit.LocalAudioTrack, |
27 |
| - livekit.LocalVideoTrack]): |
| 25 | + def on_local_track_published(publication: rtc.LocalTrackPublication, |
| 26 | + track: Union[rtc.LocalAudioTrack, |
| 27 | + rtc.LocalVideoTrack]): |
28 | 28 | logging.info("local track published: %s", publication.sid)
|
29 | 29 |
|
30 | 30 | @room.listens_to("active_speakers_changed")
|
31 |
| - def on_active_speakers_changed(speakers: list[livekit.Participant]): |
| 31 | + def on_active_speakers_changed(speakers: list[rtc.Participant]): |
32 | 32 | logging.info("active speakers changed: %s", speakers)
|
33 | 33 |
|
34 | 34 | @room.listens_to("local_track_unpublished")
|
35 |
| - def on_local_track_unpublished(publication: livekit.LocalTrackPublication): |
| 35 | + def on_local_track_unpublished(publication: rtc.LocalTrackPublication): |
36 | 36 | logging.info("local track unpublished: %s", publication.sid)
|
37 | 37 |
|
38 | 38 | @room.listens_to("track_published")
|
39 |
| - def on_track_published(publication: livekit.RemoteTrackPublication, |
40 |
| - participant: livekit.RemoteParticipant): |
| 39 | + def on_track_published(publication: rtc.RemoteTrackPublication, |
| 40 | + participant: rtc.RemoteParticipant): |
41 | 41 | logging.info("track published: %s from participant %s (%s)",
|
42 | 42 | publication.sid, participant.sid, participant.identity)
|
43 | 43 |
|
44 | 44 | @room.listens_to("track_unpublished")
|
45 |
| - def on_track_unpublished(publication: livekit.RemoteTrackPublication, |
46 |
| - participant: livekit.RemoteParticipant): |
| 45 | + def on_track_unpublished(publication: rtc.RemoteTrackPublication, |
| 46 | + participant: rtc.RemoteParticipant): |
47 | 47 | logging.info("track unpublished: %s", publication.sid)
|
48 | 48 |
|
49 | 49 | @room.listens_to("track_subscribed")
|
50 |
| - def on_track_subscribed(track: livekit.Track, |
51 |
| - publication: livekit.RemoteTrackPublication, |
52 |
| - participant: livekit.RemoteParticipant): |
| 50 | + def on_track_subscribed(track: rtc.Track, |
| 51 | + publication: rtc.RemoteTrackPublication, |
| 52 | + participant: rtc.RemoteParticipant): |
53 | 53 | logging.info("track subscribed: %s", publication.sid)
|
54 |
| - if track.kind == livekit.TrackKind.KIND_VIDEO: |
55 |
| - _video_stream = livekit.VideoStream(track) |
| 54 | + if track.kind == rtc.TrackKind.KIND_VIDEO: |
| 55 | + _video_stream = rtc.VideoStream(track) |
56 | 56 | # video_stream is an async iterator that yields VideoFrame
|
57 |
| - elif track.kind == livekit.TrackKind.KIND_AUDIO: |
| 57 | + elif track.kind == rtc.TrackKind.KIND_AUDIO: |
58 | 58 | print("Subscribed to an Audio Track")
|
59 |
| - _audio_stream = livekit.AudioStream(track) |
| 59 | + _audio_stream = rtc.AudioStream(track) |
60 | 60 | # audio_stream is an async iterator that yields AudioFrame
|
61 | 61 |
|
62 | 62 | @room.listens_to("track_unsubscribed")
|
63 |
| - def on_track_unsubscribed(track: livekit.Track, |
64 |
| - publication: livekit.RemoteTrackPublication, |
65 |
| - participant: livekit.RemoteParticipant): |
| 63 | + def on_track_unsubscribed(track: rtc.Track, |
| 64 | + publication: rtc.RemoteTrackPublication, |
| 65 | + participant: rtc.RemoteParticipant): |
66 | 66 | logging.info("track unsubscribed: %s", publication.sid)
|
67 | 67 |
|
68 | 68 | @room.listens_to("track_muted")
|
69 |
| - def on_track_muted(publication: livekit.RemoteTrackPublication, |
70 |
| - participant: livekit.RemoteParticipant): |
| 69 | + def on_track_muted(publication: rtc.RemoteTrackPublication, |
| 70 | + participant: rtc.RemoteParticipant): |
71 | 71 | logging.info("track muted: %s", publication.sid)
|
72 | 72 |
|
73 | 73 | @room.listens_to("track_unmuted")
|
74 |
| - def on_track_unmuted(publication: livekit.RemoteTrackPublication, |
75 |
| - participant: livekit.RemoteParticipant): |
| 74 | + def on_track_unmuted(publication: rtc.RemoteTrackPublication, |
| 75 | + participant: rtc.RemoteParticipant): |
76 | 76 | logging.info("track unmuted: %s", publication.sid)
|
77 | 77 |
|
78 | 78 | @room.listens_to("data_received")
|
79 | 79 | def on_data_received(data: bytes,
|
80 |
| - kind: livekit.DataPacketKind, |
81 |
| - participant: livekit.Participant): |
| 80 | + kind: rtc.DataPacketKind, |
| 81 | + participant: rtc.Participant): |
82 | 82 | logging.info("received data from %s: %s", participant.identity, data)
|
83 | 83 |
|
84 | 84 | @room.listens_to("connection_quality_changed")
|
85 |
| - def on_connection_quality_changed(participant: livekit.Participant, |
86 |
| - quality: livekit.ConnectionQuality): |
| 85 | + def on_connection_quality_changed(participant: rtc.Participant, |
| 86 | + quality: rtc.ConnectionQuality): |
87 | 87 | logging.info("connection quality changed for %s", participant.identity)
|
88 | 88 |
|
89 | 89 | @room.listens_to("track_subscription_failed")
|
90 |
| - def on_track_subscription_failed(participant: livekit.RemoteParticipant, |
| 90 | + def on_track_subscription_failed(participant: rtc.RemoteParticipant, |
91 | 91 | track_sid: str,
|
92 | 92 | error: str):
|
93 | 93 | logging.info("track subscription failed: %s %s",
|
94 | 94 | participant.identity, error)
|
95 | 95 |
|
96 | 96 | @room.listens_to("connection_state_changed")
|
97 |
| - def on_connection_state_changed(state: livekit.ConnectionState): |
| 97 | + def on_connection_state_changed(state: rtc.ConnectionState): |
98 | 98 | logging.info("connection state changed: %s", state)
|
99 | 99 |
|
100 | 100 | @room.listens_to("connected")
|
@@ -127,7 +127,7 @@ def on_reconnected() -> None:
|
127 | 127 | logging.StreamHandler()])
|
128 | 128 |
|
129 | 129 | loop = asyncio.get_event_loop()
|
130 |
| - room = livekit.Room(loop=loop) |
| 130 | + room = rtc.Room(loop=loop) |
131 | 131 |
|
132 | 132 | async def cleanup():
|
133 | 133 | await room.disconnect()
|
|
0 commit comments