Skip to content

Commit 0fa62f9

Browse files
committed
split written data into chunks
1 parent e04c6e3 commit 0fa62f9

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

livekit-rtc/livekit/rtc/data_stream.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -304,16 +304,16 @@ def __init__(
304304
file_name=self._header.file_header.file_name,
305305
)
306306

307-
async def write(self, data: bytes, chunk_index: int | None = None):
308-
if len(data) > STREAM_CHUNK_SIZE:
309-
raise ValueError("maximum chunk size exceeded")
307+
async def write(self, data: bytes):
308+
chunked_data = [data[i : i + 2] for i in range(0, len(data), 2)]
310309

311-
if chunk_index is None:
312-
chunk_index = self._next_chunk_index
310+
for chunk in chunked_data:
313311
self._next_chunk_index += 1
314-
chunk_msg = proto_DataStream.Chunk(
315-
stream_id=self._header.stream_id, chunk_index=chunk_index, content=data
316-
)
312+
chunk_msg = proto_DataStream.Chunk(
313+
stream_id=self._header.stream_id,
314+
chunk_index=self._next_chunk_index,
315+
content=chunk,
316+
)
317317
await self._send_chunk(chunk_msg)
318318

319319
@property

0 commit comments

Comments
 (0)