postmate icon indicating copy to clipboard operation
postmate copied to clipboard

Support multiple instances on a page

Open loganvolkers opened this issue 7 years ago • 4 comments

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?

loganvolkers avatar Apr 14 '17 21:04 loganvolkers

+1

Oceanswave avatar May 16 '17 00:05 Oceanswave

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.

jakiestfu avatar Sep 12 '17 05:09 jakiestfu

yes,i face same problem,expept solve it

lerit avatar Sep 15 '17 07:09 lerit

@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.

loganvolkers avatar Sep 18 '17 05:09 loganvolkers