tildeio / MessageChannel.js

27 stars 3 forks source link

Unable to post a message to a port whose entangled port has listeners on it #15

Closed hjdivad closed 11 years ago

hjdivad commented 11 years ago
var mc = new MessageChannel();
mc.port1.start();
mc.port2.start();

mc.port2.addEventListener('message', function(event){ console.log(event.data); });

mc.port1.postMessage('hai');
// => "Uncaught Error: DATA_CLONE_ERR: Kamino Exception 25"

This is because we try to encode the target port when sending a message. From what I can tell, _getPort is used both for transferring ports and to indicate the proper recipient of a message.

In the former case we need the uuid, entangled uuid and message queue. In the latter case, we really only need the uuid of the recipient.

cc @Cyril-sf

cyril-sf commented 11 years ago

We probably need to remove temporarily the listeners in MessageChannel.encodeEvent like we do for the _currentTarget

https://github.com/tildeio/MessageChannel.js/blob/master/lib/message_channel.js#L238

cyril-sf commented 11 years ago

This happens because you don't transfer the port. Otherwise the listener would be attached to the port in the other user agent.

hjdivad commented 11 years ago

@Cyril-sf I know, but that's a bug in the near-poly. You don't have to transfer the port.

cyril-sf commented 11 years ago

@hjdivad confirm