@ac-kit/net-webrtc 0.0.0-stage → 0.0.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.
- package/LICENSE +28 -0
- package/README.md +99 -2
- package/dist/_ice-servers.d.ts +15 -0
- package/dist/_ice-servers.d.ts.map +1 -0
- package/dist/_ice-servers.js +33 -0
- package/dist/_ice-servers.js.map +1 -0
- package/dist/_mdns.d.ts +53 -0
- package/dist/_mdns.d.ts.map +1 -0
- package/dist/_mdns.js +239 -0
- package/dist/_mdns.js.map +1 -0
- package/dist/_native.d.ts +82 -0
- package/dist/_native.d.ts.map +1 -0
- package/dist/_native.js +51 -0
- package/dist/_native.js.map +1 -0
- package/dist/_peer-connection-driver.d.ts +95 -0
- package/dist/_peer-connection-driver.d.ts.map +1 -0
- package/dist/_peer-connection-driver.js +500 -0
- package/dist/_peer-connection-driver.js.map +1 -0
- package/dist/_stun.d.ts +28 -0
- package/dist/_stun.d.ts.map +1 -0
- package/dist/_stun.js +115 -0
- package/dist/_stun.js.map +1 -0
- package/dist/dtls-fingerprint.d.ts +18 -0
- package/dist/dtls-fingerprint.d.ts.map +1 -0
- package/dist/dtls-fingerprint.js +25 -0
- package/dist/dtls-fingerprint.js.map +1 -0
- package/dist/errors.d.ts +27 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +42 -0
- package/dist/errors.js.map +1 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +5 -0
- package/dist/index.js.map +1 -0
- package/dist/webrtc-data-channel.d.ts +80 -0
- package/dist/webrtc-data-channel.d.ts.map +1 -0
- package/dist/webrtc-data-channel.js +138 -0
- package/dist/webrtc-data-channel.js.map +1 -0
- package/dist/webrtc-peer-connection.d.ts +205 -0
- package/dist/webrtc-peer-connection.d.ts.map +1 -0
- package/dist/webrtc-peer-connection.js +324 -0
- package/dist/webrtc-peer-connection.js.map +1 -0
- package/package.json +75 -3
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
import { EventDispatcherMapBase } from "@ac-kit/async";
|
|
2
|
+
import { type DtlsFingerprint } from "./dtls-fingerprint.js";
|
|
3
|
+
import { WebRtcDataChannel } from "./webrtc-data-channel.js";
|
|
4
|
+
/** As `RTCSdpType`. */
|
|
5
|
+
export type WebRtcSdpType = "offer" | "answer" | "pranswer" | "rollback";
|
|
6
|
+
/** As `RTCSessionDescriptionInit`: a browser's description is one already. */
|
|
7
|
+
export type WebRtcSessionDescription = {
|
|
8
|
+
readonly type: WebRtcSdpType;
|
|
9
|
+
readonly sdp: string;
|
|
10
|
+
};
|
|
11
|
+
/** As `RTCIceCandidateInit`: a browser's candidate is one already. */
|
|
12
|
+
export type WebRtcIceCandidate = {
|
|
13
|
+
/** The SDP `candidate:` attribute. */
|
|
14
|
+
readonly candidate: string;
|
|
15
|
+
/** The media stream it belongs to. */
|
|
16
|
+
readonly sdpMid?: string | null;
|
|
17
|
+
};
|
|
18
|
+
/** As `RTCPeerConnectionState`. */
|
|
19
|
+
export type WebRtcConnectionState = "new" | "connecting" | "connected" | "disconnected" | "failed" | "closed";
|
|
20
|
+
/** As `RTCIceConnectionState`. */
|
|
21
|
+
export type WebRtcIceConnectionState = "new" | "checking" | "connected" | "completed" | "failed" | "disconnected" | "closed";
|
|
22
|
+
/** As `RTCIceGatheringState`. */
|
|
23
|
+
export type WebRtcIceGatheringState = "new" | "gathering" | "complete";
|
|
24
|
+
/** As `RTCSignalingState`, less `closed`. */
|
|
25
|
+
export type WebRtcSignalingState = "stable" | "have-local-offer" | "have-remote-offer" | "have-local-pranswer" | "have-remote-pranswer";
|
|
26
|
+
/**
|
|
27
|
+
* How a data channel delivers. The default is reliable and ordered; setting
|
|
28
|
+
* `maxRetransmits` or `maxPacketLifeTime` (not both) makes it partially
|
|
29
|
+
* reliable.
|
|
30
|
+
*/
|
|
31
|
+
export type WebRtcDataChannelOptions = {
|
|
32
|
+
/** Deliver in the order sent. Default: `true`. */
|
|
33
|
+
readonly ordered?: boolean;
|
|
34
|
+
/** Retransmissions before a message is dropped; `0` sends each once. */
|
|
35
|
+
readonly maxRetransmits?: number;
|
|
36
|
+
/** Milliseconds a message may be retransmitted for before it is dropped. */
|
|
37
|
+
readonly maxPacketLifeTime?: number;
|
|
38
|
+
/** Subprotocol name both sides see. */
|
|
39
|
+
readonly protocol?: string;
|
|
40
|
+
/**
|
|
41
|
+
* SCTP stream id agreed out of band: no in-band open, and the peer must
|
|
42
|
+
* create the same channel with the same id.
|
|
43
|
+
*/
|
|
44
|
+
readonly negotiatedId?: number;
|
|
45
|
+
};
|
|
46
|
+
/** Construction options for {@link WebRtcPeerConnection}. */
|
|
47
|
+
export type WebRtcPeerConnectionOptions = {
|
|
48
|
+
/**
|
|
49
|
+
* STUN servers, as RFC 7064 URIs (`stun:host`, `stun:host:port`, port 3478 by
|
|
50
|
+
* default): each gives a server-reflexive candidate per local address when it
|
|
51
|
+
* answers. None by default: host candidates only. TURN is not supported yet.
|
|
52
|
+
*/
|
|
53
|
+
readonly iceServers?: readonly string[];
|
|
54
|
+
/**
|
|
55
|
+
* Local address ICE binds to. By default, one UDP socket per non-internal
|
|
56
|
+
* IPv4 address of the machine (the loopback one when there is none); `"::"`
|
|
57
|
+
* selects the IPv6 ones instead.
|
|
58
|
+
*/
|
|
59
|
+
readonly bindAddress?: string;
|
|
60
|
+
/** First and last local UDP port ICE may use. Any by default. */
|
|
61
|
+
readonly portRange?: readonly [first: number, last: number];
|
|
62
|
+
/**
|
|
63
|
+
* Largest message accepted, announced to the peer in the SDP: 64 KiB by
|
|
64
|
+
* default (RFC 8841), 256 KiB at most.
|
|
65
|
+
*/
|
|
66
|
+
readonly maxMessageSize?: number;
|
|
67
|
+
/** Aborting closes the connection, as {@link WebRtcPeerConnection.close}. */
|
|
68
|
+
readonly signal?: AbortSignal;
|
|
69
|
+
};
|
|
70
|
+
/**
|
|
71
|
+
* Events emitted by a {@link WebRtcPeerConnection}.
|
|
72
|
+
*
|
|
73
|
+
* - `candidate` — a local ICE candidate to signal to the peer.
|
|
74
|
+
* - `gatheringStateChange` — `complete` means no further `candidate`.
|
|
75
|
+
* - `connectionStateChange`, `iceConnectionStateChange`, `signalingStateChange` —
|
|
76
|
+
* as their `RTCPeerConnection` namesakes.
|
|
77
|
+
* - `dataChannel` — the peer opened a channel; it opens next.
|
|
78
|
+
* - `close` — the connection is closed, exactly once, after every one of its
|
|
79
|
+
* channels.
|
|
80
|
+
*/
|
|
81
|
+
export type WebRtcPeerConnectionEvents = {
|
|
82
|
+
candidate: [candidate: WebRtcIceCandidate & {
|
|
83
|
+
readonly sdpMid: string;
|
|
84
|
+
}];
|
|
85
|
+
gatheringStateChange: [state: WebRtcIceGatheringState];
|
|
86
|
+
connectionStateChange: [state: WebRtcConnectionState];
|
|
87
|
+
iceConnectionStateChange: [state: WebRtcIceConnectionState];
|
|
88
|
+
signalingStateChange: [state: WebRtcSignalingState];
|
|
89
|
+
dataChannel: [channel: WebRtcDataChannel];
|
|
90
|
+
close: [];
|
|
91
|
+
};
|
|
92
|
+
/**
|
|
93
|
+
* One WebRTC peer connection carrying data channels only. Signalling is the
|
|
94
|
+
* caller's: send what {@link setLocalDescription} returns and every `candidate`
|
|
95
|
+
* event to the peer, and pass its description and candidates to
|
|
96
|
+
* {@link setRemoteDescription} and {@link addIceCandidate}. The shapes are the
|
|
97
|
+
* browser's, so they travel unchanged between the two.
|
|
98
|
+
*
|
|
99
|
+
* ICE, DTLS and SCTP are webrtc-rs's `rtc` state machine, compiled into a
|
|
100
|
+
* native addon and driven from this thread: the connection owns its UDP sockets
|
|
101
|
+
* and timer, and keeps the process alive until it is closed.
|
|
102
|
+
*
|
|
103
|
+
* Subscribe before yielding to the event loop after a call that produces
|
|
104
|
+
* events: they are delivered on a later turn, never dropped, but never replayed
|
|
105
|
+
* either.
|
|
106
|
+
*/
|
|
107
|
+
export declare class WebRtcPeerConnection extends EventDispatcherMapBase<WebRtcPeerConnectionEvents> {
|
|
108
|
+
private readonly native;
|
|
109
|
+
private readonly channels;
|
|
110
|
+
private readonly owner;
|
|
111
|
+
private closed;
|
|
112
|
+
private connection;
|
|
113
|
+
private ice;
|
|
114
|
+
private gathering;
|
|
115
|
+
private signaling;
|
|
116
|
+
private readonly signal;
|
|
117
|
+
private readonly handleAbort;
|
|
118
|
+
/**
|
|
119
|
+
* @throws {RangeError} When `portRange` or `maxMessageSize` is invalid, or an
|
|
120
|
+
* `iceServers` entry is not a `stun:` URI.
|
|
121
|
+
* @throws {WebRtcTurnUnsupportedError} When an `iceServers` entry is a
|
|
122
|
+
* `turn:` or `turns:` URI.
|
|
123
|
+
* @throws {UnsupportedError} When an `iceServers` entry is a `stuns:` URI, or
|
|
124
|
+
* no native binding exists for this platform.
|
|
125
|
+
*/
|
|
126
|
+
constructor(options?: WebRtcPeerConnectionOptions);
|
|
127
|
+
get connectionState(): WebRtcConnectionState;
|
|
128
|
+
get iceConnectionState(): WebRtcIceConnectionState;
|
|
129
|
+
get iceGatheringState(): WebRtcIceGatheringState;
|
|
130
|
+
get signalingState(): WebRtcSignalingState;
|
|
131
|
+
/**
|
|
132
|
+
* With every candidate gathered so far; `null` before
|
|
133
|
+
* {@link setLocalDescription}.
|
|
134
|
+
*/
|
|
135
|
+
get localDescription(): WebRtcSessionDescription | null;
|
|
136
|
+
get remoteDescription(): WebRtcSessionDescription | null;
|
|
137
|
+
/**
|
|
138
|
+
* Creates the offer — or the answer, once a remote offer is set — applies it
|
|
139
|
+
* and returns it. Gathering starts: candidates follow as `candidate` events.
|
|
140
|
+
*
|
|
141
|
+
* @param type Forces the type; inferred from the signalling state otherwise.
|
|
142
|
+
* @throws {WebRtcClosedError} Once closed.
|
|
143
|
+
*/
|
|
144
|
+
setLocalDescription(type?: "offer" | "answer"): WebRtcSessionDescription;
|
|
145
|
+
/**
|
|
146
|
+
* Applies the peer's offer or answer. An offer is answered by
|
|
147
|
+
* {@link setLocalDescription} next.
|
|
148
|
+
*
|
|
149
|
+
* @throws {WebRtcClosedError} Once closed.
|
|
150
|
+
* @throws {Error} When the description is malformed or out of turn.
|
|
151
|
+
*/
|
|
152
|
+
setRemoteDescription(description: WebRtcSessionDescription): void;
|
|
153
|
+
/**
|
|
154
|
+
* Adds one remote candidate. A browser's end-of-candidates marker — an empty
|
|
155
|
+
* `candidate` — is ignored.
|
|
156
|
+
*
|
|
157
|
+
* @throws {WebRtcClosedError} Once closed.
|
|
158
|
+
* @throws {Error} When no remote description is set yet, or the candidate is
|
|
159
|
+
* malformed.
|
|
160
|
+
*/
|
|
161
|
+
addIceCandidate(candidate: WebRtcIceCandidate): void;
|
|
162
|
+
/**
|
|
163
|
+
* The DTLS fingerprints of this side's certificate, from the local
|
|
164
|
+
* description: what the peer will check the handshake against. Empty before
|
|
165
|
+
* {@link setLocalDescription}.
|
|
166
|
+
*/
|
|
167
|
+
localFingerprints(): DtlsFingerprint[];
|
|
168
|
+
/** The peer's DTLS fingerprints, from the remote description. */
|
|
169
|
+
remoteFingerprints(): DtlsFingerprint[];
|
|
170
|
+
/**
|
|
171
|
+
* The two ends of the selected candidate pair, `address:port` each, once ICE
|
|
172
|
+
* has connected; `null` before.
|
|
173
|
+
*/
|
|
174
|
+
selectedAddresses(): {
|
|
175
|
+
readonly local: string;
|
|
176
|
+
readonly remote: string;
|
|
177
|
+
} | null;
|
|
178
|
+
/**
|
|
179
|
+
* Creates a data channel. Before the first offer, it is negotiated by that
|
|
180
|
+
* offer; afterwards it opens in-band over the existing association.
|
|
181
|
+
*
|
|
182
|
+
* @throws {WebRtcClosedError} Once closed.
|
|
183
|
+
* @throws {RangeError} When both `maxRetransmits` and `maxPacketLifeTime` are
|
|
184
|
+
* set, or either or `negotiatedId` is out of range.
|
|
185
|
+
*/
|
|
186
|
+
createDataChannel(label: string, options?: WebRtcDataChannelOptions): WebRtcDataChannel;
|
|
187
|
+
/**
|
|
188
|
+
* Resolves once the connection is `connected`.
|
|
189
|
+
*
|
|
190
|
+
* @throws {WebRtcConnectionFailedError} When it fails or closes first.
|
|
191
|
+
* @throws {unknown} The signal's reason, when aborted first; the connection
|
|
192
|
+
* is left as it is.
|
|
193
|
+
*/
|
|
194
|
+
connected(signal?: AbortSignal): Promise<void>;
|
|
195
|
+
/**
|
|
196
|
+
* Closes every data channel, then the connection, and releases its native
|
|
197
|
+
* resources: each channel emits `close`, then `connectionStateChange`
|
|
198
|
+
* (`closed`) and `close` follow. Idempotent.
|
|
199
|
+
*/
|
|
200
|
+
close(): void;
|
|
201
|
+
private assertOpen;
|
|
202
|
+
private handleEvent;
|
|
203
|
+
private handleChannelEvent;
|
|
204
|
+
}
|
|
205
|
+
//# sourceMappingURL=webrtc-peer-connection.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"webrtc-peer-connection.d.ts","sourceRoot":"","sources":["../src/webrtc-peer-connection.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAE,MAAM,eAAe,CAAC;AAKvD,OAAO,EACN,KAAK,eAAe,EAEpB,MAAM,uBAAuB,CAAC;AAE/B,OAAO,EAEN,iBAAiB,EACjB,MAAM,0BAA0B,CAAC;AAElC,uBAAuB;AACvB,MAAM,MAAM,aAAa,GAAG,OAAO,GAAG,QAAQ,GAAG,UAAU,GAAG,UAAU,CAAC;AAEzE,8EAA8E;AAC9E,MAAM,MAAM,wBAAwB,GAAG;IACtC,QAAQ,CAAC,IAAI,EAAE,aAAa,CAAC;IAC7B,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;CACrB,CAAC;AAEF,sEAAsE;AACtE,MAAM,MAAM,kBAAkB,GAAG;IAChC,sCAAsC;IACtC,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,sCAAsC;IACtC,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;CAChC,CAAC;AAEF,mCAAmC;AACnC,MAAM,MAAM,qBAAqB,GAC9B,KAAK,GACL,YAAY,GACZ,WAAW,GACX,cAAc,GACd,QAAQ,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AAI,wBAAwB,GAAG,IAAI,CAIvD;IAED;;;;;;OAMG;IACH,mBAAmB,CAAC,IAAI,CAAC,EAAE,OAAO,GAAG,QAAQ,GAAG,wBAAwB,CAOvE;IAED;;;;;;OAMG;IACH,oBAAoB,CAAC,WAAW,EAAE,wBAAwB,GAAG,IAAI,CAMhE;IAED;;;;;;;OAOG;IACH,eAAe,CAAC,SAAS,EAAE,kBAAkB,GAAG,IAAI,CASnD;IAED;;;;OAIG;IACH,iBAAiB,IAAI,eAAe,EAAE,CAGrC;IAED,iEAAiE;IACjE,kBAAkB,IAAI,eAAe,EAAE,CAGtC;IAED;;;OAGG;IACH,iBAAiB,IAAI;QACpB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;QACvB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;KACxB,GAAG,IAAI,CAQP;IAED;;;;;;;OAOG;IACH,iBAAiB,CAChB,KAAK,EAAE,MAAM,EACb,OAAO,CAAC,EAAE,wBAAwB,GAChC,iBAAiB,CAkCnB;IAED;;;;;;OAMG;IACG,SAAS,CAAC,MAAM,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,IAAI,CAAC,CAiBnD;IAED;;;;OAIG;IACH,KAAK,IAAI,IAAI,CAeZ;IAED,OAAO,CAAC,UAAU;IAMlB,OAAO,CAAC,WAAW;IAqCnB,OAAO,CAAC,kBAAkB;CAiB1B"}
|
|
@@ -0,0 +1,324 @@
|
|
|
1
|
+
import { EventDispatcherMapBase } from "@ac-kit/async";
|
|
2
|
+
import { parseIceServers_ } from "./_ice-servers.js";
|
|
3
|
+
import { PeerConnectionDriver_ } from "./_peer-connection-driver.js";
|
|
4
|
+
import { parseSdpFingerprints, } from "./dtls-fingerprint.js";
|
|
5
|
+
import { WebRtcClosedError, WebRtcConnectionFailedError } from "./errors.js";
|
|
6
|
+
import { WebRtcDataChannel, } from "./webrtc-data-channel.js";
|
|
7
|
+
const SDP_TYPES = new Set(["offer", "answer", "pranswer", "rollback"]);
|
|
8
|
+
function sessionDescription_(native) {
|
|
9
|
+
if (native === null) {
|
|
10
|
+
return null;
|
|
11
|
+
}
|
|
12
|
+
if (!SDP_TYPES.has(native.type)) {
|
|
13
|
+
throw new TypeError(`Unexpected SDP type from the binding: ${native.type}`);
|
|
14
|
+
}
|
|
15
|
+
return { type: native.type, sdp: native.sdp };
|
|
16
|
+
}
|
|
17
|
+
/** What `rtc` can announce (`SctpMaxMessageSize::MAX_MESSAGE_SIZE`). */
|
|
18
|
+
const MAX_MESSAGE_SIZE_ = 256 * 1024;
|
|
19
|
+
function validPort_(port) {
|
|
20
|
+
if (!Number.isInteger(port) || port < 1 || port > 65535) {
|
|
21
|
+
throw new RangeError(`Invalid port: ${port}`);
|
|
22
|
+
}
|
|
23
|
+
return port;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* One WebRTC peer connection carrying data channels only. Signalling is the
|
|
27
|
+
* caller's: send what {@link setLocalDescription} returns and every `candidate`
|
|
28
|
+
* event to the peer, and pass its description and candidates to
|
|
29
|
+
* {@link setRemoteDescription} and {@link addIceCandidate}. The shapes are the
|
|
30
|
+
* browser's, so they travel unchanged between the two.
|
|
31
|
+
*
|
|
32
|
+
* ICE, DTLS and SCTP are webrtc-rs's `rtc` state machine, compiled into a
|
|
33
|
+
* native addon and driven from this thread: the connection owns its UDP sockets
|
|
34
|
+
* and timer, and keeps the process alive until it is closed.
|
|
35
|
+
*
|
|
36
|
+
* Subscribe before yielding to the event loop after a call that produces
|
|
37
|
+
* events: they are delivered on a later turn, never dropped, but never replayed
|
|
38
|
+
* either.
|
|
39
|
+
*/
|
|
40
|
+
export class WebRtcPeerConnection extends EventDispatcherMapBase {
|
|
41
|
+
native;
|
|
42
|
+
channels = new Map();
|
|
43
|
+
owner;
|
|
44
|
+
closed = false;
|
|
45
|
+
connection = "new";
|
|
46
|
+
ice = "new";
|
|
47
|
+
gathering = "new";
|
|
48
|
+
signaling = "stable";
|
|
49
|
+
signal;
|
|
50
|
+
handleAbort = () => this.close();
|
|
51
|
+
/**
|
|
52
|
+
* @throws {RangeError} When `portRange` or `maxMessageSize` is invalid, or an
|
|
53
|
+
* `iceServers` entry is not a `stun:` URI.
|
|
54
|
+
* @throws {WebRtcTurnUnsupportedError} When an `iceServers` entry is a
|
|
55
|
+
* `turn:` or `turns:` URI.
|
|
56
|
+
* @throws {UnsupportedError} When an `iceServers` entry is a `stuns:` URI, or
|
|
57
|
+
* no native binding exists for this platform.
|
|
58
|
+
*/
|
|
59
|
+
constructor(options) {
|
|
60
|
+
super();
|
|
61
|
+
const portRange = options?.portRange;
|
|
62
|
+
if (portRange !== undefined &&
|
|
63
|
+
validPort_(portRange[0]) > validPort_(portRange[1])) {
|
|
64
|
+
throw new RangeError(`Invalid port range: ${portRange[0]}-${portRange[1]}`);
|
|
65
|
+
}
|
|
66
|
+
const maxMessageSize = options?.maxMessageSize;
|
|
67
|
+
if (maxMessageSize !== undefined &&
|
|
68
|
+
(!Number.isInteger(maxMessageSize) ||
|
|
69
|
+
maxMessageSize < 1 ||
|
|
70
|
+
maxMessageSize > MAX_MESSAGE_SIZE_)) {
|
|
71
|
+
throw new RangeError(`Invalid maxMessageSize: ${maxMessageSize}`);
|
|
72
|
+
}
|
|
73
|
+
this.native = new PeerConnectionDriver_({
|
|
74
|
+
stunServers: parseIceServers_(options?.iceServers ?? []),
|
|
75
|
+
bindAddress: options?.bindAddress,
|
|
76
|
+
portRange,
|
|
77
|
+
maxMessageSize,
|
|
78
|
+
}, (event) => this.handleEvent(event));
|
|
79
|
+
this.owner = {
|
|
80
|
+
driver: this.native,
|
|
81
|
+
forget: (channel) => this.channels.delete(channel),
|
|
82
|
+
};
|
|
83
|
+
this.signal = options?.signal;
|
|
84
|
+
if (this.signal?.aborted) {
|
|
85
|
+
this.close();
|
|
86
|
+
}
|
|
87
|
+
else {
|
|
88
|
+
this.signal?.addEventListener("abort", this.handleAbort, { once: true });
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
get connectionState() {
|
|
92
|
+
return this.connection;
|
|
93
|
+
}
|
|
94
|
+
get iceConnectionState() {
|
|
95
|
+
return this.ice;
|
|
96
|
+
}
|
|
97
|
+
get iceGatheringState() {
|
|
98
|
+
return this.gathering;
|
|
99
|
+
}
|
|
100
|
+
get signalingState() {
|
|
101
|
+
return this.signaling;
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* With every candidate gathered so far; `null` before
|
|
105
|
+
* {@link setLocalDescription}.
|
|
106
|
+
*/
|
|
107
|
+
get localDescription() {
|
|
108
|
+
return this.closed
|
|
109
|
+
? null
|
|
110
|
+
: sessionDescription_(this.native.localDescription());
|
|
111
|
+
}
|
|
112
|
+
get remoteDescription() {
|
|
113
|
+
return this.closed
|
|
114
|
+
? null
|
|
115
|
+
: sessionDescription_(this.native.remoteDescription());
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* Creates the offer — or the answer, once a remote offer is set — applies it
|
|
119
|
+
* and returns it. Gathering starts: candidates follow as `candidate` events.
|
|
120
|
+
*
|
|
121
|
+
* @param type Forces the type; inferred from the signalling state otherwise.
|
|
122
|
+
* @throws {WebRtcClosedError} Once closed.
|
|
123
|
+
*/
|
|
124
|
+
setLocalDescription(type) {
|
|
125
|
+
this.assertOpen();
|
|
126
|
+
const description = sessionDescription_(this.native.setLocalDescription(type ?? null));
|
|
127
|
+
// The binding returns the description it just applied, never `null`.
|
|
128
|
+
return description;
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* Applies the peer's offer or answer. An offer is answered by
|
|
132
|
+
* {@link setLocalDescription} next.
|
|
133
|
+
*
|
|
134
|
+
* @throws {WebRtcClosedError} Once closed.
|
|
135
|
+
* @throws {Error} When the description is malformed or out of turn.
|
|
136
|
+
*/
|
|
137
|
+
setRemoteDescription(description) {
|
|
138
|
+
this.assertOpen();
|
|
139
|
+
this.native.setRemoteDescription({
|
|
140
|
+
type: description.type,
|
|
141
|
+
sdp: description.sdp,
|
|
142
|
+
});
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* Adds one remote candidate. A browser's end-of-candidates marker — an empty
|
|
146
|
+
* `candidate` — is ignored.
|
|
147
|
+
*
|
|
148
|
+
* @throws {WebRtcClosedError} Once closed.
|
|
149
|
+
* @throws {Error} When no remote description is set yet, or the candidate is
|
|
150
|
+
* malformed.
|
|
151
|
+
*/
|
|
152
|
+
addIceCandidate(candidate) {
|
|
153
|
+
this.assertOpen();
|
|
154
|
+
if (candidate.candidate === "") {
|
|
155
|
+
return;
|
|
156
|
+
}
|
|
157
|
+
this.native.addRemoteCandidate(candidate.candidate, candidate.sdpMid ?? null);
|
|
158
|
+
}
|
|
159
|
+
/**
|
|
160
|
+
* The DTLS fingerprints of this side's certificate, from the local
|
|
161
|
+
* description: what the peer will check the handshake against. Empty before
|
|
162
|
+
* {@link setLocalDescription}.
|
|
163
|
+
*/
|
|
164
|
+
localFingerprints() {
|
|
165
|
+
const description = this.localDescription;
|
|
166
|
+
return description === null ? [] : parseSdpFingerprints(description.sdp);
|
|
167
|
+
}
|
|
168
|
+
/** The peer's DTLS fingerprints, from the remote description. */
|
|
169
|
+
remoteFingerprints() {
|
|
170
|
+
const description = this.remoteDescription;
|
|
171
|
+
return description === null ? [] : parseSdpFingerprints(description.sdp);
|
|
172
|
+
}
|
|
173
|
+
/**
|
|
174
|
+
* The two ends of the selected candidate pair, `address:port` each, once ICE
|
|
175
|
+
* has connected; `null` before.
|
|
176
|
+
*/
|
|
177
|
+
selectedAddresses() {
|
|
178
|
+
if (this.closed) {
|
|
179
|
+
return null;
|
|
180
|
+
}
|
|
181
|
+
const addresses = this.native.selectedAddresses();
|
|
182
|
+
return addresses === null
|
|
183
|
+
? null
|
|
184
|
+
: { local: addresses[0], remote: addresses[1] };
|
|
185
|
+
}
|
|
186
|
+
/**
|
|
187
|
+
* Creates a data channel. Before the first offer, it is negotiated by that
|
|
188
|
+
* offer; afterwards it opens in-band over the existing association.
|
|
189
|
+
*
|
|
190
|
+
* @throws {WebRtcClosedError} Once closed.
|
|
191
|
+
* @throws {RangeError} When both `maxRetransmits` and `maxPacketLifeTime` are
|
|
192
|
+
* set, or either or `negotiatedId` is out of range.
|
|
193
|
+
*/
|
|
194
|
+
createDataChannel(label, options) {
|
|
195
|
+
this.assertOpen();
|
|
196
|
+
const { maxRetransmits, maxPacketLifeTime, negotiatedId } = options ?? {};
|
|
197
|
+
if (maxRetransmits !== undefined && maxPacketLifeTime !== undefined) {
|
|
198
|
+
throw new RangeError("maxRetransmits and maxPacketLifeTime are exclusive");
|
|
199
|
+
}
|
|
200
|
+
for (const [name, value, max] of [
|
|
201
|
+
["maxRetransmits", maxRetransmits, 0xffff],
|
|
202
|
+
["maxPacketLifeTime", maxPacketLifeTime, 0xffff],
|
|
203
|
+
["negotiatedId", negotiatedId, 65534],
|
|
204
|
+
]) {
|
|
205
|
+
if (value !== undefined &&
|
|
206
|
+
(!Number.isInteger(value) || value < 0 || value > max)) {
|
|
207
|
+
throw new RangeError(`Invalid ${name}: ${value}`);
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
const id = this.native.createDataChannel(label, {
|
|
211
|
+
ordered: options?.ordered ?? true,
|
|
212
|
+
maxRetransmits,
|
|
213
|
+
maxPacketLifeTime,
|
|
214
|
+
protocol: options?.protocol,
|
|
215
|
+
negotiatedId,
|
|
216
|
+
});
|
|
217
|
+
const channel = new WebRtcDataChannel(id, this.owner, this.native.dataChannelInfo(id));
|
|
218
|
+
this.channels.set(id, channel);
|
|
219
|
+
return channel;
|
|
220
|
+
}
|
|
221
|
+
/**
|
|
222
|
+
* Resolves once the connection is `connected`.
|
|
223
|
+
*
|
|
224
|
+
* @throws {WebRtcConnectionFailedError} When it fails or closes first.
|
|
225
|
+
* @throws {unknown} The signal's reason, when aborted first; the connection
|
|
226
|
+
* is left as it is.
|
|
227
|
+
*/
|
|
228
|
+
async connected(signal) {
|
|
229
|
+
if (this.connection === "connected") {
|
|
230
|
+
return;
|
|
231
|
+
}
|
|
232
|
+
if (this.connection === "failed" || this.connection === "closed") {
|
|
233
|
+
throw new WebRtcConnectionFailedError(this.connection);
|
|
234
|
+
}
|
|
235
|
+
const [state] = await this.wait("connectionStateChange", {
|
|
236
|
+
signal,
|
|
237
|
+
predicate: (next) => next === "connected" || next === "failed" || next === "closed",
|
|
238
|
+
});
|
|
239
|
+
if (state !== "connected") {
|
|
240
|
+
throw new WebRtcConnectionFailedError(state === "failed" ? "failed" : "closed");
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
/**
|
|
244
|
+
* Closes every data channel, then the connection, and releases its native
|
|
245
|
+
* resources: each channel emits `close`, then `connectionStateChange`
|
|
246
|
+
* (`closed`) and `close` follow. Idempotent.
|
|
247
|
+
*/
|
|
248
|
+
close() {
|
|
249
|
+
if (this.closed) {
|
|
250
|
+
return;
|
|
251
|
+
}
|
|
252
|
+
this.closed = true;
|
|
253
|
+
this.signal?.removeEventListener("abort", this.handleAbort);
|
|
254
|
+
this.native.close();
|
|
255
|
+
for (const channel of this.channels.values()) {
|
|
256
|
+
channel.handleClosed_(false);
|
|
257
|
+
}
|
|
258
|
+
this.channels.clear();
|
|
259
|
+
this.connection = "closed";
|
|
260
|
+
this.ice = "closed";
|
|
261
|
+
this.dispatch("connectionStateChange", ["closed"]);
|
|
262
|
+
this.dispatch("close", []);
|
|
263
|
+
}
|
|
264
|
+
assertOpen() {
|
|
265
|
+
if (this.closed) {
|
|
266
|
+
throw new WebRtcClosedError("peer connection");
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
handleEvent(event) {
|
|
270
|
+
if (this.closed) {
|
|
271
|
+
return;
|
|
272
|
+
}
|
|
273
|
+
if (event.channel !== undefined) {
|
|
274
|
+
this.handleChannelEvent(event.channel, event);
|
|
275
|
+
return;
|
|
276
|
+
}
|
|
277
|
+
// The binding sends each field its event type implies.
|
|
278
|
+
switch (event.type) {
|
|
279
|
+
case "candidate":
|
|
280
|
+
this.dispatch("candidate", [
|
|
281
|
+
{ candidate: event.candidate, sdpMid: event.mid },
|
|
282
|
+
]);
|
|
283
|
+
break;
|
|
284
|
+
case "state":
|
|
285
|
+
this.connection = event.state;
|
|
286
|
+
this.dispatch("connectionStateChange", [this.connection]);
|
|
287
|
+
break;
|
|
288
|
+
case "iceState":
|
|
289
|
+
this.ice = event.state;
|
|
290
|
+
this.dispatch("iceConnectionStateChange", [this.ice]);
|
|
291
|
+
break;
|
|
292
|
+
case "gatheringState":
|
|
293
|
+
this.gathering = event.state;
|
|
294
|
+
this.dispatch("gatheringStateChange", [this.gathering]);
|
|
295
|
+
break;
|
|
296
|
+
case "signalingState":
|
|
297
|
+
this.signaling = event.state;
|
|
298
|
+
this.dispatch("signalingStateChange", [this.signaling]);
|
|
299
|
+
break;
|
|
300
|
+
default:
|
|
301
|
+
// `description` duplicates what `setLocalDescription` returned.
|
|
302
|
+
break;
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
handleChannelEvent(id, event) {
|
|
306
|
+
// A channel the peer opened is announced by its `open`.
|
|
307
|
+
if (event.type === "open" && !this.channels.has(id)) {
|
|
308
|
+
let info;
|
|
309
|
+
try {
|
|
310
|
+
info = this.native.dataChannelInfo(id);
|
|
311
|
+
}
|
|
312
|
+
catch {
|
|
313
|
+
// Opened and already gone in the same burst — the peer closed it
|
|
314
|
+
// at once: there is nothing left to announce.
|
|
315
|
+
return;
|
|
316
|
+
}
|
|
317
|
+
const channel = new WebRtcDataChannel(id, this.owner, info);
|
|
318
|
+
this.channels.set(id, channel);
|
|
319
|
+
this.dispatch("dataChannel", [channel]);
|
|
320
|
+
}
|
|
321
|
+
this.channels.get(id)?.handleEvent_(event);
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
//# sourceMappingURL=webrtc-peer-connection.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"webrtc-peer-connection.js","sourceRoot":"","sources":["../src/webrtc-peer-connection.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE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|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ac-kit/net-webrtc",
|
|
3
|
-
"version": "0.0.0
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "0.0.0",
|
|
4
|
+
"description": "WebRTC data channels for Node.js, interoperable with browsers: peer connections signalled by the caller, reliable and partially reliable channels, over a native sans-I/O binding to webrtc-rs.",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"datachannel",
|
|
7
|
+
"mdns",
|
|
8
|
+
"nodejs",
|
|
9
|
+
"sctp",
|
|
10
|
+
"stun",
|
|
11
|
+
"webrtc",
|
|
12
|
+
"webrtc-rs"
|
|
13
|
+
],
|
|
14
|
+
"homepage": "https://anthochamp.pages.grenadine.io/node-essentials/api/net-webrtc/",
|
|
15
|
+
"bugs": {
|
|
16
|
+
"url": "https://git.grenadine.io/anthochamp/node-essentials/issues"
|
|
17
|
+
},
|
|
18
|
+
"license": "BSD-3-Clause",
|
|
19
|
+
"author": "Anthony Champagne <dev@anthonychampagne.fr>",
|
|
20
|
+
"repository": {
|
|
21
|
+
"type": "git",
|
|
22
|
+
"url": "git+https://git.grenadine.io/anthochamp/node-essentials.git",
|
|
23
|
+
"directory": "packages/net-webrtc"
|
|
24
|
+
},
|
|
25
|
+
"files": [
|
|
26
|
+
"dist"
|
|
27
|
+
],
|
|
28
|
+
"type": "module",
|
|
29
|
+
"sideEffects": false,
|
|
30
|
+
"main": "./dist/index.js",
|
|
31
|
+
"exports": {
|
|
32
|
+
".": "./dist/index.js"
|
|
33
|
+
},
|
|
34
|
+
"publishConfig": {
|
|
35
|
+
"main": "./dist/index.js",
|
|
36
|
+
"exports": {
|
|
37
|
+
".": "./dist/index.js"
|
|
38
|
+
},
|
|
39
|
+
"access": "public"
|
|
40
|
+
},
|
|
41
|
+
"scripts": {
|
|
42
|
+
"compile": "tsc -p ./tsconfig.build.json -outDir dist",
|
|
43
|
+
"compile:check": "tsc -noEmit -p ./tsconfig.json",
|
|
44
|
+
"clean": "rimraf dist",
|
|
45
|
+
"build": "yarn clean && yarn compile",
|
|
46
|
+
"build-native": "sh ./rust/rtc-node/build.sh",
|
|
47
|
+
"build-native:all": "sh ./rust/rtc-node/build.sh --all",
|
|
48
|
+
"test": "yarn run -T vitest run",
|
|
49
|
+
"prepack": "yarn build"
|
|
50
|
+
},
|
|
51
|
+
"dependencies": {
|
|
52
|
+
"@ac-kit/async": "^0.3.1",
|
|
53
|
+
"@ac-kit/core": "^0.7.0",
|
|
54
|
+
"@ac-kit/net-address": "^0.3.1",
|
|
55
|
+
"@ac-kit/node": "^0.7.0",
|
|
56
|
+
"@types/node": "^26.5.1"
|
|
57
|
+
},
|
|
58
|
+
"devDependencies": {
|
|
59
|
+
"@ac-kit/tsconfig": "0.1.0",
|
|
60
|
+
"@ac-kit/typedoc-config": "0.1.0",
|
|
61
|
+
"@ac-kit/vitest-config": "0.1.1",
|
|
62
|
+
"@typescript/native": "typescript@7.0.2",
|
|
63
|
+
"playwright-core": "1.61.1",
|
|
64
|
+
"rimraf": "6.1.4",
|
|
65
|
+
"typedoc": "0.28.20",
|
|
66
|
+
"typescript": "@typescript/typescript6@6.0.2"
|
|
67
|
+
},
|
|
68
|
+
"optionalDependencies": {
|
|
69
|
+
"@ac-kit/net-webrtc-darwin-arm64": "0.0.0",
|
|
70
|
+
"@ac-kit/net-webrtc-darwin-x64": "0.0.0",
|
|
71
|
+
"@ac-kit/net-webrtc-linux-arm64-gnu": "0.0.0",
|
|
72
|
+
"@ac-kit/net-webrtc-linux-x64-gnu": "0.0.0",
|
|
73
|
+
"@ac-kit/net-webrtc-win32-x64-msvc": "0.0.0"
|
|
74
|
+
},
|
|
75
|
+
"engines": {
|
|
76
|
+
"node": ">=24"
|
|
77
|
+
}
|
|
6
78
|
}
|