Compare commits

...

2 commits

Author SHA1 Message Date
2192657479 Add TCP vnc mode 2024-08-04 18:18:15 -04:00
cf4899da05 fix tsconfig.json dangling symlink 2024-08-04 18:02:45 -04:00
3 changed files with 38 additions and 9 deletions

View file

@ -33,12 +33,12 @@ export class QemuDisplay extends EventEmitter {
}); });
private vncShouldReconnect: boolean = false; private vncShouldReconnect: boolean = false;
private vncSocketPath: string; private vncConnectOpts: any;
constructor(socketPath: string) { constructor(vncConnectOpts: any) {
super(); super();
this.vncSocketPath = socketPath; this.vncConnectOpts = vncConnectOpts;
this.displayVnc.on('connectTimeout', () => { this.displayVnc.on('connectTimeout', () => {
this.Reconnect(); this.Reconnect();
@ -100,9 +100,7 @@ export class QemuDisplay extends EventEmitter {
// TODO: this should also give up after a max tries count // TODO: this should also give up after a max tries count
// if we fail after max tries, emit a event // if we fail after max tries, emit a event
this.displayVnc.connect({ this.displayVnc.connect(this.vncConnectOpts);
path: this.vncSocketPath
});
} }
Connect() { Connect() {

View file

@ -18,6 +18,9 @@ export type QemuVmDefinition = {
id: string; id: string;
command: string; command: string;
snapshot: boolean; snapshot: boolean;
forceTcp: boolean;
vncHost: string | undefined;
vncPort: number | undefined;
}; };
/// Temporary path base (for UNIX sockets/etc.) /// Temporary path base (for UNIX sockets/etc.)
@ -83,7 +86,16 @@ export class QemuVM extends EventEmitter {
this.qmpInstance.on('connected', async () => { this.qmpInstance.on('connected', async () => {
self.logger.info('QMP ready'); self.logger.info('QMP ready');
this.display = new QemuDisplay(this.GetVncPath()); if (process.platform === "win32") {
this.display = new QemuDisplay({
host: this.definition.vncHost || '127.0.0.1',
port: this.definition.vncPort || 5900,
})
} else {
this.display = new QemuDisplay({
path: this.GetVncPath()
});
}
self.display?.on('connected', () => { self.display?.on('connected', () => {
// The VM can now be considered started // The VM can now be considered started
@ -107,7 +119,17 @@ export class QemuVM extends EventEmitter {
if (!this.addedAdditionalArguments) { if (!this.addedAdditionalArguments) {
cmd += ' -no-shutdown'; cmd += ' -no-shutdown';
if (this.definition.snapshot) cmd += ' -snapshot'; if (this.definition.snapshot) cmd += ' -snapshot';
cmd += ` -qmp stdio -vnc unix:${this.GetVncPath()}`; cmd += ` -qmp stdio`;
if (this.definition.forceTcp || process.platform === "win32") {
let host = this.definition.vncHost || '127.0.0.1';
let port = this.definition.vncPort || 5900;
if (port < 5900) {
throw new Error('VNC port must be greater than or equal to 5900');
}
cmd += ` -vnc ${host}:${port - 5900}`;
} else {
cmd += ` -vnc unix:${this.GetVncPath()}`;
}
this.definition.command = cmd; this.definition.command = cmd;
this.addedAdditionalArguments = true; this.addedAdditionalArguments = true;
} }

View file

@ -1 +0,0 @@
../tsconfig.json

10
tsconfig.json Normal file
View file

@ -0,0 +1,10 @@
{
"compilerOptions": {
"target": "ES2022",
"module": "ES2022",
"moduleResolution": "Node",
"types": ["node"],
"allowSyntheticDefaultImports": true,
"strict": true,
}
}