Update template to new ws-relay API

This commit is contained in:
Tony Garnock-Jones 2023-02-04 12:32:00 +01:00
parent 2218702cf2
commit 4be9d1a8bc
1 changed files with 9 additions and 7 deletions

View File

@ -1,7 +1,7 @@
/// 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 } from "@syndicate-lang/core";
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';
@ -23,15 +23,17 @@ function bootApp(ds: Ref) {
* `"syndicate"` with empty "secret". See syndicate-server.config.pr.
*/
const serverCap = Sturdy.asSturdyRef(new Reader<Ref>(
'<ref "syndicate" [] #[pkgN9TBmEd3Q04grVG4Zdw==]>').next());
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({
"addr": wsRelay.RelayAddress(Schemas.transportAddress.WebSocket(
`ws://${document.location.hostname}:9001/`)),
"sturdyref": serverCap,
"route": route,
"resolved": $remoteDs_e: Embedded,
}) => {
const remoteDs = remoteDs_e.embeddedValue;