fix devenv issues

refactor
Niko PLP 21 hours ago
parent e9a3b2fe88
commit 8a5c97c0f4
  1. 2
      Cargo.toml
  2. 1
      engine/broker/auth/index.html
  3. 113
      engine/broker/auth/src/App.svelte
  4. 11
      engine/broker/auth/src/routes/Home.svelte
  5. 19
      engine/broker/auth/vite.config.js
  6. 26
      sdk/js/examples/multi-framework-signals/src/app/layouts/Layout.astro
  7. 1
      sdk/js/lib-wasm/Cargo.toml
  8. 11
      sdk/js/lib-wasm/DEV.md

@ -78,4 +78,4 @@ opt-level = 2
[workspace.metadata.scripts] [workspace.metadata.scripts]
libwasm = "cd sdk/js/lib-wasm && cargo run-script app && cd ../../.." libwasm = "cd sdk/js/lib-wasm && cargo run-script app && cd ../../.."
libwasmdev = "cd sdk/js/lib-wasm && cargo run-script appdev && cd ../../.." libwasmdev3 = "cd sdk/js/lib-wasm && cargo run-script appdev3 && cd ../../.."

@ -11,7 +11,6 @@
<!DOCTYPE html> <!DOCTYPE html>
<html lang="en"> <html lang="en">
<head> <head>
<base href="http://localhost:14401" />
<meta charset="UTF-8" /> <meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>NextGraph Auth</title> <title>NextGraph Auth</title>

@ -268,63 +268,74 @@
window.document.getElementById("app").style["display"] = "none"; window.document.getElementById("app").style["display"] = "none";
let origin = window.location.origin; let origin = window.location.origin;
let encoded_origin = encodeURIComponent(origin); let encoded_origin = encodeURIComponent(origin);
let port;
const init = () => {
if (net_auth_iframe && port)
net_auth_iframe.postMessage({ method: "init", session:value, manifest:{origin:origin_url}, port: port }, iframe_config.origin, [port]);
};
iframe.addEventListener("load", function() { iframe.addEventListener("load", function() {
net_auth_iframe = this.contentWindow; net_auth_iframe = this.contentWindow;
const ready_handler = async function(m) { //console.log(net_auth_iframe);
if (m.data.ready && m.origin === iframe_config.origin) { init();
//console.log("got ready message from", m.origin); });
//remove this listener
window.removeEventListener("message",ready_handler); const ready_handler = async function(m) {
const { port1, port2 } = new MessageChannel(); //console.log("got message from", m.origin, m.data, iframe_config.origin);
port1.onmessage = async (e) => { if (m.data.ready && m.origin === iframe_config.origin) {
if (e.data.done) { //remove this listener
// end of session window.removeEventListener("message",ready_handler);
window.location.href = origin_url; const { port1, port2 } = new MessageChannel();
port1.onmessage = async (e) => {
if (e.data.done) {
// end of session
window.location.href = origin_url;
} else {
const method = e.data.method;
const args = e.data.args;
const port = e.data.port;
// TODO: add other stream RPC methods
if ( method === "doc_subscribe" ) {
//console.log("processing streamed request ...",method, args);
args.push((callbacked)=> {
port.postMessage({stream:true, ret:callbacked});
});
try {
let cancel_function = () => {};
port.onclose = () => {
cancel_function();
};
cancel_function = await Reflect.apply(ng[method], null, args);
} catch (e) {
port.postMessage({ok:false, ret:e});
port.close();
}
} else { } else {
const method = e.data.method; // forwarding to ng
const args = e.data.args; //console.log("processing...",method, args);
const port = e.data.port; try {
// TODO: add other stream RPC methods let res = await Reflect.apply(ng[method], null, args);
if ( method === "doc_subscribe" ) { //console.log("got res=",res)
//console.log("processing streamed request ...",method, args); port.postMessage({ok:true, ret:res});
args.push((callbacked)=> { port.close();
port.postMessage({stream:true, ret:callbacked}); } catch (e) {
}); port.postMessage({ok:false, ret:e});
try { port.close();
let cancel_function = () => {};
port.onclose = () => {
cancel_function();
};
cancel_function = await Reflect.apply(ng[method], null, args);
} catch (e) {
port.postMessage({ok:false, ret:e});
port.close();
}
} else {
// forwarding to ng
//console.log("processing...",method, args);
try {
let res = await Reflect.apply(ng[method], null, args);
//console.log("got res=",res)
port.postMessage({ok:true, ret:res});
port.close();
} catch (e) {
port.postMessage({ok:false, ret:e});
port.close();
}
} }
} }
}; }
//console.log("sending init message to app-auth"); };
net_auth_iframe.postMessage({ method: "init", session:value, manifest:{origin:origin_url}, port: port2 }, iframe_config.origin, [port2]); port = port2;
} else if (m.data.status == "error" && m.origin === iframe_config.origin) { init();
console.error(m.data.error); //console.log("sending init message to app-auth");
window.location.href = origin_url; } else if (m.data.status == "error" && m.origin === iframe_config.origin) {
} console.error(m.data.error);
}; window.location.href = origin_url;
window.addEventListener("message",ready_handler); }
}); };
window.addEventListener("message",ready_handler);
iframe.src = `${iframe_config.src}${encoded_origin}`; iframe.src = `${iframe_config.src}${encoded_origin}`;
} else if (logged_in) { } else if (logged_in) {
// we redirect to the unauthenticated origin // we redirect to the unauthenticated origin

@ -17,7 +17,7 @@
<script> <script>
import Home from "../lib/Home.svelte"; import Home from "../lib/Home.svelte";
import { NoWallet } from "@ng-org/ui-common/lib"; import { NoWallet } from "@ng-org/ui-common/lib";
import { push } from "svelte-spa-router"; import { push, location} from "svelte-spa-router";
import { onMount, onDestroy } from "svelte"; import { onMount, onDestroy } from "svelte";
import { import {
active_wallet, active_wallet,
@ -39,11 +39,14 @@
//console.log(value); //console.log(value);
if (!value[0] && value[1]) { if (!value[0] && value[1]) {
push("#/wallet/login"); push("#/wallet/login");
} else if (import.meta.env.NG_DEV3 && $origin) {
let r = `${$location}?o=`+encodeURIComponent($origin);
push(r);
} }
}); });
if (import.meta.env.NG_DEV3 && $origin) { // if (import.meta.env.NG_DEV3 && $origin) {
push("#/?o="+encodeURIComponent($origin)); // push("#/?o="+encodeURIComponent($origin));
} // }
}); });
onDestroy(() => { onDestroy(() => {

@ -66,5 +66,24 @@ export default defineConfig({
}), }),
viteSingleFile(), viteSingleFile(),
jsToBottom(), jsToBottom(),
{
name: 'inject-web-script',
transformIndexHtml: {
order: 'pre', // Tells Vite to run this before other processes
handler: function transform(html) {
if (!process.env.NG_DEV3) return html;
else
return [
{
tag: "base",
attrs: {
"href": "http://localhost:14401"
},
injectTo: "head-prepend"
}]
}
}
}
] ]
}) })

