-
Notifications
You must be signed in to change notification settings - Fork 0
/
App.js
42 lines (33 loc) · 1006 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
const exppres = require('express');
const http = require('http');
const app = exppres();
//Server Port
const PORT = process.env.PORT || 3000;
// http server
app.use(exppres.static('public'));
const server = http.createServer(app);
const io = require('socket.io')(server);
// Server Route Create Append Html File
app.get('/', (req, res) => {
res.sendFile(__dirname + '/public/index.html');
});
//Short list of users
let connectedPeers = [];
// Socket Connection
io.on('connection', (socket) => {
connectedPeers.push(socket.id);
console.log(connectedPeers, 'List');
console.log('Socket ID: ' + socket.id);
socket.on('disconnect', () => {
console.log('User Disconnected');
const newConnectedPeers = connectedPeers.filter((perrSocketId) => {
return perrSocketId !== socket.id;
});
connectedPeers = newConnectedPeers;
console.log(connectedPeers, 'List');
});
});
// listen Server
server.listen(PORT, () => {
console.log(`Server is running on port ${PORT}`);
});