johnandersen777.bsky.social/atlibs-webrtc
WebRTC transport for atlibs: com.fedfork.exec.webrtc.connect in the browser, and webrtc-peer, its guest side
0
0
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>loading</title>
<!-- The webrtc transport against a local guest (`webrtc-peer --origin <this page>`), no account, no PDS:
?signal=<webrtc-peer url>&user=<ssh user>. Driven by tests/loopback.test.mjs. -->
<script type="importmap">
{
"imports": {
"age-encryption": "https://esm.sh/age-encryption@0.3.1",
"@microsoft/dev-tunnels-ssh": "https://esm.sh/@microsoft/dev-tunnels-ssh@3.12.42",
"buffer": "https://esm.sh/buffer@5.7.1",
"@publicdomainrelay/atlibs-webrtc/": "./webrtc/",
"@publicdomainrelay/atlibs/": "./atlibs/"
}
}
</script>
<script type="module">
import * as age from "age-encryption";
import * as devTunnelsSsh from "@microsoft/dev-tunnels-ssh";
import { Buffer } from "buffer";
import { Cubit } from "@publicdomainrelay/atlibs/cubit/index.js";
import { WEBRTC_STATE, WebrtcHost, localSignals, webrtcUrl } from "@publicdomainrelay/atlibs-webrtc/index.js";
const query = new URLSearchParams(location.search);
const signals = localSignals(query.get("signal"));
// The store holds the transport's state; host.calls as a page's hostCall would route them, and
// host.fetchers() as runModule's fetchers (webrtc: URLs).
const cubit = new Cubit({ ...WEBRTC_STATE });
const host = new WebrtcHost({ store: cubit, events: () => signals.events(), signal: (input) => signals.signal(input), makePeer: (config) => new RTCPeerConnection(config), age, ssh: { ...devTunnelsSsh, Buffer } });
cubit.call = (nsid, request) => (Object.hasOwn(host.calls, nsid) ? host.calls[nsid](request) : Promise.reject(new Error(`${nsid}: not served here`)));
const fetchers = host.fetchers();
cubit.fetch = ({ receipt, tag, path, ...request }) => fetchers["webrtc:"]({ ...request, url: webrtcUrl({ receipt }, tag, path) });
cubit.sshKey = () => host.sshKey();
cubit.sshExec = (command, user, stdin) => host.sshExec(command, user, stdin);
// An unprivileged local sshd logs in only its own user; on a guest it is root.
if (query.get("user")) cubit.emit({ ssh: { ...cubit.state.ssh, user: query.get("user") } });
globalThis.webrtcCubit = cubit;
document.title = "ready";
</script>
</head>
<body></body>
</html>