AAEO.io/index.js

36 lines
834 B
JavaScript
Raw Normal View History

2019-07-28 01:26:48 +00:00
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");
});