sueta / client / src / lib / protocol.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
/** Wire types shared by the p2p lib. See docs/PROTOCOL.md. */

import type { Envelope } from "./crypto";

// signaling server frames

export type ClientFrame =
  | { t: "join"; room: string; peer: string }
  | { t: "signal"; to: string; payload: Envelope }
  | { t: "leave" }
  | { t: "ping" };

export type ServerFrame =
  | { t: "peers"; peers: string[] }
  | { t: "peer-joined"; peer: string }
  | { t: "peer-left"; peer: string }
  | { t: "signal"; from: string; payload: Envelope }
  | { t: "pong" }
  | { t: "error"; code: string };

// encrypted signaling payloads (plaintext shape)

export type SignalPayload =
  | { kind: "offer"; sdp: string; name: string }
  | { kind: "answer"; sdp: string; name: string }
  | { kind: "ice"; candidate: RTCIceCandidateInit | null; name: string };

// per-peer connection state surfaced to the app

export type PeerConnState = "connecting" | "direct" | "relayed" | "disconnected";