@@ -1567,6 +1567,42 @@ export default class LocalParticipant extends Participant {
15671567 return writer . info ;
15681568 }
15691569
1570+ /** @experimental CAUTION, might get removed or changed in a minor release */
1571+ async updateText (
1572+ streamId : string ,
1573+ text : string ,
1574+ options ?: {
1575+ topic ?: string ;
1576+ destinationIdentities ?: Array < string > ;
1577+ } ,
1578+ ) : Promise < TextStreamInfo > {
1579+ const textInBytes = new TextEncoder ( ) . encode ( text ) ;
1580+ const totalTextLength = textInBytes . byteLength ;
1581+
1582+ const writer = await this . streamText ( {
1583+ streamId,
1584+ totalSize : totalTextLength ,
1585+ destinationIdentities : options ?. destinationIdentities ,
1586+ topic : options ?. topic ,
1587+ type : 'update' ,
1588+ } ) ;
1589+
1590+ const textChunkSize = Math . floor ( STREAM_CHUNK_SIZE / 4 ) ; // utf8 is at most 4 bytes long, so play it safe and take a quarter of the byte size to slice the string
1591+ const totalTextChunks = Math . ceil ( totalTextLength / textChunkSize ) ;
1592+
1593+ for ( let i = 0 ; i < totalTextChunks ; i ++ ) {
1594+ const chunkData = text . slice (
1595+ i * textChunkSize ,
1596+ Math . min ( ( i + 1 ) * textChunkSize , totalTextLength ) ,
1597+ ) ;
1598+ await this . engine . waitForBufferStatusLow ( DataPacket_Kind . RELIABLE ) ;
1599+ await writer . write ( chunkData ) ;
1600+ }
1601+
1602+ await writer . close ( ) ;
1603+ return writer . info ;
1604+ }
1605+
15701606 /**
15711607 * @internal
15721608 * @experimental CAUTION, might get removed in a minor release
@@ -1580,6 +1616,8 @@ export default class LocalParticipant extends Participant {
15801616 timestamp : Date . now ( ) ,
15811617 topic : options ?. topic ?? '' ,
15821618 size : options ?. totalSize ,
1619+ version : options ?. version ,
1620+ type : options ?. type ?? 'create' ,
15831621 } ;
15841622 const header = new DataStream_Header ( {
15851623 streamId,
@@ -1590,11 +1628,11 @@ export default class LocalParticipant extends Participant {
15901628 contentHeader : {
15911629 case : 'textHeader' ,
15921630 value : new DataStream_TextHeader ( {
1593- version : options ?. version ,
1631+ version : info ?. version ,
15941632 attachedStreamIds : options ?. attachedStreamIds ,
15951633 replyToStreamId : options ?. replyToStreamId ,
15961634 operationType :
1597- options ? .type === 'update'
1635+ info . type === 'update'
15981636 ? DataStream_OperationType . UPDATE
15991637 : DataStream_OperationType . CREATE ,
16001638 } ) ,
0 commit comments