Javascript sending an Image through ofxLibwebsockets

I’m sending a snapshot of my webcam, to my openframeworks server, using websockets:

	    var ws = new WebSocket("ws://192.168.1.130:9093");
    	ws.binaryType = "arraybuffer";

    var ctx = canvas.getContext('2d');
    ctx.drawImage(video, 0, 0);

    	var image = canvas.toDataURL("image/jpeg");
    	ws.send(image);

But on the server, using the “example_server_blob” from ofxLibwebsockets. The image doesn’t arrive on args.data, it arrives on args.message:

void ofApp::onMessage(ofxLibwebsockets::Event& args) {
    ...
   	if (args.isBinary) {

isBinary is false. args.data.size() is 0. The jpeg image, is placed in args.message, I don’t know why. But even if I try to assign the information from message to the buffer:

buff.clear();
buff.set(args.message);

locked = true;
needToLoad = true;

I have an error on turboJpeg:

Error in tjDecompressHeader2():
Not a JPEG file: starts with 0x64 0x61

I tried at onMessage, to return back the same message to the client:

args.conn.send(args.message);

And I assigned to an image on the page. And It works properly, so It looks like the information sent is correct:

ws.onmessage = function(e) {
		console.log("Receiving message");
		document.getElementById("streamed").src = e.data;
	}

So, right now the problem is why the image is arriving on the message attribute of the event.

thanks to the response by @robotconscience https://github.com/robotconscience/ofxLibwebsockets/issues/69#issuecomment-227734567

The method canvas.toBlob was the correct way to send the image for ofxTurboJpeg to read it.

So, the JS Client side, would be:

var ws = new WebSocket("ws://192.168.1.130:9093");
ws.binaryType = "blob";

var ctx = canvas.getContext('2d');
ctx.drawImage(video, 0, 0);

	canvas.toBlob(function(blob) {			
		ws.send(blob);
	}, "image/jpeg", 1);

And, on the server side, it would work perfectly with the code of “example_server_blob” from ofxLibwebsockets.