mirror of
https://github.com/vrtmrz/obsidian-livesync.git
synced 2026-09-01 08:17:07 +00:00
Route P2P Setup probes through the room owner
This commit is contained in:
@@ -1,4 +1,17 @@
|
||||
export type P2PSetupConnectionProbeResult = { ok: true } | { ok: false; reason: string };
|
||||
import {
|
||||
ACTIVE_P2P_RELAY_BINDING_CONFLICT,
|
||||
type P2PConnectionProbeAdmission,
|
||||
type P2PConnectionProbeSettings,
|
||||
} from "@vrtmrz/livesync-commonlib/p2p";
|
||||
|
||||
export type P2PSetupConnectionProbeResult =
|
||||
| { readonly ok: true }
|
||||
| { readonly ok: false; readonly reason: string }
|
||||
| {
|
||||
readonly ok: false;
|
||||
readonly kind: "blocked";
|
||||
readonly reason: typeof ACTIVE_P2P_RELAY_BINDING_CONFLICT;
|
||||
};
|
||||
|
||||
export interface P2PSetupConnectionProbe {
|
||||
setOnSetup(): void | Promise<void>;
|
||||
@@ -6,6 +19,25 @@ export interface P2PSetupConnectionProbe {
|
||||
open(): Promise<void>;
|
||||
}
|
||||
|
||||
/** Interpret the stable P2P owner's admission without constructing transport eagerly. */
|
||||
export async function coordinateP2PSetupConnectionProbe(
|
||||
admission: P2PConnectionProbeAdmission,
|
||||
trialSettings: P2PConnectionProbeSettings,
|
||||
runOwnedTrial: () => Promise<P2PSetupConnectionProbeResult>
|
||||
): Promise<P2PSetupConnectionProbeResult> {
|
||||
const settlement = await admission.run(trialSettings, runOwnedTrial);
|
||||
if (settlement.status === "observed-active") return { ok: true };
|
||||
if (settlement.status === "blocked") {
|
||||
return {
|
||||
ok: false,
|
||||
kind: "blocked",
|
||||
reason: settlement.reason,
|
||||
};
|
||||
}
|
||||
return settlement.result;
|
||||
}
|
||||
|
||||
/** Open one separately owned signalling connection and report its outcome. */
|
||||
export async function probeP2PSetupConnection(
|
||||
replicator: P2PSetupConnectionProbe
|
||||
): Promise<P2PSetupConnectionProbeResult> {
|
||||
|
||||
Reference in New Issue
Block a user