@mh-gg/cli 0.1.1-alpha.20260613T085325975Z
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +5 -0
- package/bin/matterhorn.cjs +57 -0
- package/package.json +49 -0
- package/runtime/bin/appFrontend/artifacts.cjs +25 -0
- package/runtime/bin/appFrontend/buildServers.cjs +176 -0
- package/runtime/bin/appFrontend/commandEnv.cjs +74 -0
- package/runtime/bin/appFrontend/commandPolicy.cjs +23 -0
- package/runtime/bin/appFrontend/devServers.cjs +150 -0
- package/runtime/bin/appFrontend/httpServers.cjs +221 -0
- package/runtime/bin/appFrontend/paths.cjs +103 -0
- package/runtime/bin/appFrontend/ports.cjs +36 -0
- package/runtime/bin/appFrontend/processes.cjs +127 -0
- package/runtime/bin/appFrontend.cjs +45 -0
- package/runtime/bin/appHostCommand.cjs +381 -0
- package/runtime/bin/matterhorn.cjs +501 -0
- package/runtime/bin/matterhornAppLoader.cjs +588 -0
- package/runtime/bin/matterhornApps.cjs +223 -0
- package/runtime/bin/matterhornDeploy.cjs +108 -0
- package/runtime/bin/matterhornEmitAppBundle.cjs +20 -0
- package/runtime/bin/matterhornInstall.cjs +609 -0
- package/runtime/host/callAuth.cjs +76 -0
- package/runtime/host/host.cjs +103 -0
- package/runtime/host/hostAnnouncement.cjs +70 -0
- package/runtime/host/hostClients/constants.cjs +7 -0
- package/runtime/host/hostClients/frontendBundleRefresh.cjs +158 -0
- package/runtime/host/hostClients/frontendRequests.cjs +166 -0
- package/runtime/host/hostClients/index.cjs +68 -0
- package/runtime/host/hostClients/rejections.cjs +37 -0
- package/runtime/host/hostSession.cjs +160 -0
- package/runtime/host/inlineProgressBar.cjs +128 -0
- package/runtime/host/localPeerServer.cjs +114 -0
- package/runtime/host/localRelayClient.cjs +151 -0
- package/runtime/host/matterhornrc.cjs +75 -0
- package/runtime/host/memberRootRegistry.cjs +132 -0
- package/runtime/host/nodePeer.cjs +127 -0
- package/runtime/host/nodePeerRacePatch.cjs +106 -0
- package/runtime/host/peerJsConfig.cjs +26 -0
- package/runtime/host/pushEgress.cjs +48 -0
- package/runtime/host/pushStorage.cjs +233 -0
- package/runtime/host/relay/config.cjs +179 -0
- package/runtime/host/relay/connectionCleanup.cjs +34 -0
- package/runtime/host/relay/connectionDispatcher.cjs +140 -0
- package/runtime/host/relay/matterhornOperationEvents.cjs +100 -0
- package/runtime/host/relay/matterhornRuntimeEventBridge.cjs +182 -0
- package/runtime/host/relay/nostrRelay.cjs +30 -0
- package/runtime/host/relay/peerStartup.cjs +81 -0
- package/runtime/host/relay.cjs +653 -0
- package/runtime/host/relayClientRouting.cjs +1054 -0
- package/runtime/host/relayConfig.cjs +156 -0
- package/runtime/host/relayHostAuth.cjs +39 -0
- package/runtime/host/relayHostMessages.cjs +367 -0
- package/runtime/host/relayHttp.cjs +48 -0
- package/runtime/host/relayIdentity.cjs +496 -0
- package/runtime/host/relayIncomingGate.cjs +153 -0
- package/runtime/host/relayMeshEnvelopes.cjs +522 -0
- package/runtime/host/relayPeerLifecycle.cjs +96 -0
- package/runtime/host/relayPeerSignals.cjs +175 -0
- package/runtime/host/relayRoomRuntimePersistence.cjs +129 -0
- package/runtime/host/relayStatus.cjs +160 -0
- package/runtime/host/sfuRelay.cjs +553 -0
- package/runtime/host/sqliteRelayStorage.cjs +352 -0
- package/runtime/host/wireValidation/client.cjs +213 -0
- package/runtime/host/wireValidation/host.cjs +33 -0
- package/runtime/host/wireValidation/index.cjs +13 -0
- package/runtime/host/wireValidation/peerSignal.cjs +35 -0
- package/runtime/host/wireValidation/presenceEvent.cjs +49 -0
- package/runtime/host/wireValidation/push.cjs +49 -0
- package/runtime/host/wireValidation/relay.cjs +131 -0
- package/runtime/host/wireValidation/shared.cjs +49 -0
- package/runtime/scripts/ensureWorkspaceSdkBuild.cjs +148 -0
- package/runtime/scripts/killChildTree.cjs +18 -0
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
const { waitForPeerOpen } = require("@mh-gg/relay-runtime");
|
|
2
|
+
|
|
3
|
+
function isLocalPeerIdUnavailableError(error) {
|
|
4
|
+
const type = String(error?.type || "").toLowerCase();
|
|
5
|
+
const message = String(error?.message || error || "").toLowerCase();
|
|
6
|
+
return type === "unavailable-id"
|
|
7
|
+
|| type === "peer-unavailable"
|
|
8
|
+
|| message.includes("unavailable-id")
|
|
9
|
+
|| message.includes("id is taken")
|
|
10
|
+
|| message.includes("id already taken")
|
|
11
|
+
|| message.includes("is already taken")
|
|
12
|
+
|| message.includes("is unavailable");
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
async function startRelayPeers({ attachConnection, config, debugRelay, mesh, peerLifecycle, peerReconnects, sfu }) {
|
|
16
|
+
if (!config.startPeer) return { roomPeer: undefined, relayPeer: undefined };
|
|
17
|
+
return startRelayPeersOnce({ attachConnection, config, debugRelay, mesh, peerLifecycle, peerReconnects, sfu }).catch(async (error) => {
|
|
18
|
+
if (!isLocalPeerIdUnavailableError(error) || typeof config.rotateRelayTransportIdentity !== "function") throw error;
|
|
19
|
+
debugRelay(`relay transport id unavailable; rotating signed relay transport identity: ${error?.message || String(error)}`);
|
|
20
|
+
config.rotateRelayTransportIdentity(error);
|
|
21
|
+
mesh.updateLocalRelayIdentity?.(config.relayAddress, config.relayMeshPeerId);
|
|
22
|
+
return startRelayPeersOnce({ attachConnection, config, debugRelay, mesh, peerLifecycle, peerReconnects, sfu });
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
async function startRelayPeersOnce({ attachConnection, config, debugRelay, mesh, peerLifecycle, peerReconnects, sfu }) {
|
|
27
|
+
const roomPeer = await config.createPeer(config.relayPeerId, config.iceServers, { signaling: config.peerJsSignaling });
|
|
28
|
+
let relayPeer;
|
|
29
|
+
try {
|
|
30
|
+
relayPeer = await config.createPeer(config.relayMeshPeerId, config.iceServers, { signaling: config.peerJsSignaling });
|
|
31
|
+
} catch (error) {
|
|
32
|
+
roomPeer?.destroy?.();
|
|
33
|
+
throw error;
|
|
34
|
+
}
|
|
35
|
+
roomPeer.MatterhornStableId = config.relayPeerId;
|
|
36
|
+
relayPeer.MatterhornStableId = config.relayMeshPeerId;
|
|
37
|
+
|
|
38
|
+
roomPeer.on("open", (id) => peerReconnects.logOpen("matterhorn room relay peer", id, roomPeer));
|
|
39
|
+
roomPeer.on("connection", (conn) => attachConnection(conn, { relayPeer: false }));
|
|
40
|
+
roomPeer.on("error", (error) => peerLifecycle.handlePeerError(roomPeer, "matterhorn room relay peer", error));
|
|
41
|
+
roomPeer.on("disconnected", () => peerLifecycle.reconnectPeer(roomPeer, "matterhorn room relay peer", "disconnected event"));
|
|
42
|
+
|
|
43
|
+
relayPeer.on("open", (id) => {
|
|
44
|
+
peerReconnects.logOpen("matterhorn relay mesh peer", id, relayPeer);
|
|
45
|
+
mesh.onRelayPeerOpen();
|
|
46
|
+
});
|
|
47
|
+
relayPeer.on("connection", (conn) => {
|
|
48
|
+
const relayPeerConnection = mesh.connectionHasRelayMetadata(conn);
|
|
49
|
+
const connectionLabel = relayPeerConnection ? "relay mesh incoming" : "relay mesh probe";
|
|
50
|
+
debugRelay(`${connectionLabel} ${conn.peer || "unknown"}`);
|
|
51
|
+
if (relayPeerConnection && mesh.activeRelayCount() >= config.activeRelayFanout) {
|
|
52
|
+
debugRelay(`relay mesh incoming rejected ${conn.peer || "unknown"}; fanout limit reached`);
|
|
53
|
+
conn.close?.();
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
conn.on("open", () => debugRelay(`${connectionLabel} open ${conn.peer || "unknown"}`));
|
|
57
|
+
conn.on("close", () => debugRelay(`${connectionLabel} closed ${conn.peer || "unknown"}`));
|
|
58
|
+
conn.on("error", (error) => debugRelay(`${connectionLabel} error ${conn.peer || "unknown"}: ${error?.message || String(error)}`));
|
|
59
|
+
attachConnection(conn, { relayPeer: relayPeerConnection });
|
|
60
|
+
});
|
|
61
|
+
relayPeer.on("error", (error) => peerLifecycle.handlePeerError(relayPeer, "matterhorn relay mesh peer", error));
|
|
62
|
+
relayPeer.on("disconnected", () => peerLifecycle.reconnectPeer(relayPeer, "matterhorn relay mesh peer", "disconnected event"));
|
|
63
|
+
|
|
64
|
+
try {
|
|
65
|
+
await Promise.all([
|
|
66
|
+
waitForPeerOpen(roomPeer, "matterhorn room relay peer"),
|
|
67
|
+
waitForPeerOpen(relayPeer, "matterhorn relay mesh peer"),
|
|
68
|
+
sfu.start()
|
|
69
|
+
]);
|
|
70
|
+
} catch (error) {
|
|
71
|
+
roomPeer?.destroy?.();
|
|
72
|
+
relayPeer?.destroy?.();
|
|
73
|
+
throw error;
|
|
74
|
+
}
|
|
75
|
+
return { roomPeer, relayPeer };
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
module.exports = {
|
|
79
|
+
isLocalPeerIdUnavailableError,
|
|
80
|
+
startRelayPeers
|
|
81
|
+
};
|