Skip to content

Instantly share code, notes, and snippets.

@anhnguyen1618
Created September 4, 2017 22:01
Show Gist options
  • Save anhnguyen1618/b9e655db6bb48b6f0569c1bc684bf35e to your computer and use it in GitHub Desktop.
Save anhnguyen1618/b9e655db6bb48b6f0569c1bc684bf35e to your computer and use it in GitHub Desktop.
var app = require('express')();
var http = require('http').Server(app);
var io = require('socket.io')(http);
var port = process.env.PORT || 3000;
app.get('/', function(req, res){
res.sendFile(__dirname + '/index.html');
});
let queue = [];
io.on('connection', function(socket){
socket.on('chat message', function(msg){
console.log(socket.id);
io.emit('chat message', msg);
});
socket.join("Toilet");
socket.on('book', function(msg){
queue.push(socket.id);
socket.emit('book', queue.length);
});
socket.on('done', function(msg){
queue = queue.filter(id => id !== socket.id)
console.log(queue);
io.to('Toilet').emit('done', {});
});
});
http.listen(port, function(){
console.log('listening on *:' + port);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment