slideshow.io/lib/socket.js

35 lines
978 B
JavaScript
Raw Normal View History

2016-09-09 17:20:59 +01:00
module.exports = function(io) {
io.on('connection', function(socket) {
socket.emit('welcome');
socket.on('viewer', function(filename) {
socket.join(filename);
});
socket.on('speaker', function(filename, socketId) {
socket.join(filename);
socket.speakerId = socketId;
});
socket.on('change-slide', function(filename, pageNumber) {
socket.broadcast.to(filename).emit('update', pageNumber);
});
socket.on('pointer', function(filename, id, x, y) {
if (id === socket.speakerId) {
socket.broadcast.to(filename).emit('pointer', 'speaker', x, y);
} else {
socket.broadcast.to(filename).emit('pointer', 'speaker', x, y);
}
});
socket.on('viewer-laser', function(filename, enabled) {
socket.broadcast.to(filename).emit('viewer-laser', enabled);
});
});
}