-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
45 lines (35 loc) · 1.09 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
const app = require('express')();
const server = require('http').Server(app) //run the server on app
const io = require('socket.io')(server); //run our server on socket.io
const port = 3000;
server.listen(port, ()=> {
console.log(`Server is listening on Port: ${port}`)
});
app.get('/', (req, res)=> {
res.sendFile(__dirname + '/public/index.html')
});
app.get('/phyton', (req, res)=> {
res.sendFile(__dirname + '/public/phyton.html')
});
app.get('/javascript', (req, res)=> {
res.sendFile(__dirname + '/public/javascript.html')
});
app.get('/swift', (req, res)=> {
res.sendFile(__dirname + '/public/swift.html')
});
const tech = io.of('/tech');
tech.on('connection', (socket)=>{
// console.log('A user connected')
socket.on('join', (data) => {
socket.join(data.room);
tech.in(data.room).emit('message', `New User Joiner ${data.room} root!`)
});
socket.on('message', (data)=> {
tech.in(data.room).emit('message', data.msg);
console.log(data)
});
io.on('disconnect', ()=> {
console.log('User Disconnected')
tech.emit('message', 'User Disconnected')
})
});