Skip to content

Commit

Permalink
cleanup demo
Browse files Browse the repository at this point in the history
  • Loading branch information
nwaughachukwuma committed Jan 21, 2024
1 parent 9f2131d commit 2d667fc
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
7 changes: 3 additions & 4 deletions app/src/routes/index.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
wsClient = webSocket();
wsClient.on('message', (event) => {
wsResponse = String(event.data);
wsResponse = event.data;
});
wsClient.on('error', (error) => {
Expand All @@ -26,8 +26,7 @@
});
const sendMessage = (message: string) => {
const payload = { message };
wsClient.send(JSON.stringify(payload));
wsClient.send(JSON.stringify({ message }));
};
</script>

Expand Down Expand Up @@ -61,7 +60,7 @@
<div class="response-area">
<h1>WebSocket response</h1>
<span>
{JSON.stringify(wsResponse, null, 2)}
{wsResponse}
</span>
</div>
</message-container>
Expand Down
6 changes: 4 additions & 2 deletions server/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
Expand Down

0 comments on commit 2d667fc

Please sign in to comment.