From e8e3265c902236cf72c99fe4d894ce17eb2df2fb Mon Sep 17 00:00:00 2001 From: lukasIO Date: Fri, 21 Feb 2025 14:14:42 +0100 Subject: [PATCH 1/3] Update attributes set in trailer --- livekit-rtc/livekit/rtc/data_stream.py | 1 + 1 file changed, 1 insertion(+) diff --git a/livekit-rtc/livekit/rtc/data_stream.py b/livekit-rtc/livekit/rtc/data_stream.py index c7a22bf5..b9e53c3c 100644 --- a/livekit-rtc/livekit/rtc/data_stream.py +++ b/livekit-rtc/livekit/rtc/data_stream.py @@ -70,6 +70,7 @@ async def _on_chunk_update(self, chunk: proto_DataStream.Chunk): await self._queue.put(chunk) async def _on_stream_close(self, trailer: proto_DataStream.Trailer): + self.info.attributes.update(trailer.attributes) await self._queue.put(None) def __aiter__(self) -> AsyncIterator[str]: From 2cc48252f2d3a0817a4bf7cb41b37bee3231388d Mon Sep 17 00:00:00 2001 From: lukasIO Date: Fri, 21 Feb 2025 14:16:37 +0100 Subject: [PATCH 2/3] Update attributes set in trailer --- livekit-rtc/livekit/rtc/data_stream.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/livekit-rtc/livekit/rtc/data_stream.py b/livekit-rtc/livekit/rtc/data_stream.py index b9e53c3c..bbcef9f1 100644 --- a/livekit-rtc/livekit/rtc/data_stream.py +++ b/livekit-rtc/livekit/rtc/data_stream.py @@ -70,7 +70,10 @@ async def _on_chunk_update(self, chunk: proto_DataStream.Chunk): await self._queue.put(chunk) async def _on_stream_close(self, trailer: proto_DataStream.Trailer): - self.info.attributes.update(trailer.attributes) + if self.info.attributes is None: + self.info.attributes = dict(trailer.attributes) + else: + self.info.attributes.update(trailer.attributes) await self._queue.put(None) def __aiter__(self) -> AsyncIterator[str]: @@ -119,6 +122,10 @@ async def _on_chunk_update(self, chunk: proto_DataStream.Chunk): await self._queue.put(chunk) async def _on_stream_close(self, trailer: proto_DataStream.Trailer): + if self.info.attributes is None: + self.info.attributes = dict(trailer.attributes) + else: + self.info.attributes.update(trailer.attributes) await self._queue.put(None) def __aiter__(self) -> AsyncIterator[bytes]: From 35e19641639ebb3381696b1ab543b60582a9477c Mon Sep 17 00:00:00 2001 From: lukasIO Date: Fri, 21 Feb 2025 14:35:23 +0100 Subject: [PATCH 3/3] make it nicer --- livekit-rtc/livekit/rtc/data_stream.py | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/livekit-rtc/livekit/rtc/data_stream.py b/livekit-rtc/livekit/rtc/data_stream.py index bbcef9f1..9e994805 100644 --- a/livekit-rtc/livekit/rtc/data_stream.py +++ b/livekit-rtc/livekit/rtc/data_stream.py @@ -70,10 +70,8 @@ async def _on_chunk_update(self, chunk: proto_DataStream.Chunk): await self._queue.put(chunk) async def _on_stream_close(self, trailer: proto_DataStream.Trailer): - if self.info.attributes is None: - self.info.attributes = dict(trailer.attributes) - else: - self.info.attributes.update(trailer.attributes) + self.info.attributes = self.info.attributes or {} + self.info.attributes.update(trailer.attributes) await self._queue.put(None) def __aiter__(self) -> AsyncIterator[str]: @@ -122,10 +120,8 @@ async def _on_chunk_update(self, chunk: proto_DataStream.Chunk): await self._queue.put(chunk) async def _on_stream_close(self, trailer: proto_DataStream.Trailer): - if self.info.attributes is None: - self.info.attributes = dict(trailer.attributes) - else: - self.info.attributes.update(trailer.attributes) + self.info.attributes = self.info.attributes or {} + self.info.attributes.update(trailer.attributes) await self._queue.put(None) def __aiter__(self) -> AsyncIterator[bytes]: