-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
48 lines (35 loc) · 1 KB
/
server.js
File metadata and controls
48 lines (35 loc) · 1 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
38
39
40
41
42
43
44
45
46
47
48
const http=require('http')
const express=require('express')
const socketio=require('socket.io')
const app=express()
const server =http.createServer(app)
const io=socketio(server)
var r;
let userid={} // 1 2 3 4
//var roomid={} // A-> 2,3 | B -> 1,4
app.use('/',express.static(__dirname+'/public'))
io.on('connection',(soc)=>{
console.log('connection on' ,soc.id)
soc.on('id',(data)=>{
r=data.username
soc.join(r);
if(userid[r]>=1){
userid[r]++
console.log("1")
}
else{
userid[r]=1;
console.log('2')
}
//console.log(data.username)
soc.emit('data_send',data)
})
soc.on('draw',(data)=>{
console.log(data.username)
console.log(data.input)
io.to(data.username).emit('msg_send',data) //.in(data.username)
})
})
server.listen(4444,()=>{
console.log("server is started")
})