Reputation: 4047
Is there a way to broadcast mouse events such as mousedown, mouseup and mousemove to all nodes connected to the nodejs server? I am trying to replicated events at certain (x,y) coordinates. Is there a way this can be achieved?
Upvotes: 1
Views: 268
Reputation: 5055
Yes it is
window.addEventListener('mousedown', function(event) {
var data = extractMouseData(event); //extract data from event.
io.emit('mousedown', data);
});
io.on('mousedown', function(data) {
processMouseEvent(data);
});
io.on('connection', function (socket) {
socket.on('mousedown', function (data) {
socket.broadcast.emit('mousedown', data);
});
});
Just implement extractMouseData
and processMouseEvent
functions and make them to do what you want to do and here you go.
Upvotes: 1