Created
September 4, 2017 22:01
-
-
Save anhnguyen1618/b9e655db6bb48b6f0569c1bc684bf35e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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