How to efficiently deal with a large amount of HTML5 canvas pixel data over websockets
- by user730569
Using
imageData = context.getImageData(0, 0, width, height);
JSON.stringify(imageData.data);
I grab the pixel data, convert it to a string, and then send it over the wire via websockets. However, this string can be pretty large, depending on the size of the canvas object. I tried using the compression technique found here: JavaScript implementation of Gzip but socket.io throws the error Websocket message contains invalid character(s). Is there an effective way to compress this data so that it can be sent over websockets?