I’m trying to use transferable objects, but am getting “type error” when calling webkitPostMessage.
var message = new Object();
message.type = "mask";
message.mask = mmask;
message.width = width;
message.height = height;
message.useTransferable = transferableObjects;
webWorker[curWorker].webkitPostMessage(message, [message]);
I’m getting the same error in the worker thread as well.
Am I missing something? Do you need more info?
From the spec:
http://www.whatwg.org/specs/web-apps/current-work/multipage/common-dom-interfaces.html#transferable-objects
So your options for transferring data through to a web worker are pretty limited right now. But check out:
http://updates.html5rocks.com/2012/06/How-to-convert-ArrayBuffer-to-and-from-String
So you could convert your object to a JSON string with
window.JSON.parse()and then use the method in the link to change it to an array buffer, and then send that array buffer to the worker.