mirror of
https://github.com/vrtmrz/obsidian-livesync.git
synced 2026-08-27 13:57:07 +00:00
24 lines
696 B
TypeScript
24 lines
696 B
TypeScript
export type P2PSetupConnectionProbeResult = { ok: true } | { ok: false; reason: string };
|
|
|
|
export interface P2PSetupConnectionProbe {
|
|
setOnSetup(): void | Promise<void>;
|
|
allowReconnection(): void | Promise<void>;
|
|
open(): Promise<void>;
|
|
}
|
|
|
|
export async function probeP2PSetupConnection(
|
|
replicator: P2PSetupConnectionProbe
|
|
): Promise<P2PSetupConnectionProbeResult> {
|
|
try {
|
|
await replicator.setOnSetup();
|
|
await replicator.allowReconnection();
|
|
await replicator.open();
|
|
return { ok: true };
|
|
} catch (error) {
|
|
return {
|
|
ok: false,
|
|
reason: error instanceof Error ? error.message : String(error),
|
|
};
|
|
}
|
|
}
|