3030if TYPE_CHECKING :
3131 from .participant import LocalParticipant
3232
33-
3433STREAM_CHUNK_SIZE = 15_000
3534
3635
@@ -146,6 +145,7 @@ def __init__(
146145 total_size : int | None = None ,
147146 mime_type : str = "" ,
148147 destination_identities : Optional [List [str ]] = None ,
148+ sender_identity : str | None = None ,
149149 ):
150150 self ._local_participant = local_participant
151151 if stream_id is None :
@@ -161,14 +161,15 @@ def __init__(
161161 )
162162 self ._next_chunk_index : int = 0
163163 self ._destination_identities = destination_identities
164+ self ._sender_identity = sender_identity or self ._local_participant .identity
164165
165166 async def _send_header (self ):
166167 req = proto_ffi .FfiRequest (
167168 send_stream_header = proto_room .SendStreamHeaderRequest (
168169 header = self ._header ,
169170 local_participant_handle = self ._local_participant ._ffi_handle .handle ,
170171 destination_identities = self ._destination_identities ,
171- sender_identity = self ._local_participant . identity ,
172+ sender_identity = self ._sender_identity ,
172173 )
173174 )
174175
@@ -230,10 +231,12 @@ async def _send_trailer(self, trailer: proto_DataStream.Trailer):
230231 if cb .send_stream_chunk .error :
231232 raise ConnectionError (cb .send_stream_trailer .error )
232233
233- async def aclose (self ):
234+ async def aclose (
235+ self , * , reason : str = "" , attributes : Optional [Dict [str , str ]] = None
236+ ):
234237 await self ._send_trailer (
235238 trailer = proto_DataStream .Trailer (
236- stream_id = self ._header .stream_id , reason = ""
239+ stream_id = self ._header .stream_id , reason = reason , attributes = attributes
237240 )
238241 )
239242
@@ -249,6 +252,7 @@ def __init__(
249252 total_size : int | None = None ,
250253 reply_to_id : str | None = None ,
251254 destination_identities : Optional [List [str ]] = None ,
255+ sender_identity : str | None = None ,
252256 ) -> None :
253257 super ().__init__ (
254258 local_participant ,
@@ -258,6 +262,7 @@ def __init__(
258262 total_size ,
259263 mime_type = "text/plain" ,
260264 destination_identities = destination_identities ,
265+ sender_identity = sender_identity ,
261266 )
262267 self ._header .text_header .operation_type = proto_DataStream .OperationType .CREATE
263268 if reply_to_id :
@@ -276,6 +281,7 @@ def __init__(
276281 async def write (self , text : str ):
277282 async with self ._write_lock :
278283 for chunk in split_utf8 (text , STREAM_CHUNK_SIZE ):
284+ logger .info ("Sending chunk: %s" , chunk )
279285 content = chunk .encode ()
280286 chunk_index = self ._next_chunk_index
281287 self ._next_chunk_index += 1
0 commit comments