-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
35 lines (26 loc) · 873 Bytes
/
index.js
File metadata and controls
35 lines (26 loc) · 873 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
const express = require('express');
const path = require('path');
const PORT = process.env.PORT || 5000;
const Lobby = require('./game/lobby')
const WebSocket = require('ws');
const server = express()
.use(express.static(path.join(__dirname, 'public')))
.set('views', path.join(__dirname, 'views'))
.set('view engine', 'ejs')
.get('/', (req, res) => res.render('pages/index'))
.listen(PORT, () => console.log(`Listening on ${ PORT }`))
const ws = new WebSocket.Server({ server });
var mLobbies = [createLobby()];
function createLobby(){
var nwLobby = new Lobby();
nwLobby.onFinished(l => {
mLobbies = mLobbies.filter(x => x !== l);
});
nwLobby.onStart(l => {
mLobbies.push(createLobby());
});
return nwLobby;
}
ws.on('connection', function(socket){
mLobbies[mLobbies.length-1].addSocket(socket);
});