-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
57 lines (46 loc) · 967 Bytes
/
app.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
51
52
53
54
55
56
57
const express=require('express')
const app=express()
const bodyParser=require('body-parser')
const http = require('http').Server(app);
const io=require('socket.io')(http,
{cors: {
origin: "*",
methods: ["GET", "POST"]
}})
app.get('/', function(req, res) {
res.send('hello')
});
let user=[]
let msg=[]
//function
app.use(bodyParser.urlencoded({limit:'5mb'}))
io.on('connection',(socket)=>{
// online
socket.emit('online',true)
//join
socket.on('join',(res)=>{
let data={username:res,text:`${res} jast join`}
msg.push(data)
io.emit('show',msg)
// console.log(user)
})
//show msg
io.emit('show',msg)
//send msg
socket.on('msg',(res)=>{
msg.push(res)
console.log(msg)
io.emit('show',msg)
})
socket.on('file',(res)=>{
msg.push(res)
console.log(msg)
io.emit('show',msg)
})
socket.on('disconnect', ()=>{
console.log('disconnect')
});
})
http.listen(process.env.PORT||3030, function() {
console.log('listening on *:3030');
});