mirror of
https://github.com/nestriness/nestri.git
synced 2026-03-17 03:43:07 +02:00
feat: WIP s6-overlay and friends
This commit is contained in:
@@ -7,22 +7,22 @@
|
||||
".": "./src/index.ts"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@bufbuild/buf": "^1.59.0",
|
||||
"@bufbuild/protoc-gen-es": "^2.10.0"
|
||||
"@bufbuild/buf": "^1.61.0",
|
||||
"@bufbuild/protoc-gen-es": "^2.10.2"
|
||||
},
|
||||
"dependencies": {
|
||||
"@bufbuild/protobuf": "^2.10.0",
|
||||
"@bufbuild/protobuf": "^2.10.2",
|
||||
"@chainsafe/libp2p-noise": "^17.0.0",
|
||||
"@chainsafe/libp2p-quic": "^1.1.3",
|
||||
"@chainsafe/libp2p-quic": "^1.1.8",
|
||||
"@chainsafe/libp2p-yamux": "^8.0.1",
|
||||
"@libp2p/identify": "^4.0.5",
|
||||
"@libp2p/interface": "^3.0.2",
|
||||
"@libp2p/ping": "^3.0.5",
|
||||
"@libp2p/websockets": "^10.0.6",
|
||||
"@libp2p/webtransport": "^6.0.7",
|
||||
"@libp2p/utils": "^7.0.5",
|
||||
"@libp2p/identify": "^4.0.9",
|
||||
"@libp2p/interface": "^3.1.0",
|
||||
"@libp2p/ping": "^3.0.9",
|
||||
"@libp2p/websockets": "^10.1.2",
|
||||
"@libp2p/webtransport": "^6.0.11",
|
||||
"@libp2p/utils": "^7.0.9",
|
||||
"@multiformats/multiaddr": "^13.0.1",
|
||||
"libp2p": "^3.0.6",
|
||||
"libp2p": "^3.1.2",
|
||||
"uint8arraylist": "^2.4.8"
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,11 @@
|
||||
import { keyCodeToLinuxEventCode } from "./codes";
|
||||
import { WebRTCStream } from "./webrtc-stream";
|
||||
import { ProtoKeyDownSchema, ProtoKeyUpSchema } from "./proto/types_pb";
|
||||
import { create, toBinary } from "@bufbuild/protobuf";
|
||||
import {
|
||||
ProtoKeyDownSchema,
|
||||
ProtoKeyUpSchema,
|
||||
//ProtoClipboardSchema,
|
||||
} from "./proto/types_pb";
|
||||
import { create, Message, toBinary } from "@bufbuild/protobuf";
|
||||
import { createMessage } from "./utils";
|
||||
import { ProtoMessageSchema } from "./proto/messages_pb";
|
||||
|
||||
@@ -13,21 +17,40 @@ export class Keyboard {
|
||||
protected wrtc: WebRTCStream;
|
||||
protected connected!: boolean;
|
||||
|
||||
private onEscapeCallback?: () => void;
|
||||
|
||||
// Store references to event listeners
|
||||
private readonly keydownListener: (e: KeyboardEvent) => void;
|
||||
private readonly keyupListener: (e: KeyboardEvent) => void;
|
||||
|
||||
constructor({ webrtc }: Props) {
|
||||
this.wrtc = webrtc;
|
||||
this.keydownListener = this.createKeyboardListener((e: any) =>
|
||||
create(ProtoKeyDownSchema, {
|
||||
key: this.keyToVirtualKeyCode(e.code),
|
||||
}),
|
||||
this.keydownListener = this.createKeyboardListener(
|
||||
async (e: KeyboardEvent) => {
|
||||
let rets = [];
|
||||
if (e.shiftKey && e.code === "Escape" && this.onEscapeCallback !== undefined) {
|
||||
this.onEscapeCallback();
|
||||
return rets;
|
||||
}
|
||||
/*if (e.ctrlKey && e.key === "v" && navigator.clipboard) {
|
||||
rets.push(create(ProtoClipboardSchema, {
|
||||
content: await navigator.clipboard.readText(),
|
||||
}));
|
||||
}*/
|
||||
rets.push(
|
||||
create(ProtoKeyDownSchema, {
|
||||
key: this.keyToVirtualKeyCode(e.code),
|
||||
}),
|
||||
);
|
||||
return rets;
|
||||
},
|
||||
);
|
||||
this.keyupListener = this.createKeyboardListener((e: any) =>
|
||||
create(ProtoKeyUpSchema, {
|
||||
key: this.keyToVirtualKeyCode(e.code),
|
||||
}),
|
||||
this.keyupListener = this.createKeyboardListener(
|
||||
async (e: KeyboardEvent) => [
|
||||
create(ProtoKeyUpSchema, {
|
||||
key: this.keyToVirtualKeyCode(e.code),
|
||||
}),
|
||||
],
|
||||
);
|
||||
this.run();
|
||||
}
|
||||
@@ -56,10 +79,12 @@ export class Keyboard {
|
||||
// Prevent repeated key events from being sent (important for games)
|
||||
if ((e as any).repeat) return;
|
||||
|
||||
const data = dataCreator(e as any);
|
||||
|
||||
const message = createMessage(data, "input");
|
||||
this.wrtc.sendBinary(toBinary(ProtoMessageSchema, message));
|
||||
dataCreator(e as any).then((datas: Message[]) => {
|
||||
datas.forEach((data) => {
|
||||
const message = createMessage(data, "input");
|
||||
this.wrtc.sendBinary(toBinary(ProtoMessageSchema, message));
|
||||
});
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
@@ -68,6 +93,10 @@ export class Keyboard {
|
||||
this.connected = false;
|
||||
}
|
||||
|
||||
public setOnEscape(cb: () => void) {
|
||||
this.onEscapeCallback = cb;
|
||||
}
|
||||
|
||||
private keyToVirtualKeyCode(code: string) {
|
||||
// Treat Home key as Escape - TODO: Make user-configurable
|
||||
if (code === "Home") return 1;
|
||||
|
||||
@@ -76,9 +76,15 @@ export class Mouse {
|
||||
if (document.pointerLockElement == this.canvas) {
|
||||
this.connected = true;
|
||||
this.canvas.addEventListener("mousemove", this.mousemoveListener);
|
||||
this.canvas.addEventListener("mousedown", this.mousedownListener);
|
||||
this.canvas.addEventListener("mouseup", this.mouseupListener);
|
||||
this.canvas.addEventListener("wheel", this.mousewheelListener);
|
||||
this.canvas.addEventListener("mousedown", this.mousedownListener, {
|
||||
passive: true,
|
||||
});
|
||||
this.canvas.addEventListener("mouseup", this.mouseupListener, {
|
||||
passive: true,
|
||||
});
|
||||
this.canvas.addEventListener("wheel", this.mousewheelListener, {
|
||||
passive: true,
|
||||
});
|
||||
} else {
|
||||
if (this.connected) {
|
||||
this.stop();
|
||||
@@ -119,7 +125,6 @@ export class Mouse {
|
||||
dataCreator: (e: Event) => any,
|
||||
): (e: Event) => void {
|
||||
return (e: Event) => {
|
||||
e.preventDefault();
|
||||
e.stopPropagation();
|
||||
const data = dataCreator(e as any);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user