type Server

This commit is contained in:
Reto Brunner 2024-04-07 14:17:32 +02:00
parent e15b121080
commit 5ee9c2b338
2 changed files with 9 additions and 8 deletions

View file

@ -10,7 +10,7 @@ import Config from "./config";
import {NetworkConfig} from "./models/network"; import {NetworkConfig} from "./models/network";
import WebPush from "./plugins/webpush"; import WebPush from "./plugins/webpush";
import log from "./log"; import log from "./log";
import {Server} from "socket.io"; import {Server} from "./server";
class ClientManager { class ClientManager {
clients: Client[]; clients: Client[];

View file

@ -3,7 +3,7 @@ import {Server as wsServer} from "ws";
import express, {NextFunction, Request, Response} from "express"; import express, {NextFunction, Request, Response} from "express";
import fs from "fs"; import fs from "fs";
import path from "path"; import path from "path";
import {Server, Socket as ioSocket} from "socket.io"; import {Server as ioServer, Socket as ioSocket} from "socket.io";
import dns from "dns"; import dns from "dns";
import colors from "chalk"; import colors from "chalk";
import net from "net"; import net from "net";
@ -52,6 +52,12 @@ type IndexTemplateConfiguration = ServerConfiguration & {
}; };
type Socket = ioSocket<ClientToServerEvents, ServerToClientEvents, InterServerEvents, SocketData>; type Socket = ioSocket<ClientToServerEvents, ServerToClientEvents, InterServerEvents, SocketData>;
export type Server = ioServer<
ClientToServerEvents,
ServerToClientEvents,
InterServerEvents,
SocketData
>;
// A random number that will force clients to reload the page if it differs // A random number that will force clients to reload the page if it differs
const serverHash = Math.floor(Date.now() * Math.random()); const serverHash = Math.floor(Date.now() * Math.random());
@ -211,12 +217,7 @@ export default async function (
return; return;
} }
const sockets = new Server< const sockets: Server = new ioServer(server, {
ClientToServerEvents,
ServerToClientEvents,
InterServerEvents,
SocketData
>(server, {
wsEngine: wsServer, wsEngine: wsServer,
cookie: false, cookie: false,
serveClient: false, serveClient: false,