werift 0.22.9 → 0.24.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/README.md +46 -0
- package/lib/common/src/transport.d.ts +22 -9
- package/lib/common/src/transport.js +152 -25
- package/lib/common/src/transport.js.map +1 -1
- package/lib/dtls/src/flight/server/flight6.js +12 -2
- package/lib/dtls/src/flight/server/flight6.js.map +1 -1
- package/lib/dtls/src/server.js +6 -1
- package/lib/dtls/src/server.js.map +1 -1
- package/lib/dtls/src/socket.d.ts +1 -0
- package/lib/dtls/src/socket.js +3 -0
- package/lib/dtls/src/socket.js.map +1 -1
- package/lib/ice/src/candidate.d.ts +16 -1
- package/lib/ice/src/candidate.js +99 -15
- package/lib/ice/src/candidate.js.map +1 -1
- package/lib/ice/src/ice.d.ts +2 -0
- package/lib/ice/src/ice.js +171 -41
- package/lib/ice/src/ice.js.map +1 -1
- package/lib/ice/src/iceBase.d.ts +23 -2
- package/lib/ice/src/iceBase.js +63 -1
- package/lib/ice/src/iceBase.js.map +1 -1
- package/lib/ice/src/index.d.ts +2 -0
- package/lib/ice/src/index.js +2 -0
- package/lib/ice/src/index.js.map +1 -1
- package/lib/ice/src/stun/const.d.ts +1 -26
- package/lib/ice/src/stun/const.js +15 -54
- package/lib/ice/src/stun/const.js.map +1 -1
- package/lib/ice/src/stun/message.d.ts +1 -25
- package/lib/ice/src/stun/message.js +15 -149
- package/lib/ice/src/stun/message.js.map +1 -1
- package/lib/ice/src/stun/protocol.d.ts +1 -1
- package/lib/ice/src/stun/protocol.js +2 -2
- package/lib/ice/src/stun/protocol.js.map +1 -1
- package/lib/ice/src/stun/tcpFrame.d.ts +5 -0
- package/lib/ice/src/stun/tcpFrame.js +26 -0
- package/lib/ice/src/stun/tcpFrame.js.map +1 -0
- package/lib/ice/src/stun/tcpProtocol.d.ts +51 -0
- package/lib/ice/src/stun/tcpProtocol.js +326 -0
- package/lib/ice/src/stun/tcpProtocol.js.map +1 -0
- package/lib/ice/src/stun/transaction.d.ts +2 -1
- package/lib/ice/src/stun/transaction.js +9 -3
- package/lib/ice/src/stun/transaction.js.map +1 -1
- package/lib/ice/src/turn/frame.d.ts +1 -0
- package/lib/ice/src/turn/frame.js +18 -0
- package/lib/ice/src/turn/frame.js.map +1 -0
- package/lib/ice/src/turn/protocol.d.ts +9 -7
- package/lib/ice/src/turn/protocol.js +32 -44
- package/lib/ice/src/turn/protocol.js.map +1 -1
- package/lib/ice/src/types/model.d.ts +1 -1
- package/lib/ice/src/types/model.js.map +1 -1
- package/lib/{ice → ice-server}/src/stun/attributes.d.ts +12 -5
- package/lib/{ice → ice-server}/src/stun/attributes.js +60 -19
- package/lib/ice-server/src/stun/attributes.js.map +1 -0
- package/lib/ice-server/src/stun/const.d.ts +28 -0
- package/lib/ice-server/src/stun/const.js +88 -0
- package/lib/ice-server/src/stun/const.js.map +1 -0
- package/lib/ice-server/src/stun/message.d.ts +37 -0
- package/lib/ice-server/src/stun/message.js +190 -0
- package/lib/ice-server/src/stun/message.js.map +1 -0
- package/lib/ice-server/src/turn/auth.d.ts +1 -0
- package/lib/ice-server/src/turn/auth.js +10 -0
- package/lib/ice-server/src/turn/auth.js.map +1 -0
- package/lib/ice-server/src/turn/frame.d.ts +13 -0
- package/lib/ice-server/src/turn/frame.js +69 -0
- package/lib/ice-server/src/turn/frame.js.map +1 -0
- package/lib/index.mjs +3075 -883
- package/lib/nonstandard/index.mjs +1964 -447
- package/lib/rtp/src/extra/container/mp4/container.d.ts +9 -6
- package/lib/rtp/src/extra/container/mp4/container.js +258 -173
- package/lib/rtp/src/extra/container/mp4/container.js.map +1 -1
- package/lib/rtp/src/extra/container/mp4/h264.d.ts +1 -0
- package/lib/rtp/src/extra/container/mp4/h264.js +13 -0
- package/lib/rtp/src/extra/container/mp4/h264.js.map +1 -1
- package/lib/rtp/src/extra/processor/mp4.d.ts +11 -7
- package/lib/rtp/src/extra/processor/mp4.js +115 -60
- package/lib/rtp/src/extra/processor/mp4.js.map +1 -1
- package/lib/rtp/src/extra/processor/mp4Callback.d.ts +2 -3
- package/lib/rtp/src/extra/processor/mp4Callback.js +5 -3
- package/lib/rtp/src/extra/processor/mp4Callback.js.map +1 -1
- package/lib/rtp/src/index.d.ts +1 -0
- package/lib/rtp/src/index.js +1 -0
- package/lib/rtp/src/index.js.map +1 -1
- package/lib/rtp/src/srtp/cipher/ctr.d.ts +3 -3
- package/lib/rtp/src/srtp/cipher/ctr.js +25 -14
- package/lib/rtp/src/srtp/cipher/ctr.js.map +1 -1
- package/lib/rtp/src/srtp/cipher/gcm.d.ts +3 -3
- package/lib/rtp/src/srtp/cipher/gcm.js +57 -20
- package/lib/rtp/src/srtp/cipher/gcm.js.map +1 -1
- package/lib/rtp/src/srtp/cipher/index.d.ts +1 -1
- package/lib/rtp/src/srtp/cipher/index.js +1 -1
- package/lib/rtp/src/srtp/cipher/index.js.map +1 -1
- package/lib/rtp/src/srtp/context/srtp.d.ts +2 -1
- package/lib/rtp/src/srtp/context/srtp.js +22 -5
- package/lib/rtp/src/srtp/context/srtp.js.map +1 -1
- package/lib/rtp/src/srtp/error.d.ts +3 -0
- package/lib/rtp/src/srtp/error.js +11 -0
- package/lib/rtp/src/srtp/error.js.map +1 -0
- package/lib/rtp/src/srtp/packet.d.ts +5 -0
- package/lib/rtp/src/srtp/packet.js +48 -0
- package/lib/rtp/src/srtp/packet.js.map +1 -0
- package/lib/webrtc/src/dataChannel.d.ts +4 -2
- package/lib/webrtc/src/dataChannel.js +14 -4
- package/lib/webrtc/src/dataChannel.js.map +1 -1
- package/lib/webrtc/src/errors.d.ts +3 -0
- package/lib/webrtc/src/errors.js +11 -0
- package/lib/webrtc/src/errors.js.map +1 -0
- package/lib/webrtc/src/helper.d.ts +5 -1
- package/lib/webrtc/src/helper.js +33 -1
- package/lib/webrtc/src/helper.js.map +1 -1
- package/lib/webrtc/src/media/receiver/statistics.d.ts +4 -1
- package/lib/webrtc/src/media/receiver/statistics.js +22 -0
- package/lib/webrtc/src/media/receiver/statistics.js.map +1 -1
- package/lib/webrtc/src/media/rtpReceiver.d.ts +15 -2
- package/lib/webrtc/src/media/rtpReceiver.js +135 -20
- package/lib/webrtc/src/media/rtpReceiver.js.map +1 -1
- package/lib/webrtc/src/media/rtpSender.d.ts +32 -7
- package/lib/webrtc/src/media/rtpSender.js +177 -28
- package/lib/webrtc/src/media/rtpSender.js.map +1 -1
- package/lib/webrtc/src/media/rtpTransceiver.d.ts +13 -4
- package/lib/webrtc/src/media/rtpTransceiver.js +26 -5
- package/lib/webrtc/src/media/rtpTransceiver.js.map +1 -1
- package/lib/webrtc/src/media/stats.d.ts +15 -1
- package/lib/webrtc/src/media/stats.js +55 -1
- package/lib/webrtc/src/media/stats.js.map +1 -1
- package/lib/webrtc/src/media/track.d.ts +2 -1
- package/lib/webrtc/src/media/track.js +7 -1
- package/lib/webrtc/src/media/track.js.map +1 -1
- package/lib/webrtc/src/nonstandard/dummyMedia.d.ts +19 -0
- package/lib/webrtc/src/nonstandard/dummyMedia.js +157 -0
- package/lib/webrtc/src/nonstandard/dummyMedia.js.map +1 -0
- package/lib/webrtc/src/nonstandard/navigator.d.ts +18 -8
- package/lib/webrtc/src/nonstandard/navigator.js +96 -32
- package/lib/webrtc/src/nonstandard/navigator.js.map +1 -1
- package/lib/webrtc/src/nonstandard/userMedia/packetizer.d.ts +16 -0
- package/lib/webrtc/src/nonstandard/userMedia/packetizer.js +360 -0
- package/lib/webrtc/src/nonstandard/userMedia/packetizer.js.map +1 -0
- package/lib/webrtc/src/nonstandard/userMedia.d.ts +71 -31
- package/lib/webrtc/src/nonstandard/userMedia.js +454 -108
- package/lib/webrtc/src/nonstandard/userMedia.js.map +1 -1
- package/lib/webrtc/src/peerConnection.d.ts +185 -49
- package/lib/webrtc/src/peerConnection.js +477 -107
- package/lib/webrtc/src/peerConnection.js.map +1 -1
- package/lib/webrtc/src/sctpManager.d.ts +2 -2
- package/lib/webrtc/src/sctpManager.js +30 -9
- package/lib/webrtc/src/sctpManager.js.map +1 -1
- package/lib/webrtc/src/sdp.d.ts +10 -7
- package/lib/webrtc/src/sdp.js +39 -9
- package/lib/webrtc/src/sdp.js.map +1 -1
- package/lib/webrtc/src/sdpManager.d.ts +5 -4
- package/lib/webrtc/src/sdpManager.js +53 -31
- package/lib/webrtc/src/sdpManager.js.map +1 -1
- package/lib/webrtc/src/secureTransportManager.d.ts +13 -4
- package/lib/webrtc/src/secureTransportManager.js +101 -23
- package/lib/webrtc/src/secureTransportManager.js.map +1 -1
- package/lib/webrtc/src/transceiverManager.d.ts +5 -4
- package/lib/webrtc/src/transceiverManager.js +64 -64
- package/lib/webrtc/src/transceiverManager.js.map +1 -1
- package/lib/webrtc/src/transport/dtls.d.ts +16 -4
- package/lib/webrtc/src/transport/dtls.js +208 -35
- package/lib/webrtc/src/transport/dtls.js.map +1 -1
- package/lib/webrtc/src/transport/ice.d.ts +21 -3
- package/lib/webrtc/src/transport/ice.js +159 -30
- package/lib/webrtc/src/transport/ice.js.map +1 -1
- package/lib/webrtc/src/transport/sctp.d.ts +10 -3
- package/lib/webrtc/src/transport/sctp.js +44 -13
- package/lib/webrtc/src/transport/sctp.js.map +1 -1
- package/lib/webrtc/src/utils.d.ts +14 -4
- package/lib/webrtc/src/utils.js +138 -16
- package/lib/webrtc/src/utils.js.map +1 -1
- package/package.json +7 -4
- package/lib/ice/src/stun/attributes.js.map +0 -1
- package/lib/rtp/src/extra/container/mp4/mp4box.d.ts +0 -5
- package/lib/rtp/src/extra/container/mp4/mp4box.js +0 -32
- package/lib/rtp/src/extra/container/mp4/mp4box.js.map +0 -1
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
export type TcpCandidateType = "active" | "passive" | "so";
|
|
1
2
|
export declare class Candidate {
|
|
2
3
|
foundation: string;
|
|
3
4
|
component: number;
|
|
@@ -11,10 +12,24 @@ export declare class Candidate {
|
|
|
11
12
|
tcptype?: string | undefined;
|
|
12
13
|
generation?: number | undefined;
|
|
13
14
|
ufrag?: string | undefined;
|
|
15
|
+
id: string;
|
|
14
16
|
constructor(foundation: string, component: number, transport: string, priority: number, host: string, port: number, type: string, relatedAddress?: string | undefined, relatedPort?: number | undefined, tcptype?: string | undefined, generation?: number | undefined, ufrag?: string | undefined);
|
|
17
|
+
refreshId(): void;
|
|
15
18
|
static fromSdp(sdp: string): Candidate;
|
|
16
19
|
canPairWith(other: Candidate): boolean;
|
|
17
20
|
toSdp(): string;
|
|
18
21
|
}
|
|
22
|
+
export declare function candidateLocalPreference({ candidateType, transport, tcptype, otherPreference, }: {
|
|
23
|
+
candidateType: string;
|
|
24
|
+
transport?: string;
|
|
25
|
+
tcptype?: string;
|
|
26
|
+
otherPreference?: number;
|
|
27
|
+
}): number;
|
|
19
28
|
export declare function candidateFoundation(candidateType: string, candidateTransport: string, baseAddress: string): string;
|
|
20
|
-
export declare function candidatePriority(candidateType: string,
|
|
29
|
+
export declare function candidatePriority(candidateType: string, options?: number | {
|
|
30
|
+
transport?: string;
|
|
31
|
+
tcptype?: string;
|
|
32
|
+
localPreference?: number;
|
|
33
|
+
otherPreference?: number;
|
|
34
|
+
}): number;
|
|
35
|
+
export declare function remoteTcpTypeForIncoming(localTcpType?: string): TcpCandidateType;
|
package/lib/ice/src/candidate.js
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.Candidate = void 0;
|
|
4
|
+
exports.candidateLocalPreference = candidateLocalPreference;
|
|
4
5
|
exports.candidateFoundation = candidateFoundation;
|
|
5
6
|
exports.candidatePriority = candidatePriority;
|
|
7
|
+
exports.remoteTcpTypeForIncoming = remoteTcpTypeForIncoming;
|
|
6
8
|
const crypto_1 = require("crypto");
|
|
7
9
|
const net_1 = require("net");
|
|
8
10
|
class Candidate {
|
|
9
|
-
// An ICE candidate.
|
|
10
11
|
constructor(foundation, component, transport, priority, host, port, type, relatedAddress, relatedPort, tcptype, generation, ufrag) {
|
|
11
12
|
Object.defineProperty(this, "foundation", {
|
|
12
13
|
enumerable: true,
|
|
@@ -80,6 +81,16 @@ class Candidate {
|
|
|
80
81
|
writable: true,
|
|
81
82
|
value: ufrag
|
|
82
83
|
});
|
|
84
|
+
// An ICE candidate.
|
|
85
|
+
Object.defineProperty(this, "id", {
|
|
86
|
+
enumerable: true,
|
|
87
|
+
configurable: true,
|
|
88
|
+
writable: true,
|
|
89
|
+
value: (0, crypto_1.randomUUID)().toString()
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
refreshId() {
|
|
93
|
+
this.id = (0, crypto_1.randomUUID)().toString();
|
|
83
94
|
}
|
|
84
95
|
static fromSdp(sdp) {
|
|
85
96
|
// Parse a :class:`Candidate` from SDP.
|
|
@@ -130,6 +141,7 @@ class Candidate {
|
|
|
130
141
|
const b = (0, net_1.isIPv4)(other.host);
|
|
131
142
|
return (this.component === other.component &&
|
|
132
143
|
this.transport.toLowerCase() === other.transport.toLowerCase() &&
|
|
144
|
+
canPairTcpCandidates(this, other) &&
|
|
133
145
|
a === b);
|
|
134
146
|
}
|
|
135
147
|
toSdp() {
|
|
@@ -148,6 +160,70 @@ class Candidate {
|
|
|
148
160
|
}
|
|
149
161
|
}
|
|
150
162
|
exports.Candidate = Candidate;
|
|
163
|
+
const UDP_TYPE_PREFERENCE = {
|
|
164
|
+
host: 126,
|
|
165
|
+
prflx: 110,
|
|
166
|
+
srflx: 100,
|
|
167
|
+
relay: 0,
|
|
168
|
+
};
|
|
169
|
+
const TCP_TYPE_PREFERENCE = {
|
|
170
|
+
host: 105,
|
|
171
|
+
prflx: 90,
|
|
172
|
+
srflx: 80,
|
|
173
|
+
relay: 0,
|
|
174
|
+
};
|
|
175
|
+
const ACTIVE_PASSIVE_DIRECTION_PREFERENCE = {
|
|
176
|
+
active: 6,
|
|
177
|
+
passive: 4,
|
|
178
|
+
so: 2,
|
|
179
|
+
};
|
|
180
|
+
const REFLEXIVE_DIRECTION_PREFERENCE = {
|
|
181
|
+
active: 4,
|
|
182
|
+
passive: 2,
|
|
183
|
+
so: 6,
|
|
184
|
+
};
|
|
185
|
+
function normalizeTransport(transport) {
|
|
186
|
+
return transport?.toLowerCase() ?? "udp";
|
|
187
|
+
}
|
|
188
|
+
function normalizeTcpType(tcptype) {
|
|
189
|
+
switch (tcptype) {
|
|
190
|
+
case "active":
|
|
191
|
+
case "passive":
|
|
192
|
+
case "so":
|
|
193
|
+
return tcptype;
|
|
194
|
+
default:
|
|
195
|
+
return undefined;
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
function canPairTcpCandidates(local, remote) {
|
|
199
|
+
if (normalizeTransport(local.transport) !== "tcp") {
|
|
200
|
+
return true;
|
|
201
|
+
}
|
|
202
|
+
const localType = normalizeTcpType(local.tcptype);
|
|
203
|
+
const remoteType = normalizeTcpType(remote.tcptype);
|
|
204
|
+
if (!localType || !remoteType) {
|
|
205
|
+
return false;
|
|
206
|
+
}
|
|
207
|
+
return ((localType === "active" && remoteType === "passive") ||
|
|
208
|
+
(localType === "passive" && remoteType === "active") ||
|
|
209
|
+
(localType === "so" && remoteType === "so"));
|
|
210
|
+
}
|
|
211
|
+
function candidateLocalPreference({ candidateType, transport = "udp", tcptype, otherPreference = 8191, }) {
|
|
212
|
+
if (normalizeTransport(transport) !== "tcp") {
|
|
213
|
+
return otherPreference;
|
|
214
|
+
}
|
|
215
|
+
const tcpType = normalizeTcpType(tcptype) ?? "active";
|
|
216
|
+
const directionPreference = candidateType === "srflx" || candidateType === "prflx"
|
|
217
|
+
? REFLEXIVE_DIRECTION_PREFERENCE[tcpType]
|
|
218
|
+
: ACTIVE_PASSIVE_DIRECTION_PREFERENCE[tcpType];
|
|
219
|
+
return (1 << 13) * directionPreference + otherPreference;
|
|
220
|
+
}
|
|
221
|
+
function candidateTypePreference(candidateType, transport = "udp") {
|
|
222
|
+
const table = normalizeTransport(transport) === "tcp"
|
|
223
|
+
? TCP_TYPE_PREFERENCE
|
|
224
|
+
: UDP_TYPE_PREFERENCE;
|
|
225
|
+
return table[candidateType] ?? 0;
|
|
226
|
+
}
|
|
151
227
|
function candidateFoundation(candidateType, candidateTransport, baseAddress) {
|
|
152
228
|
// """
|
|
153
229
|
// See RFC 5245 - 4.1.1.3. Computing Foundations
|
|
@@ -156,22 +232,30 @@ function candidateFoundation(candidateType, candidateTransport, baseAddress) {
|
|
|
156
232
|
return (0, crypto_1.createHash)("md5").update(key, "ascii").digest("hex").slice(7);
|
|
157
233
|
}
|
|
158
234
|
// priorityを決める
|
|
159
|
-
function candidatePriority(candidateType,
|
|
235
|
+
function candidatePriority(candidateType, options = 65535) {
|
|
160
236
|
const candidateComponent = 1;
|
|
161
237
|
// See RFC 5245 - 4.1.2.1. Recommended Formula
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
typePref = 0;
|
|
174
|
-
}
|
|
238
|
+
const transport = typeof options === "number" ? "udp" : normalizeTransport(options.transport);
|
|
239
|
+
const localPref = typeof options === "number"
|
|
240
|
+
? options
|
|
241
|
+
: (options.localPreference ??
|
|
242
|
+
candidateLocalPreference({
|
|
243
|
+
candidateType,
|
|
244
|
+
transport,
|
|
245
|
+
tcptype: options.tcptype,
|
|
246
|
+
otherPreference: options.otherPreference,
|
|
247
|
+
}));
|
|
248
|
+
const typePref = candidateTypePreference(candidateType, transport);
|
|
175
249
|
return ((1 << 24) * typePref + (1 << 8) * localPref + (256 - candidateComponent));
|
|
176
250
|
}
|
|
251
|
+
function remoteTcpTypeForIncoming(localTcpType) {
|
|
252
|
+
switch (localTcpType) {
|
|
253
|
+
case "passive":
|
|
254
|
+
return "active";
|
|
255
|
+
case "active":
|
|
256
|
+
return "passive";
|
|
257
|
+
default:
|
|
258
|
+
return "so";
|
|
259
|
+
}
|
|
260
|
+
}
|
|
177
261
|
//# sourceMappingURL=candidate.js.map
|
|
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nimport { isIPv4 } from \"net\";\n\nexport class Candidate {\n // An ICE candidate.\n\n constructor(\n public foundation: string,\n public component: number,\n public transport: string,\n public priority: number,\n public host: string,\n public port: number,\n public type: string,\n public relatedAddress?: string,\n public relatedPort?: number,\n public tcptype?: string,\n public generation?: number,\n public ufrag?: string,\n ) {}\n\n static fromSdp(sdp: string) {\n // Parse a :class:`Candidate` from SDP.\n // .. code-block:: python\n // Candidate.from_sdp(\n // '6815297761 1 udp 659136 1.2.3.4 31102 typ host generation 0 ufrag b7l3')\n\n const bits = sdp.split(\" \");\n if (bits.length < 8) {\n throw new Error(\"SDP does not have enough properties\");\n }\n\n // 固定ワード\n const kwargs = {\n foundation: bits[0],\n component: Number(bits[1]),\n transport: bits[2],\n priority: Number(bits[3]),\n host: bits[4],\n port: Number(bits[5]),\n type: bits[7],\n };\n\n for (let i = 8, il = bits.length - 1; i < il; i += 2) {\n if (bits[i] === \"raddr\") {\n (kwargs as any)[\"related_address\"] = bits[i + 1];\n } else if (bits[i] === \"rport\") {\n (kwargs as any)[\"related_port\"] = Number(bits[i + 1]);\n } else if (bits[i] === \"tcptype\") {\n (kwargs as any)[\"tcptype\"] = bits[i + 1];\n } else if (bits[i] === \"generation\") {\n (kwargs as any)[\"generation\"] = Number(bits[i + 1]);\n } else if (bits[i] === \"ufrag\") {\n (kwargs as any)[\"ufrag\"] = bits[i + 1];\n }\n }\n const { foundation, component, transport, priority, host, port, type } =\n kwargs;\n\n return new Candidate(\n foundation,\n component,\n transport,\n priority,\n host,\n port,\n type,\n (kwargs as any)[\"related_address\"],\n (kwargs as any)[\"related_port\"],\n (kwargs as any)[\"tcptype\"],\n (kwargs as any)[\"generation\"],\n (kwargs as any)[\"ufrag\"],\n );\n }\n\n canPairWith(other: Candidate) {\n // \"\"\"\n // A local candidate is paired with a remote candidate if and only if\n // the two candidates have the same component ID and have the same IP\n // address version.\n // \"\"\"\n const a = isIPv4(this.host);\n const b = isIPv4(other.host);\n return (\n this.component === other.component &&\n this.transport.toLowerCase() === other.transport.toLowerCase() &&\n a === b\n );\n }\n\n toSdp() {\n let sdp = `${this.foundation} ${this.component} ${this.transport} ${this.priority} ${this.host} ${this.port} typ ${this.type}`;\n\n if (this.relatedAddress) sdp += ` raddr ${this.relatedAddress}`;\n if (this.relatedPort != undefined) sdp += ` rport ${this.relatedPort}`;\n if (this.tcptype) sdp += ` tcptype ${this.tcptype}`;\n if (this.generation != undefined) sdp += ` generation ${this.generation}`;\n if (this.ufrag != undefined) sdp += ` ufrag ${this.ufrag}`;\n\n return sdp;\n }\n}\n\nexport function candidateFoundation(\n candidateType: string,\n candidateTransport: string,\n baseAddress: string,\n) {\n // \"\"\"\n // See RFC 5245 - 4.1.1.3. Computing Foundations\n // \"\"\"\n const key = `${candidateType}|${candidateTransport}|${baseAddress}`;\n\n return createHash(\"md5\").update(key, \"ascii\").digest(\"hex\").slice(7);\n}\n\n// priorityを決める\nexport function candidatePriority(candidateType: string, localPref = 65535) {\n const candidateComponent: number = 1;\n // See RFC 5245 - 4.1.2.1. Recommended Formula\n let typePref = 0;\n if (candidateType === \"host\") {\n typePref = 126;\n } else if (candidateType === \"prflx\") {\n typePref = 110;\n } else if (candidateType === \"srflx\") {\n typePref = 100;\n } else {\n typePref = 0;\n }\n return (\n (1 << 24) * typePref + (1 << 8) * localPref + (256 - candidateComponent)\n );\n}\n"]}
|
|
1
|
+
{"version":3,"file":"candidate.js","sourceRoot":"","sources":["../../../../ice/src/candidate.ts"],"names":[],"mappings":";;;AA0KA,4DAsBC;AAUD,kDAWC;AAGD,8CA6BC;AAED,4DAWC;AAlQD,mCAAgD;AAChD,6BAA6B;AAI7B,MAAa,SAAS;IAIpB,YACS,UAAkB,EAClB,SAAiB,EACjB,SAAiB,EACjB,QAAgB,EAChB,IAAY,EACZ,IAAY,EACZ,IAAY,EACZ,cAAuB,EACvB,WAAoB,EACpB,OAAgB,EAChB,UAAmB,EACnB,KAAc;QAXrB;;;;mBAAO,UAAU;WAAQ;QACzB;;;;mB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CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;AACvE,CAAC;AAED,eAAe;AACf,SAAgB,iBAAiB,CAC/B,aAAqB,EACrB,UAOQ,KAAK;IAEb,MAAM,kBAAkB,GAAW,CAAC,CAAC;IACrC,8CAA8C;IAC9C,MAAM,SAAS,GACb,OAAO,OAAO,KAAK,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,kBAAkB,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC;IAC9E,MAAM,SAAS,GACb,OAAO,OAAO,KAAK,QAAQ;QACzB,CAAC,CAAC,OAAO;QACT,CAAC,CAAC,CAAC,OAAO,CAAC,eAAe;YACxB,wBAAwB,CAAC;gBACvB,aAAa;gBACb,SAAS;gBACT,OAAO,EAAE,OAAO,CAAC,OAAO;gBACxB,eAAe,EAAE,OAAO,CAAC,eAAe;aACzC,CAAC,CAAC,CAAC;IACV,MAAM,QAAQ,GAAG,uBAAuB,CAAC,aAAa,EAAE,SAAS,CAAC,CAAC;IACnE,OAAO,CACL,CAAC,CAAC,IAAI,EAAE,CAAC,GAAG,QAAQ,GAAG,CAAC,CAAC,IAAI,CAAC,CAAC,GAAG,SAAS,GAAG,CAAC,GAAG,GAAG,kBAAkB,CAAC,CACzE,CAAC;AACJ,CAAC;AAED,SAAgB,wBAAwB,CACtC,YAAqB;IAErB,QAAQ,YAAY,EAAE,CAAC;QACrB,KAAK,SAAS;YACZ,OAAO,QAAQ,CAAC;QAClB,KAAK,QAAQ;YACX,OAAO,SAAS,CAAC;QACnB;YACE,OAAO,IAAI,CAAC;IAChB,CAAC;AACH,CAAC","sourcesContent":["import { createHash, randomUUID } from \"crypto\";\nimport { isIPv4 } from \"net\";\n\nexport type TcpCandidateType = \"active\" | \"passive\" | \"so\";\n\nexport class Candidate {\n // An ICE candidate.\n id = randomUUID().toString();\n\n constructor(\n public foundation: string,\n public component: number,\n public transport: string,\n public priority: number,\n public host: string,\n public port: number,\n public type: string,\n public relatedAddress?: string,\n public relatedPort?: number,\n public tcptype?: string,\n public generation?: number,\n public ufrag?: string,\n ) {}\n\n refreshId() {\n this.id = randomUUID().toString();\n }\n\n static fromSdp(sdp: string) {\n // Parse a :class:`Candidate` from SDP.\n // .. code-block:: python\n // Candidate.from_sdp(\n // '6815297761 1 udp 659136 1.2.3.4 31102 typ host generation 0 ufrag b7l3')\n\n const bits = sdp.split(\" \");\n if (bits.length < 8) {\n throw new Error(\"SDP does not have enough properties\");\n }\n\n // 固定ワード\n const kwargs = {\n foundation: bits[0],\n component: Number(bits[1]),\n transport: bits[2],\n priority: Number(bits[3]),\n host: bits[4],\n port: Number(bits[5]),\n type: bits[7],\n };\n\n for (let i = 8, il = bits.length - 1; i < il; i += 2) {\n if (bits[i] === \"raddr\") {\n (kwargs as any)[\"related_address\"] = bits[i + 1];\n } else if (bits[i] === \"rport\") {\n (kwargs as any)[\"related_port\"] = Number(bits[i + 1]);\n } else if (bits[i] === \"tcptype\") {\n (kwargs as any)[\"tcptype\"] = bits[i + 1];\n } else if (bits[i] === \"generation\") {\n (kwargs as any)[\"generation\"] = Number(bits[i + 1]);\n } else if (bits[i] === \"ufrag\") {\n (kwargs as any)[\"ufrag\"] = bits[i + 1];\n }\n }\n const { foundation, component, transport, priority, host, port, type } =\n kwargs;\n\n return new Candidate(\n foundation,\n component,\n transport,\n priority,\n host,\n port,\n type,\n (kwargs as any)[\"related_address\"],\n (kwargs as any)[\"related_port\"],\n (kwargs as any)[\"tcptype\"],\n (kwargs as any)[\"generation\"],\n (kwargs as any)[\"ufrag\"],\n );\n }\n\n canPairWith(other: Candidate) {\n // \"\"\"\n // A local candidate is paired with a remote candidate if and only if\n // the two candidates have the same component ID and have the same IP\n // address version.\n // \"\"\"\n const a = isIPv4(this.host);\n const b = isIPv4(other.host);\n return (\n this.component === other.component &&\n this.transport.toLowerCase() === other.transport.toLowerCase() &&\n canPairTcpCandidates(this, other) &&\n a === b\n );\n }\n\n toSdp() {\n let sdp = `${this.foundation} ${this.component} ${this.transport} ${this.priority} ${this.host} ${this.port} typ ${this.type}`;\n\n if (this.relatedAddress) sdp += ` raddr ${this.relatedAddress}`;\n if (this.relatedPort != undefined) sdp += ` rport ${this.relatedPort}`;\n if (this.tcptype) sdp += ` tcptype ${this.tcptype}`;\n if (this.generation != undefined) sdp += ` generation ${this.generation}`;\n if (this.ufrag != undefined) sdp += ` ufrag ${this.ufrag}`;\n\n return sdp;\n }\n}\n\nconst UDP_TYPE_PREFERENCE: Record<string, number> = {\n host: 126,\n prflx: 110,\n srflx: 100,\n relay: 0,\n};\n\nconst TCP_TYPE_PREFERENCE: Record<string, number> = {\n host: 105,\n prflx: 90,\n srflx: 80,\n relay: 0,\n};\n\nconst ACTIVE_PASSIVE_DIRECTION_PREFERENCE: Record<TcpCandidateType, number> = {\n active: 6,\n passive: 4,\n so: 2,\n};\n\nconst REFLEXIVE_DIRECTION_PREFERENCE: Record<TcpCandidateType, number> = {\n active: 4,\n passive: 2,\n so: 6,\n};\n\nfunction normalizeTransport(transport?: string) {\n return transport?.toLowerCase() ?? \"udp\";\n}\n\nfunction normalizeTcpType(tcptype?: string) {\n switch (tcptype) {\n case \"active\":\n case \"passive\":\n case \"so\":\n return tcptype;\n default:\n return undefined;\n }\n}\n\nfunction canPairTcpCandidates(local: Candidate, remote: Candidate) {\n if (normalizeTransport(local.transport) !== \"tcp\") {\n return true;\n }\n\n const localType = normalizeTcpType(local.tcptype);\n const remoteType = normalizeTcpType(remote.tcptype);\n if (!localType || !remoteType) {\n return false;\n }\n\n return (\n (localType === \"active\" && remoteType === \"passive\") ||\n (localType === \"passive\" && remoteType === \"active\") ||\n (localType === \"so\" && remoteType === \"so\")\n );\n}\n\nexport function candidateLocalPreference({\n candidateType,\n transport = \"udp\",\n tcptype,\n otherPreference = 8191,\n}: {\n candidateType: string;\n transport?: string;\n tcptype?: string;\n otherPreference?: number;\n}) {\n if (normalizeTransport(transport) !== \"tcp\") {\n return otherPreference;\n }\n\n const tcpType = normalizeTcpType(tcptype) ?? \"active\";\n const directionPreference =\n candidateType === \"srflx\" || candidateType === \"prflx\"\n ? REFLEXIVE_DIRECTION_PREFERENCE[tcpType]\n : ACTIVE_PASSIVE_DIRECTION_PREFERENCE[tcpType];\n\n return (1 << 13) * directionPreference + otherPreference;\n}\n\nfunction candidateTypePreference(candidateType: string, transport = \"udp\") {\n const table =\n normalizeTransport(transport) === \"tcp\"\n ? TCP_TYPE_PREFERENCE\n : UDP_TYPE_PREFERENCE;\n return table[candidateType] ?? 0;\n}\n\nexport function candidateFoundation(\n candidateType: string,\n candidateTransport: string,\n baseAddress: string,\n) {\n // \"\"\"\n // See RFC 5245 - 4.1.1.3. Computing Foundations\n // \"\"\"\n const key = `${candidateType}|${candidateTransport}|${baseAddress}`;\n\n return createHash(\"md5\").update(key, \"ascii\").digest(\"hex\").slice(7);\n}\n\n// priorityを決める\nexport function candidatePriority(\n candidateType: string,\n options:\n | number\n | {\n transport?: string;\n tcptype?: string;\n localPreference?: number;\n otherPreference?: number;\n } = 65535,\n) {\n const candidateComponent: number = 1;\n // See RFC 5245 - 4.1.2.1. Recommended Formula\n const transport =\n typeof options === \"number\" ? \"udp\" : normalizeTransport(options.transport);\n const localPref =\n typeof options === \"number\"\n ? options\n : (options.localPreference ??\n candidateLocalPreference({\n candidateType,\n transport,\n tcptype: options.tcptype,\n otherPreference: options.otherPreference,\n }));\n const typePref = candidateTypePreference(candidateType, transport);\n return (\n (1 << 24) * typePref + (1 << 8) * localPref + (256 - candidateComponent)\n );\n}\n\nexport function remoteTcpTypeForIncoming(\n localTcpType?: string,\n): TcpCandidateType {\n switch (localTcpType) {\n case \"passive\":\n return \"active\";\n case \"active\":\n return \"passive\";\n default:\n return \"so\";\n }\n}\n"]}
|
package/lib/ice/src/ice.d.ts
CHANGED
|
@@ -41,6 +41,7 @@ export declare class Connection implements IceConnection {
|
|
|
41
41
|
constructor(_iceControlling: boolean, options?: Partial<IceOptions>);
|
|
42
42
|
get iceControlling(): boolean;
|
|
43
43
|
set iceControlling(value: boolean);
|
|
44
|
+
get iceLite(): boolean;
|
|
44
45
|
restart(): Promise<void>;
|
|
45
46
|
resetNominatedPair(): void;
|
|
46
47
|
setRemoteParams({ iceLite, usernameFragment, password, }: {
|
|
@@ -79,5 +80,6 @@ export declare class Connection implements IceConnection {
|
|
|
79
80
|
private pairLocalProtocol;
|
|
80
81
|
private pairRemoteCandidate;
|
|
81
82
|
private buildRequest;
|
|
83
|
+
private pruneTcpConnections;
|
|
82
84
|
private respondError;
|
|
83
85
|
}
|
package/lib/ice/src/ice.js
CHANGED
|
@@ -50,6 +50,7 @@ const iceBase_1 = require("./iceBase");
|
|
|
50
50
|
const const_1 = require("./stun/const");
|
|
51
51
|
const message_1 = require("./stun/message");
|
|
52
52
|
const protocol_1 = require("./stun/protocol");
|
|
53
|
+
const tcpProtocol_1 = require("./stun/tcpProtocol");
|
|
53
54
|
const protocol_2 = require("./turn/protocol");
|
|
54
55
|
const utils_1 = require("./utils");
|
|
55
56
|
const log = (0, common_1.debug)("werift-ice : packages/ice/src/ice.ts : log");
|
|
@@ -248,6 +249,9 @@ class Connection {
|
|
|
248
249
|
configurable: true,
|
|
249
250
|
writable: true,
|
|
250
251
|
value: () => {
|
|
252
|
+
if (this.iceLite) {
|
|
253
|
+
return;
|
|
254
|
+
}
|
|
251
255
|
if (this.queryConsentHandle) {
|
|
252
256
|
this.queryConsentHandle.resolve();
|
|
253
257
|
}
|
|
@@ -278,9 +282,17 @@ class Connection {
|
|
|
278
282
|
localUsername,
|
|
279
283
|
remoteUsername,
|
|
280
284
|
iceControlling,
|
|
285
|
+
localCandidate: nominated.localCandidate,
|
|
281
286
|
});
|
|
282
287
|
try {
|
|
283
|
-
|
|
288
|
+
nominated.consentRequestsSent++;
|
|
289
|
+
nominated.requestsSent++;
|
|
290
|
+
await nominated.protocol.request(request, nominated.remoteAddr, Buffer.from(this.remotePassword, "utf8"), 0, (attempt) => {
|
|
291
|
+
if (attempt > 0) {
|
|
292
|
+
nominated.retransmissionsSent++;
|
|
293
|
+
}
|
|
294
|
+
});
|
|
295
|
+
nominated.responsesReceived++;
|
|
284
296
|
failures = 0;
|
|
285
297
|
if (this.state === "disconnected") {
|
|
286
298
|
this.setState("connected");
|
|
@@ -344,11 +356,18 @@ class Connection {
|
|
|
344
356
|
localUsername,
|
|
345
357
|
remoteUsername,
|
|
346
358
|
iceControlling: this.iceControlling,
|
|
359
|
+
localCandidate: pair.localCandidate,
|
|
347
360
|
});
|
|
348
361
|
// Record start time for RTT calculation
|
|
349
362
|
const startTime = performance.now();
|
|
350
363
|
try {
|
|
351
|
-
|
|
364
|
+
pair.requestsSent++;
|
|
365
|
+
const [response, addr] = await pair.protocol.request(request, pair.remoteAddr, Buffer.from(remotePassword, "utf8"), pair.localCandidate.transport.toLowerCase() === "tcp" ? 0 : 4, (attempt) => {
|
|
366
|
+
if (attempt > 0) {
|
|
367
|
+
pair.retransmissionsSent++;
|
|
368
|
+
}
|
|
369
|
+
});
|
|
370
|
+
pair.responsesReceived++;
|
|
352
371
|
// Calculate RTT
|
|
353
372
|
const endTime = performance.now();
|
|
354
373
|
const rtt = (endTime - startTime) / 1000; // Convert to seconds
|
|
@@ -421,9 +440,16 @@ class Connection {
|
|
|
421
440
|
localUsername,
|
|
422
441
|
remoteUsername,
|
|
423
442
|
iceControlling: this.iceControlling,
|
|
443
|
+
localCandidate: pair.localCandidate,
|
|
424
444
|
});
|
|
425
445
|
try {
|
|
426
|
-
|
|
446
|
+
pair.requestsSent++;
|
|
447
|
+
await pair.protocol.request(request, pair.remoteAddr, Buffer.from(this.remotePassword, "utf8"), pair.localCandidate.transport.toLowerCase() === "tcp" ? 0 : 4, (attempt) => {
|
|
448
|
+
if (attempt > 0) {
|
|
449
|
+
pair.retransmissionsSent++;
|
|
450
|
+
}
|
|
451
|
+
});
|
|
452
|
+
pair.responsesReceived++;
|
|
427
453
|
}
|
|
428
454
|
catch (error) {
|
|
429
455
|
pair.updateState(iceBase_1.CandidatePairState.FAILED);
|
|
@@ -451,6 +477,9 @@ class Connection {
|
|
|
451
477
|
...iceBase_1.defaultOptions,
|
|
452
478
|
...options,
|
|
453
479
|
};
|
|
480
|
+
if (this.iceLite) {
|
|
481
|
+
this._iceControlling = false;
|
|
482
|
+
}
|
|
454
483
|
const { stunServer, turnServer } = this.options;
|
|
455
484
|
this.stunServer = (0, iceBase_1.validateAddress)(stunServer) ?? [
|
|
456
485
|
"stun.l.google.com",
|
|
@@ -464,6 +493,9 @@ class Connection {
|
|
|
464
493
|
return this._iceControlling;
|
|
465
494
|
}
|
|
466
495
|
set iceControlling(value) {
|
|
496
|
+
if (this.iceLite) {
|
|
497
|
+
value = false;
|
|
498
|
+
}
|
|
467
499
|
if (this.generation > 0 || this.nominated) {
|
|
468
500
|
return;
|
|
469
501
|
}
|
|
@@ -472,6 +504,9 @@ class Connection {
|
|
|
472
504
|
pair.iceControlling = value;
|
|
473
505
|
}
|
|
474
506
|
}
|
|
507
|
+
get iceLite() {
|
|
508
|
+
return this.options.iceLite;
|
|
509
|
+
}
|
|
475
510
|
async restart() {
|
|
476
511
|
this.generation++;
|
|
477
512
|
this.localUsername = (0, helper_1.randomString)(4);
|
|
@@ -502,6 +537,7 @@ class Connection {
|
|
|
502
537
|
// protocolsはincomingのearlyCheckに使うかもしれないので残す
|
|
503
538
|
for (const protocol of this.protocols) {
|
|
504
539
|
if (protocol.localCandidate) {
|
|
540
|
+
protocol.localCandidate.refreshId();
|
|
505
541
|
protocol.localCandidate.generation = this.generation;
|
|
506
542
|
protocol.localCandidate.ufrag = this.localUsername;
|
|
507
543
|
}
|
|
@@ -570,8 +606,10 @@ class Connection {
|
|
|
570
606
|
}
|
|
571
607
|
else if (!iceControlling &&
|
|
572
608
|
msg.attributesKeys.includes("ICE-CONTROLLED")) {
|
|
573
|
-
if (this.
|
|
609
|
+
if (this.iceLite ||
|
|
610
|
+
this.tieBreaker < msg.getAttributeValue("ICE-CONTROLLED")) {
|
|
574
611
|
this.respondError(msg, addr, protocol, [487, "Role Conflict"]);
|
|
612
|
+
return;
|
|
575
613
|
}
|
|
576
614
|
else {
|
|
577
615
|
this.switchRole(true);
|
|
@@ -614,7 +652,15 @@ class Connection {
|
|
|
614
652
|
});
|
|
615
653
|
}
|
|
616
654
|
getCandidatePromises(addresses, timeout = 5) {
|
|
617
|
-
|
|
655
|
+
const candidatePromises = [];
|
|
656
|
+
const { stunServer, turnServer } = this;
|
|
657
|
+
const { turnUsername, turnPassword } = this.options;
|
|
658
|
+
const gatherIceLite = this.iceLite;
|
|
659
|
+
const gatherRelayOnly = !gatherIceLite &&
|
|
660
|
+
this.options.forceTurn &&
|
|
661
|
+
turnServer &&
|
|
662
|
+
turnUsername &&
|
|
663
|
+
turnPassword;
|
|
618
664
|
addresses = addresses.filter((address) => {
|
|
619
665
|
// ice restartで同じアドレスが追加されるのを防ぐ
|
|
620
666
|
if (this.protocols.find((protocol) => protocol.localIp === address)) {
|
|
@@ -622,29 +668,63 @@ class Connection {
|
|
|
622
668
|
}
|
|
623
669
|
return true;
|
|
624
670
|
});
|
|
625
|
-
const localStunPromises =
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
671
|
+
const localStunPromises = gatherRelayOnly
|
|
672
|
+
? []
|
|
673
|
+
: addresses.map(async (address) => {
|
|
674
|
+
// # create transport
|
|
675
|
+
const protocol = new protocol_1.StunProtocol();
|
|
676
|
+
this.ensureProtocol(protocol);
|
|
677
|
+
try {
|
|
678
|
+
await protocol.connectionMade((0, net_1.isIPv4)(address), this.options.portRange, this.options.interfaceAddresses);
|
|
679
|
+
protocol.localIp = address;
|
|
680
|
+
this.protocols.push(protocol);
|
|
681
|
+
log("protocol", protocol.localIp);
|
|
682
|
+
// # add host candidate
|
|
683
|
+
const candidateAddress = [
|
|
684
|
+
address,
|
|
685
|
+
protocol.getExtraInfo()[1],
|
|
686
|
+
];
|
|
687
|
+
protocol.localCandidate = new candidate_1.Candidate((0, candidate_1.candidateFoundation)("host", "udp", candidateAddress[0]), 1, "udp", (0, candidate_1.candidatePriority)("host", { transport: "udp" }), candidateAddress[0], candidateAddress[1], "host", undefined, undefined, undefined, this.generation, this.localUsername);
|
|
688
|
+
this.pairLocalProtocol(protocol);
|
|
689
|
+
this.appendLocalCandidate(protocol.localCandidate);
|
|
690
|
+
return protocol;
|
|
691
|
+
}
|
|
692
|
+
catch (error) {
|
|
693
|
+
log("error protocol STUN", error);
|
|
694
|
+
}
|
|
695
|
+
});
|
|
696
|
+
if (!gatherRelayOnly) {
|
|
697
|
+
candidatePromises.push(...localStunPromises.map((localPromise) => localPromise.then((protocol) => protocol?.localCandidate)));
|
|
698
|
+
}
|
|
699
|
+
if (!gatherRelayOnly && this.options.useTcp) {
|
|
700
|
+
const tcpCandidatePromises = addresses.map(async (address) => {
|
|
701
|
+
const passiveProtocol = new tcpProtocol_1.TcpPassiveProtocol();
|
|
702
|
+
this.ensureProtocol(passiveProtocol);
|
|
703
|
+
await passiveProtocol.connectionMade(address, this.options.portRange);
|
|
704
|
+
passiveProtocol.localIp = address;
|
|
705
|
+
passiveProtocol.localCandidate = new candidate_1.Candidate((0, candidate_1.candidateFoundation)("host", "tcp", address), 1, "tcp", (0, candidate_1.candidatePriority)("host", {
|
|
706
|
+
transport: "tcp",
|
|
707
|
+
tcptype: "passive",
|
|
708
|
+
}), address, passiveProtocol.listeningPort, "host", undefined, undefined, "passive", this.generation, this.localUsername);
|
|
709
|
+
this.protocols.push(passiveProtocol);
|
|
710
|
+
this.appendLocalCandidate(passiveProtocol.localCandidate);
|
|
711
|
+
if (!gatherIceLite) {
|
|
712
|
+
const activeProtocol = new tcpProtocol_1.TcpActiveProtocol();
|
|
713
|
+
this.ensureProtocol(activeProtocol);
|
|
714
|
+
await activeProtocol.connectionMade(address);
|
|
715
|
+
activeProtocol.localIp = address;
|
|
716
|
+
activeProtocol.localCandidate = new candidate_1.Candidate((0, candidate_1.candidateFoundation)("host", "tcp", address), 1, "tcp", (0, candidate_1.candidatePriority)("host", {
|
|
717
|
+
transport: "tcp",
|
|
718
|
+
tcptype: "active",
|
|
719
|
+
}), address, 9, "host", undefined, undefined, "active", this.generation, this.localUsername);
|
|
720
|
+
this.protocols.push(activeProtocol);
|
|
721
|
+
this.pairLocalProtocol(activeProtocol);
|
|
722
|
+
this.appendLocalCandidate(activeProtocol.localCandidate);
|
|
723
|
+
}
|
|
724
|
+
});
|
|
725
|
+
candidatePromises.push(...tcpCandidatePromises);
|
|
726
|
+
}
|
|
727
|
+
if (!gatherIceLite && !gatherRelayOnly && stunServer) {
|
|
648
728
|
const stunCandidatePromises = localStunPromises.map(async (protocolPromise) => {
|
|
649
729
|
const protocol = await protocolPromise;
|
|
650
730
|
if (!protocol)
|
|
@@ -673,9 +753,9 @@ class Connection {
|
|
|
673
753
|
});
|
|
674
754
|
candidatePromises.push(...stunCandidatePromises);
|
|
675
755
|
}
|
|
676
|
-
|
|
677
|
-
if (turnServer && turnUsername && turnPassword) {
|
|
756
|
+
if (!gatherIceLite && turnServer && turnUsername && turnPassword) {
|
|
678
757
|
const turnCandidatePromise = (async () => {
|
|
758
|
+
const turnTransport = this.options.turnTransport ?? "udp";
|
|
679
759
|
const protocol = await (0, protocol_2.createStunOverTurnClient)({
|
|
680
760
|
address: turnServer,
|
|
681
761
|
username: turnUsername,
|
|
@@ -683,9 +763,10 @@ class Connection {
|
|
|
683
763
|
}, {
|
|
684
764
|
portRange: this.options.portRange,
|
|
685
765
|
interfaceAddresses: this.options.interfaceAddresses,
|
|
686
|
-
transport:
|
|
766
|
+
transport: turnTransport,
|
|
767
|
+
tlsOptions: this.options.turnTlsOptions,
|
|
687
768
|
}).catch(async (e) => {
|
|
688
|
-
if (
|
|
769
|
+
if (turnTransport === "udp") {
|
|
689
770
|
return await (0, protocol_2.createStunOverTurnClient)({
|
|
690
771
|
address: turnServer,
|
|
691
772
|
username: turnUsername,
|
|
@@ -711,9 +792,6 @@ class Connection {
|
|
|
711
792
|
})().catch((error) => {
|
|
712
793
|
log("query TURN server", error);
|
|
713
794
|
});
|
|
714
|
-
if (this.options.forceTurn) {
|
|
715
|
-
candidatePromises = [];
|
|
716
|
-
}
|
|
717
795
|
candidatePromises.push(turnCandidatePromise);
|
|
718
796
|
}
|
|
719
797
|
return candidatePromises;
|
|
@@ -739,7 +817,9 @@ class Connection {
|
|
|
739
817
|
this.pairRemoteCandidate(c);
|
|
740
818
|
}
|
|
741
819
|
this.sortCheckList();
|
|
742
|
-
this.
|
|
820
|
+
if (!this.iceLite) {
|
|
821
|
+
this.unfreezeInitial();
|
|
822
|
+
}
|
|
743
823
|
log("earlyChecks", this.localPassword, this.earlyChecks.length);
|
|
744
824
|
// # handle early checks
|
|
745
825
|
for (const earlyCheck of this.earlyChecks) {
|
|
@@ -747,6 +827,23 @@ class Connection {
|
|
|
747
827
|
}
|
|
748
828
|
this.earlyChecks = [];
|
|
749
829
|
this.earlyChecksDone = true;
|
|
830
|
+
if (this.iceLite) {
|
|
831
|
+
if (!this.nominated) {
|
|
832
|
+
let res = iceBase_1.ICE_FAILED;
|
|
833
|
+
while (!this.checkListDone && this.state !== "closed") {
|
|
834
|
+
res = await this.checkListState.get();
|
|
835
|
+
log("checkListState", res);
|
|
836
|
+
if (res === iceBase_1.ICE_COMPLETED) {
|
|
837
|
+
break;
|
|
838
|
+
}
|
|
839
|
+
}
|
|
840
|
+
if (res !== iceBase_1.ICE_COMPLETED && !this.nominated) {
|
|
841
|
+
throw new Error("ICE negotiation failed");
|
|
842
|
+
}
|
|
843
|
+
}
|
|
844
|
+
this.setState("connected");
|
|
845
|
+
return;
|
|
846
|
+
}
|
|
750
847
|
// # perform checks
|
|
751
848
|
// 5.8. Scheduling Checks
|
|
752
849
|
for (;;) {
|
|
@@ -942,6 +1039,7 @@ class Connection {
|
|
|
942
1039
|
log("nominated", pair.toJSON());
|
|
943
1040
|
this.nominated = pair;
|
|
944
1041
|
this.nominating = false;
|
|
1042
|
+
this.pruneTcpConnections(pair);
|
|
945
1043
|
// 8.1.2. Updating States
|
|
946
1044
|
// The agent MUST remove all Waiting and Frozen pairs in the check
|
|
947
1045
|
// list and triggered check queue for the same component as the
|
|
@@ -1015,7 +1113,9 @@ class Connection {
|
|
|
1015
1113
|
}
|
|
1016
1114
|
if (!remoteCandidate) {
|
|
1017
1115
|
// 7.2.1.3. Learning Peer Reflexive Candidates
|
|
1018
|
-
remoteCandidate = new candidate_1.Candidate((0, helper_1.randomString)(10), 1, "udp", message.getAttributeValue("PRIORITY"), host, port, "prflx", undefined, undefined,
|
|
1116
|
+
remoteCandidate = new candidate_1.Candidate((0, helper_1.randomString)(10), 1, protocol.localCandidate?.transport ?? "udp", message.getAttributeValue("PRIORITY"), host, port, "prflx", undefined, undefined, protocol.localCandidate?.transport === "tcp"
|
|
1117
|
+
? (0, candidate_1.remoteTcpTypeForIncoming)(protocol.localCandidate.tcptype)
|
|
1118
|
+
: undefined, undefined, undefined);
|
|
1019
1119
|
this._remoteCandidates.push(remoteCandidate);
|
|
1020
1120
|
}
|
|
1021
1121
|
// find pair
|
|
@@ -1025,6 +1125,9 @@ class Connection {
|
|
|
1025
1125
|
pair.updateState(iceBase_1.CandidatePairState.WAITING);
|
|
1026
1126
|
this.addPair(pair);
|
|
1027
1127
|
}
|
|
1128
|
+
pair.noteIncomingRequest(message.transactionIdHex);
|
|
1129
|
+
pair.requestsReceived++;
|
|
1130
|
+
pair.responsesSent++;
|
|
1028
1131
|
pair.localCandidate.ufrag = localUsername;
|
|
1029
1132
|
log("Triggered Checks", message.toJSON(), pair.toJSON(), {
|
|
1030
1133
|
localUsername: this.localUsername,
|
|
@@ -1033,6 +1136,16 @@ class Connection {
|
|
|
1033
1136
|
remotePassword: this.remotePassword,
|
|
1034
1137
|
generation: this.generation,
|
|
1035
1138
|
});
|
|
1139
|
+
if (this.iceLite) {
|
|
1140
|
+
if (message.attributesKeys.includes("USE-CANDIDATE") &&
|
|
1141
|
+
!this.iceControlling) {
|
|
1142
|
+
pair.remoteNominated = true;
|
|
1143
|
+
pair.nominated = true;
|
|
1144
|
+
pair.updateState(iceBase_1.CandidatePairState.SUCCEEDED);
|
|
1145
|
+
this.checkComplete(pair);
|
|
1146
|
+
}
|
|
1147
|
+
return;
|
|
1148
|
+
}
|
|
1036
1149
|
// 7.2.1.4. Triggered Checks
|
|
1037
1150
|
if ([iceBase_1.CandidatePairState.WAITING, iceBase_1.CandidatePairState.FAILED].includes(pair.state)) {
|
|
1038
1151
|
pair.handle = this.checkStart(pair);
|
|
@@ -1049,6 +1162,9 @@ class Connection {
|
|
|
1049
1162
|
}
|
|
1050
1163
|
tryPair(protocol, remoteCandidate) {
|
|
1051
1164
|
if (protocol.localCandidate?.canPairWith(remoteCandidate) &&
|
|
1165
|
+
!(protocol.localCandidate.transport.toLowerCase() === "tcp" &&
|
|
1166
|
+
protocol.localCandidate.tcptype === "passive" &&
|
|
1167
|
+
remoteCandidate.type !== "prflx") &&
|
|
1052
1168
|
!this.findPair(protocol, remoteCandidate)) {
|
|
1053
1169
|
const pair = new iceBase_1.CandidatePair(protocol, remoteCandidate, this.iceControlling);
|
|
1054
1170
|
if (this.options.filterCandidatePair &&
|
|
@@ -1064,12 +1180,13 @@ class Connection {
|
|
|
1064
1180
|
this.tryPair(protocol, remoteCandidate);
|
|
1065
1181
|
}
|
|
1066
1182
|
}
|
|
1067
|
-
buildRequest({ nominate, remoteUsername, localUsername, iceControlling, }) {
|
|
1183
|
+
buildRequest({ nominate, remoteUsername, localUsername, iceControlling, localCandidate, }) {
|
|
1068
1184
|
const txUsername = encodeTxUsername({ remoteUsername, localUsername });
|
|
1069
1185
|
const request = new message_1.Message(const_1.methods.BINDING, const_1.classes.REQUEST);
|
|
1070
|
-
request
|
|
1071
|
-
|
|
1072
|
-
|
|
1186
|
+
request.setAttribute("USERNAME", txUsername).setAttribute("PRIORITY", (0, candidate_1.candidatePriority)("prflx", {
|
|
1187
|
+
transport: localCandidate?.transport,
|
|
1188
|
+
tcptype: localCandidate?.tcptype,
|
|
1189
|
+
}));
|
|
1073
1190
|
if (iceControlling) {
|
|
1074
1191
|
request.setAttribute("ICE-CONTROLLING", this.tieBreaker);
|
|
1075
1192
|
if (nominate) {
|
|
@@ -1081,6 +1198,19 @@ class Connection {
|
|
|
1081
1198
|
}
|
|
1082
1199
|
return request;
|
|
1083
1200
|
}
|
|
1201
|
+
pruneTcpConnections(selectedPair) {
|
|
1202
|
+
for (const protocol of this.protocols) {
|
|
1203
|
+
if (protocol.localCandidate?.transport.toLowerCase() !== "tcp") {
|
|
1204
|
+
continue;
|
|
1205
|
+
}
|
|
1206
|
+
if ("pruneForSelection" in protocol &&
|
|
1207
|
+
typeof protocol.pruneForSelection === "function") {
|
|
1208
|
+
void protocol.pruneForSelection(protocol === selectedPair.protocol
|
|
1209
|
+
? selectedPair.remoteAddr
|
|
1210
|
+
: undefined);
|
|
1211
|
+
}
|
|
1212
|
+
}
|
|
1213
|
+
}
|
|
1084
1214
|
respondError(request, addr, protocol, errorCode) {
|
|
1085
1215
|
const response = new message_1.Message(request.messageMethod, const_1.classes.ERROR, request.transactionId);
|
|
1086
1216
|
response
|