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

check data stream closed #369

Merged
merged 2 commits into from
Feb 25, 2025
Merged
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
6 changes: 6 additions & 0 deletions livekit-rtc/livekit/rtc/data_stream.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ def __init__(
self._next_chunk_index: int = 0
self._destination_identities = destination_identities
self._sender_identity = sender_identity or self._local_participant.identity
self._closed = False

async def _send_header(self):
req = proto_ffi.FfiRequest(
Expand All @@ -191,6 +192,8 @@ async def _send_header(self):
raise ConnectionError(cb.send_stream_header.error)

async def _send_chunk(self, chunk: proto_DataStream.Chunk):
if self._closed:
raise RuntimeError(f"Cannot send chunk after stream is closed: {chunk}")
req = proto_ffi.FfiRequest(
send_stream_chunk=proto_room.SendStreamChunkRequest(
chunk=chunk,
Expand Down Expand Up @@ -238,6 +241,9 @@ async def _send_trailer(self, trailer: proto_DataStream.Trailer):
async def aclose(
self, *, reason: str = "", attributes: Optional[Dict[str, str]] = None
):
if self._closed:
raise RuntimeError("Stream already closed")
self._closed = True
await self._send_trailer(
trailer=proto_DataStream.Trailer(
stream_id=self._header.stream_id, reason=reason, attributes=attributes
Expand Down
Loading