From 1abee4f9d797dcdd7e8de07311de92b25f622735 Mon Sep 17 00:00:00 2001 From: "Glitch (hello-express)" Date: Thu, 9 Apr 2020 11:04:28 +0000 Subject: [PATCH] =?UTF-8?q?=F0=9F=A4=96=F0=9F=8D=B2=20Checkpoint=20./room.?= =?UTF-8?q?js:530995/86=20./server.js:530995/1413=20./package.json:530995/?= =?UTF-8?q?1484=20./views/room.handlebars:530995/1594?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.json | 3 ++- room.js | 1 + server.js | 21 +++++++++++++++++---- shrinkwrap.yaml | 11 +++++++++++ views/room.handlebars | 16 ++++++++++++++++ 5 files changed, 47 insertions(+), 5 deletions(-) diff --git a/package.json b/package.json index daa1af0..b2c5d3d 100644 --- a/package.json +++ b/package.json @@ -13,7 +13,8 @@ "express": "^4.17.1", "express-handlebars": "^4.0.3", "body-parser": "^1.19.0", - "express-fingerprint": "^1.1.3" + "express-fingerprint": "^1.1.3", + "ws": "^7.2.3" }, "engines": { "node": "12.x" diff --git a/room.js b/room.js index 5d6a380..6af732d 100644 --- a/room.js +++ b/room.js @@ -26,3 +26,4 @@ function addParticipant(roomId, participantId, participantName) { rooms[roomId] = room; } +module.exports = {getOrCreateRoom, addParticipant} \ No newline at end of file diff --git a/server.js b/server.js index 697c666..069abd9 100644 --- a/server.js +++ b/server.js @@ -1,11 +1,14 @@ const express = require("express"); const exphbs = require('express-handlebars'); -const bodyParser = require('body-parser') -const Fingerprint = require('express-fingerprint') +const bodyParser = require('body-parser'); +const Fingerprint = require('express-fingerprint'); +const WebSocket = require('ws'); +const http = require('http'); const rooms = require('./room'); const app = express(); +const server = http.createServer(app); app.use(Fingerprint({ parameters:[ @@ -50,6 +53,16 @@ app.post("/:roomId/join", (request, response) => { }); }); -const listener = app.listen(process.env.PORT, () => { - console.log("Your app is listening on port " + listener.address().port); +server.listen(process.env.PORT, () => { + console.log("Your app is listening on port " + server.address().port); }); + + +const wss = new WebSocket.Server({ server }); +wss.on('connection', (ws) => { + ws.on('message', (message) => { + console.log('received: %s', message); + }); + + ws.send('Connected'); +}); \ No newline at end of file diff --git a/shrinkwrap.yaml b/shrinkwrap.yaml index e9bb170..2335d17 100644 --- a/shrinkwrap.yaml +++ b/shrinkwrap.yaml @@ -3,6 +3,7 @@ dependencies: express: 4.17.1 express-fingerprint: 1.1.3 express-handlebars: 4.0.3 + ws: 7.2.3 packages: /accepts/1.3.7: dependencies: @@ -705,6 +706,15 @@ packages: dev: false resolution: integrity: sha1-tSQ9jz7BqjXxNkYFvA0QNuMKtp8= + /ws/7.2.3: + dev: false + engines: + node: '>=8.3.0' + peerDependencies: + bufferutil: ^4.0.1 + utf-8-validate: ^5.0.2 + resolution: + integrity: sha512-HTDl9G9hbkNDk98naoR/cHDws7+EyYMOdL1BmjsZXRUjf7d+MficC4B7HLUPlSiho0vg+CWKrGIt/VJBd1xunQ== /yallist/2.1.2: dev: false resolution: @@ -724,3 +734,4 @@ specifiers: express: ^4.17.1 express-fingerprint: ^1.1.3 express-handlebars: ^4.0.3 + ws: ^7.2.3 diff --git a/views/room.handlebars b/views/room.handlebars index 6e57e6b..26fe6b7 100644 --- a/views/room.handlebars +++ b/views/room.handlebars @@ -22,5 +22,21 @@ BUZZ + +