@ -4,18 +4,18 @@ import Highlight from "../components/Highlight.astro";
<!doctype html> <!doctype html>
<html lang="en" data-theme="dark"> <html lang="en" data-theme="dark">
<head> <head>
<meta name="viewport" content="width=device-width" /> <meta name="viewport" content="width=device-width" />
<meta name="generator" content={Astro.generator} /> <meta name="generator" content={Astro.generator} />
<title>Multi-Framework Signal Experiments</title> <title>Multi-Framework Signal examples</title>
</head> </head>
<body> <body>
<Highlight astro> <Highlight astro>
<header class="container">Multi-Framework Signal Experiments</header> <header class="container">Multi-Framework Signal examples</header>
<main class="container"> <main class="container">
<slot /> <slot />
</main> </main>
</Highlight> </Highlight>
</body> </body>
</html> </html>

@ -18,6 +18,7 @@ wasm-opt = false
[package.metadata.scripts] [package.metadata.scripts]
appdev = "wasm-pack build --dev --target bundler && node prepare-web.js" appdev = "wasm-pack build --dev --target bundler && node prepare-web.js"
appdev3 = "wasm-pack build --target bundler && node prepare-web.js"
app = "rm -rf pkg/snippets && wasm-pack build --target bundler && node prepare-web.js" app = "rm -rf pkg/snippets && wasm-pack build --target bundler && node prepare-web.js"
nodedev = "rm -rf pkg-node/snippets && wasm-pack build --dev -t nodejs -d pkg-node && node prepare-node.js" nodedev = "rm -rf pkg-node/snippets && wasm-pack build --dev -t nodejs -d pkg-node && node prepare-node.js"
node = "rm -rf pkg-node/snippets && wasm-pack build -t nodejs -d pkg-node && node prepare-node.js" node = "rm -rf pkg-node/snippets && wasm-pack build -t nodejs -d pkg-node && node prepare-node.js"

@ -60,7 +60,7 @@ cargo run-script buildfrontdev3
cargo run cargo run
``` ```
start your local ngd in a separate terminal, from the root of the mono-repo, start your local ngd
``` ```
export NG_DEV3=1; cargo run -r -p ngd -- -vv --save-key -l 14400 export NG_DEV3=1; cargo run -r -p ngd -- -vv --save-key -l 14400
@ -68,7 +68,8 @@ export NG_DEV3=1; cargo run -r -p ngd -- -vv --save-key -l 14400
http://localhost:14400 http://localhost:14400
``` ```
finally, start your local third party webapp you will use to test the WASM SDK finally, start your local third party webapp you will use to test the WASM SDK.
in a separate terminal, from the root of the mono-repo,
``` ```
// this is up to you. by example : // this is up to you. by example :
@ -77,11 +78,11 @@ pnpm dev
// then open that app in your browser // then open that app in your browser
``` ```
every time you modify the SDK, re-run (at the root of momo-repo) : every time you modify the SDK, re-run (at the root of mono-repo) :
``` ```
cargo run-script libwasmdev cargo run-script libwasmdev3
// or in the sdk/js/lib-wasm folder run cargo run-script appdev // or in the sdk/js/lib-wasm folder run cargo run-script appdev3
``` ```
## Production build ## Production build

Loading…
Cancel
Save