Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rtc: add (*LocalPublication).wait_for_subscriber() #238

Merged
merged 7 commits into from
Aug 22, 2024
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
1 change: 1 addition & 0 deletions livekit-rtc/livekit/rtc/room.py
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,7 @@ def _on_room_event(self, event: proto_room.RoomEvent):
elif which == "local_track_subscribed":
sid = event.local_track_subscribed.track_sid
lpublication = self.local_participant.track_publications[sid]
lpublication._first_subscription.set_result(None)
self.emit("local_track_subscribed", lpublication.track)
elif which == "track_published":
rparticipant = self.remote_participants[
Expand Down
5 changes: 5 additions & 0 deletions livekit-rtc/livekit/rtc/track_publication.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
# limitations under the License.

from typing import Optional
import asyncio

from ._ffi_client import FfiHandle, FfiClient
from ._proto import e2ee_pb2 as proto_e2ee
Expand Down Expand Up @@ -71,6 +72,10 @@ def encryption_type(self) -> proto_e2ee.EncryptionType.ValueType:
class LocalTrackPublication(TrackPublication):
def __init__(self, owned_info: proto_track.OwnedTrackPublication):
super().__init__(owned_info)
self._first_subscription: asyncio.Future[None] = asyncio.Future()

async def wait_for_subscription(self) -> None:
await asyncio.shield(self._first_subscription)


class RemoteTrackPublication(TrackPublication):
Expand Down
Loading