From 30e6e61c81442dc67371dff67c0001a7ad2779d0 Mon Sep 17 00:00:00 2001 From: Holly Date: Wed, 9 Oct 2024 10:31:55 +0100 Subject: [PATCH] switch to ultimate-ws --- server/index.ts | 7 ++++--- server/objects/RemoteUser.ts | 1 - server/package-lock.json | 35 +++++++++++++++++++++++------------ server/package.json | 3 +-- 4 files changed, 28 insertions(+), 18 deletions(-) diff --git a/server/index.ts b/server/index.ts index ee04695..1b3fcbb 100644 --- a/server/index.ts +++ b/server/index.ts @@ -27,7 +27,6 @@ const messagesOut = metrics.addMetric(new Counter("multiprobe_msg_out")); dataIn.setHelpText("Total messages sent by the server"); import { createReader, createWriter, Endian } from "bufferstuff"; -import { WebSocketServer } from "ws"; import Fastify from "fastify"; import FastifyFormBody from "@fastify/formbody"; import FastifyCookie from "@fastify/cookie"; @@ -55,6 +54,8 @@ import BadgeCache from "./objects/BadgeCache"; import ScriptParameters from "./interfaces/ScriptParameters"; import { BadgeUnlockResult } from "./enums/BadgeUnlockResult"; +const { WebSocketServer } = require("ultimate-ws"); + Console.customHeader(`MultiProbe server started at ${new Date()}`); const users = new FunkyArray(); @@ -196,7 +197,7 @@ async function updateConnectionMetrics() { const keepalivePacket = createWriter(Endian.LE, 1).writeByte(MessageType.KeepAlive).toBuffer(); -websocketServer.on("connection", (socket) => { +websocketServer.on("connection", (socket: any) => { const myUUID = crypto.randomUUID(); let user:RemoteUser; @@ -247,7 +248,7 @@ websocketServer.on("connection", (socket) => { socket.on("close", closeOrError); socket.on("error", closeOrError); - socket.on("message", async (data) => { + socket.on("message", async (data: any) => { const reader = createReader(Endian.LE, data as Buffer); dataIn.add(reader.length); messagesIn.add(1); diff --git a/server/objects/RemoteUser.ts b/server/objects/RemoteUser.ts index 87bb492..3332fff 100644 --- a/server/objects/RemoteUser.ts +++ b/server/objects/RemoteUser.ts @@ -1,6 +1,5 @@ import { createWriter, Endian } from "bufferstuff"; import IMetric from "simple-prom/lib/interfaces/IMetric"; -import { WebSocket } from "ws"; import { MessageType } from "../enums/MessageType"; export default class RemoteUser { diff --git a/server/package-lock.json b/server/package-lock.json index 7f74f21..4c102f1 100644 --- a/server/package-lock.json +++ b/server/package-lock.json @@ -19,12 +19,11 @@ "hsconsole": "^1.0.2", "mysql2": "^3.11.3", "simple-prom": "^1.0.1", - "ws": "^8.16.0" + "ultimate-ws": "^1.0.8" }, "devDependencies": { "@types/ejs": "^3.1.5", "@types/node": "^22.7.5", - "@types/ws": "^8.5.12", "@vercel/ncc": "^0.38.2", "check-outdated": "^2.12.0", "nodemon": "^3.1.7", @@ -288,16 +287,6 @@ "undici-types": "~6.19.2" } }, - "node_modules/@types/ws": { - "version": "8.5.12", - "resolved": "https://registry.npmjs.org/@types/ws/-/ws-8.5.12.tgz", - "integrity": "sha512-3tPRkv1EtkDpzlgyKyI8pGsGZAGPEaXeu0DOj5DI25Ja91bdAYddYHbADRYVrZMRbfW+1l5YwXVDKohDJNQxkQ==", - "dev": true, - "license": "MIT", - "dependencies": { - "@types/node": "*" - } - }, "node_modules/@vercel/ncc": { "version": "0.38.2", "resolved": "https://registry.npmjs.org/@vercel/ncc/-/ncc-0.38.2.tgz", @@ -3349,6 +3338,12 @@ } } }, + "node_modules/tseep": { + "version": "1.3.1", + "resolved": "https://registry.npmjs.org/tseep/-/tseep-1.3.1.tgz", + "integrity": "sha512-ZPtfk1tQnZVyr7BPtbJ93qaAh2lZuIOpTMjhrYa4XctT8xe7t4SAW9LIxrySDuYMsfNNayE51E/WNGrNVgVicQ==", + "license": "MIT" + }, "node_modules/typed-array-buffer": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/typed-array-buffer/-/typed-array-buffer-1.0.2.tgz", @@ -3436,6 +3431,17 @@ "node": ">=14.17" } }, + "node_modules/ultimate-ws": { + "version": "1.0.8", + "resolved": "https://registry.npmjs.org/ultimate-ws/-/ultimate-ws-1.0.8.tgz", + "integrity": "sha512-pk/PM+G6IK3l1BdgXXHdOuFul0/hyyi3AluNdgYjaXap/u47wRRJDE6YCPks0wgcHkb9iOTu9AiHFkH1ezXkOw==", + "license": "Apache-2.0", + "dependencies": { + "tseep": "^1.3.1", + "uWebSockets.js": "github:uNetworking/uWebSockets.js#v20.48.0", + "ws": "^8.18.0" + } + }, "node_modules/unbox-primitive": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/unbox-primitive/-/unbox-primitive-1.0.2.tgz", @@ -3464,6 +3470,11 @@ "dev": true, "license": "MIT" }, + "node_modules/uWebSockets.js": { + "version": "20.48.0", + "resolved": "git+ssh://git@github.com/uNetworking/uWebSockets.js.git#51ae1d1fd92dff77cbbdc7c431021f85578da1a6", + "license": "Apache-2.0" + }, "node_modules/v8-compile-cache-lib": { "version": "3.0.1", "resolved": "https://registry.npmjs.org/v8-compile-cache-lib/-/v8-compile-cache-lib-3.0.1.tgz", diff --git a/server/package.json b/server/package.json index 91d3aa2..81246a9 100644 --- a/server/package.json +++ b/server/package.json @@ -22,12 +22,11 @@ "hsconsole": "^1.0.2", "mysql2": "^3.11.3", "simple-prom": "^1.0.1", - "ws": "^8.16.0" + "ultimate-ws": "^1.0.8" }, "devDependencies": { "@types/ejs": "^3.1.5", "@types/node": "^22.7.5", - "@types/ws": "^8.5.12", "@vercel/ncc": "^0.38.2", "check-outdated": "^2.12.0", "nodemon": "^3.1.7",