-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
47 lines (35 loc) · 1.07 KB
/
index.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
const app = require('express')()
const server = require('http').Server(app)
const io = require('socket.io')(server)
const port = 3000
server.listen(port, ()=>{
console.log(`Server is running on port ${port}`)
})
app.get('/', (req, res)=>{
res.sendFile(__dirname + '/public/index.html')
})
app.get('/javascript', (req, res)=>{
res.sendFile(__dirname + '/public/javascript.html')
})
app.get('/css', (req, res)=>{
res.sendFile(__dirname + '/public/css.html')
})
app.get('/html', (req, res)=>{
res.sendFile(__dirname + '/public/html.html')
})
// tech namespace
const tech = io.of('/tech')
tech.on('connection', (socket)=>{
socket.on('join', (data)=>{
socket.join(data.room)
tech.in(data.room).emit('message', `New user joined ${data.room} room!`)
})
socket.on('message', (data)=>{
console.log(`message : ${data.msg}`)
tech.in(data.room).emit('message', data.msg)
})
socket.on('disconnect', ()=>{
console.log('user disconnected')
tech.emit('message', 'user disconnected')
})
})