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

Refactor iframe communication and use MessageChannel #9945

Merged
merged 7 commits into from
Apr 2, 2024

Conversation

riknoll
Copy link
Member

@riknoll riknoll commented Mar 28, 2024

This PR does a few things:

  1. Refactors the IFrameDriver into a base class and adds a new EditorDriver that takes the place of the old class
  2. Adds another IFrameDriver that can be used to drive the asset editor embed (arcade.makecode.com/--asseteditor)
  3. Adds a new IFrameEmbeddedClient that can be used within the embedded iframe to handle communication with the parent frame
  4. Refactors our messaging protocol to use a MessageChannel so that we can support multiple iframe embeds at the same time

This is all 100% backwards compatible with old embeds. To use the new MessageChannel stuff, you need to add ?frameid=<some-unique-id> to the iframe's src url, then everything will just work and it will automatically switch to using the MessageChannel. If you don't add that, the new code falls back to using the good old postMessage for communication. I went ahead and added it to the embed for the teacher tool and everything is working fine.

We still have a few iframe embeds that I'll want to eventually switch over to this new stuff:

  • pxtrunner (both --docs and --run)
  • the simulator (this will involve refactoring the existing pxsim SimDriver class)

@riknoll riknoll requested review from jwunderl and a team March 28, 2024 17:03
gulpfile.js Show resolved Hide resolved
gulpfile.js Show resolved Hide resolved
pxtservices/iframeEmbeddedClient.ts Outdated Show resolved Hide resolved
pxtservices/iframeEmbeddedClient.ts Outdated Show resolved Hide resolved
pxtservices/iframeEmbeddedClient.ts Show resolved Hide resolved
riknoll and others added 2 commits March 28, 2024 10:44
Co-authored-by: Eric Anderson <eanders@microsoft.com>
Co-authored-by: Eric Anderson <eanders@microsoft.com>
Copy link
Contributor

@eanders-ms eanders-ms left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. (Lint disagrees, but I'm not sure why).

@riknoll riknoll merged commit f4e9aad into master Apr 2, 2024
6 checks passed
@riknoll riknoll deleted the dev/riknoll/iframe-comm branch April 2, 2024 17:04
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

Successfully merging this pull request may close these issues.

None yet

2 participants