-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
36 lines (26 loc) · 838 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
const express = require('express');
const http = require('http');
const PORT = process.env.PORT || 3000;
const app = express();
const server = http.createServer(app);
const io = require('socket.io')(server);
app.use(express.static("public"))
app.get('/', (req, res) => {
res.sendFile(__dirname + '/public/index.html');
})
let connectedPeers = [];
io.on('connection', (socket) => {
connectedPeers.push(socket.id);
console.log(connectedPeers);
socket.on('disconnect', () => {
console.log("user diconnected");
const newConnectedPeers = connectedPeers.filter((peerSocketId) => {
return peerSocketId !== socket.id;
})
connectedPeers = newConnectedPeers;
console.log(connectedPeers);
})
});
server.listen(PORT, () => {
console.log('listening on ${PORT}')
});