@@ -241,7 +241,7 @@ function getConfigDirectory(roaming: boolean): string {
241241 }
242242}
243243
244- function encodeStringWithLength ( header : object , payload : ArrayBuffer ) : ArrayBuffer {
244+ function encodeStringWithLength ( header : object , payload : Uint8Array ) : ArrayBuffer {
245245 const headerString = JSON . stringify ( header ) ;
246246 const length = headerString . length ;
247247 const lengthString = length . toString ( ) . padStart ( 4 , "0" ) ;
@@ -257,7 +257,7 @@ function encodeStringWithLength(header: object, payload: ArrayBuffer): ArrayBuff
257257 // Copy the length, string, and payload into the output ArrayBuffer
258258 outputView . set ( lengthBytes , 0 ) ;
259259 outputView . set ( stringBytes , lengthBytes . length ) ;
260- outputView . set ( new Uint8Array ( payload ) , lengthBytes . length + stringBytes . length ) ;
260+ outputView . set ( payload , lengthBytes . length + stringBytes . length ) ;
261261
262262 return outputBuffer ;
263263}
@@ -281,7 +281,7 @@ function addEventListeners(socket: WebSocket) { // , messageFunc: EventFunction<
281281async function sendResponse ( socket : WebSocket , response : string , state : States ) {
282282 const resp = { response : response , state : state . toString ( ) } ;
283283 //console.log(JSON.stringify(resp));
284- const msg = encodeStringWithLength ( resp , new ArrayBuffer ( 0 ) ) ;
284+ const msg = encodeStringWithLength ( resp , new Uint8Array ( ) ) ;
285285 return socket . send ( msg ) ;
286286}
287287
@@ -384,7 +384,7 @@ async function localMain() {
384384 } ) ;
385385 for await ( const chunk of tcpConn . readable ) {
386386 const payload = { } ;
387- await socket . send ( encodeStringWithLength ( payload , chunk . buffer ) ) ;
387+ await socket . send ( encodeStringWithLength ( payload , chunk ) ) ;
388388 }
389389 } catch ( error ) {
390390 if ( error instanceof Deno . errors . BadResource ) {
@@ -496,7 +496,7 @@ async function remoteMain() {
496496 while ( true ) {
497497 const payload = { command : 'ping' } ;
498498 console . log ( "Starting with a ping" ) ;
499- socket . send ( encodeStringWithLength ( payload , new Uint8Array ( ) . buffer ) ) ;
499+ socket . send ( encodeStringWithLength ( payload , new Uint8Array ( ) ) ) ;
500500 const event = await waitForMessage ( socket ) ; // TODO timeout/retry/unintended or pending messages?
501501 const buffer = await event . data . arrayBuffer ( ) ;
502502 const decoded = decodeStringWithLength ( buffer ) ;
@@ -512,12 +512,12 @@ async function remoteMain() {
512512 }
513513 if ( remoteState === States . ERROR ) {
514514 const payload = { command : 'reset' } ;
515- socket . send ( encodeStringWithLength ( payload , new Uint8Array ( ) . buffer ) ) ;
515+ socket . send ( encodeStringWithLength ( payload , new Uint8Array ( ) ) ) ;
516516 await sleep ( 1 ) ; // let reset complete on local client
517517 }
518518 if ( remoteState === States . OPEN ) {
519519 const payload = { command : 'close' } ;
520- socket . send ( encodeStringWithLength ( payload , new Uint8Array ( ) . buffer ) ) ;
520+ socket . send ( encodeStringWithLength ( payload , new Uint8Array ( ) ) ) ;
521521 const event = await waitForMessage ( socket ) ; // TODO timeout
522522 const buffer = await event . data . arrayBuffer ( ) ;
523523 const decoded = decodeStringWithLength ( buffer ) ;
@@ -526,7 +526,7 @@ async function remoteMain() {
526526 }
527527 if ( remoteState === States . CLOSED ) {
528528 const payload = { command : 'ack_closed' } ;
529- socket . send ( encodeStringWithLength ( payload , new Uint8Array ( ) . buffer ) ) ;
529+ socket . send ( encodeStringWithLength ( payload , new Uint8Array ( ) ) ) ;
530530 const event = await waitForMessage ( socket ) ; // TODO timeout
531531 const buffer = await event . data . arrayBuffer ( ) ;
532532 const decoded = decodeStringWithLength ( buffer ) ;
@@ -544,7 +544,7 @@ async function remoteMain() {
544544 const initialEventListener = new EventTarget ( ) ;
545545
546546 const payload = { command : 'ping' } ;
547- socket . send ( encodeStringWithLength ( payload , new Uint8Array ( ) . buffer ) ) ;
547+ socket . send ( encodeStringWithLength ( payload , new Uint8Array ( ) ) ) ;
548548 // TODO await pong with timeout? remote state?
549549 } , 5000 ) ;
550550
@@ -577,7 +577,7 @@ async function remoteMain() {
577577 }
578578
579579 if ( responseHeader . response === "update" && responseHeader . state === States . CLOSED ) { // only complete command chain (no pong)
580- await socket . send ( encodeStringWithLength ( { command : 'ack_closed' } , new Uint8Array ( ) . buffer ) ) ;
580+ await socket . send ( encodeStringWithLength ( { command : 'ack_closed' } , new Uint8Array ( ) ) ) ;
581581 }
582582 }
583583 }
@@ -604,7 +604,7 @@ async function remoteMain() {
604604 }
605605 writerQueue = new QueueProcessor < Blob > ( processWriter ) ;
606606 try {
607- await socket . send ( encodeStringWithLength ( { command : 'open' } , new Uint8Array ( ) . buffer ) ) ;
607+ await socket . send ( encodeStringWithLength ( { command : 'open' } , new Uint8Array ( ) ) ) ;
608608 console . log ( "awaiting chunks" ) ;
609609 async function readChunks ( remoteConn : Deno . Conn ) {
610610 for await ( const chunk of remoteConn . readable ) {
@@ -613,7 +613,7 @@ async function remoteMain() {
613613 }
614614 if ( remoteState !== States . CLOSED && remoteState !== States . CLOSING ) { // TODO !== States.OPEN
615615 const payload = { } ;
616- await socket . send ( encodeStringWithLength ( payload , chunk . buffer ) ) ;
616+ await socket . send ( encodeStringWithLength ( payload , chunk ) ) ;
617617 }
618618 }
619619 }
@@ -628,7 +628,7 @@ async function remoteMain() {
628628 } finally {
629629 writerQueue = null ;
630630 if ( remoteState === States . OPEN ) {
631- await socket . send ( encodeStringWithLength ( { command : 'close' } , new Uint8Array ( ) . buffer ) ) ;
631+ await socket . send ( encodeStringWithLength ( { command : 'close' } , new Uint8Array ( ) ) ) ;
632632 while ( true ) {
633633 const event = await waitForMessage ( socket ) ; // TODO timeout
634634 const buffer = await event . data . arrayBuffer ( ) ;
0 commit comments