diff --git a/src/QemuDisplay.ts b/src/QemuDisplay.ts index 9d54b8d..ebfab52 100644 --- a/src/QemuDisplay.ts +++ b/src/QemuDisplay.ts @@ -33,12 +33,12 @@ export class QemuDisplay extends EventEmitter { }); private vncShouldReconnect: boolean = false; - private vncSocketPath: string; + private vncConnectOpts: any; - constructor(socketPath: string) { + constructor(vncConnectOpts: any) { super(); - this.vncSocketPath = socketPath; + this.vncConnectOpts = vncConnectOpts; this.displayVnc.on('connectTimeout', () => { this.Reconnect(); @@ -100,9 +100,7 @@ export class QemuDisplay extends EventEmitter { // TODO: this should also give up after a max tries count // if we fail after max tries, emit a event - this.displayVnc.connect({ - path: this.vncSocketPath - }); + this.displayVnc.connect(this.vncConnectOpts); } Connect() { diff --git a/src/QemuVM.ts b/src/QemuVM.ts index efce662..2df083e 100644 --- a/src/QemuVM.ts +++ b/src/QemuVM.ts @@ -18,6 +18,9 @@ export type QemuVmDefinition = { id: string; command: string; snapshot: boolean; + forceTcp: boolean; + vncHost: string | undefined; + vncPort: number | undefined; }; /// Temporary path base (for UNIX sockets/etc.) @@ -83,7 +86,16 @@ export class QemuVM extends EventEmitter { this.qmpInstance.on('connected', async () => { 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', () => { // The VM can now be considered started @@ -107,7 +119,17 @@ export class QemuVM extends EventEmitter { if (!this.addedAdditionalArguments) { cmd += ' -no-shutdown'; 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.addedAdditionalArguments = true; }