werift 0.27.0 → 0.28.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (224) hide show
  1. package/README.md +119 -8
  2. package/lib/common/src/event.d.ts +26 -0
  3. package/lib/common/src/event.js +87 -2
  4. package/lib/common/src/event.js.map +1 -1
  5. package/lib/common/src/network.d.ts +6 -1
  6. package/lib/common/src/network.js +8 -2
  7. package/lib/common/src/network.js.map +1 -1
  8. package/lib/common/src/transport.d.ts +12 -5
  9. package/lib/common/src/transport.js +3 -2
  10. package/lib/common/src/transport.js.map +1 -1
  11. package/lib/dtls/src/alert.d.ts +49 -0
  12. package/lib/dtls/src/alert.js +103 -0
  13. package/lib/dtls/src/alert.js.map +1 -0
  14. package/lib/dtls/src/client.js +15 -1
  15. package/lib/dtls/src/client.js.map +1 -1
  16. package/lib/dtls/src/context/dtls.d.ts +2 -0
  17. package/lib/dtls/src/context/dtls.js +7 -0
  18. package/lib/dtls/src/context/dtls.js.map +1 -1
  19. package/lib/dtls/src/context/transport.d.ts +17 -1
  20. package/lib/dtls/src/context/transport.js +38 -2
  21. package/lib/dtls/src/context/transport.js.map +1 -1
  22. package/lib/dtls/src/flight/client/flight5.js +4 -1
  23. package/lib/dtls/src/flight/client/flight5.js.map +1 -1
  24. package/lib/dtls/src/flight/flight.d.ts +5 -0
  25. package/lib/dtls/src/flight/flight.js +10 -1
  26. package/lib/dtls/src/flight/flight.js.map +1 -1
  27. package/lib/dtls/src/flight/server/flight6.js +4 -1
  28. package/lib/dtls/src/flight/server/flight6.js.map +1 -1
  29. package/lib/dtls/src/index.d.ts +3 -1
  30. package/lib/dtls/src/index.js +10 -1
  31. package/lib/dtls/src/index.js.map +1 -1
  32. package/lib/dtls/src/record/const.d.ts +9 -0
  33. package/lib/dtls/src/record/const.js +9 -1
  34. package/lib/dtls/src/record/const.js.map +1 -1
  35. package/lib/dtls/src/record/receive.d.ts +6 -0
  36. package/lib/dtls/src/record/receive.js +50 -19
  37. package/lib/dtls/src/record/receive.js.map +1 -1
  38. package/lib/dtls/src/server.js +19 -1
  39. package/lib/dtls/src/server.js.map +1 -1
  40. package/lib/dtls/src/socket.d.ts +134 -2
  41. package/lib/dtls/src/socket.js +322 -6
  42. package/lib/dtls/src/socket.js.map +1 -1
  43. package/lib/ice/src/candidateError.d.ts +155 -0
  44. package/lib/ice/src/candidateError.js +246 -0
  45. package/lib/ice/src/candidateError.js.map +1 -0
  46. package/lib/ice/src/candidateGatherer.d.ts +127 -0
  47. package/lib/ice/src/candidateGatherer.js +745 -0
  48. package/lib/ice/src/candidateGatherer.js.map +1 -0
  49. package/lib/ice/src/consent.d.ts +49 -0
  50. package/lib/ice/src/consent.js +258 -0
  51. package/lib/ice/src/consent.js.map +1 -0
  52. package/lib/ice/src/ice.d.ts +223 -71
  53. package/lib/ice/src/ice.js +873 -975
  54. package/lib/ice/src/ice.js.map +1 -1
  55. package/lib/ice/src/iceBase.d.ts +207 -8
  56. package/lib/ice/src/iceBase.js +94 -31
  57. package/lib/ice/src/iceBase.js.map +1 -1
  58. package/lib/ice/src/index.d.ts +1 -0
  59. package/lib/ice/src/index.js +1 -0
  60. package/lib/ice/src/index.js.map +1 -1
  61. package/lib/ice/src/internal/checkMessages.d.ts +41 -0
  62. package/lib/ice/src/internal/checkMessages.js +63 -0
  63. package/lib/ice/src/internal/checkMessages.js.map +1 -0
  64. package/lib/ice/src/internal/defaultRoute.d.ts +20 -0
  65. package/lib/ice/src/internal/defaultRoute.js +134 -0
  66. package/lib/ice/src/internal/defaultRoute.js.map +1 -0
  67. package/lib/ice/src/internal/hostInterfaces.d.ts +17 -0
  68. package/lib/ice/src/internal/hostInterfaces.js +77 -0
  69. package/lib/ice/src/internal/hostInterfaces.js.map +1 -0
  70. package/lib/ice/src/internal/hostPreference.d.ts +24 -0
  71. package/lib/ice/src/internal/hostPreference.js +38 -0
  72. package/lib/ice/src/internal/hostPreference.js.map +1 -0
  73. package/lib/ice/src/internal/resolveHostAddresses.d.ts +56 -8
  74. package/lib/ice/src/internal/resolveHostAddresses.js +127 -24
  75. package/lib/ice/src/internal/resolveHostAddresses.js.map +1 -1
  76. package/lib/ice/src/internal/selectAddresses.d.ts +27 -0
  77. package/lib/ice/src/internal/selectAddresses.js +37 -18
  78. package/lib/ice/src/internal/selectAddresses.js.map +1 -1
  79. package/lib/ice/src/nomination/regularNomination.d.ts +200 -0
  80. package/lib/ice/src/nomination/regularNomination.js +311 -0
  81. package/lib/ice/src/nomination/regularNomination.js.map +1 -0
  82. package/lib/ice/src/nomination/selectionReplacement.d.ts +138 -0
  83. package/lib/ice/src/nomination/selectionReplacement.js +371 -0
  84. package/lib/ice/src/nomination/selectionReplacement.js.map +1 -0
  85. package/lib/ice/src/provisional.d.ts +139 -0
  86. package/lib/ice/src/provisional.js +468 -0
  87. package/lib/ice/src/provisional.js.map +1 -0
  88. package/lib/ice/src/stun/protocol.d.ts +9 -2
  89. package/lib/ice/src/stun/protocol.js +16 -17
  90. package/lib/ice/src/stun/protocol.js.map +1 -1
  91. package/lib/ice/src/stun/tcpProtocol.d.ts +1 -1
  92. package/lib/ice/src/stun/tcpProtocol.js +7 -7
  93. package/lib/ice/src/stun/tcpProtocol.js.map +1 -1
  94. package/lib/ice/src/stun/transaction.js +4 -2
  95. package/lib/ice/src/stun/transaction.js.map +1 -1
  96. package/lib/ice/src/turn/protocol.d.ts +2 -2
  97. package/lib/ice/src/turn/protocol.js +6 -3
  98. package/lib/ice/src/turn/protocol.js.map +1 -1
  99. package/lib/ice/src/types/model.d.ts +16 -5
  100. package/lib/ice/src/types/model.js.map +1 -1
  101. package/lib/ice-server/src/stun/attributes.js +4 -0
  102. package/lib/ice-server/src/stun/attributes.js.map +1 -1
  103. package/lib/ice-server/src/stun/const.d.ts +20 -1
  104. package/lib/ice-server/src/stun/const.js +9 -1
  105. package/lib/ice-server/src/stun/const.js.map +1 -1
  106. package/lib/ice-server/src/stun/message.d.ts +28 -1
  107. package/lib/ice-server/src/stun/message.js +102 -15
  108. package/lib/ice-server/src/stun/message.js.map +1 -1
  109. package/lib/index.mjs +13394 -7732
  110. package/lib/nonstandard/index.mjs +680 -286
  111. package/lib/polyfill/dom.mjs +19605 -14243
  112. package/lib/polyfill/index.mjs +19605 -14243
  113. package/lib/rtp/src/index.d.ts +1 -0
  114. package/lib/rtp/src/index.js +1 -0
  115. package/lib/rtp/src/index.js.map +1 -1
  116. package/lib/rtp/src/rtp/continuity.d.ts +14 -1
  117. package/lib/rtp/src/rtp/continuity.js +24 -4
  118. package/lib/rtp/src/rtp/continuity.js.map +1 -1
  119. package/lib/rtp/src/rtp/timelineRewriter.d.ts +178 -0
  120. package/lib/rtp/src/rtp/timelineRewriter.js +417 -0
  121. package/lib/rtp/src/rtp/timelineRewriter.js.map +1 -0
  122. package/lib/sctp/src/sctp.d.ts +5 -0
  123. package/lib/sctp/src/sctp.js +81 -47
  124. package/lib/sctp/src/sctp.js.map +1 -1
  125. package/lib/webrtc/src/api/compatibilityOptions.d.ts +33 -0
  126. package/lib/webrtc/src/api/compatibilityOptions.js +33 -0
  127. package/lib/webrtc/src/api/compatibilityOptions.js.map +1 -0
  128. package/lib/webrtc/src/api/peerConfig.d.ts +348 -34
  129. package/lib/webrtc/src/api/peerConfig.js +90 -24
  130. package/lib/webrtc/src/api/peerConfig.js.map +1 -1
  131. package/lib/webrtc/src/api/peerConnectionEvents.d.ts +77 -1
  132. package/lib/webrtc/src/api/peerConnectionEvents.js +105 -1
  133. package/lib/webrtc/src/api/peerConnectionEvents.js.map +1 -1
  134. package/lib/webrtc/src/helper.d.ts +8 -0
  135. package/lib/webrtc/src/helper.js +40 -4
  136. package/lib/webrtc/src/helper.js.map +1 -1
  137. package/lib/webrtc/src/media/codecCompatibility.d.ts +87 -1
  138. package/lib/webrtc/src/media/codecCompatibility.js +338 -12
  139. package/lib/webrtc/src/media/codecCompatibility.js.map +1 -1
  140. package/lib/webrtc/src/media/receiver/nack.d.ts +43 -10
  141. package/lib/webrtc/src/media/receiver/nack.js +245 -88
  142. package/lib/webrtc/src/media/receiver/nack.js.map +1 -1
  143. package/lib/webrtc/src/media/router.d.ts +239 -51
  144. package/lib/webrtc/src/media/router.js +664 -237
  145. package/lib/webrtc/src/media/router.js.map +1 -1
  146. package/lib/webrtc/src/media/routing/pendingRoutes.d.ts +26 -0
  147. package/lib/webrtc/src/media/routing/pendingRoutes.js +48 -0
  148. package/lib/webrtc/src/media/routing/pendingRoutes.js.map +1 -0
  149. package/lib/webrtc/src/media/routing/ridRouting.d.ts +37 -0
  150. package/lib/webrtc/src/media/routing/ridRouting.js +74 -0
  151. package/lib/webrtc/src/media/routing/ridRouting.js.map +1 -0
  152. package/lib/webrtc/src/media/routing/routeTable.d.ts +60 -0
  153. package/lib/webrtc/src/media/routing/routeTable.js +95 -0
  154. package/lib/webrtc/src/media/routing/routeTable.js.map +1 -0
  155. package/lib/webrtc/src/media/routing/rtcpRouting.d.ts +34 -0
  156. package/lib/webrtc/src/media/routing/rtcpRouting.js +165 -0
  157. package/lib/webrtc/src/media/routing/rtcpRouting.js.map +1 -0
  158. package/lib/webrtc/src/media/routing/unknownSsrc.d.ts +55 -0
  159. package/lib/webrtc/src/media/routing/unknownSsrc.js +117 -0
  160. package/lib/webrtc/src/media/routing/unknownSsrc.js.map +1 -0
  161. package/lib/webrtc/src/media/rtpReceiver.d.ts +222 -0
  162. package/lib/webrtc/src/media/rtpReceiver.js +668 -28
  163. package/lib/webrtc/src/media/rtpReceiver.js.map +1 -1
  164. package/lib/webrtc/src/media/rtpSender.d.ts +7 -0
  165. package/lib/webrtc/src/media/rtpSender.js +9 -3
  166. package/lib/webrtc/src/media/rtpSender.js.map +1 -1
  167. package/lib/webrtc/src/media/rtpTransceiver.d.ts +18 -0
  168. package/lib/webrtc/src/media/rtpTransceiver.js +64 -2
  169. package/lib/webrtc/src/media/rtpTransceiver.js.map +1 -1
  170. package/lib/webrtc/src/media/sender/senderReportHistory.d.ts +51 -0
  171. package/lib/webrtc/src/media/sender/senderReportHistory.js +111 -0
  172. package/lib/webrtc/src/media/sender/senderReportHistory.js.map +1 -0
  173. package/lib/webrtc/src/media/sender/senderStats.d.ts +6 -5
  174. package/lib/webrtc/src/media/sender/senderStats.js +14 -19
  175. package/lib/webrtc/src/media/sender/senderStats.js.map +1 -1
  176. package/lib/webrtc/src/media/track.d.ts +9 -0
  177. package/lib/webrtc/src/media/track.js +9 -0
  178. package/lib/webrtc/src/media/track.js.map +1 -1
  179. package/lib/webrtc/src/negotiation/remoteMediaApplication.d.ts +23 -6
  180. package/lib/webrtc/src/negotiation/remoteMediaApplication.js +46 -22
  181. package/lib/webrtc/src/negotiation/remoteMediaApplication.js.map +1 -1
  182. package/lib/webrtc/src/negotiation/transceiverPairing.d.ts +1 -0
  183. package/lib/webrtc/src/negotiation/transceiverPairing.js +62 -0
  184. package/lib/webrtc/src/negotiation/transceiverPairing.js.map +1 -0
  185. package/lib/webrtc/src/negotiation/transportActivation.d.ts +8 -1
  186. package/lib/webrtc/src/negotiation/transportActivation.js +21 -0
  187. package/lib/webrtc/src/negotiation/transportActivation.js.map +1 -1
  188. package/lib/webrtc/src/negotiationTransaction.d.ts +35 -4
  189. package/lib/webrtc/src/negotiationTransaction.js +111 -8
  190. package/lib/webrtc/src/negotiationTransaction.js.map +1 -1
  191. package/lib/webrtc/src/peerConnection.d.ts +65 -6
  192. package/lib/webrtc/src/peerConnection.js +283 -28
  193. package/lib/webrtc/src/peerConnection.js.map +1 -1
  194. package/lib/webrtc/src/polyfill/globals.d.ts +2 -1
  195. package/lib/webrtc/src/polyfill/globals.js.map +1 -1
  196. package/lib/webrtc/src/polyfill/install.js +2 -0
  197. package/lib/webrtc/src/polyfill/install.js.map +1 -1
  198. package/lib/webrtc/src/sctpManager.js +4 -0
  199. package/lib/webrtc/src/sctpManager.js.map +1 -1
  200. package/lib/webrtc/src/sdp.d.ts +69 -0
  201. package/lib/webrtc/src/sdp.js +139 -14
  202. package/lib/webrtc/src/sdp.js.map +1 -1
  203. package/lib/webrtc/src/sdpManager.d.ts +85 -4
  204. package/lib/webrtc/src/sdpManager.js +214 -14
  205. package/lib/webrtc/src/sdpManager.js.map +1 -1
  206. package/lib/webrtc/src/secureTransportManager.d.ts +38 -1
  207. package/lib/webrtc/src/secureTransportManager.js +82 -7
  208. package/lib/webrtc/src/secureTransportManager.js.map +1 -1
  209. package/lib/webrtc/src/transceiverManager.d.ts +82 -4
  210. package/lib/webrtc/src/transceiverManager.js +231 -38
  211. package/lib/webrtc/src/transceiverManager.js.map +1 -1
  212. package/lib/webrtc/src/transport/dtls.d.ts +95 -1
  213. package/lib/webrtc/src/transport/dtls.js +324 -28
  214. package/lib/webrtc/src/transport/dtls.js.map +1 -1
  215. package/lib/webrtc/src/transport/ice.d.ts +61 -4
  216. package/lib/webrtc/src/transport/ice.js +180 -11
  217. package/lib/webrtc/src/transport/ice.js.map +1 -1
  218. package/lib/webrtc/src/transport/sctp.d.ts +23 -0
  219. package/lib/webrtc/src/transport/sctp.js +87 -2
  220. package/lib/webrtc/src/transport/sctp.js.map +1 -1
  221. package/lib/webrtc/src/utils.d.ts +33 -0
  222. package/lib/webrtc/src/utils.js +52 -3
  223. package/lib/webrtc/src/utils.js.map +1 -1
  224. package/package.json +2 -1
@@ -1,7 +1,9 @@
1
1
  import { Candidate } from "./candidate";
2
+ import { type IceCandidateErrorInfo, type IceServerReachedInfo } from "./candidateError";
2
3
  import type { MdnsLookup } from "./dns/lookup";
3
4
  import type { Cancelable } from "./helper";
4
5
  import { type Address, type Event, type InterfaceAddresses, type TlsConnectionOptions } from "./imports/common";
6
+ import { type MessageIntegrityMode } from "./stun/const";
5
7
  import { Message } from "./stun/message";
6
8
  import type { Protocol } from "./types/model";
7
9
  export interface IceConnection {
@@ -12,6 +14,20 @@ export interface IceConnection {
12
14
  remotePassword: string;
13
15
  remoteUsername: string;
14
16
  remoteIsLite: boolean;
17
+ /**
18
+ * The peer advertised `a=ice-options:renomination`. With
19
+ * {@link IceOptions.renomination} the controlling agent then nominates with
20
+ * the NOMINATION attribute (see `renomination`).
21
+ */
22
+ remoteRenomination?: boolean;
23
+ /**
24
+ * The remote `a=ice-options` tokens (RFC 8839 §5.6), e.g. `trickle`,
25
+ * `ice2`. Informational: werift already follows RFC 8445, so no token
26
+ * changes how checks or nomination run.
27
+ */
28
+ remoteIceOptions?: string[];
29
+ /** The remote declared `ice2`: an RFC 8445 agent (RFC 8445 §10). */
30
+ readonly remoteIce2?: boolean;
15
31
  checkList: CandidatePair[];
16
32
  localCandidates: Candidate[];
17
33
  remoteCandidates: Candidate[];
@@ -32,13 +48,34 @@ export interface IceConnection {
32
48
  options: IceOptions;
33
49
  remoteCandidatesEnd: boolean;
34
50
  localCandidatesEnd: boolean;
51
+ /**
52
+ * Resolves when `localCandidatesEnd` becomes true after `gatherCandidates()`
53
+ * returned (server-reflexive queries that continue in the background), or
54
+ * when the generation ends. Optional so that other implementations of this
55
+ * interface keep compiling; without it gathering ends when
56
+ * `gatherCandidates()` returns.
57
+ */
58
+ waitForLocalCandidatesEnd?(): Promise<void>;
35
59
  state: IceState;
36
60
  lookup?: MdnsLookup;
37
61
  nominated?: CandidatePair;
38
62
  readonly onData: Event<[Buffer]>;
39
63
  readonly stateChanged: Event<[IceState]>;
40
64
  readonly onIceCandidate: Event<[Candidate]>;
65
+ /**
66
+ * A STUN or TURN server of the current generation's gathering gave no
67
+ * candidate (see {@link IceCandidateErrorInfo}). Optional so that other
68
+ * implementations of this interface keep compiling.
69
+ */
70
+ readonly onIceCandidateError?: Event<[IceCandidateErrorInfo]>;
71
+ /**
72
+ * A STUN or TURN server of the current generation's gathering answered
73
+ * (see {@link IceServerReachedInfo}). Optional like onIceCandidateError.
74
+ */
75
+ readonly onIceServerReached?: Event<[IceServerReachedInfo]>;
41
76
  restart(): void;
77
+ /** Record the remote `a=ice-options` tokens (see remoteIceOptions). */
78
+ setRemoteIceOptions?(options: string[]): void;
42
79
  /**
43
80
  * Optional staged-restart and provisional-generation support. An
44
81
  * implementation without them still restarts ICE at the final answer, but
@@ -112,6 +149,18 @@ export declare class CandidatePair implements CandidatePairStats {
112
149
  handle?: Cancelable<void>;
113
150
  nominated: boolean;
114
151
  remoteNominated: boolean;
152
+ /**
153
+ * The largest nomination the peer sent for this pair while this agent was
154
+ * controlled: the NOMINATION attribute's value (renomination), or 1 for
155
+ * USE-CANDIDATE. The controlled agent selects the nominated pair with the
156
+ * largest value, the higher-priority one between equal values.
157
+ */
158
+ remoteNomination: number;
159
+ /**
160
+ * The NOMINATION value this agent (controlling, renomination) sent for the
161
+ * pair and the peer answered; 0 when it did not renominate the pair.
162
+ */
163
+ nomination: number;
115
164
  private _state;
116
165
  get state(): CandidatePairState;
117
166
  packetsSent: number;
@@ -192,6 +241,26 @@ export type TurnServerOptions = {
192
241
  password: string;
193
242
  /** Defaults to "udp" (with a TCP fallback when the UDP allocation fails). */
194
243
  transport?: "udp" | "tcp" | "tls";
244
+ /**
245
+ * The application's names (URLs) for this server. Metadata only: the
246
+ * allocation does not use them. They are passed through unchanged to
247
+ * {@link IceServerRef.urls} of `Connection.onIceCandidateError`, so a
248
+ * failure can be matched to the configured server without exposing the
249
+ * credential. Duplicates merged by {@link normalizeIceServerOptions} have
250
+ * their urls merged.
251
+ */
252
+ urls?: string[];
253
+ };
254
+ /** A TURN server as gathering uses it (see {@link normalizeIceServerOptions}). */
255
+ export type NormalizedTurnServer = Required<Omit<TurnServerOptions, "urls">> & Pick<TurnServerOptions, "urls">;
256
+ /**
257
+ * The application's name (URL) of a STUN server, reported in
258
+ * {@link IceServerRef.urls} of `Connection.onIceCandidateError`. Metadata
259
+ * only; several entries may name the same address.
260
+ */
261
+ export type StunServerUrl = {
262
+ address: Address;
263
+ url: string;
195
264
  };
196
265
  export interface IceOptions {
197
266
  /** Advertise and operate as an ICE lite agent. */
@@ -209,6 +278,10 @@ export interface IceOptions {
209
278
  * Defaults to 5. Where UDP is blocked these STUN queries are never answered,
210
279
  * so the wait always runs to the timeout; agents that must not stall on such
211
280
  * networks can lower it.
281
+ *
282
+ * `gatherCandidates()` waits only for the representative sockets' queries
283
+ * (see `stunServers`); the other host sockets' queries continue up to this
284
+ * timeout in the background and end-of-candidates follows them.
212
285
  */
213
286
  stunGatherTimeout?: number;
214
287
  /**
@@ -216,17 +289,84 @@ export interface IceOptions {
216
289
  * Defaults to 8.
217
290
  */
218
291
  turnConnectTimeout?: number;
292
+ /**
293
+ * With `nomination: "regular"`: milliseconds the controlling agent keeps
294
+ * checking before it nominates (RFC 8445 §8.1.1 regular nomination). The
295
+ * default semi-aggressive nomination does not wait. Counted from the later of the first
296
+ * valid pair and the last pair added that outranks the best valid pair, so
297
+ * a higher-priority candidate trickled shortly after a lower-priority one
298
+ * succeeded can still be selected. Once both sides signalled
299
+ * end-of-candidates and no higher-priority pair is still being checked, the
300
+ * best valid pair is nominated at once. Defaults to 300; 0 nominates the
301
+ * best valid pair as soon as one exists. A negative or non-finite value
302
+ * falls back to the default.
303
+ */
304
+ nominationDelayMs?: number;
305
+ /**
306
+ * How the controlling agent nominates toward a full ICE peer when
307
+ * renomination is not in use (see `renomination`).
308
+ *
309
+ * - `"semi-aggressive"` (default, as libwebrtc / Chrome): a check carries
310
+ * USE-CANDIDATE while no pair is selected and for every pair that
311
+ * outranks the selected one. The first pair whose check succeeds is
312
+ * selected at once; checks of higher-priority pairs go on, and one that
313
+ * succeeds later replaces the selection. Consent checks of the selected
314
+ * pair carry USE-CANDIDATE as well.
315
+ * - `"regular"`: RFC 8445 §8.1.1 regular nomination. Checks carry no
316
+ * USE-CANDIDATE; after `nominationDelayMs` (or end-of-candidates) the
317
+ * best valid pair is nominated once with a separate check and never
318
+ * replaced.
319
+ *
320
+ * Toward an ICE-lite peer the first valid pair is nominated in either mode.
321
+ */
322
+ nomination?: "semi-aggressive" | "regular";
323
+ /**
324
+ * Renomination (draft-thatcher-ice-renomination, as libwebrtc implements
325
+ * it). When enabled the agent advertises `a=ice-options:renomination`
326
+ * (packages/webrtc). When the peer advertised it too, the controlling agent
327
+ * nominates with the NOMINATION attribute (0xC001) and an increasing value
328
+ * instead of USE-CANDIDATE: it nominates the first valid pair, keeps
329
+ * checking higher-priority pairs and renominates a better one when its
330
+ * check succeeds. This replaces `nomination` for that session.
331
+ *
332
+ * The controlled agent always honours the NOMINATION attribute: it selects
333
+ * the pair with the largest value. Defaults to false.
334
+ */
335
+ renomination?: boolean;
219
336
  /**
220
337
  * STUN servers queried while gathering, in priority order. Every IPv4 UDP
221
338
  * host socket queries each of them in parallel; equal mappings are
222
339
  * advertised once, different ones (a NAT that maps per destination) each.
223
- * Gathering ends when the slowest server answers or `stunGatherTimeout`
224
- * runs out.
340
+ *
341
+ * Without `interfaceAddresses`, each family with a STUN server also gets a
342
+ * UDP socket bound to the wildcard address that advertises no host
343
+ * candidate: the OS picks its route (a full-tunnel VPN, an interface the
344
+ * host sockets do not cover), and its server-reflexive candidates carry
345
+ * the related address `0.0.0.0` / `::`. The IPv4 wildcard socket queries
346
+ * every server, the IPv6 one only the IPv6 literal servers. It checks only
347
+ * the remote candidates whose route leaves from an address no UDP host
348
+ * socket is bound to, so a peer on a covered path learns no
349
+ * peer-reflexive candidate from it.
350
+ *
351
+ * `gatherCandidates()` returns once the representative sockets answered or
352
+ * `stunGatherTimeout` ran out: the wildcard sockets and the host socket of
353
+ * the default-route address (every host socket when a family has neither).
354
+ * The other host sockets' server-reflexive candidates trickle through
355
+ * `onIceCandidate`, and `localCandidatesEnd` follows the last of them
356
+ * (`waitForLocalCandidatesEnd()`), so an interface that cannot reach the
357
+ * STUN server does not delay the description.
225
358
  *
226
359
  * Merged with the deprecated `stunServer`: the singular one comes first,
227
360
  * duplicates are dropped (see {@link normalizeIceServerOptions}).
228
361
  */
229
362
  stunServers?: Address[];
363
+ /**
364
+ * The application's names (URLs) of {@link IceOptions.stunServers}, by
365
+ * address. Metadata only, reported in {@link IceServerRef.urls} of
366
+ * `Connection.onIceCandidateError`; replaced together with the STUN
367
+ * servers (see {@link mergeIceServerOptions}).
368
+ */
369
+ stunServerUrls?: StunServerUrl[];
230
370
  /**
231
371
  * TURN servers allocated on while gathering, in priority order. Each one
232
372
  * gets its own allocation with its own credential and transport; one that
@@ -283,8 +423,30 @@ export interface IceOptions {
283
423
  * gathered. If the bind fails, the family has no UDP host candidate.
284
424
  *
285
425
  * A family left unspecified while the other one is set gathers no
286
- * enumerated addresses (only its `additionalHostAddresses`). Without any
287
- * family set, every enumerated address is gathered over wildcard sockets.
426
+ * enumerated addresses (only its `additionalHostAddresses`).
427
+ *
428
+ * Without any family set, every enumerated address gets its own UDP host
429
+ * socket bound to that address (an IPv6 link-local one with its zone), so
430
+ * the socket's packets leave from the advertised candidate address even on
431
+ * a host with several network interfaces. An address whose bind fails, or
432
+ * whose sends fail, loses only its own candidate; the other addresses are
433
+ * unaffected. An `additionalHostAddresses` entry that is not assigned to a
434
+ * local interface (a 1:1 NAT public address, for example) is gathered over
435
+ * a wildcard socket. The enumerated addresses include costly networks (VPN
436
+ * / tunnel interfaces: `ipsec`, `tun`, `utun`, `tap`) with a low local
437
+ * preference; `vmnet` / `veth` interfaces are excluded. The default-route
438
+ * address gets the highest local preference, so checks start with the path
439
+ * the OS uses: the source address of the route to the first configured
440
+ * STUN / TURN server that resolves in the family and has a route (UDP
441
+ * `connect()`, no packet is sent). A family without such a server has no
442
+ * default-route address: no other address (no public one) is probed in
443
+ * its place, and its host candidates keep the gathering order. With a STUN
444
+ * server, a wildcard socket per family maps the route the
445
+ * OS picks (see `stunServers`).
446
+ *
447
+ * A family set to the wildcard address (`0.0.0.0` / `::`) gathers its
448
+ * enumerated and additional addresses over wildcard sockets instead;
449
+ * the wildcard address itself is never advertised.
288
450
  */
289
451
  interfaceAddresses?: InterfaceAddresses;
290
452
  /**
@@ -295,6 +457,20 @@ export interface IceOptions {
295
457
  additionalHostAddresses?: string[];
296
458
  filterStunResponse?: (message: Message, addr: Address, protocol: Protocol) => boolean;
297
459
  filterCandidatePair?: (pair: CandidatePair) => boolean;
460
+ /**
461
+ * Integrity attributes of the connectivity checks and consent requests this
462
+ * agent sends (short-term credentials, RFC 8489):
463
+ * - `"sha1"` (default): MESSAGE-INTEGRITY only, what every browser accepts.
464
+ * - `"sha256"`: MESSAGE-INTEGRITY-SHA256 only. A peer that does not know
465
+ * the comprehension-required 0x001C attribute rejects such checks (420
466
+ * or no answer), so use it only with a peer known to support it.
467
+ * - `"both"`: MESSAGE-INTEGRITY followed by MESSAGE-INTEGRITY-SHA256.
468
+ *
469
+ * Received requests and responses are accepted with either algorithm, and
470
+ * a response is always signed with the algorithm of its request
471
+ * (MESSAGE-INTEGRITY-SHA256 when the request carried it, RFC 8489 §9.1.3).
472
+ */
473
+ messageIntegrity?: MessageIntegrityMode;
298
474
  }
299
475
  export declare const defaultOptions: IceOptions;
300
476
  export declare function validateRemoteCandidate(candidate: Candidate): Candidate;
@@ -305,11 +481,33 @@ export declare function sortCandidatePairs(pairs: {
305
481
  localCandidate: Pick<Candidate, "priority">;
306
482
  remoteCandidate: Pick<Candidate, "priority">;
307
483
  }[];
484
+ /**
485
+ * `2^32 * MIN(G,D) + 2 * MAX(G,D) + (G > D ? 1 : 0)` (RFC 8445 §6.1.2.3).
486
+ * The value can exceed `Number.MAX_SAFE_INTEGER`, so it is approximate;
487
+ * order pairs with `compareCandidatePairPriority`, which is exact.
488
+ */
308
489
  export declare function candidatePairPriority(local: Pick<Candidate, "priority">, remote: Pick<Candidate, "priority">, iceControlling: boolean): number;
309
- export declare function serverReflexiveCandidate(protocol: Protocol, stunServer: Address): Promise<Candidate | undefined>;
490
+ /**
491
+ * Exact comparison of two pair priorities (RFC 8445 §6.1.2.3): negative
492
+ * when pair `a` has the lower priority, positive when the higher, 0 when equal.
493
+ */
494
+ export declare function compareCandidatePairPriority(aLocal: Pick<Candidate, "priority">, aRemote: Pick<Candidate, "priority">, bLocal: Pick<Candidate, "priority">, bRemote: Pick<Candidate, "priority">, iceControlling: boolean): number;
495
+ /**
496
+ * Query `stunServer` from `protocol` for a server-reflexive candidate.
497
+ * Unlike {@link serverReflexiveCandidate} it rejects with the reason of a
498
+ * failure. `base` is used for wildcard sockets that advertise no host
499
+ * candidate themselves.
500
+ */
501
+ export declare function queryServerReflexiveCandidate(protocol: Protocol, stunServer: Address, base?: Pick<Candidate, "host" | "port" | "transport" | "component"> & Partial<Pick<Candidate, "tcptype">>): Promise<Candidate>;
502
+ /**
503
+ * Query a STUN server for a server-reflexive candidate. This compatibility
504
+ * helper resolves `undefined` on failure; use
505
+ * {@link queryServerReflexiveCandidate} when the failure reason is needed.
506
+ */
507
+ export declare function serverReflexiveCandidate(protocol: Protocol, stunServer: Address, base?: Pick<Candidate, "host" | "port" | "transport" | "component"> & Partial<Pick<Candidate, "tcptype">>): Promise<Candidate | undefined>;
310
508
  export declare function validateAddress(addr?: Address): Address | undefined;
311
509
  /** The STUN/TURN server fields of {@link IceOptions}, singular and plural. */
312
- export type IceServerFields = Partial<Pick<IceOptions, "stunServer" | "stunServers" | "turnServer" | "turnServers" | "turnUsername" | "turnPassword" | "turnTransport">>;
510
+ export type IceServerFields = Partial<Pick<IceOptions, "stunServer" | "stunServers" | "stunServerUrls" | "turnServer" | "turnServers" | "turnUsername" | "turnPassword" | "turnTransport">>;
313
511
  /**
314
512
  * The STUN and TURN servers `options` configure, the one place the singular
315
513
  * (deprecated) and plural fields are merged:
@@ -319,14 +517,15 @@ export type IceServerFields = Partial<Pick<IceOptions, "stunServer" | "stunServe
319
517
  * credential) are kept once, at their first position;
320
518
  * - an invalid address (see {@link validateAddress}) is dropped, and so is a
321
519
  * TURN server without username or password (it cannot allocate);
322
- * - a TURN transport left unset is "udp".
520
+ * - a TURN transport left unset is "udp";
521
+ * - the `urls` of merged TURN duplicates are merged (in order, once each).
323
522
  *
324
523
  * The built-in default STUN server is not added here; Connection falls back
325
524
  * to it when the result has no STUN server.
326
525
  */
327
526
  export declare function normalizeIceServerOptions(options: IceServerFields): {
328
527
  stunServers: Address[];
329
- turnServers: Required<TurnServerOptions>[];
528
+ turnServers: NormalizedTurnServer[];
330
529
  };
331
530
  /**
332
531
  * `current` with an ICE server update applied (Connection.setIceServers): the
@@ -5,6 +5,8 @@ exports.consentResponseTimeoutMs = consentResponseTimeoutMs;
5
5
  exports.validateRemoteCandidate = validateRemoteCandidate;
6
6
  exports.sortCandidatePairs = sortCandidatePairs;
7
7
  exports.candidatePairPriority = candidatePairPriority;
8
+ exports.compareCandidatePairPriority = compareCandidatePairPriority;
9
+ exports.queryServerReflexiveCandidate = queryServerReflexiveCandidate;
8
10
  exports.serverReflexiveCandidate = serverReflexiveCandidate;
9
11
  exports.validateAddress = validateAddress;
10
12
  exports.normalizeIceServerOptions = normalizeIceServerOptions;
@@ -14,6 +16,7 @@ exports.hasTurnServer = hasTurnServer;
14
16
  exports.isCandidateAllowedByGatherOptions = isCandidateAllowedByGatherOptions;
15
17
  const crypto_1 = require("crypto");
16
18
  const candidate_1 = require("./candidate");
19
+ const candidateError_1 = require("./candidateError");
17
20
  const common_1 = require("./imports/common");
18
21
  const const_1 = require("./stun/const");
19
22
  const message_1 = require("./stun/message");
@@ -75,6 +78,28 @@ class CandidatePair {
75
78
  writable: true,
76
79
  value: false
77
80
  });
81
+ /**
82
+ * The largest nomination the peer sent for this pair while this agent was
83
+ * controlled: the NOMINATION attribute's value (renomination), or 1 for
84
+ * USE-CANDIDATE. The controlled agent selects the nominated pair with the
85
+ * largest value, the higher-priority one between equal values.
86
+ */
87
+ Object.defineProperty(this, "remoteNomination", {
88
+ enumerable: true,
89
+ configurable: true,
90
+ writable: true,
91
+ value: 0
92
+ });
93
+ /**
94
+ * The NOMINATION value this agent (controlling, renomination) sent for the
95
+ * pair and the peer answered; 0 when it did not renominate the pair.
96
+ */
97
+ Object.defineProperty(this, "nomination", {
98
+ enumerable: true,
99
+ configurable: true,
100
+ writable: true,
101
+ value: 0
102
+ });
78
103
  // 5.7.4. Computing States
79
104
  Object.defineProperty(this, "_state", {
80
105
  enumerable: true,
@@ -267,39 +292,66 @@ function validateRemoteCandidate(candidate) {
267
292
  return candidate;
268
293
  }
269
294
  function sortCandidatePairs(pairs, iceControlling) {
270
- return pairs
271
- .sort((a, b) => candidatePairPriority(a.localCandidate, a.remoteCandidate, iceControlling) -
272
- candidatePairPriority(b.localCandidate, b.remoteCandidate, iceControlling))
273
- .reverse();
295
+ // Highest priority first; pairs of equal priority keep their order.
296
+ return pairs.sort((a, b) => compareCandidatePairPriority(b.localCandidate, b.remoteCandidate, a.localCandidate, a.remoteCandidate, iceControlling));
297
+ }
298
+ /** RFC 8445 §6.1.2.3: G is the controlling agent's candidate priority, D the controlled one's. */
299
+ function pairPriorityTerms(local, remote, iceControlling) {
300
+ const G = iceControlling ? local.priority : remote.priority;
301
+ const D = iceControlling ? remote.priority : local.priority;
302
+ return { min: Math.min(G, D), max: Math.max(G, D), tie: G > D ? 1 : 0 };
274
303
  }
275
304
  // 5.7.2. Computing Pair Priority and Ordering Pairs
305
+ /**
306
+ * `2^32 * MIN(G,D) + 2 * MAX(G,D) + (G > D ? 1 : 0)` (RFC 8445 §6.1.2.3).
307
+ * The value can exceed `Number.MAX_SAFE_INTEGER`, so it is approximate;
308
+ * order pairs with `compareCandidatePairPriority`, which is exact.
309
+ */
276
310
  function candidatePairPriority(local, remote, iceControlling) {
277
- const G = (iceControlling && local.priority) || remote.priority;
278
- const D = (iceControlling && remote.priority) || local.priority;
279
- return (1 << 32) * Math.min(G, D) + 2 * Math.max(G, D) + (G > D ? 1 : 0);
311
+ const { min, max, tie } = pairPriorityTerms(local, remote, iceControlling);
312
+ return 2 ** 32 * min + 2 * max + tie;
280
313
  }
281
- async function serverReflexiveCandidate(protocol, stunServer) {
282
- // """
283
- // Query STUN server to obtain a server-reflexive candidate.
284
- // """
285
- // # perform STUN query
314
+ /**
315
+ * Exact comparison of two pair priorities (RFC 8445 §6.1.2.3): negative
316
+ * when pair `a` has the lower priority, positive when the higher, 0 when equal.
317
+ */
318
+ function compareCandidatePairPriority(aLocal, aRemote, bLocal, bRemote, iceControlling) {
319
+ const a = pairPriorityTerms(aLocal, aRemote, iceControlling);
320
+ const b = pairPriorityTerms(bLocal, bRemote, iceControlling);
321
+ return a.min - b.min || a.max - b.max || a.tie - b.tie;
322
+ }
323
+ /**
324
+ * Query `stunServer` from `protocol` for a server-reflexive candidate.
325
+ * Unlike {@link serverReflexiveCandidate} it rejects with the reason of a
326
+ * failure. `base` is used for wildcard sockets that advertise no host
327
+ * candidate themselves.
328
+ */
329
+ async function queryServerReflexiveCandidate(protocol, stunServer, base) {
330
+ const localCandidate = base ?? protocol.localCandidate;
331
+ if (!localCandidate) {
332
+ throw new Error("protocol has no local candidate");
333
+ }
286
334
  const request = new message_1.Message(const_1.methods.BINDING, const_1.classes.REQUEST);
287
- try {
288
- const [response] = await protocol.request(request, stunServer);
289
- const localCandidate = protocol.localCandidate;
290
- if (!localCandidate) {
291
- throw new Error("not exist");
292
- }
293
- const candidate = new candidate_1.Candidate((0, candidate_1.candidateFoundation)("srflx", localCandidate.transport, localCandidate.host), localCandidate.component, localCandidate.transport, (0, candidate_1.candidatePriority)("srflx", {
294
- transport: localCandidate.transport,
295
- tcptype: localCandidate.tcptype,
296
- }), response.getAttributeValue("XOR-MAPPED-ADDRESS")[0], response.getAttributeValue("XOR-MAPPED-ADDRESS")[1], "srflx", localCandidate.host, localCandidate.port, localCandidate.tcptype);
297
- return candidate;
335
+ const [response] = await protocol.request(request, stunServer);
336
+ const mapped = response.getAttributeValue("XOR-MAPPED-ADDRESS");
337
+ if (!mapped) {
338
+ throw new candidateError_1.MissingMappedAddressError(stunServer);
298
339
  }
299
- catch (error) {
300
- // todo fix
340
+ return new candidate_1.Candidate((0, candidate_1.candidateFoundation)("srflx", localCandidate.transport, localCandidate.host), localCandidate.component, localCandidate.transport, (0, candidate_1.candidatePriority)("srflx", {
341
+ transport: localCandidate.transport,
342
+ tcptype: localCandidate.tcptype,
343
+ }), mapped[0], mapped[1], "srflx", localCandidate.host, localCandidate.port, localCandidate.tcptype);
344
+ }
345
+ /**
346
+ * Query a STUN server for a server-reflexive candidate. This compatibility
347
+ * helper resolves `undefined` on failure; use
348
+ * {@link queryServerReflexiveCandidate} when the failure reason is needed.
349
+ */
350
+ async function serverReflexiveCandidate(protocol, stunServer, base) {
351
+ return queryServerReflexiveCandidate(protocol, stunServer, base).catch((error) => {
301
352
  log("error serverReflexiveCandidate", error);
302
- }
353
+ return undefined;
354
+ });
303
355
  }
304
356
  function validateAddress(addr) {
305
357
  if (addr && Number.isNaN(addr[1])) {
@@ -331,7 +383,8 @@ const sameAddress = (a, b) => a[0] === b[0] && a[1] === b[1];
331
383
  * credential) are kept once, at their first position;
332
384
  * - an invalid address (see {@link validateAddress}) is dropped, and so is a
333
385
  * TURN server without username or password (it cannot allocate);
334
- * - a TURN transport left unset is "udp".
386
+ * - a TURN transport left unset is "udp";
387
+ * - the `urls` of merged TURN duplicates are merged (in order, once each).
335
388
  *
336
389
  * The built-in default STUN server is not added here; Connection falls back
337
390
  * to it when the result has no STUN server.
@@ -376,16 +429,25 @@ function normalizeIceServerOptions(options) {
376
429
  log("TURN server without username / credential ignored", address);
377
430
  continue;
378
431
  }
432
+ const urls = Array.isArray(server.urls)
433
+ ? server.urls.filter((url) => typeof url === "string")
434
+ : undefined;
379
435
  const entry = {
380
436
  address,
381
437
  username,
382
438
  password,
383
439
  transport: server.transport ?? "udp",
440
+ ...(urls ? { urls: [...new Set(urls)] } : {}),
384
441
  };
385
- if (turnServers.some((existing) => sameAddress(existing.address, entry.address) &&
386
- existing.transport === entry.transport &&
387
- existing.username === entry.username &&
388
- existing.password === entry.password)) {
442
+ const existing = turnServers.find((known) => sameAddress(known.address, entry.address) &&
443
+ known.transport === entry.transport &&
444
+ known.username === entry.username &&
445
+ known.password === entry.password);
446
+ if (existing) {
447
+ // One allocation serves both: it answers to every name of them.
448
+ if (entry.urls) {
449
+ existing.urls = [...new Set([...(existing.urls ?? []), ...entry.urls])];
450
+ }
389
451
  continue;
390
452
  }
391
453
  turnServers.push(entry);
@@ -403,6 +465,7 @@ function mergeIceServerOptions(current, update) {
403
465
  ...current,
404
466
  stunServer: update.stunServer,
405
467
  stunServers: update.stunServers,
468
+ stunServerUrls: update.stunServerUrls,
406
469
  turnServer: update.turnServer,
407
470
  turnServers: update.turnServers,
408
471
  turnUsername: update.turnUsername,