Skip to content

Commit

Permalink
Merge pull request #7 from finos-labs/rob-first-version
Browse files Browse the repository at this point in the history
Rob first version
  • Loading branch information
robmoffat authored Aug 10, 2023
2 parents 9210942 + 36eaeec commit a732960
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 12 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"version": "0.0.0",
"type": "module",
"scripts": {
"dev": "vite --port 5000",
"dev": "vite --port 8080 --host ",
"build": "tsc && vite build",
"preview": "vite preview"
},
Expand Down
24 changes: 21 additions & 3 deletions src/demo/dummy-desktop-agent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,26 @@ window.addEventListener("load", () => {

const instances : AppIdentifierAndWindow[] = []

function useFrames() : boolean {
const cb = document.getElementById("frames") as HTMLInputElement;
return (cb.checked)
}

function openTab(url: string) : Window {
var ifrm = document.createElement("iframe");
ifrm.setAttribute("src", url);
ifrm.style.width = "640px";
ifrm.style.height = "480px";
document.body.appendChild(ifrm);
return ifrm.contentWindow!!;
}

function openFrame(url: string) : Window {
return window.open(url, "_blank")!!;
}

function launch(url: string, appId: string) {
const w : Window = window.open(url, "_blank")!!;
const w = useFrames() ? openTab(url): openFrame(url);
const instance = currentInstance++;
w.name = "App"+instance;
instances.push({
Expand Down Expand Up @@ -41,8 +59,8 @@ window.addEventListener("load", () => {

// hook up the buttons
document.getElementById("app1")?.addEventListener("click", () => launch("/static/app1/index.html", "1"));
document.getElementById("app2")?.addEventListener("click", () => launch("/static/app2/index.html", "2"));
document.getElementById("app3")?.addEventListener("click", () => launch("/static/app3/index.html", "3"));
document.getElementById("app2")?.addEventListener("click", () => launch("http://robs-pro:8080/static/app2/index.html", "2"));
document.getElementById("app3")?.addEventListener("click", () => launch("http://localhost:8080/static/app3/index.html", "3"));


// implementation of broadcast, desktop-agent side
Expand Down
20 changes: 15 additions & 5 deletions src/demo/implementation.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,25 @@ class DummyDesktopAgent {
appId: this.details.appId,
instanceId: this.details.instanceId
}

const img = document.createElement("img");
img.setAttribute("width", 70);
img.setAttribute("height", 70);
img.src= "https://cosaic.io/wp-content/uploads/2022/09/fdc3-check.png"
img.style = "position: absolute; bottom: 0px; right: 0px;"
document.body.appendChild(img)
}

broadcast(context) {
console.log("Broadcasting: "+JSON.stringify(context))
window.opener.postMessage({
type: "Broadcast",
context: context,
from: this.id
}, "*") // in a real desktop agent, don't use *
const da = window.opener ?? window.parent;
if (da) {
da.postMessage({
type: "Broadcast",
context: context,
from: this.id
}, "*") // in a real desktop agent, don't use *
}
}

addContextListener(type, callback) {
Expand Down
6 changes: 3 additions & 3 deletions src/lib/strategies/post-message-load-js.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export const supplier: Supplier = (url: string, checker: AppChecker, detailsReso
const origin = event.origin;
const source = event.source as Window
if (checker(source)) {
console.log(`API Request Origin: ${origin} Source: ${source}`);
console.log(`API Request Origin: ${origin}`);
source.postMessage(createResponseMessage(source), origin);
}
}
Expand Down Expand Up @@ -53,10 +53,10 @@ export const loader: Loader = (_options: Options) => {
}, { once: true });
});

const da = window.opener;
const da = window.opener ?? window.parent;

if (da != null) {
window.opener.postMessage(FDC3_API_REQUEST_MESSAGE_TYPE, "*");
da.postMessage(FDC3_API_REQUEST_MESSAGE_TYPE, "*");
}

return out;
Expand Down
6 changes: 6 additions & 0 deletions static/da/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,18 @@
<body>
<p>Dummy Desktop Agent</p>

<input type="checkbox" id="frames"> Use Frames</input>

<p>

<a type="button" href="#" id="app1" >Open App 1</a>

<a type="button" href="#" id="app2" >Open App 2</a>

<a type="button" href="#" id="app3" >Open App 3</a>

</p>

</body>

</html>

0 comments on commit a732960

Please sign in to comment.