Add TCP vnc mode
This commit is contained in:
parent
cf4899da05
commit
2192657479
2 changed files with 28 additions and 8 deletions
|
@ -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() {
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue