| 1 | package protocol |
| 2 | |
| 3 | // Quality and problem reports (spec §15.26, 2026-10-03): the wire shape a |
| 4 | // client POSTs, client-neutral like the rest of this package. |
| 5 | // |
| 6 | // A quality report is a fixed schema of numbers and enums about how this |
| 7 | // client's connections went over the last window: no names, no addresses, |
| 8 | // no device names, no meeting, nothing typed by a person. Every number is |
| 9 | // optional (absent means "this client could not measure it"), finite and |
| 10 | // non-negative, and has a ceiling the server enforces; every string is an |
| 11 | // enum or a version. Counts are what happened during the window (a delta), |
| 12 | // not running totals. The server re-encodes what it validated and drops |
| 13 | // anything it does not know, so a member a newer client adds is tolerated |
| 14 | // and never logged. |
| 15 | |
| 16 | // QualityVersion is the schema's version, the report's "v". |
| 17 | const QualityVersion = 1 |
| 18 | |
| 19 | // Bounds the server enforces, here so a client can clamp to the same ones. |
| 20 | const ( |
| 21 | MaxQualityPeers = 4 // remote peers in one report: the mesh holds three, and one spare for a connection on its way out |
| 22 | MaxQualitySeconds = 600 // a window, in seconds |
| 23 | MaxQualityMillis = 600_000 // any rtt, jitter or buffer delay, in ms |
| 24 | MaxQualityCount = 1e9 // any count of packets, frames or samples |
| 25 | MaxQualityKbps = 1e6 // any bitrate, in kbit/s |
| 26 | MaxQualityPixels = 16384 // a frame's width or height |
| 27 | MaxQualityFPS = 240 // frames per second |
| 28 | MaxQualityCPUPct = 12800 // a process's CPU, percent of one core: 128 cores' worth |
| 29 | MaxQualityMemMB = 1 << 20 // resident memory, in MB |
| 30 | MaxQualityLoad = 10000 // a load average |
| 31 | MaxQualityBody = 16 << 10 |
| 32 | MaxProblemNote = 1000 // characters of "What went wrong?" |
| 33 | MaxProblemBody = 64 << 10 // the whole problem report, diagnostics included |
| 34 | ) |
| 35 | |
| 36 | // The automatic report (spec §15.29, 2026-10-28): what a client counts as |
| 37 | // a call struggling, and how often it may say so. A client sends an |
| 38 | // AutoReport when one of these holds, at most once every AutoReportEvery |
| 39 | // and at most AutoReportsPerCall times in one participation; the server |
| 40 | // enforces both limits on its own. |
| 41 | const ( |
| 42 | AutoFreezes = 3 // inbound freezes, this window and the one before it: at least this many in each |
| 43 | AutoRTTMillis = 800 // the window's highest round trip, this window and the one before it: above this in each |
| 44 | AutoReconnectingSeconds = 5 // "Reconnecting…" (the call's or a person's) shown for longer than this in one window |
| 45 | AutoReportsPerCall = 3 |
| 46 | AutoReportEveryMinutes = 10 |
| 47 | ) |
| 48 | |
| 49 | // QualityReport is one window's summary. |
| 50 | type QualityReport struct { |
| 51 | V int `json:"v"` |
| 52 | Final bool `json:"final,omitempty"` // the report sent at leave or end |
| 53 | Seconds *float64 `json:"seconds"` // how long the window was |
| 54 | Client ReportClient `json:"client"` |
| 55 | Devices *Devices `json:"devices,omitempty"` |
| 56 | Events *CallEvents `json:"events,omitempty"` |
| 57 | Peers []PeerQuality `json:"peers,omitempty"` |
| 58 | // AutoReport is the reference of the automatic report this client |
| 59 | // sent with this window (§15.29), when it sent one. Eight characters |
| 60 | // of Crockford's alphabet, as every report reference is. |
| 61 | AutoReport string `json:"autoReport,omitempty"` |
| 62 | // Host is how the machine itself fared in the window (spec §15.30, |
| 63 | // 2026-10-29): whether Calls, or something else, was eating it. |
| 64 | Host *HostLoad `json:"host,omitempty"` |
| 65 | } |
| 66 | |
| 67 | // HostLoad is the reporting machine's own load over the window. Every |
| 68 | // member is optional: the apps send what they can measure, and the web |
| 69 | // only Thermal, where the browser has the Compute Pressure API. |
| 70 | type HostLoad struct { |
| 71 | ProcCPUPct *float64 `json:"procCpuPct,omitempty"` // the client's own process, percent of one core, over the window |
| 72 | ProcMemMB *float64 `json:"procMemMB,omitempty"` // its resident memory at the window's end |
| 73 | SysLoad1 *float64 `json:"sysLoad1,omitempty"` // the system's one-minute load average (Mac) |
| 74 | Thermal string `json:"thermal,omitempty"` // ThermalStates: the worst in the window |
| 75 | LowPower *bool `json:"lowPower,omitempty"` // Low Power Mode, at any point in the window |
| 76 | } |
| 77 | |
| 78 | // ThermalStates are the values HostLoad.Thermal may carry: Apple's |
| 79 | // ProcessInfo.ThermalState, and the Compute Pressure API's states, which |
| 80 | // have the same four names. |
| 81 | var ThermalStates = []string{"nominal", "fair", "serious", "critical"} |
| 82 | |
| 83 | // ReportClient says what is reporting. Enums, and versions as digits and |
| 84 | // dots: never a user agent string, a device model or a machine name. |
| 85 | type ReportClient struct { |
| 86 | App string `json:"app"` // web, mac, iphone, ipad |
| 87 | Version string `json:"version,omitempty"` // the app's version, or the server's build for web |
| 88 | Browser string `json:"browser,omitempty"` // chrome, safari, firefox, edge, other (web only) |
| 89 | BrowserVersion string `json:"browserVersion,omitempty"` // major[.minor] |
| 90 | OS string `json:"os,omitempty"` // macos, ios, ipados, windows, linux, android, chromeos, other |
| 91 | OSVersion string `json:"osVersion,omitempty"` |
| 92 | } |
| 93 | |
| 94 | // Devices are the kinds of microphone and speaker in use, by transport: |
| 95 | // never a device's name, which can be personal ("Paul's AirPods Pro"). |
| 96 | type Devices struct { |
| 97 | Input string `json:"input,omitempty"` // DeviceKinds |
| 98 | Output string `json:"output,omitempty"` // DeviceKinds |
| 99 | } |
| 100 | |
| 101 | // DeviceKinds are the values Devices may carry. |
| 102 | var DeviceKinds = []string{"built-in", "bluetooth", "usb", "wired", "airplay", "virtual", "continuity", "other", "none", "unknown"} |
| 103 | |
| 104 | // CallEvents are the notices this client showed for the whole call during |
| 105 | // the window (§15.23), and whether its browser blocked playing sound |
| 106 | // (§15.20). |
| 107 | type CallEvents struct { |
| 108 | Reconnecting *float64 `json:"reconnecting,omitempty"` // times "Reconnecting…" was shown |
| 109 | ReconnectingSeconds *float64 `json:"reconnectingSeconds,omitempty"` // for how long |
| 110 | AudioBlocked bool `json:"audioBlocked,omitempty"` |
| 111 | // VideoSetting is the person's own "Video quality" choice (spec |
| 112 | // §15.30), when it is not Auto: "low" (Low bandwidth) or "audio" |
| 113 | // (Audio only). VideoSettings. |
| 114 | VideoSetting string `json:"videoSetting,omitempty"` |
| 115 | } |
| 116 | |
| 117 | // VideoSettings are the values CallEvents.VideoSetting may carry. |
| 118 | var VideoSettings = []string{"low", "audio"} |
| 119 | |
| 120 | // PeerQuality is one remote peer's connection, from this side. |
| 121 | type PeerQuality struct { |
| 122 | // Peer is the remote peer's id as this client knows it. The server |
| 123 | // logs the peer's tag in its place and never the id. |
| 124 | Peer PeerID `json:"peer"` |
| 125 | Path *Path `json:"path,omitempty"` |
| 126 | RTT *float64 `json:"rtt,omitempty"` // the selected candidate pair's, ms |
| 127 | // The window's round trip and jitter (2026-10-28): RTTAvg is the |
| 128 | // pair's mean over the window (its total round trip over its |
| 129 | // responses, or the mean of once-a-second readings), RTTMax the |
| 130 | // highest once-a-second reading; JitterAvg and JitterMax are the |
| 131 | // peer's inbound audio jitter read once a second, in ms. |
| 132 | RTTAvg *float64 `json:"rttAvg,omitempty"` |
| 133 | RTTMax *float64 `json:"rttMax,omitempty"` |
| 134 | JitterAvg *float64 `json:"jitterAvg,omitempty"` |
| 135 | JitterMax *float64 `json:"jitterMax,omitempty"` |
| 136 | // Candidates is this side's account of how the connection was found: |
| 137 | // what it gathered and what it was offered, by type, and which kinds |
| 138 | // of pair worked. Types and counts only, never an address. |
| 139 | Candidates *Candidates `json:"candidates,omitempty"` |
| 140 | Out *Outbound `json:"out,omitempty"` |
| 141 | In *Inbound `json:"in,omitempty"` |
| 142 | Events *PeerEvents `json:"events,omitempty"` |
| 143 | } |
| 144 | |
| 145 | // Candidates says why a connection took the path it took (2026-10-28): a |
| 146 | // relayed call is told apart as "this side never found its own public |
| 147 | // address" (no srflx), "this side found it and nothing direct worked" |
| 148 | // (srflx, no direct pair), or "the far side offered only the relay". The |
| 149 | // booleans are meaningful only when the struct is present: a client that |
| 150 | // cannot read candidates sends no Candidates at all. |
| 151 | type Candidates struct { |
| 152 | // Local candidates gathered, by type. |
| 153 | Host *float64 `json:"host,omitempty"` |
| 154 | Srflx *float64 `json:"srflx,omitempty"` |
| 155 | Prflx *float64 `json:"prflx,omitempty"` |
| 156 | Relay *float64 `json:"relay,omitempty"` |
| 157 | // Remote candidates the peer offered, by type. |
| 158 | RemoteHost *float64 `json:"remoteHost,omitempty"` |
| 159 | RemoteSrflx *float64 `json:"remoteSrflx,omitempty"` |
| 160 | RemotePrflx *float64 `json:"remotePrflx,omitempty"` |
| 161 | RemoteRelay *float64 `json:"remoteRelay,omitempty"` |
| 162 | // DirectOK: a pair with neither end a relay succeeded. LocalDirectOK: |
| 163 | // a pair whose local end is not a relay succeeded (this side's own |
| 164 | // network reached the far side, or the far side's relay). UDPOK: a |
| 165 | // pair carried over UDP the whole way to the peer or the relay |
| 166 | // succeeded. |
| 167 | DirectOK bool `json:"directOk,omitempty"` |
| 168 | LocalDirectOK bool `json:"localDirectOk,omitempty"` |
| 169 | UDPOK bool `json:"udpOk,omitempty"` |
| 170 | } |
| 171 | |
| 172 | // Path is the selected candidate pair: what kind of candidate each end |
| 173 | // used, and the transport. Never an address or a port. |
| 174 | type Path struct { |
| 175 | Local string `json:"local,omitempty"` // CandidateKinds |
| 176 | Remote string `json:"remote,omitempty"` // CandidateKinds |
| 177 | Protocol string `json:"protocol,omitempty"` // udp, tcp, tls, unknown |
| 178 | } |
| 179 | |
| 180 | // CandidateKinds are the values Path.Local and Path.Remote may carry. |
| 181 | var CandidateKinds = []string{"host", "srflx", "prflx", "relay", "unknown"} |
| 182 | |
| 183 | // PathProtocols are the values Path.Protocol may carry. "tls" is a relay |
| 184 | // reached over TURN/TLS. |
| 185 | var PathProtocols = []string{"udp", "tcp", "tls", "unknown"} |
| 186 | |
| 187 | // Outbound is what this client sends to the peer. |
| 188 | type Outbound struct { |
| 189 | Audio *OutStream `json:"audio,omitempty"` |
| 190 | Video *OutStream `json:"video,omitempty"` |
| 191 | Screen *OutStream `json:"screen,omitempty"` |
| 192 | } |
| 193 | |
| 194 | // OutStream is one outbound stream. Lost, RTT and Jitter are the |
| 195 | // receiver's own account (remote-inbound-rtp). |
| 196 | type OutStream struct { |
| 197 | Kbps *float64 `json:"kbps,omitempty"` |
| 198 | Packets *float64 `json:"packets,omitempty"` |
| 199 | Lost *float64 `json:"lost,omitempty"` |
| 200 | RTT *float64 `json:"rtt,omitempty"` |
| 201 | Jitter *float64 `json:"jitter,omitempty"` |
| 202 | Limit string `json:"limit,omitempty"` // QualityLimits |
| 203 | Width *float64 `json:"width,omitempty"` |
| 204 | Height *float64 `json:"height,omitempty"` |
| 205 | FPS *float64 `json:"fps,omitempty"` |
| 206 | // The screen-share recovery ladder's steps toward this peer during |
| 207 | // the window (§15.22): keyframes sent, rebuilds, shares again, and |
| 208 | // times it gave up. |
| 209 | Keyframes *float64 `json:"keyframes,omitempty"` |
| 210 | Rebuilds *float64 `json:"rebuilds,omitempty"` |
| 211 | Reshares *float64 `json:"reshares,omitempty"` |
| 212 | Failures *float64 `json:"failures,omitempty"` |
| 213 | // Steps held back because rebuilding only ever mended it briefly (a |
| 214 | // loop), and times the screen stopped leaving for this peer while |
| 215 | // frames went in (2026-10-21). |
| 216 | Damped *float64 `json:"damped,omitempty"` |
| 217 | EncoderStalls *float64 `json:"encoderStalls,omitempty"` |
| 218 | // 2026-10-28. Limit is the reason that held the encoder back for most |
| 219 | // of the window where the stack says (qualityLimitationDurations), and |
| 220 | // the latest reason where it does not; LimitedBandwidthSeconds and |
| 221 | // LimitedCPUSeconds are how long in the window each held it back. |
| 222 | // Encoder is hardware or software, never the implementation's name; |
| 223 | // Codec the codec's family; Mode the screen's share mode. |
| 224 | LimitedBandwidthSeconds *float64 `json:"limitedBandwidthSeconds,omitempty"` |
| 225 | LimitedCPUSeconds *float64 `json:"limitedCpuSeconds,omitempty"` |
| 226 | Encoder string `json:"encoder,omitempty"` // CoderKinds |
| 227 | Codec string `json:"codec,omitempty"` // Codecs |
| 228 | Mode string `json:"mode,omitempty"` // ShareModes, the screen only |
| 229 | } |
| 230 | |
| 231 | // QualityLimits are qualityLimitationReason's values. |
| 232 | var QualityLimits = []string{"none", "cpu", "bandwidth", "other"} |
| 233 | |
| 234 | // CoderKinds say whether a video encoder or decoder is the platform's |
| 235 | // hardware one or a software one: the implementation's own name |
| 236 | // ("VideoToolbox", "libvpx") is never sent. |
| 237 | var CoderKinds = []string{"hardware", "software", "unknown"} |
| 238 | |
| 239 | // Codecs are a stream's codec family, from its MIME type. |
| 240 | var Codecs = []string{"vp8", "vp9", "h264", "h265", "av1", "opus", "other"} |
| 241 | |
| 242 | // ShareModes are the screen share's modes (§15.22): the browser's |
| 243 | // SHARE_MODES and the apps' ScreenShareMode. |
| 244 | var ShareModes = []string{"balanced", "detail", "motion"} |
| 245 | |
| 246 | // Inbound is what arrives from the peer. |
| 247 | type Inbound struct { |
| 248 | Audio *InAudio `json:"audio,omitempty"` |
| 249 | Video *InVideo `json:"video,omitempty"` |
| 250 | Screen *InVideo `json:"screen,omitempty"` |
| 251 | } |
| 252 | |
| 253 | // InAudio is the peer's audio as it arrives here. |
| 254 | type InAudio struct { |
| 255 | Kbps *float64 `json:"kbps,omitempty"` |
| 256 | Packets *float64 `json:"packets,omitempty"` |
| 257 | Lost *float64 `json:"lost,omitempty"` |
| 258 | Jitter *float64 `json:"jitter,omitempty"` // ms |
| 259 | Samples *float64 `json:"samples,omitempty"` // totalSamplesReceived |
| 260 | Concealed *float64 `json:"concealed,omitempty"` // concealedSamples |
| 261 | Inserted *float64 `json:"inserted,omitempty"` // insertedSamplesForDeceleration |
| 262 | Removed *float64 `json:"removed,omitempty"` // removedSamplesForAcceleration |
| 263 | JitterBufferMs *float64 `json:"jitterBufferMs,omitempty"` // mean jitterBufferDelay per emitted sample over the window |
| 264 | } |
| 265 | |
| 266 | // InVideo is the peer's camera or screen as it arrives here. |
| 267 | type InVideo struct { |
| 268 | Kbps *float64 `json:"kbps,omitempty"` |
| 269 | Packets *float64 `json:"packets,omitempty"` |
| 270 | Lost *float64 `json:"lost,omitempty"` |
| 271 | Jitter *float64 `json:"jitter,omitempty"` |
| 272 | Freezes *float64 `json:"freezes,omitempty"` // freezeCount |
| 273 | FreezeSeconds *float64 `json:"freezeSeconds,omitempty"` // totalFreezesDuration |
| 274 | Decoded *float64 `json:"decoded,omitempty"` |
| 275 | Dropped *float64 `json:"dropped,omitempty"` |
| 276 | Width *float64 `json:"width,omitempty"` |
| 277 | Height *float64 `json:"height,omitempty"` |
| 278 | FPS *float64 `json:"fps,omitempty"` |
| 279 | Reattaches *float64 `json:"reattaches,omitempty"` // a stalled screen handed to its view again (§15.22) |
| 280 | // Times this client judged the screen stalled (§15.21), and of those, |
| 281 | // how many with no packets arriving and how many with packets arriving |
| 282 | // and nothing decoded: the receiver's verdict (2026-10-21). |
| 283 | Stalls *float64 `json:"stalls,omitempty"` |
| 284 | StallsNoPackets *float64 `json:"stallsNoPackets,omitempty"` |
| 285 | StallsUndecoded *float64 `json:"stallsUndecoded,omitempty"` |
| 286 | // The decoder, hardware or software, and the codec (2026-10-28). |
| 287 | Decoder string `json:"decoder,omitempty"` // CoderKinds |
| 288 | Codec string `json:"codec,omitempty"` // Codecs |
| 289 | } |
| 290 | |
| 291 | // PeerEvents are the notices about this peer during the window. |
| 292 | type PeerEvents struct { |
| 293 | Reconnecting *float64 `json:"reconnecting,omitempty"` // "Reconnecting to …" shown |
| 294 | ReconnectingSeconds *float64 `json:"reconnectingSeconds,omitempty"` // for how long |
| 295 | CantHearSeconds *float64 `json:"cantHearSeconds,omitempty"` // "… can't hear you yet" (§15.24) |
| 296 | NoSound bool `json:"noSound,omitempty"` // this client listed them in noSoundFrom (§15.20) |
| 297 | NoSoundFromUs bool `json:"noSoundFromUs,omitempty"` // they listed this client |
| 298 | AudioBlocked bool `json:"audioBlocked,omitempty"` // they said their browser blocked sound |
| 299 | ScreenStalled bool `json:"screenStalled,omitempty"` // this client reported their screen stalled (§15.21) |
| 300 | // The connection's own recovery (§15.28) during the window: ICE |
| 301 | // restarts this client made on its own, and times it had the pair |
| 302 | // rebuilt from nothing (a `reset`). Older servers drop both. |
| 303 | AutoRestarts *float64 `json:"autoRestarts,omitempty"` |
| 304 | AutoRebuilds *float64 `json:"autoRebuilds,omitempty"` |
| 305 | // Adaptive video (spec §15.30) during the window, as seconds at each |
| 306 | // level below normal in the order reduced, minimal, audio: AskedSeconds |
| 307 | // is how long this client, receiving, asked the peer for each; SentSeconds |
| 308 | // how long this client, sending, sent the peer less because the peer |
| 309 | // asked. Exactly three numbers when present (VideoLevelCount), arrays |
| 310 | // rather than six members because the largest line has to fit the |
| 311 | // platform's 8 KB. Older servers drop both. |
| 312 | AskedSeconds []*float64 `json:"askedSeconds,omitempty"` |
| 313 | SentSeconds []*float64 `json:"sentSeconds,omitempty"` |
| 314 | } |
| 315 | |
| 316 | // VideoLevelCount is the length of PeerEvents.AskedSeconds and |
| 317 | // SentSeconds: one number for each of VideoLevels. |
| 318 | const VideoLevelCount = 3 |
| 319 | |
| 320 | // ProblemReport is "Report a problem": what the person typed, and the |
| 321 | // text "Copy call diagnostics" would copy, with the people in the call |
| 322 | // named by short peer ids rather than their names. |
| 323 | type ProblemReport struct { |
| 324 | Note string `json:"note"` |
| 325 | Diagnostics string `json:"diagnostics"` |
| 326 | Client ReportClient `json:"client"` |
| 327 | } |
| 328 | |
| 329 | // AutoReport is the automatic "Report a problem" (§15.29, 2026-10-28): |
| 330 | // sent by a client, with nobody pressing anything, when its call is |
| 331 | // struggling. The diagnostics are what Report a problem sends, scrubbed |
| 332 | // the same way; there is no note, because nobody typed one. Trigger says |
| 333 | // which of the rules above fired. |
| 334 | type AutoReport struct { |
| 335 | Trigger string `json:"trigger"` // AutoTriggers |
| 336 | Diagnostics string `json:"diagnostics"` |
| 337 | Client ReportClient `json:"client"` |
| 338 | } |
| 339 | |
| 340 | // AutoTriggers are the rules an AutoReport may name, in the order a |
| 341 | // client checks them. |
| 342 | var AutoTriggers = []string{"freezes", "rtt", "reconnecting", "screen"} |
| 343 | |
| 344 | // ProblemReceipt is the server's answer: the reference to quote. An |
| 345 | // AutoReport is answered the same way. |
| 346 | type ProblemReceipt struct { |
| 347 | Ref string `json:"ref"` |
| 348 | } |
| 349 | |