mirror of
https://github.com/darkwire/darkwire.io.git
synced 2025-07-18 18:54:52 +00:00
Added support for static rooms
This commit is contained in:
parent
260fd711b0
commit
b31d758306
15
src/app.js
15
src/app.js
@ -10,6 +10,8 @@ import fs from 'fs';
|
|||||||
|
|
||||||
import Room from './room';
|
import Room from './room';
|
||||||
|
|
||||||
|
let usage = 0;
|
||||||
|
|
||||||
const $CONFIG = {
|
const $CONFIG = {
|
||||||
port: process.env.port || 3000
|
port: process.env.port || 3000
|
||||||
};
|
};
|
||||||
@ -30,19 +32,12 @@ app.use(express.static(__dirname + '/public'));
|
|||||||
function generateNewRoom(req, res, id) {
|
function generateNewRoom(req, res, id) {
|
||||||
const room = new Room(io, id);
|
const room = new Room(io, id);
|
||||||
rooms.push(room);
|
rooms.push(room);
|
||||||
console.log('generating new room');
|
console.log(`rooms created: ${usage++}`);
|
||||||
|
|
||||||
room.on('empty', function() {
|
|
||||||
rooms = _.without(rooms, _.findWhere(rooms, {_id: room._id}));
|
|
||||||
});
|
|
||||||
|
|
||||||
return res.redirect(`/${id}`);
|
return res.redirect(`/${id}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
app.get('/', (req, res) => {
|
app.get('/', (req, res) => generateNewRoom(req, res, 'lobby') );
|
||||||
const id = shortid.generate();
|
|
||||||
generateNewRoom(req, res, id);
|
|
||||||
});
|
|
||||||
|
|
||||||
app.get('/:roomId', (req, res) => {
|
app.get('/:roomId', (req, res) => {
|
||||||
const roomId = req.params.roomId || false;
|
const roomId = req.params.roomId || false;
|
||||||
@ -59,7 +54,7 @@ app.get('/:roomId', (req, res) => {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
return res.redirect('/');
|
return generateNewRoom(req, res, roomId);
|
||||||
});
|
});
|
||||||
|
|
||||||
server.listen($CONFIG.port, () => {
|
server.listen($CONFIG.port, () => {
|
||||||
|
@ -70,6 +70,7 @@ class Room {
|
|||||||
|
|
||||||
// when the user disconnects.. perform this
|
// when the user disconnects.. perform this
|
||||||
socket.on('disconnect', () => {
|
socket.on('disconnect', () => {
|
||||||
|
console.log('disconnected');
|
||||||
if (addedUser) {
|
if (addedUser) {
|
||||||
--this.numUsers;
|
--this.numUsers;
|
||||||
this.users = _.without(this.users, socket.user);
|
this.users = _.without(this.users, socket.user);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user