social-kit / types / net.d.ts
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
/**
 * Hand-authored declarations for the "./net" export of ardegazu-social-kit —
 * the compiled dist/net.js. A standalone libp2p node for apps that don't
 * already run one (the hub). Requires the optional libp2p peerDependency
 * family at runtime; the main entry needs none of it.
 */
import type { Libp2p } from "libp2p";
import type { PubsubLike } from "./index.js";

export interface RelayInfo {
  peerId: string;
  multiaddrs: string[];
}

/** Fetch the /.well-known/ap2p descriptor; falls back to compiled-in relay info. */
export declare function fetchRelayInfo(descriptorUrl: string, fallback: RelayInfo, timeoutMs?: number): Promise<RelayInfo>;

/** Ephemeral TURN credentials (coturn REST scheme) → RTCConfiguration, cached. */
export declare class IceConfig {
  constructor(endpoint: string, forceRelay?: boolean);
  get(): Promise<RTCConfiguration>;
}

export declare class NetNode {
  readonly node: Libp2p;
  readonly relayId: string;
  static create(relay: RelayInfo, ice: IceConfig): Promise<NetNode>;
  relayConnected(): boolean;
  /** Dial (or re-dial after a suspend) the relay; the circuit listener re-takes its reservation. */
  redialRelay(): Promise<void>;
  private constructor();
}

export interface SocialNetConfig {
  descriptorUrl: string;
  turnUrl: string;
  relayFallback: RelayInfo;
}

export interface SocialNet {
  node: NetNode["node"];
  pubsub: PubsubLike;
  relayId: string;
  relayConnected(): boolean;
  close(): Promise<void>;
}

export declare function createSocialNode(cfg: SocialNetConfig): Promise<SocialNet>;

static mirror of HEAD · about · clone: git clone https://git.ardegazu.ro/social-kit.git