🌜🌊 Checkpoint

./server.js:530995/754
./views/room.handlebars:530995/303
This commit is contained in:
Glitch (hello-express) 2020-04-09 11:16:26 +00:00
parent 1abee4f9d7
commit cd9cb268ef
2 changed files with 17 additions and 10 deletions

View File

@ -37,7 +37,9 @@ app.get("/:roomId/join", (request, response) => {
response.render('room', { response.render('room', {
layout: false, layout: false,
room: request.params.roomId, room: request.params.roomId,
name: participant.participantName name: participant.participantName,
participantName: participant.participantName,
participantId: participant.participantId,
}); });
} else { } else {
response.render('join', {layout: false, room: request.params.roomId}); 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) => { app.post("/:roomId/join", (request, response) => {
rooms.addParticipant(request.params.roomId, request.fingerprint.hash, request.body.name); rooms.addParticipant(request.params.roomId, request.fingerprint.hash, request.body.name);
response.render('room', { response.redirect(`/${request.params.roomId}/join`);
layout: false,
room: request.params.roomId,
name: request.body.name
});
}); });
server.listen(process.env.PORT, () => { server.listen(process.env.PORT, () => {
@ -59,9 +57,12 @@ server.listen(process.env.PORT, () => {
const wss = new WebSocket.Server({ server }); const wss = new WebSocket.Server({ server });
wss.on('connection', (ws) => { wss.on('connection', (ws, req) => {
ws.on('message', (message) => { 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'); ws.send('Connected');

View File

@ -27,11 +27,17 @@
let socket = new WebSocket(`wss://${window.location.hostname}`); let socket = new WebSocket(`wss://${window.location.hostname}`);
socket.onopen = function(e) { socket.onopen = function(e) {
socket.send("My name is John"); socket.send({
type: "join",
data: {
participantId: '{{participantId}}',
participantName: '{{participantName}}',
}
});
}; };
socket.onmessage = function(event) { socket.onmessage = function(event) {
a
}; };
socket.onerror = function(error) { socket.onerror = function(error) {