diff --git a/package.json b/package.json index 8c0cdd5..3995936 100644 --- a/package.json +++ b/package.json @@ -15,12 +15,14 @@ "dotenv": "^16.3.1", "esbuild": "0.19.0", "express": "^4.18.2", + "express-ws": "^5.0.2", "firebase": "^10.1.0", "preact": "^10.16.0", "ts-node": "^10.9.1", "wrtc": "^0.4.7" }, "devDependencies": { - "@types/express": "^4.17.17" + "@types/express": "^4.17.17", + "@types/express-ws": "^3.0.1" } } diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 6b01848..038143a 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -17,6 +17,9 @@ dependencies: express: specifier: ^4.18.2 version: 4.18.2 + express-ws: + specifier: ^5.0.2 + version: 5.0.2(express@4.18.2) firebase: specifier: ^10.1.0 version: 10.1.0(react-native@0.72.3) @@ -34,6 +37,9 @@ devDependencies: '@types/express': specifier: ^4.17.17 version: 4.17.17 + '@types/express-ws': + specifier: ^3.0.1 + version: 3.0.1 packages: @@ -2618,6 +2624,14 @@ packages: '@types/send': 0.17.1 dev: true + /@types/express-ws@3.0.1: + resolution: {integrity: sha512-VguRXzcpPBF0IggIGpUoM65cZJDfMQxoc6dKoCz1yLzcwcXW7ft60yhq3ygKhyEhEIQFtLrWjyz4AJ1qjmzCFw==} + dependencies: + '@types/express': 4.17.17 + '@types/express-serve-static-core': 4.17.35 + '@types/ws': 8.5.5 + dev: true + /@types/express@4.17.17: resolution: {integrity: sha512-Q4FmmuLGBG58btUnfS1c1r/NQdlp3DMfGDGig8WhfpA2YRUtEkxAjkZb0yvplJGYdF1fsQ81iMDcH24sSCNC/Q==} dependencies: @@ -2689,6 +2703,12 @@ packages: resolution: {integrity: sha512-Hl219/BT5fLAaz6NDkSuhzasy49dwQS/DSdu4MdggFB8zcXv7vflBI3xp7FEmkmdDkBUI2bPUNeMttp2knYdxw==} dev: false + /@types/ws@8.5.5: + resolution: {integrity: sha512-lwhs8hktwxSjf9UaZ9tG5M03PGogvFaH8gUgLNbN9HKIg0dvv6q+gkSuJ8HN4/VbyxkuLzCjlN7GquQ0gUJfIg==} + dependencies: + '@types/node': 20.4.9 + dev: true + /@types/yargs-parser@21.0.0: resolution: {integrity: sha512-iO9ZQHkZxHn4mSakYV0vFHAVDyEOIJQrV2uZ06HxEPcx+mt8swXoZHIbaaJ2crJYFfErySgktuTZ3BeLz+XmFA==} dev: false @@ -3536,6 +3556,19 @@ packages: strip-final-newline: 2.0.0 dev: false + /express-ws@5.0.2(express@4.18.2): + resolution: {integrity: sha512-0uvmuk61O9HXgLhGl3QhNSEtRsQevtmbL94/eILaliEADZBHZOQUAiHFrGPrgsjikohyrmSG5g+sCfASTt0lkQ==} + engines: {node: '>=4.5.0'} + peerDependencies: + express: ^4.0.0 || ^5.0.0-alpha.1 + dependencies: + express: 4.18.2 + ws: 7.5.9 + transitivePeerDependencies: + - bufferutil + - utf-8-validate + dev: false + /express@4.18.2: resolution: {integrity: sha512-5/PsL6iGPdfQ/lKM1UuielYgv3BUoJfz1aUwU9vHZ+J7gyvwdQXFEBIEIaxeGf0GIcreATNyBExtalisDbuMqQ==} engines: {node: '>= 0.10.0'} diff --git a/server/main.ts b/server/main.ts index 306a614..3b15bc9 100644 --- a/server/main.ts +++ b/server/main.ts @@ -1,5 +1,6 @@ import dotenv from "dotenv"; import express from "express"; +import expressWs from "express-ws"; import * as wrtc from "wrtc"; const configuration = { @@ -66,7 +67,9 @@ async function connect( } } -const app = express(); +const app = express() as unknown as expressWs.Application; +expressWs(app); + app.use(express.json()); app.use((req, res, next) => { res.header("Access-Control-Allow-Origin", "*"); @@ -87,4 +90,11 @@ app.post("/connect", (req, res) => { } }); +app.ws("/dev-ws", (ws, req) => { + console.log("ws connect"); + ws.on("message", (msg) => { + console.log({ msg }); + }); +}); + app.listen(3000, () => console.log("listening"));