Implement HostInfo as a class

Replace POJO definition of HostInfo with a class that properly manages
its own serialisation to JSON.
This commit is contained in:
Hornwitser committed 2023-12-09 17:23:24 +01:00
1 parent 20330bc2c3
commit c248363895
6 files changed
+137 -60

No files matched your search

+2 -15
View File
@@ -1,5 +1,4 @@
import type WsServerConnector from "./WsServerConnector";
import type { HostInfo } from "./HostConnection";
import events from "events";
@@ -188,7 +187,7 @@ export default class ControlConnection extends BaseConnection {
throw new Error(`Unknown host id (${request.hostId})`);
}
host.token_valid_after = Math.floor(Date.now() / 1000);
host.tokenValidAfter = Math.floor(Date.now() / 1000);
const hostConnection = this._controller.wsServer.hostConnections.get(request.hostId);
if (hostConnection) {
@@ -199,19 +198,7 @@ export default class ControlConnection extends BaseConnection {
}
async handleHostListRequest(): Promise<lib.HostDetails[]> {
let list = [];
for (let host of this._controller.hosts.values()) {
list.push(new lib.HostDetails(
host.agent,
host.version,
host.name,
host.id,
this._controller.wsServer.hostConnections.has(host.id),
host.public_address,
host.token_valid_after,
));
}
return list;
return [...this._controller.hosts.values()].map(host => host.toHostDetails());
}
async handleHostGenerateTokenRequest(message: lib.HostGenerateTokenRequest) {