AAEO.io/index.js
2019-07-28 03:26:48 +02:00

36 lines
No EOL
834 B
JavaScript

var app = require('express')();
var http = require('http').createServer(app);
var io = require('socket.io')(http);
var buffer = {};
app.get('/', (req, res) => {
res.sendFile(__dirname + '/views/index.html');
});
io.on('connection', (socket) => {
console.log('Nutzer verbunden!');
socket.on('disconnect', () => {
console.log('Nutzer verbindung unterbrochen')
});
socket.on('cursor_pos', function (data) {
if (buffer[data.id] == null) {
buffer[data.id] = data.pos;
console.log("first fill");
}
if (data.pos.x != buffer[data.id].x) {
socket.broadcast.emit('cursor_draw', { pos: data.pos, id: data.id });
buffer[data.id] = data.pos;
}
});
});
http.listen(1234, () => {
console.log("up and run on port 1234");
});