2022-10-18 19:01:47 +00:00
|
|
|
import { Dataspace, Ref, Sturdy, Reader, Schemas, Embedded, randomId } from "@syndicate-lang/core";
|
2022-04-22 11:54:49 +00:00
|
|
|
import html from "@syndicate-lang/html";
|
|
|
|
import wsRelay from "@syndicate-lang/ws-relay";
|
|
|
|
import { ExampleDefinition } from './gen/example';
|
|
|
|
|
|
|
|
export function main() {
|
|
|
|
Dataspace.boot(ds => {
|
|
|
|
html.boot(ds);
|
|
|
|
wsRelay.boot(ds, true /* remove this `true` to turn off client/server debug logging */);
|
|
|
|
bootApp(ds);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function bootApp(ds: Ref) {
|
|
|
|
spawn named 'app' {
|
|
|
|
at ds {
|
|
|
|
/*
|
|
|
|
* This example expects a syndicate-server instance running on port 9001 on the
|
|
|
|
* server hosting index.html, exposing a dataspace entity via a capability called
|
|
|
|
* `"syndicate"` with empty "secret". See syndicate-server.config.pr.
|
|
|
|
*/
|
|
|
|
|
|
|
|
const serverCap = Sturdy.asSturdyRef(new Reader<Ref>(
|
|
|
|
'<ref "syndicate" [] #[pkgN9TBmEd3Q04grVG4Zdw==]>').next());
|
|
|
|
|
2022-10-18 19:01:47 +00:00
|
|
|
const this_instance = randomId(16);
|
2022-04-22 11:54:49 +00:00
|
|
|
|
|
|
|
during wsRelay.Resolved({
|
|
|
|
"addr": wsRelay.RelayAddress(Schemas.transportAddress.WebSocket(
|
|
|
|
`ws://${document.location.hostname}:9001/`)),
|
|
|
|
"sturdyref": serverCap,
|
|
|
|
"resolved": $remoteDs_e: Embedded,
|
|
|
|
}) => {
|
|
|
|
const remoteDs = remoteDs_e.embeddedValue;
|
|
|
|
|
|
|
|
at remoteDs {
|
|
|
|
assert ExampleDefinition(this_instance);
|
|
|
|
during ExampleDefinition($who: string) => {
|
|
|
|
const ui = new html.Anchor();
|
|
|
|
at ds {
|
|
|
|
assert ui.html(
|
|
|
|
'#main',
|
|
|
|
html.template`<p>We see <span class="example-definition">${who}</span></p>`,
|
|
|
|
who);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|