From cd9cb268effa33e5799664294e3556460341bd94 Mon Sep 17 00:00:00 2001 From: "Glitch (hello-express)" Date: Thu, 9 Apr 2020 11:16:26 +0000 Subject: [PATCH] =?UTF-8?q?=F0=9F=8C=9C=F0=9F=8C=8A=20Checkpoint=20./serve?= =?UTF-8?q?r.js:530995/754=20./views/room.handlebars:530995/303?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server.js | 17 +++++++++-------- views/room.handlebars | 10 ++++++++-- 2 files changed, 17 insertions(+), 10 deletions(-) diff --git a/server.js b/server.js index 069abd9..498fa20 100644 --- a/server.js +++ b/server.js @@ -37,7 +37,9 @@ app.get("/:roomId/join", (request, response) => { response.render('room', { layout: false, room: request.params.roomId, - name: participant.participantName + name: participant.participantName, + participantName: participant.participantName, + participantId: participant.participantId, }); } else { response.render('join', {layout: false, room: request.params.roomId}); @@ -46,11 +48,7 @@ app.get("/:roomId/join", (request, response) => { app.post("/:roomId/join", (request, response) => { rooms.addParticipant(request.params.roomId, request.fingerprint.hash, request.body.name); - response.render('room', { - layout: false, - room: request.params.roomId, - name: request.body.name - }); + response.redirect(`/${request.params.roomId}/join`); }); server.listen(process.env.PORT, () => { @@ -59,9 +57,12 @@ server.listen(process.env.PORT, () => { const wss = new WebSocket.Server({ server }); -wss.on('connection', (ws) => { +wss.on('connection', (ws, req) => { ws.on('message', (message) => { - console.log('received: %s', message); + message = JSON.stringify(message); + console.log(message) + console.log(message.type) + console.log(message.data) }); ws.send('Connected'); diff --git a/views/room.handlebars b/views/room.handlebars index 26fe6b7..15efa15 100644 --- a/views/room.handlebars +++ b/views/room.handlebars @@ -27,11 +27,17 @@ let socket = new WebSocket(`wss://${window.location.hostname}`); socket.onopen = function(e) { - socket.send("My name is John"); + socket.send({ + type: "join", + data: { + participantId: '{{participantId}}', + participantName: '{{participantName}}', + } + }); }; socket.onmessage = function(event) { - a + }; socket.onerror = function(error) {