🦁🐂 Checkpoint
./package.json:530995/436 ./views/audience.handlebars:530995/1631 ./views/index.handlebars:530995/4739 ./views/join.handlebars:530995/1631 ./views/room.handlebars:530995/1975 ./room.js:530995/66 ./server.js:530995/292
This commit is contained in:
parent
6c1a308a03
commit
ef0cfb7dbd
30
README.md
30
README.md
@ -1,30 +0,0 @@
|
||||
# hello-express
|
||||
|
||||
A server that serves a webpage, its resources, and some data
|
||||
|
||||
|
||||
## Your Project
|
||||
|
||||
On the front-end,
|
||||
|
||||
- Edit `views/index.html` to change the content of the webpage
|
||||
- `public/client.js` is the javacript that runs when you load the webpage
|
||||
- `public/style.css` is the styles for `views/index.html`
|
||||
- Drag in `assets`, like images or music, to add them to your project
|
||||
|
||||
On the back-end,
|
||||
|
||||
- your app starts at `server.js`
|
||||
- add frameworks and packages in `package.json`
|
||||
- safely store app secrets in `.env` (nobody can see this but you and people you invite)
|
||||
|
||||
Click `Show` in the header to see your app live. Updates to your code will instantly deploy.
|
||||
|
||||
|
||||
## Made by [Glitch](https://glitch.com/)
|
||||
|
||||
**Glitch** is the friendly community where you'll build the app of your dreams. Glitch lets you instantly create, remix, edit, and host an app, bot or site, and you can invite collaborators or helpers to simultaneously edit code with you.
|
||||
|
||||
Find out more [about Glitch](https://glitch.com/about).
|
||||
|
||||
( ᵔ ᴥ ᵔ )
|
17
package.json
17
package.json
@ -1,10 +1,6 @@
|
||||
{
|
||||
"//1": "describes your app and its dependencies",
|
||||
"//2": "https://docs.npmjs.com/files/package.json",
|
||||
"//3": "updating this file will download and update your packages",
|
||||
"name": "hello-express",
|
||||
"name": "buzzers",
|
||||
"version": "0.0.1",
|
||||
"description": "A simple Node app built on Express, instantly up and running.",
|
||||
"main": "server.js",
|
||||
"scripts": {
|
||||
"start": "node server.js"
|
||||
@ -18,14 +14,5 @@
|
||||
},
|
||||
"engines": {
|
||||
"node": "12.x"
|
||||
},
|
||||
"repository": {
|
||||
"url": "https://glitch.com/edit/#!/hello-express"
|
||||
},
|
||||
"license": "MIT",
|
||||
"keywords": [
|
||||
"node",
|
||||
"glitch",
|
||||
"express"
|
||||
]
|
||||
}
|
||||
}
|
10
room.js
10
room.js
@ -2,11 +2,11 @@ const chars = require('./characters.json');
|
||||
const rooms = {};
|
||||
|
||||
function shuffle(a) {
|
||||
for (let i = a.length - 1; i > 0; i--) {
|
||||
const j = Math.floor(Math.random() * (i + 1));
|
||||
[a[i], a[j]] = [a[j], a[i]];
|
||||
}
|
||||
return a;
|
||||
for (let i = a.length - 1; i > 0; i--) {
|
||||
const j = Math.floor(Math.random() * (i + 1));
|
||||
[a[i], a[j]] = [a[j], a[i]];
|
||||
}
|
||||
return a;
|
||||
}
|
||||
|
||||
function getOrCreateRoom(roomId) {
|
||||
|
22
server.js
22
server.js
@ -11,11 +11,7 @@ const app = express();
|
||||
const server = http.createServer(app);
|
||||
|
||||
app.use(Fingerprint({
|
||||
parameters:[
|
||||
Fingerprint.useragent,
|
||||
Fingerprint.acceptHeaders,
|
||||
Fingerprint.geoip
|
||||
]
|
||||
parameters: [Fingerprint.useragent, Fingerprint.acceptHeaders, Fingerprint.geoip]
|
||||
}));
|
||||
|
||||
app.use(bodyParser.json());
|
||||
@ -33,7 +29,6 @@ app.get("/", (request, response) => {
|
||||
});
|
||||
|
||||
app.get("/:roomId/join", (request, response) => {
|
||||
|
||||
let room = rooms.getOrCreateRoom(request.params.roomId);
|
||||
let participant = room.participants.find(p => p.participantId === request.fingerprint.hash);
|
||||
|
||||
@ -47,13 +42,12 @@ app.get("/:roomId/join", (request, response) => {
|
||||
character: participant.character,
|
||||
});
|
||||
} else {
|
||||
response.render('join', {layout: false, room: request.params.roomId});
|
||||
response.render('join', {layout: false, room: request.params.roomId});
|
||||
}
|
||||
});
|
||||
|
||||
app.get("/:roomId/audience", (request, response) => {
|
||||
let room = rooms.getOrCreateRoom(request.params.roomId);
|
||||
|
||||
response.render('audience', {layout: false, room: request.params.roomId, participants: room.participants });
|
||||
});
|
||||
|
||||
@ -63,20 +57,19 @@ app.post("/:roomId/join", (request, response) => {
|
||||
});
|
||||
|
||||
server.listen(process.env.PORT, () => {
|
||||
console.log("Your app is listening on port " + server.address().port);
|
||||
console.log("Your app is listening on port " + server.address().port);
|
||||
});
|
||||
|
||||
|
||||
const wss = new WebSocket.Server({ server });
|
||||
|
||||
wss.on('connection', (ws, req) => {
|
||||
let participant;
|
||||
let roomId = req.url.substring(1);
|
||||
|
||||
if (roomId.includes("/audience")) {
|
||||
roomId = roomId.replace("/audience", "");
|
||||
|
||||
rooms.addAudienceWS(roomId, ws);
|
||||
} else {
|
||||
let participant;
|
||||
ws.on('message', (message) => {
|
||||
message = JSON.parse(message);
|
||||
if (message.type === "join") {
|
||||
@ -89,9 +82,10 @@ wss.on('connection', (ws, req) => {
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
ws.on('close', () => {
|
||||
rooms.removeParticipant(roomId, participant.participantId);
|
||||
if (participant) {
|
||||
rooms.removeParticipant(roomId, participant.participantId);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
@ -5,10 +5,8 @@
|
||||
<title>Buzzers</title>
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<meta name="description" content="A cool thing made with Glitch">
|
||||
<link id="favicon" rel="icon" href="https://glitch.com/edit/favicon-app.ico" type="image/x-icon">
|
||||
<link rel="icon" href="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADAAAAAwCAYAAABXAvmHAAAABmJLR0QA/wD/AP+gvaeTAAADuUlEQVRoge2YW2hcVRSGv31ym2YyoraasanFEWtaQW0StAYRB2JRFAKCpm1C6c0bSCg++dKHWH32QX0Sq7QkLZlSxcubUGpS0Je0RtJipZnElIIWhlDmkrn1LB9mjMnkzLnMnDO2MN/LMGuvtde/zl57nz0DderUuaNRbk0ku0JPguoD9QxIJ/Ag0FYcTgALoP5Ayc+InFXjc9Nu5K2qAOnvDODLvoXSDoFscxh+GTiGvu5zdfpSolINFRUg4XAjwYVhhCPAvZUmLyiQGKI+4u/Nn6lz5/KOw50GyJ6HtqJrp4DtTmMtZr6Izh51eu6KkyhHBcjuUD+ixvivt1fzaDfseAm2dMGGjdB2N0RnYGSX3RRxRIZUZO57uwGNdh1ld2gvor40jXn/GPjvsjulEQGU+loGQgdUZG7UToCtFSg++TOUiu/pg3wOpicK35/th/s2wew0XL8KiZuQTTsroUAeeFWNR3+wcrQsQAYf3sItpoDAsrGhAfaPwM5BSMXhoMvboUACTX9KnZr/3cxJMxuUcLiRW0QoFX/404L4bBq++sAduWtpQ9fGJBw2bXPTAgguDFN62uwfgadfhORNODoIk99UK9SMbtoX3jVzKNtCsrfdT9Y/D2xYNva+Aoc/KTz5o0Nw9VfXlJZXKDFSzSH13ZW40XD5Fci0vsNK8QD7jhQ+j39YG/EAotazLvdmueHy/VW4Hqy2nf8WtAY4O+6aPpscAj42GjBsoeLFrEaP2C7qcTU+O1NqNW4h4QXP9ThG+oysxgUobYenWipCeo2sZTaxbPVSSmWoTiNrmRWQjZ5qqYxNRsYye0AFDO3/L4aa7F3mzvAAOvNAs5uKTMghhNQA160cza8S/6LzNrUTD9CEouzLayXWt9EIzSj+BIJVy3LGDfxsVi+TMXOyXgGNAWovHuB+krxm5WRdgDDsipzKeM/Kwfgqcbn0EnR7oB5bq9feJr6Nsf2j3gkXoh1EfnmC2b/WA/BIMMbrvb/RHbI8FR3jeguNTnRxYqLHcGzf81MMPXex0qm9b6GpaAcnJnoQIJNKkFiMEV+MkU4lEeD4Tz1ciHa4mdLdAkYnuwHIpJJklpbQdR3RdbJLKTKpZNGny82U7hSQzjUyNtnFpWvtAOQza/8LyqULtplrQU6e304m7872M9wDOwffqOoYjS/GEF1fnUhrIHBPdf8D/3jyi9oco00tPgNbixepvDlGW1r9AOSKrdTU4lu2uY0nBSjA1+rH55Holdzxb+J6AXXq1KlTFf8AtEULoLOzQvEAAAAASUVORK5CYII=">
|
||||
<link rel="stylesheet" href="/style.css">
|
||||
<script src="/script.js" defer></script>
|
||||
</head>
|
||||
<body>
|
||||
<header>
|
||||
|
@ -5,10 +5,8 @@
|
||||
<title>Buzzers</title>
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<meta name="description" content="A cool thing made with Glitch">
|
||||
<link id="favicon" rel="icon" href="https://glitch.com/edit/favicon-app.ico" type="image/x-icon">
|
||||
<link rel="icon" href="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADAAAAAwCAYAAABXAvmHAAAABmJLR0QA/wD/AP+gvaeTAAADuUlEQVRoge2YW2hcVRSGv31ym2YyoraasanFEWtaQW0StAYRB2JRFAKCpm1C6c0bSCg++dKHWH32QX0Sq7QkLZlSxcubUGpS0Je0RtJipZnElIIWhlDmkrn1LB9mjMnkzLnMnDO2MN/LMGuvtde/zl57nz0DderUuaNRbk0ku0JPguoD9QxIJ/Ag0FYcTgALoP5Ayc+InFXjc9Nu5K2qAOnvDODLvoXSDoFscxh+GTiGvu5zdfpSolINFRUg4XAjwYVhhCPAvZUmLyiQGKI+4u/Nn6lz5/KOw50GyJ6HtqJrp4DtTmMtZr6Izh51eu6KkyhHBcjuUD+ixvivt1fzaDfseAm2dMGGjdB2N0RnYGSX3RRxRIZUZO57uwGNdh1ld2gvor40jXn/GPjvsjulEQGU+loGQgdUZG7UToCtFSg++TOUiu/pg3wOpicK35/th/s2wew0XL8KiZuQTTsroUAeeFWNR3+wcrQsQAYf3sItpoDAsrGhAfaPwM5BSMXhoMvboUACTX9KnZr/3cxJMxuUcLiRW0QoFX/404L4bBq++sAduWtpQ9fGJBw2bXPTAgguDFN62uwfgadfhORNODoIk99UK9SMbtoX3jVzKNtCsrfdT9Y/D2xYNva+Aoc/KTz5o0Nw9VfXlJZXKDFSzSH13ZW40XD5Fci0vsNK8QD7jhQ+j39YG/EAotazLvdmueHy/VW4Hqy2nf8WtAY4O+6aPpscAj42GjBsoeLFrEaP2C7qcTU+O1NqNW4h4QXP9ThG+oysxgUobYenWipCeo2sZTaxbPVSSmWoTiNrmRWQjZ5qqYxNRsYye0AFDO3/L4aa7F3mzvAAOvNAs5uKTMghhNQA160cza8S/6LzNrUTD9CEouzLayXWt9EIzSj+BIJVy3LGDfxsVi+TMXOyXgGNAWovHuB+krxm5WRdgDDsipzKeM/Kwfgqcbn0EnR7oB5bq9feJr6Nsf2j3gkXoh1EfnmC2b/WA/BIMMbrvb/RHbI8FR3jeguNTnRxYqLHcGzf81MMPXex0qm9b6GpaAcnJnoQIJNKkFiMEV+MkU4lEeD4Tz1ciHa4mdLdAkYnuwHIpJJklpbQdR3RdbJLKTKpZNGny82U7hSQzjUyNtnFpWvtAOQza/8LyqULtplrQU6e304m7872M9wDOwffqOoYjS/GEF1fnUhrIHBPdf8D/3jyi9oco00tPgNbixepvDlGW1r9AOSKrdTU4lu2uY0nBSjA1+rH55Holdzxb+J6AXXq1KlTFf8AtEULoLOzQvEAAAAASUVORK5CYII=">
|
||||
<link rel="stylesheet" href="/style.css">
|
||||
<script src="/script.js" defer></script>
|
||||
</head>
|
||||
<body>
|
||||
<header>
|
||||
|
@ -5,10 +5,8 @@
|
||||
<title>Buzzers</title>
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<meta name="description" content="A cool thing made with Glitch">
|
||||
<link id="favicon" rel="icon" href="https://glitch.com/edit/favicon-app.ico" type="image/x-icon">
|
||||
<link rel="icon" href="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADAAAAAwCAYAAABXAvmHAAAABmJLR0QA/wD/AP+gvaeTAAADuUlEQVRoge2YW2hcVRSGv31ym2YyoraasanFEWtaQW0StAYRB2JRFAKCpm1C6c0bSCg++dKHWH32QX0Sq7QkLZlSxcubUGpS0Je0RtJipZnElIIWhlDmkrn1LB9mjMnkzLnMnDO2MN/LMGuvtde/zl57nz0DderUuaNRbk0ku0JPguoD9QxIJ/Ag0FYcTgALo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vEAAAAASUVORK5CYII=">
|
||||
<link rel="stylesheet" href="/style.css">
|
||||
<script src="/script.js" defer></script>
|
||||
</head>
|
||||
<body>
|
||||
<header>
|
||||
|
@ -5,10 +5,8 @@
|
||||
<title>Buzzers</title>
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<meta name="description" content="A cool thing made with Glitch">
|
||||
<link id="favicon" rel="icon" href="https://glitch.com/edit/favicon-app.ico" type="image/x-icon">
|
||||
<link rel="icon" href="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADAAAAAwCAYAAABXAvmHAAAABmJLR0QA/wD/AP+gvaeTAAADuUlEQVRoge2YW2hcVRSGv31ym2YyoraasanFEWtaQW0StAYRB2JRFAKCpm1C6c0bSCg++dKHWH32QX0Sq7QkLZlSxcubUGpS0Je0RtJipZnElIIWhlDmkrn1LB9mjMnkzLnMnDO2MN/LMGuvtde/zl57nz0DderUuaNRbk0ku0JPguoD9QxIJ/Ag0FYcTgALoP5Ayc+InFXjc9Nu5K2qAOnvDODLvoXSDoFscxh+GTiGvu5zdfpSolINFRUg4XAjwYVhhCPAvZUmLyiQGKI+4u/Nn6lz5/KOw50GyJ6HtqJrp4DtTmMtZr6Izh51eu6KkyhHBcjuUD+ixvivt1fzaDfseAm2dMGGjdB2N0RnYGSX3RRxRIZUZO57uwGNdh1ld2gvor40jXn/GPjvsjulEQGU+loGQgdUZG7UToCtFSg++TOUiu/pg3wOpicK35/th/s2wew0XL8KiZuQTTsroUAeeFWNR3+wcrQsQAYf3sItpoDAsrGhAfaPwM5BSMXhoMvboUACTX9KnZr/3cxJMxuUcLiRW0QoFX/404L4bBq++sAduWtpQ9fGJBw2bXPTAgguDFN62uwfgadfhORNODoIk99UK9SMbtoX3jVzKNtCsrfdT9Y/D2xYNva+Aoc/KTz5o0Nw9VfXlJZXKDFSzSH13ZW40XD5Fci0vsNK8QD7jhQ+j39YG/EAotazLvdmueHy/VW4Hqy2nf8WtAY4O+6aPpscAj42GjBsoeLFrEaP2C7qcTU+O1NqNW4h4QXP9ThG+oysxgUobYenWipCeo2sZTaxbPVSSmWoTiNrmRWQjZ5qqYxNRsYye0AFDO3/L4aa7F3mzvAAOvNAs5uKTMghhNQA160cza8S/6LzNrUTD9CEouzLayXWt9EIzSj+BIJVy3LGDfxsVi+TMXOyXgGNAWovHuB+krxm5WRdgDDsipzKeM/Kwfgqcbn0EnR7oB5bq9feJr6Nsf2j3gkXoh1EfnmC2b/WA/BIMMbrvb/RHbI8FR3jeguNTnRxYqLHcGzf81MMPXex0qm9b6GpaAcnJnoQIJNKkFiMEV+MkU4lEeD4Tz1ciHa4mdLdAkYnuwHIpJJklpbQdR3RdbJLKTKpZNGny82U7hSQzjUyNtnFpWvtAOQza/8LyqULtplrQU6e304m7872M9wDOwffqOoYjS/GEF1fnUhrIHBPdf8D/3jyi9oco00tPgNbixepvDlGW1r9AOSKrdTU4lu2uY0nBSjA1+rH55Holdzxb+J6AXXq1KlTFf8AtEULoLOzQvEAAAAASUVORK5CYII=">
|
||||
<link rel="stylesheet" href="/style.css">
|
||||
<script src="/script.js" defer></script>
|
||||
</head>
|
||||
<body>
|
||||
<header>
|
||||
|
Loading…
Reference in New Issue
Block a user