Replace minimist, convert build scripts to ES modules + misc refactoring

This commit is contained in:
hensm
2022-08-19 03:09:59 +01:00
parent 170b80283d
commit a186570dc8
17 changed files with 702 additions and 505 deletions

View File

@@ -6,24 +6,28 @@ import WebSocket from "ws";
import { spawn } from "child_process";
import { Readable } from "stream";
import { DecodeTransform, EncodeTransform } from "./transforms";
import { DecodeTransform, EncodeTransform } from "./transforms.js";
interface DaemonOpts {
host: string;
port: number;
password: string;
password?: string;
}
export function init(opts: DaemonOpts) {
const server = http.createServer();
const wss = new WebSocket.Server({ noServer: true });
process.stdout.write("Starting WebSocket server... ");
process.stdout.write(
`Starting WebSocket server at ws://${
opts.host.includes(":") ? `[${opts.host}]` : opts.host
}:${opts.port}... `
);
server.on("listening", () => {
process.stdout.write("Done!\n");
});
wss.on("error", err => {
server.on("error", err => {
console.error("Failed!");
console.error(err.message);
});