-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
37 lines (30 loc) · 1.03 KB
/
server.js
File metadata and controls
37 lines (30 loc) · 1.03 KB
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
36
37
var express = require('express');
var app = express();
var http = require('http').Server(app);
var io = require('socket.io')(http);
var port = process.env.PORT || 3000;
var users = [];
app.use(express.static('public'))
app.get('/', function(req, res){
res.sendFile(__dirname + '/index.html');
});
app.get('/pixijs', function(req, res){
res.sendFile(__dirname + '/indexPixi.html');
});
io.on('connection', function(socket){
socket.on('chat message', function(msg){
io.emit('chat message', msg + socket.id);
});
socket.on('sign in', function(msg, callback){
var data = JSON.parse(msg);
data.socket_id = socket.id;
users.push( data);
io.emit('chat message', JSON.stringify(users) + ' are the users');
// io.to(socket.id).emit('thanks for joining ', socket.id);
io.to(socket.id).emit('chat message', 'thanks for joining '+ socket.id + ' ya jerk');
callback(socket.id, users);
});
});
http.listen(port, function(){
console.log('listening on *:' + port);
});