Wednesday, 15 March 2017

Broadcasting mouse movements through Websockets

I have implemented a simple "online whiteboard" using Nodejs on the server side, and websockets on the client side.

A "master" sends mouse coords to all the other connected clients. Extremely simplified:

client..

whiteboard.onmousemove = 
function()
{
 Client_Send({x:event.pageX, y:event.pageY});
}

server..

socket.on("text") =
function(text)
{
 // ...GET A LIST OF CONNECTED USERS MINUS THE MASTER...
 Broadcast(users, text); 
}

The problem:

  • If I send every single mouse movement, the clients appear to get "flooded" with updates, with messages arriving in clusters of 5-10, then a hiccup, then more clustered messages

  • If send an update only every few milliseconds, (ex. using setInterval rather than sending upon every single MouseMove event), I still get some clustering, even with just 8-10 updates per second

Is there some fundamental of websockets that I am missing here? (Using them for the first time)



via resle

No comments:

Post a Comment