From 2d667fc36c250e29f4fdf66f0a0341de1400f76d Mon Sep 17 00:00:00 2001 From: Chukwuma Nwaugha Date: Sun, 21 Jan 2024 20:02:24 +0100 Subject: [PATCH] cleanup demo --- app/src/routes/index.svelte | 7 +++---- server/index.js | 6 ++++-- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/app/src/routes/index.svelte b/app/src/routes/index.svelte index 91bea29..2e1710c 100644 --- a/app/src/routes/index.svelte +++ b/app/src/routes/index.svelte @@ -9,7 +9,7 @@ wsClient = webSocket(); wsClient.on('message', (event) => { - wsResponse = String(event.data); + wsResponse = event.data; }); wsClient.on('error', (error) => { @@ -26,8 +26,7 @@ }); const sendMessage = (message: string) => { - const payload = { message }; - wsClient.send(JSON.stringify(payload)); + wsClient.send(JSON.stringify({ message })); }; @@ -61,7 +60,7 @@

WebSocket response

- {JSON.stringify(wsResponse, null, 2)} + {wsResponse}
diff --git a/server/index.js b/server/index.js index cc6fa15..24530c1 100644 --- a/server/index.js +++ b/server/index.js @@ -25,10 +25,12 @@ fastify() app.get("/ws/*", { websocket: true }, ({ socket }, req) => { socket.on("message", (msg) => { - console.log("from client", msg.toString(), req.url); + const msgStr = String(msg); + console.log(JSON.parse(msgStr), req.url); + const res = JSON.stringify({ pong: `acked: ${Date.now()}`, - msg: `${msg}`, + msg: msgStr, }); socket.send(res); });