-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
52 lines (41 loc) · 1.18 KB
/
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
const { Console } = require('console');
var app = require('express')();
var http = require('http').createServer(app);
const io = require("socket.io")(http, {
cors: {
origin: "http://localhost:3000",
}
});
app.get('/', (req, res) => {
res.sendFile(__dirname + '/index.html');
});
io.on('connection', (socket) => {
console.log('a user connected :' + socket.id);
console.log(socket.rooms)
socket.on('createJoinRoom', function(data) {
socket.join(data.chatID);
console.log(socket.rooms)
});
socket.on('createJoinOfferRoom', function(data) {
socket.join(data.offerID);
console.log(socket.rooms)
});
socket.on('offerChanged',(offerRoom)=>{
console.log('offer change')
console.log(offerRoom)
io.to(offerRoom).emit("updateOffer");
})
socket.on("private message", (data) => {
socket.to(data.chatID).emit("shouldUpdateMessage", data.msg);
})
socket.on('leaveRoom', function(room) {
io.to(room).emit('onlineStatus',false)
console.log('user leaves room now')
});
socket.on('disconnect', () => {
console.log('a user disconnected' + socket.id);
})
});
http.listen(3001, () => {
console.log('listening on *3001');
});