I couldn’t find a way to create a MessageChannel
in framescript so what I’m doing is spawning a webworker, having it create the ports, then transfer them both to the framescript:
var portWorker = new Worker(core.addon.path.scripts + 'msgchanWorker.js');
portWorker.onmessage = function(e) {
portWorker.terminate();
var port = e.data.port1;
var port2 = e.data.port2;
console.log('port:', port, 'port2:', port2);
}
I terminate the worker there too.
Here is code in worker:
var msgchan = new MessageChannel();
self.postMessage({
port1: msgchan.port1,
port2: msgchan.port2
}, [msgchan.port1, msgchan.port2]);
This works, but spawining a worker, especially during startup of the browser is not ideal.
Does anyone have any other ways to create a MessageChannel
in these scopes?