-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
50 lines (37 loc) · 900 Bytes
/
server.js
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
38
39
40
41
42
43
44
45
46
47
48
49
50
var express = require('express');
var app = express();
var http = require('http').Server(app);
var io = require('socket.io')(http);
app.use('/static',express.static('bower_components'));
app.get('/',(req,resp)=>
{
resp.sendfile('public/index.html');
})
var conversation = [];
var users = [];
function createUser()
{
var number = Math.random();
//has to be unique
return number;
}
io.on('connection',(socket)=>
{
var user = createUser();
console.log('adding user '+user);
io.emit('userCreated', user);
users.push(user);
console.log('connected');
socket.on('messagePublished',function(ms)
{
conversation.push(ms);
io.emit('messageBroadcasted', ms);
console.log(ms);
}
)
socket.on('disconnect',()=>{console.log('disconnected');
console.log(conversation);});
})
http.listen(3000,()=>{
console.log('listening ');
})