Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problem with 2 way communication to & from iframe #34

Closed
ssured opened this issue Oct 30, 2017 · 2 comments
Closed

Problem with 2 way communication to & from iframe #34

ssured opened this issue Oct 30, 2017 · 2 comments

Comments

@ssured
Copy link

ssured commented Oct 30, 2017

I extended the iframe example a little, see https://gist.github.com/ssured/79471d3e78332e60567012969f716355

When running I get proper results and 2 errors:
image

Line 67 refers to

let that = await irequest.callPath.slice(0, -1).reduce((obj, propName) => obj[propName], rootObj as any);

Changing this line:

if (!event.data.id)

to if (!event.data.id || !event.data.callPath) fixes the problem, but I really don't know if thats OK.

Thanks for the library. Any help on getting 2 way communication done is greatly appreciated.

@surma
Copy link
Collaborator

surma commented Oct 30, 2017

Ah, you can’t re-use the same postMessage channel for multiple expose() calls. It’s been “used up” already. Maybe that’s something I should change. I’ll think about it.

For now, I’d recommend just defining a function where you pass the parentApi object as a parameter and wrap it in proxyValue(). I whipped up a Glitch (demo, code) using your code as a starting point.

Let me know if that helps :)

@ssured
Copy link
Author

ssured commented Nov 1, 2017

Thanks @surma. It totally helps 👍 Dunno but for me 2 way communication is essential to talk to a remote webpage and back. Your code exposes a really nice way to set this up between browsers. Maybe nice to add to the README?
I did not test yet in a 'real' scenario yet though, as I was hitting cross-origin issues when talking from our company page to a github.io hosted static PWA.

Thanks for your help!

@ssured ssured closed this as completed Nov 1, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants