@@ -513,29 +513,33 @@ class V86Backend {
513
513
binaryType = "arraybuffer" ;
514
514
constructor ( hostname : string , port : string ) {
515
515
super ( ) ;
516
- this . pty = anura . x86 ! . ptyNum ++ ;
516
+ console . log ( "creating socket: " + hostname ) ;
517
+
517
518
( async ( ) => {
518
- this . pty = await anura . x86 ! . sendWispFrame ( {
519
+ this . pty = anura . x86 ! . ptyNum ++ ;
520
+ await anura . x86 ! . sendWispFrame ( {
519
521
type : "CONNECT" ,
520
522
streamType : 0x01 ,
521
523
streamID : this . pty ,
522
524
port : port ,
523
525
command : hostname ,
524
526
dataCallback : ( data : Uint8Array ) => {
525
- this . onmessage ( data ) ;
527
+ this . onmessage ( { data : data . buffer } ) ;
526
528
527
529
this . dispatchEvent (
528
530
//@ts -expect-error idk why?
529
531
new CustomEvent ( "message" , { data : data . buffer } ) ,
530
532
) ;
531
533
} ,
532
534
closeCallback : ( data : number ) => {
533
- this . onclose ( ) ;
535
+ if ( this . onclose ) {
536
+ this . onclose ( ) ;
537
+ }
534
538
this . dispatchEvent ( new CustomEvent ( "close" ) ) ;
535
539
} ,
536
540
} ) ;
541
+ this . dispatchEvent ( new CustomEvent ( "open" ) ) ;
537
542
if ( this . onopen ) {
538
- console . log ( "calling onopen" ) ;
539
543
this . onopen ( ) ;
540
544
}
541
545
} ) ( ) ;
@@ -682,7 +686,6 @@ class V86Backend {
682
686
//console.log(frame);
683
687
const view = new DataView ( frame . buffer ) ;
684
688
const streamID = view . getUint32 ( 1 , true ) ;
685
- console . log ( "Got packet type " + frame [ 0 ] ) ;
686
689
switch ( frame [ 0 ] ) {
687
690
case 1 : // CONNECT
688
691
// The server should never send this actually
@@ -700,7 +703,6 @@ class V86Backend {
700
703
701
704
break ;
702
705
case 3 : // CONTINUE
703
- console . log ( "Got continue!" ) ;
704
706
if ( connections [ streamID ] ) {
705
707
console . log (
706
708
`setting congestion for ${ streamID } to ${ view . getUint32 ( 5 , true ) } ` ,
@@ -712,7 +714,6 @@ class V86Backend {
712
714
}
713
715
714
716
if ( connections [ streamID ] . congested ) {
715
- console . log ( "Continuing transmission" ) ;
716
717
for ( const packet of congestedBuffer ) {
717
718
sendPacket ( packet . data , packet . type , streamID ) ;
718
719
}
@@ -777,16 +778,15 @@ class V86Backend {
777
778
frameObj . command ,
778
779
) ;
779
780
fullPacket = new Uint8Array (
780
- 4 + 5 + 1 + 1 + commandBuffer . length ,
781
+ 4 + 5 + 1 + 2 + commandBuffer . length ,
781
782
) ;
782
783
view = new DataView ( fullPacket . buffer ) ;
783
784
view . setUint32 ( 0 , fullPacket . length - 4 , true ) ; // Packet size
784
785
view . setUint8 ( 4 , 0x01 ) ; // FRAME TYPE (CONNECT)
785
786
view . setUint32 ( 5 , frameObj . streamID , true ) ; // Stream ID
786
787
view . setUint8 ( 9 , frameObj . streamType || 0x03 ) ; // TCP
787
- view . setUint16 ( 10 , frameObj . port || 10 ) ; // PORT (unused, hardcoded to 10)
788
- fullPacket . set ( commandBuffer , 11 ) ; // command
789
-
788
+ view . setUint16 ( 10 , frameObj . port || 10 , true ) ; // PORT (unused, hardcoded to 10)
789
+ fullPacket . set ( commandBuffer , 12 ) ; // command
790
790
// Setting callbacks
791
791
connections [ frameObj . streamID ] = {
792
792
dataCallback : frameObj . dataCallback ,
0 commit comments