Skip to content

Commit 4d1bc67

Browse files
v86 internal socket foxes
1 parent 92ef130 commit 4d1bc67

File tree

1 file changed

+12
-12
lines changed

1 file changed

+12
-12
lines changed

src/v86.tsx

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -513,29 +513,33 @@ class V86Backend {
513513
binaryType = "arraybuffer";
514514
constructor(hostname: string, port: string) {
515515
super();
516-
this.pty = anura.x86!.ptyNum++;
516+
console.log("creating socket: " + hostname);
517+
517518
(async () => {
518-
this.pty = await anura.x86!.sendWispFrame({
519+
this.pty = anura.x86!.ptyNum++;
520+
await anura.x86!.sendWispFrame({
519521
type: "CONNECT",
520522
streamType: 0x01,
521523
streamID: this.pty,
522524
port: port,
523525
command: hostname,
524526
dataCallback: (data: Uint8Array) => {
525-
this.onmessage(data);
527+
this.onmessage({ data: data.buffer });
526528

527529
this.dispatchEvent(
528530
//@ts-expect-error idk why?
529531
new CustomEvent("message", { data: data.buffer }),
530532
);
531533
},
532534
closeCallback: (data: number) => {
533-
this.onclose();
535+
if (this.onclose) {
536+
this.onclose();
537+
}
534538
this.dispatchEvent(new CustomEvent("close"));
535539
},
536540
});
541+
this.dispatchEvent(new CustomEvent("open"));
537542
if (this.onopen) {
538-
console.log("calling onopen");
539543
this.onopen();
540544
}
541545
})();
@@ -682,7 +686,6 @@ class V86Backend {
682686
//console.log(frame);
683687
const view = new DataView(frame.buffer);
684688
const streamID = view.getUint32(1, true);
685-
console.log("Got packet type " + frame[0]);
686689
switch (frame[0]) {
687690
case 1: // CONNECT
688691
// The server should never send this actually
@@ -700,7 +703,6 @@ class V86Backend {
700703

701704
break;
702705
case 3: // CONTINUE
703-
console.log("Got continue!");
704706
if (connections[streamID]) {
705707
console.log(
706708
`setting congestion for ${streamID} to ${view.getUint32(5, true)}`,
@@ -712,7 +714,6 @@ class V86Backend {
712714
}
713715

714716
if (connections[streamID].congested) {
715-
console.log("Continuing transmission");
716717
for (const packet of congestedBuffer) {
717718
sendPacket(packet.data, packet.type, streamID);
718719
}
@@ -777,16 +778,15 @@ class V86Backend {
777778
frameObj.command,
778779
);
779780
fullPacket = new Uint8Array(
780-
4 + 5 + 1 + 1 + commandBuffer.length,
781+
4 + 5 + 1 + 2 + commandBuffer.length,
781782
);
782783
view = new DataView(fullPacket.buffer);
783784
view.setUint32(0, fullPacket.length - 4, true); // Packet size
784785
view.setUint8(4, 0x01); // FRAME TYPE (CONNECT)
785786
view.setUint32(5, frameObj.streamID, true); // Stream ID
786787
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
790790
// Setting callbacks
791791
connections[frameObj.streamID] = {
792792
dataCallback: frameObj.dataCallback,

0 commit comments

Comments
 (0)