postmate
postmate copied to clipboard
Support multiple instances on a page
I'm writing an application where a parent would initiate connections with several children on the same page:
new Postmate({ ... }).then(child1 => {
child1.on('some-event', data => console.log("Message from Child 1", data));
});
new Postmate({ ... }).then(child2 => {
child2.on('some-event', data => console.log("Message from Child 2", data));
});
The problem is that if either child sends the event some-event
, then we get the callbacks called twice:
Message from Child 1 Hello World
Message from Child 2 Hello World
I believe this is the problem:
this.parent.addEventListener('message', this.listener, false); // 'message' listener will receive all messages from all children
Previously I used EasyXDM for cross domain communication. They solve this problem by having a unique ID associated with every handshake/connection.
Would you consider adding support for this?
+1
I would consider adding support for this. Would you be interested in authoring the solution for this @loganvolkers? If so, we can talk in greater detail about the design.
yes,i face same problem,expept solve it
@jakiestfu Thanks for thinking of me but I found that https://github.com/Aaronius/penpal better serves my needs for a number of reasons.
I'll be putting all my eggs in that basket.