-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
31 lines (26 loc) · 751 Bytes
/
server.js
File metadata and controls
31 lines (26 loc) · 751 Bytes
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
const express = require('express');
const socketIO = require('socket.io');
const path = require('path');
const PORT = process.env.PORT || 3000;
const INDEX = path.join(__dirname, 'index.html');
let history = [];
const server = express()
.use((req, res) => res.sendFile(INDEX) )
.listen(PORT, () => console.log(`Listening on ${ PORT }`));
const io = socketIO(server);
io.on('connection', (socket) => {
function send() {
io.emit('wms send', history);
}
console.log('Client connected');
send();
socket.on('disconnect', () => console.log('Client disconnected'));
socket.on('wms send', (msg) => {
console.log("wms send");
while (history.length > 30) {
history.shift()
}
history.push(msg);
send()
});
});