two way communication with cables #170
-
Hi, For example I have simple PLAY button that I would like to connect to an action in my calbes patch. Or I would like so send the xy coordinates from my patch to an other script on my site. I found this already on the cables-page: https://cables.gl/docs/4_export_embed/dev_embed_functions/dev_embed_functions thanks! |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 1 reply
-
I'm not sure if it will work with the hosted iframe (because of cross origin restrictions), but you could try postmessage https://developer.mozilla.org/en-US/docs/Web/API/Window/postMessage Otherwise, you could host your own files and communicate simply by dispatching custom events on the window, then listening for them in a custom op that routes the messages to the rest of the graph. |
Beta Was this translation helpful? Give feedback.
-
@inst5 you found the docs, it should be all in there there is also a repo with some examples: https://github.com/cables-gl/cables-embedding example_vars_getset shows exactly what you are asking |
Beta Was this translation helpful? Give feedback.
-
Hi, It works in the same html file but not with an iframe with cables patch an calling the function from outside. |
Beta Was this translation helpful? Give feedback.
-
hey, yeah, iframes cannot communicate with each others that way for security reasons. you will have to fo with what @positlabs posted and somehow implement your own "protocol", or, if possible, not use an iframe (which can also lead to different other issues with your patch not being focussed and scrolling behaviour). |
Beta Was this translation helpful? Give feedback.
I'm not sure if it will work with the hosted iframe (because of cross origin restrictions), but you could try postmessage https://developer.mozilla.org/en-US/docs/Web/API/Window/postMessage
Otherwise, you could host your own files and communicate simply by dispatching custom events on the window, then listening for them in a custom op that routes the messages to the rest of the graph.