"use strict";
const UI = activate require("@syndicate-lang/driver-browser-ui");
// @jsx UI.html
// @jsxFrag UI.htmlFragment
const { Bytes } = require("@syndicate-lang/core");
const { WSServer, ToServer, FromServer, ServerConnected } = activate require("./client");
const P = activate require("./internal_protocol");
const Federation = require("./federation");
assertion type DetectedOverlay(scope);
assertion type AddressMap(from, nodeId, to);
assertion type OverlayLink(downNode, upNode);
assertion type OverlayNode(id);
assertion type OverlayRoot();
spawn {
const ui = new UI.Anchor();
assert ui.html('body',
Server monitor
Local scopes
Federation
Overlays
);
const url = (function () {
const u = new URL(document.location);
u.protocol = u.protocol.replace(/^http/, 'ws');
u.pathname = '/';
return u.toString();
})();
const addr = WSServer(url, "monitor");
during ServerConnected(addr) {
during FromServer(addr, P.POAScope(_, $scope)) {
const ui = new UI.Anchor();
assert ui.html('#scopes',
);
during FromServer(addr, P.POAScope($id, scope)) {
const ui = new UI.Anchor();
assert ui.html(`#scopes div.scope_${scope} ul`,
{id.toString()} );
on message UI.UIEvent(ui.fragmentId, 'button.disconnect', 'click', _) {
send ToServer(addr, P.Disconnect(id));
}
}
}
during FromServer(addr, Federation.ManagementScope($scope)) {
const addr = WSServer(url, scope);
during ServerConnected(addr) {
const ui = new UI.Anchor();
assert ui.html('#federated_scopes',
);
during FromServer(addr, P.FederatedLink($id, $federatedScope)) {
assert DetectedOverlay(federatedScope);
const ui = new UI.Anchor();
assert ui.html(`#federated_scopes div.fs_${scope} ul`,
FederatedLink:
session {id.toString()}
scope {federatedScope.toString()}
);
}
}
}
during DetectedOverlay($scope) {
const addr = WSServer(url, scope);
during ServerConnected(addr) {
const ui = new UI.Anchor();
assert ui.html('#overlays',
);
const nodeName = (n) => {
if (OverlayNode.isClassOf(n)) return "node_" + Bytes.from(OverlayNode._id(n)).toHex();
return "root";
};
during FromServer(addr, $item(OverlayLink($down, $up))) {
console.log(down.toString(), '-->', up.toString());
const ui = new UI.Anchor();
assert ui.html(`#overlays div.o_${scope} ul.${nodeName(up)}`,
{down.toString()});
}
during FromServer(addr, $item(AddressMap(_, _, _))) {
const ui = new UI.Anchor();
assert ui.html(`#overlays div.o_${scope} ul.vaddrs`,
{item && item.toString()});
}
}
}
}
}