-
Notifications
You must be signed in to change notification settings - Fork 135
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #9 from finos-labs/nested-iframe
Nested iframe
- Loading branch information
Showing
23 changed files
with
6,748 additions
and
183 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import { DesktopAgent } from "@finos/fdc3"; | ||
import { AbstractDesktopAgent } from "../lib/agent/AbstractDesktopAgent"; | ||
import { FDC3Initialiser } from "../lib/methods/js-inject"; | ||
import { DesktopAgentDetails, Options } from "../lib/types"; | ||
import { BroadcastAgentRequest, RequestMessageType } from "../lib/BridgingTypes"; | ||
|
||
/** | ||
* This dummy desktop agent just implements broadcast and addContextListener for the | ||
* purposes of the demo. Communication is also via post-message. | ||
*/ | ||
class DummyDesktopAgent extends AbstractDesktopAgent { | ||
|
||
constructor(details: DesktopAgentDetails, options: Options) { | ||
super(details, options); | ||
|
||
// set up the post message listener for events coming from the server | ||
window.addEventListener("message", (event) => { | ||
const data = event.data; | ||
|
||
if (data.type == RequestMessageType.BroadcastRequest) { | ||
const typedData = data as BroadcastAgentRequest; | ||
const meta = typedData.meta; | ||
const payload = typedData.payload; | ||
const context = payload.context; | ||
this.listeners.forEach(l => l.handle(context, meta)) | ||
} | ||
}); | ||
} | ||
|
||
postInternal(m: object) { | ||
// this DA is a bit sloppy about frame origin, whereas the other one isn't. | ||
this.options.frame!!.postMessage(m, "*"); | ||
} | ||
|
||
getIcon() { | ||
return "https://cosaic.io/wp-content/uploads/2022/09/fdc3-check.png"; | ||
} | ||
|
||
} | ||
|
||
const init : FDC3Initialiser = (details: DesktopAgentDetails, options: Options) => { | ||
return new DummyDesktopAgent(details, options) as any as DesktopAgent; | ||
} | ||
|
||
export default init; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
/** | ||
* This instantiates a page where a nested iframe strategy is used. | ||
*/ | ||
|
||
const parentWindow = window.parent; // opener of iframe. | ||
const child = (document.getElementById("iframe") as HTMLIFrameElement) | ||
const childWindow = child?.contentWindow!!; | ||
|
||
// implementation of broadcast, desktop-agent side (post-message-protocol version) | ||
window.addEventListener( | ||
"message", | ||
(event) => { | ||
const data = event.data; | ||
if (event.source == parentWindow) { | ||
// from the parent | ||
childWindow.postMessage(event.data, "*"); | ||
} else if (event.source == childWindow) { | ||
parentWindow.postMessage(event.data, "*"); | ||
} | ||
}); | ||
|
||
// next, set up the child | ||
const url = window.location.href; | ||
const childLocation = url.substring(url.lastIndexOf("url=")+4); | ||
child?.setAttribute("src", childLocation); |
Oops, something went wrong.