57 lines
2.1 KiB
TypeScript
57 lines
2.1 KiB
TypeScript
/// SPDX-License-Identifier: GPL-3.0-or-later
|
|
/// SPDX-FileCopyrightText: Copyright © 2023 Tony Garnock-Jones <tonyg@leastfixedpoint.com>
|
|
|
|
import { Dataspace, Ref, Sturdy, Reader, Schemas, Embedded, randomId, fromJS } from "@syndicate-lang/core";
|
|
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 this_instance = randomId(16);
|
|
|
|
const route = wsRelay.Noise.Route<Ref>({
|
|
"transports": [fromJS(Schemas.transportAddress.WebSocket(
|
|
`ws://${document.location.hostname}:9001/`))],
|
|
"steps": [wsRelay.Noise.RouteStep.GatekeeperStep(Sturdy.asSturdyRef(
|
|
new Reader<Ref>('<ref "syndicate" [] #[pkgN9TBmEd3Q04grVG4Zdw==]>').next()))],
|
|
});
|
|
|
|
during wsRelay.Resolved({
|
|
"route": route,
|
|
"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);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|