How to efficiently deal with a large amount of HTML5 canvas pixel data over websockets

Posted by user730569 on Stack Overflow See other posts from Stack Overflow or by user730569
Published on 2012-06-25T19:42:16Z Indexed on 2012/06/25 21:16 UTC
Read the original article Hit count: 200

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?

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about canvas