27
27
from ._utils import split_utf8
28
28
from typing import TYPE_CHECKING
29
29
30
+
30
31
if TYPE_CHECKING :
31
32
from .participant import LocalParticipant
32
33
33
-
34
34
STREAM_CHUNK_SIZE = 15_000
35
35
36
36
@@ -65,7 +65,6 @@ def __init__(
65
65
attachments = list (header .text_header .attached_stream_ids ),
66
66
)
67
67
self ._queue : asyncio .Queue [proto_DataStream .Chunk | None ] = asyncio .Queue ()
68
- self ._chunks : Dict [int , proto_DataStream .Chunk ] = {}
69
68
70
69
async def _on_chunk_update (self , chunk : proto_DataStream .Chunk ):
71
70
await self ._queue .put (chunk )
@@ -146,6 +145,7 @@ def __init__(
146
145
total_size : int | None = None ,
147
146
mime_type : str = "" ,
148
147
destination_identities : Optional [List [str ]] = None ,
148
+ sender_identity : str | None = None ,
149
149
):
150
150
self ._local_participant = local_participant
151
151
if stream_id is None :
@@ -161,14 +161,15 @@ def __init__(
161
161
)
162
162
self ._next_chunk_index : int = 0
163
163
self ._destination_identities = destination_identities
164
+ self ._sender_identity = sender_identity or self ._local_participant .identity
164
165
165
166
async def _send_header (self ):
166
167
req = proto_ffi .FfiRequest (
167
168
send_stream_header = proto_room .SendStreamHeaderRequest (
168
169
header = self ._header ,
169
170
local_participant_handle = self ._local_participant ._ffi_handle .handle ,
170
171
destination_identities = self ._destination_identities ,
171
- sender_identity = self ._local_participant . identity ,
172
+ sender_identity = self ._sender_identity ,
172
173
)
173
174
)
174
175
@@ -230,10 +231,12 @@ async def _send_trailer(self, trailer: proto_DataStream.Trailer):
230
231
if cb .send_stream_chunk .error :
231
232
raise ConnectionError (cb .send_stream_trailer .error )
232
233
233
- async def aclose (self ):
234
+ async def aclose (
235
+ self , * , reason : str = "" , attributes : Optional [Dict [str , str ]] = None
236
+ ):
234
237
await self ._send_trailer (
235
238
trailer = proto_DataStream .Trailer (
236
- stream_id = self ._header .stream_id , reason = ""
239
+ stream_id = self ._header .stream_id , reason = reason , attributes = attributes
237
240
)
238
241
)
239
242
@@ -249,6 +252,7 @@ def __init__(
249
252
total_size : int | None = None ,
250
253
reply_to_id : str | None = None ,
251
254
destination_identities : Optional [List [str ]] = None ,
255
+ sender_identity : str | None = None ,
252
256
) -> None :
253
257
super ().__init__ (
254
258
local_participant ,
@@ -258,6 +262,7 @@ def __init__(
258
262
total_size ,
259
263
mime_type = "text/plain" ,
260
264
destination_identities = destination_identities ,
265
+ sender_identity = sender_identity ,
261
266
)
262
267
self ._header .text_header .operation_type = proto_DataStream .OperationType .CREATE
263
268
if reply_to_id :
@@ -276,7 +281,7 @@ def __init__(
276
281
async def write (self , text : str ):
277
282
async with self ._write_lock :
278
283
for chunk in split_utf8 (text , STREAM_CHUNK_SIZE ):
279
- content = chunk . encode ()
284
+ content = chunk
280
285
chunk_index = self ._next_chunk_index
281
286
self ._next_chunk_index += 1
282
287
chunk_msg = proto_DataStream .Chunk (
0 commit comments