File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -516,23 +516,32 @@ class WSUser {
516516 */
517517 onStreamMessage ( _room , ms ) {
518518 if ( ms . length > 0 ) {
519- const encoder = encoding . createEncoder ( )
519+ /** @type {Array<Uint8Array<ArrayBuffer>> } */
520+ const ydocUpdates = [ ]
521+ /** @type {Array<Uint8Array<ArrayBuffer>> } */
522+ const awarenessUpdates = [ ]
520523 ms . forEach ( message => {
521524 switch ( message . type ) {
522525 case 'ydoc:update:v1' : {
523- protocol . writeSyncUpdate ( encoder , message . update )
526+ ydocUpdates . push ( message . update )
524527 break
525528 }
526529 case 'awareness:v1' : {
527- protocol . writeAwarenessUpdate ( encoder , message . update )
530+ awarenessUpdates . push ( message . update )
528531 break
529532 }
530533 default : {
531534 this . log . error ( 'unexpected message type on stream: ' + /** @type {any } */ ( message ) . type )
532535 }
533536 }
534537 } )
535- this . sendData ( encoding . toUint8Array ( encoder ) )
538+ // @todo send this as a single update message
539+ if ( ydocUpdates . length > 0 ) {
540+ this . sendData ( protocol . encodeSyncUpdate ( Y . mergeUpdates ( ydocUpdates ) ) )
541+ }
542+ if ( awarenessUpdates . length > 0 ) {
543+ this . sendData ( protocol . mergeAwarenessUpdates ( awarenessUpdates ) )
544+ }
536545 }
537546 }
538547
You can’t perform that action at this time.
0 commit comments