Skip to content

Commit

Permalink
add comments around MessageChannel port1
Browse files Browse the repository at this point in the history
  • Loading branch information
turnekybc committed Dec 20, 2024
1 parent 6479be7 commit 8f83d02
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion packages/iframe-stamper/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,8 @@ export class IframeStamper {
this.iframePublicKey = null;

/**
* The MessageChannel API is used to establish secure communication between the parent page and the iframe.
* The MessageChannel API is used to establish secure communication between two execution contexts.
* In this case, the parent page and the iframe.
* See https://developer.mozilla.org/en-US/docs/Web/API/MessageChannel
*/
this.messageChannel = new MessageChannel();
Expand Down Expand Up @@ -192,6 +193,12 @@ export class IframeStamper {
});

return new Promise((resolve, _reject) => {
/**
* The MessageChannel port1 property is the port that gets attached
* to the context that instantiated the MessageChannel. This class, the IframeStamper,
* instantied the MessageChannel and will use port1 to send messages to the iframe.
* See https://developer.mozilla.org/en-US/docs/Web/API/MessageChannel/port1
*/
this.messageChannel.port1.onmessage = (event) => {
if (event.data?.type === IframeEventType.PublicKeyReady) {
this.iframePublicKey = event.data["value"];
Expand Down

0 comments on commit 8f83d02

Please sign in to comment.