misc stuff from production

(also refactors qemu a bit)
This commit is contained in:
modeco80
2024-06-19 23:30:29 -04:00
parent 97de887518
commit 39521a4b1d
4 changed files with 69 additions and 34 deletions

View File

@@ -6,7 +6,7 @@ import * as guac from '@cvmts/guac-rs';
import CircularBuffer from 'mnemonist/circular-buffer.js';
import Queue from 'mnemonist/queue.js';
import { createHash } from 'crypto';
import { QemuVM, QemuVmDefinition } from '@cvmts/qemu';
import { VMState, QemuVM, QemuVmDefinition } from '@cvmts/qemu';
import { IPDataManager } from './IPData.js';
import { readFileSync } from 'node:fs';
import path from 'node:path';
@@ -21,6 +21,10 @@ const __dirname = import.meta.dirname;
const kCVMTSAssetsRoot = path.resolve(__dirname, '../../assets');
const kRestartTimeout = 5000;
type ChatHistory = {
user: string;
msg: string;
@@ -110,6 +114,19 @@ export default class CollabVMServer {
this.VM = vm;
// hack but whatever (TODO: less rickity)
if(config.vm.type == "qemu") {
(vm as QemuVM).on('statechange', (newState: VMState) => {
if(newState == VMState.Stopped) {
this.logger.Info("stopped ?");
setTimeout(async () => {
this.logger.Info("restarting VM");
await this.VM.Start();
}, kRestartTimeout)
}
});
}
// authentication manager
this.auth = auth;
}