werift 0.23.0 → 0.24.1
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/binary.js +2 -3
- package/lib/common/src/binary.js.map +1 -1
- 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/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 +175 -50
- 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/internal/selectAddresses.d.ts +9 -0
- package/lib/ice/src/internal/selectAddresses.js +40 -0
- package/lib/ice/src/internal/selectAddresses.js.map +1 -0
- 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/src/utils.js +2 -31
- package/lib/ice/src/utils.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 +69 -66
- 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/ip.d.ts +12 -0
- package/lib/ice-server/src/stun/ip.js +88 -0
- package/lib/ice-server/src/stun/ip.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 +2866 -946
- package/lib/nonstandard/index.mjs +1872 -455
- package/lib/rtp/src/codec/av1.js +11 -5
- package/lib/rtp/src/codec/av1.js.map +1 -1
- package/lib/rtp/src/codec/leb128.d.ts +5 -0
- package/lib/rtp/src/codec/leb128.js +24 -0
- package/lib/rtp/src/codec/leb128.js.map +1 -0
- 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/rtp/rtx.js +4 -6
- package/lib/rtp/src/rtp/rtx.js.map +1 -1
- package/lib/rtp/src/srtp/context/context.d.ts +2 -0
- package/lib/rtp/src/srtp/context/context.js +12 -12
- package/lib/rtp/src/srtp/context/context.js.map +1 -1
- package/lib/sctp/src/param.js +31 -15
- package/lib/sctp/src/param.js.map +1 -1
- package/lib/sctp/src/sctp.js +10 -9
- package/lib/sctp/src/sctp.js.map +1 -1
- package/lib/webrtc/src/dataChannel.d.ts +3 -2
- package/lib/webrtc/src/dataChannel.js +9 -2
- 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 +179 -31
- 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 +183 -50
- package/lib/webrtc/src/peerConnection.js +458 -109
- package/lib/webrtc/src/peerConnection.js.map +1 -1
- package/lib/webrtc/src/sctpManager.d.ts +1 -1
- package/lib/webrtc/src/sctpManager.js +27 -7
- package/lib/webrtc/src/sctpManager.js.map +1 -1
- package/lib/webrtc/src/sdp.d.ts +10 -7
- package/lib/webrtc/src/sdp.js +40 -44
- package/lib/webrtc/src/sdp.js.map +1 -1
- package/lib/webrtc/src/sdpManager.d.ts +4 -3
- package/lib/webrtc/src/sdpManager.js +50 -27
- package/lib/webrtc/src/sdpManager.js.map +1 -1
- package/lib/webrtc/src/secureTransportManager.d.ts +13 -4
- package/lib/webrtc/src/secureTransportManager.js +100 -22
- package/lib/webrtc/src/secureTransportManager.js.map +1 -1
- package/lib/webrtc/src/transceiverManager.d.ts +5 -4
- package/lib/webrtc/src/transceiverManager.js +61 -62
- package/lib/webrtc/src/transceiverManager.js.map +1 -1
- package/lib/webrtc/src/transport/dtls.d.ts +15 -4
- package/lib/webrtc/src/transport/dtls.js +91 -23
- 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 +1 -0
- package/lib/webrtc/src/transport/sctp.js +26 -22
- package/lib/webrtc/src/transport/sctp.js.map +1 -1
- package/lib/webrtc/src/utils.d.ts +12 -4
- package/lib/webrtc/src/utils.js +118 -16
- package/lib/webrtc/src/utils.js.map +1 -1
- package/package.json +7 -10
- 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
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
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"candidate.js","sourceRoot":"","sources":["../../../../ice/src/candidate.ts"],"names":[],"mappings":";;;AAuGA,kDAWC;AAGD,8CAgBC;AArID,mCAAoC;AACpC,6BAA6B;AAE7B,MAAa,SAAS;IACpB,oBAAoB;IAEpB,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;;;;mBAAO,SAAS;WAAQ;QACxB;;;;mBAAO,SAAS;WAAQ;QACxB;;;;mBAAO,QAAQ;WAAQ;QACvB;;;;mBAAO,IAAI;WAAQ;QACnB;;;;mBAAO,IAAI;WAAQ;QACnB;;;;mBAAO,IAAI;WAAQ;QACnB;;;;mBAAO,cAAc;WAAS;QAC9B;;;;mBAAO,WAAW;WAAS;QAC3B;;;;mBAAO,OAAO;WAAS;QACvB;;;;mBAAO,UAAU;WAAS;QAC1B;;;;mBAAO,KAAK;WAAS;IACpB,CAAC;IAEJ,MAAM,CAAC,OAAO,CAAC,GAAW;QACxB,uCAAuC;QACvC,yBAAyB;QACzB,yBAAyB;QACzB,gFAAgF;QAEhF,MAAM,IAAI,GAAG,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;QAC5B,IAAI,IAAI,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YACpB,MAAM,IAAI,KAAK,CAAC,qCAAqC,CAAC,CAAC;QACzD,CAAC;QAED,QAAQ;QACR,MAAM,MAAM,GAAG;YACb,UAAU,EAAE,IAAI,CAAC,CAAC,CAAC;YACnB,SAAS,EAAE,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;YAC1B,SAAS,EAAE,IAAI,CAAC,CAAC,CAAC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ACzE,CAAC;AACJ,CAAC","sourcesContent":["import { createHash } from \"crypto\";\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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K,CAAC,CAAC,MAAM,CAAC,GAAG,EAAE,OAAO,CAAC,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
|
@@ -32,16 +32,11 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
32
32
|
return result;
|
|
33
33
|
};
|
|
34
34
|
})();
|
|
35
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
36
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
37
|
-
};
|
|
38
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
36
|
exports.Connection = void 0;
|
|
40
37
|
const crypto_1 = require("crypto");
|
|
41
38
|
const net_1 = require("net");
|
|
42
|
-
const Int64 = __importStar(require("int64-buffer"));
|
|
43
39
|
const timers = __importStar(require("node:timers/promises"));
|
|
44
|
-
const fast_deep_equal_1 = __importDefault(require("fast-deep-equal"));
|
|
45
40
|
const common_1 = require("./imports/common");
|
|
46
41
|
const candidate_1 = require("./candidate");
|
|
47
42
|
const lookup_1 = require("./dns/lookup");
|
|
@@ -50,6 +45,7 @@ const iceBase_1 = require("./iceBase");
|
|
|
50
45
|
const const_1 = require("./stun/const");
|
|
51
46
|
const message_1 = require("./stun/message");
|
|
52
47
|
const protocol_1 = require("./stun/protocol");
|
|
48
|
+
const tcpProtocol_1 = require("./stun/tcpProtocol");
|
|
53
49
|
const protocol_2 = require("./turn/protocol");
|
|
54
50
|
const utils_1 = require("./utils");
|
|
55
51
|
const log = (0, common_1.debug)("werift-ice : packages/ice/src/ice.ts : log");
|
|
@@ -149,7 +145,7 @@ class Connection {
|
|
|
149
145
|
enumerable: true,
|
|
150
146
|
configurable: true,
|
|
151
147
|
writable: true,
|
|
152
|
-
value:
|
|
148
|
+
value: (0, crypto_1.randomBytes)(8).readBigUInt64BE(0)
|
|
153
149
|
});
|
|
154
150
|
Object.defineProperty(this, "state", {
|
|
155
151
|
enumerable: true,
|
|
@@ -248,6 +244,9 @@ class Connection {
|
|
|
248
244
|
configurable: true,
|
|
249
245
|
writable: true,
|
|
250
246
|
value: () => {
|
|
247
|
+
if (this.iceLite) {
|
|
248
|
+
return;
|
|
249
|
+
}
|
|
251
250
|
if (this.queryConsentHandle) {
|
|
252
251
|
this.queryConsentHandle.resolve();
|
|
253
252
|
}
|
|
@@ -278,9 +277,17 @@ class Connection {
|
|
|
278
277
|
localUsername,
|
|
279
278
|
remoteUsername,
|
|
280
279
|
iceControlling,
|
|
280
|
+
localCandidate: nominated.localCandidate,
|
|
281
281
|
});
|
|
282
282
|
try {
|
|
283
|
-
|
|
283
|
+
nominated.consentRequestsSent++;
|
|
284
|
+
nominated.requestsSent++;
|
|
285
|
+
await nominated.protocol.request(request, nominated.remoteAddr, Buffer.from(this.remotePassword, "utf8"), 0, (attempt) => {
|
|
286
|
+
if (attempt > 0) {
|
|
287
|
+
nominated.retransmissionsSent++;
|
|
288
|
+
}
|
|
289
|
+
});
|
|
290
|
+
nominated.responsesReceived++;
|
|
284
291
|
failures = 0;
|
|
285
292
|
if (this.state === "disconnected") {
|
|
286
293
|
this.setState("connected");
|
|
@@ -344,11 +351,18 @@ class Connection {
|
|
|
344
351
|
localUsername,
|
|
345
352
|
remoteUsername,
|
|
346
353
|
iceControlling: this.iceControlling,
|
|
354
|
+
localCandidate: pair.localCandidate,
|
|
347
355
|
});
|
|
348
356
|
// Record start time for RTT calculation
|
|
349
357
|
const startTime = performance.now();
|
|
350
358
|
try {
|
|
351
|
-
|
|
359
|
+
pair.requestsSent++;
|
|
360
|
+
const [response, addr] = await pair.protocol.request(request, pair.remoteAddr, Buffer.from(remotePassword, "utf8"), pair.localCandidate.transport.toLowerCase() === "tcp" ? 0 : 4, (attempt) => {
|
|
361
|
+
if (attempt > 0) {
|
|
362
|
+
pair.retransmissionsSent++;
|
|
363
|
+
}
|
|
364
|
+
});
|
|
365
|
+
pair.responsesReceived++;
|
|
352
366
|
// Calculate RTT
|
|
353
367
|
const endTime = performance.now();
|
|
354
368
|
const rtt = (endTime - startTime) / 1000; // Convert to seconds
|
|
@@ -402,7 +416,8 @@ class Connection {
|
|
|
402
416
|
}
|
|
403
417
|
}
|
|
404
418
|
// # check remote address matches
|
|
405
|
-
if (
|
|
419
|
+
if (result.addr[0] !== pair.remoteAddr[0] ||
|
|
420
|
+
result.addr[1] !== pair.remoteAddr[1]) {
|
|
406
421
|
pair.updateState(iceBase_1.CandidatePairState.FAILED);
|
|
407
422
|
this.checkComplete(pair);
|
|
408
423
|
r();
|
|
@@ -421,9 +436,16 @@ class Connection {
|
|
|
421
436
|
localUsername,
|
|
422
437
|
remoteUsername,
|
|
423
438
|
iceControlling: this.iceControlling,
|
|
439
|
+
localCandidate: pair.localCandidate,
|
|
424
440
|
});
|
|
425
441
|
try {
|
|
426
|
-
|
|
442
|
+
pair.requestsSent++;
|
|
443
|
+
await pair.protocol.request(request, pair.remoteAddr, Buffer.from(this.remotePassword, "utf8"), pair.localCandidate.transport.toLowerCase() === "tcp" ? 0 : 4, (attempt) => {
|
|
444
|
+
if (attempt > 0) {
|
|
445
|
+
pair.retransmissionsSent++;
|
|
446
|
+
}
|
|
447
|
+
});
|
|
448
|
+
pair.responsesReceived++;
|
|
427
449
|
}
|
|
428
450
|
catch (error) {
|
|
429
451
|
pair.updateState(iceBase_1.CandidatePairState.FAILED);
|
|
@@ -451,6 +473,9 @@ class Connection {
|
|
|
451
473
|
...iceBase_1.defaultOptions,
|
|
452
474
|
...options,
|
|
453
475
|
};
|
|
476
|
+
if (this.iceLite) {
|
|
477
|
+
this._iceControlling = false;
|
|
478
|
+
}
|
|
454
479
|
const { stunServer, turnServer } = this.options;
|
|
455
480
|
this.stunServer = (0, iceBase_1.validateAddress)(stunServer) ?? [
|
|
456
481
|
"stun.l.google.com",
|
|
@@ -464,6 +489,9 @@ class Connection {
|
|
|
464
489
|
return this._iceControlling;
|
|
465
490
|
}
|
|
466
491
|
set iceControlling(value) {
|
|
492
|
+
if (this.iceLite) {
|
|
493
|
+
value = false;
|
|
494
|
+
}
|
|
467
495
|
if (this.generation > 0 || this.nominated) {
|
|
468
496
|
return;
|
|
469
497
|
}
|
|
@@ -472,6 +500,9 @@ class Connection {
|
|
|
472
500
|
pair.iceControlling = value;
|
|
473
501
|
}
|
|
474
502
|
}
|
|
503
|
+
get iceLite() {
|
|
504
|
+
return this.options.iceLite;
|
|
505
|
+
}
|
|
475
506
|
async restart() {
|
|
476
507
|
this.generation++;
|
|
477
508
|
this.localUsername = (0, helper_1.randomString)(4);
|
|
@@ -502,6 +533,7 @@ class Connection {
|
|
|
502
533
|
// protocolsはincomingのearlyCheckに使うかもしれないので残す
|
|
503
534
|
for (const protocol of this.protocols) {
|
|
504
535
|
if (protocol.localCandidate) {
|
|
536
|
+
protocol.localCandidate.refreshId();
|
|
505
537
|
protocol.localCandidate.generation = this.generation;
|
|
506
538
|
protocol.localCandidate.ufrag = this.localUsername;
|
|
507
539
|
}
|
|
@@ -570,8 +602,10 @@ class Connection {
|
|
|
570
602
|
}
|
|
571
603
|
else if (!iceControlling &&
|
|
572
604
|
msg.attributesKeys.includes("ICE-CONTROLLED")) {
|
|
573
|
-
if (this.
|
|
605
|
+
if (this.iceLite ||
|
|
606
|
+
this.tieBreaker < msg.getAttributeValue("ICE-CONTROLLED")) {
|
|
574
607
|
this.respondError(msg, addr, protocol, [487, "Role Conflict"]);
|
|
608
|
+
return;
|
|
575
609
|
}
|
|
576
610
|
else {
|
|
577
611
|
this.switchRole(true);
|
|
@@ -614,7 +648,15 @@ class Connection {
|
|
|
614
648
|
});
|
|
615
649
|
}
|
|
616
650
|
getCandidatePromises(addresses, timeout = 5) {
|
|
617
|
-
|
|
651
|
+
const candidatePromises = [];
|
|
652
|
+
const { stunServer, turnServer } = this;
|
|
653
|
+
const { turnUsername, turnPassword } = this.options;
|
|
654
|
+
const gatherIceLite = this.iceLite;
|
|
655
|
+
const gatherRelayOnly = !gatherIceLite &&
|
|
656
|
+
this.options.forceTurn &&
|
|
657
|
+
turnServer &&
|
|
658
|
+
turnUsername &&
|
|
659
|
+
turnPassword;
|
|
618
660
|
addresses = addresses.filter((address) => {
|
|
619
661
|
// ice restartで同じアドレスが追加されるのを防ぐ
|
|
620
662
|
if (this.protocols.find((protocol) => protocol.localIp === address)) {
|
|
@@ -622,29 +664,63 @@ class Connection {
|
|
|
622
664
|
}
|
|
623
665
|
return true;
|
|
624
666
|
});
|
|
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
|
-
|
|
667
|
+
const localStunPromises = gatherRelayOnly
|
|
668
|
+
? []
|
|
669
|
+
: addresses.map(async (address) => {
|
|
670
|
+
// # create transport
|
|
671
|
+
const protocol = new protocol_1.StunProtocol();
|
|
672
|
+
this.ensureProtocol(protocol);
|
|
673
|
+
try {
|
|
674
|
+
await protocol.connectionMade((0, net_1.isIPv4)(address), this.options.portRange, this.options.interfaceAddresses);
|
|
675
|
+
protocol.localIp = address;
|
|
676
|
+
this.protocols.push(protocol);
|
|
677
|
+
log("protocol", protocol.localIp);
|
|
678
|
+
// # add host candidate
|
|
679
|
+
const candidateAddress = [
|
|
680
|
+
address,
|
|
681
|
+
protocol.getExtraInfo()[1],
|
|
682
|
+
];
|
|
683
|
+
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);
|
|
684
|
+
this.pairLocalProtocol(protocol);
|
|
685
|
+
this.appendLocalCandidate(protocol.localCandidate);
|
|
686
|
+
return protocol;
|
|
687
|
+
}
|
|
688
|
+
catch (error) {
|
|
689
|
+
log("error protocol STUN", error);
|
|
690
|
+
}
|
|
691
|
+
});
|
|
692
|
+
if (!gatherRelayOnly) {
|
|
693
|
+
candidatePromises.push(...localStunPromises.map((localPromise) => localPromise.then((protocol) => protocol?.localCandidate)));
|
|
694
|
+
}
|
|
695
|
+
if (!gatherRelayOnly && this.options.useTcp) {
|
|
696
|
+
const tcpCandidatePromises = addresses.map(async (address) => {
|
|
697
|
+
const passiveProtocol = new tcpProtocol_1.TcpPassiveProtocol();
|
|
698
|
+
this.ensureProtocol(passiveProtocol);
|
|
699
|
+
await passiveProtocol.connectionMade(address, this.options.portRange);
|
|
700
|
+
passiveProtocol.localIp = address;
|
|
701
|
+
passiveProtocol.localCandidate = new candidate_1.Candidate((0, candidate_1.candidateFoundation)("host", "tcp", address), 1, "tcp", (0, candidate_1.candidatePriority)("host", {
|
|
702
|
+
transport: "tcp",
|
|
703
|
+
tcptype: "passive",
|
|
704
|
+
}), address, passiveProtocol.listeningPort, "host", undefined, undefined, "passive", this.generation, this.localUsername);
|
|
705
|
+
this.protocols.push(passiveProtocol);
|
|
706
|
+
this.appendLocalCandidate(passiveProtocol.localCandidate);
|
|
707
|
+
if (!gatherIceLite) {
|
|
708
|
+
const activeProtocol = new tcpProtocol_1.TcpActiveProtocol();
|
|
709
|
+
this.ensureProtocol(activeProtocol);
|
|
710
|
+
await activeProtocol.connectionMade(address);
|
|
711
|
+
activeProtocol.localIp = address;
|
|
712
|
+
activeProtocol.localCandidate = new candidate_1.Candidate((0, candidate_1.candidateFoundation)("host", "tcp", address), 1, "tcp", (0, candidate_1.candidatePriority)("host", {
|
|
713
|
+
transport: "tcp",
|
|
714
|
+
tcptype: "active",
|
|
715
|
+
}), address, 9, "host", undefined, undefined, "active", this.generation, this.localUsername);
|
|
716
|
+
this.protocols.push(activeProtocol);
|
|
717
|
+
this.pairLocalProtocol(activeProtocol);
|
|
718
|
+
this.appendLocalCandidate(activeProtocol.localCandidate);
|
|
719
|
+
}
|
|
720
|
+
});
|
|
721
|
+
candidatePromises.push(...tcpCandidatePromises);
|
|
722
|
+
}
|
|
723
|
+
if (!gatherIceLite && !gatherRelayOnly && stunServer) {
|
|
648
724
|
const stunCandidatePromises = localStunPromises.map(async (protocolPromise) => {
|
|
649
725
|
const protocol = await protocolPromise;
|
|
650
726
|
if (!protocol)
|
|
@@ -673,9 +749,9 @@ class Connection {
|
|
|
673
749
|
});
|
|
674
750
|
candidatePromises.push(...stunCandidatePromises);
|
|
675
751
|
}
|
|
676
|
-
|
|
677
|
-
if (turnServer && turnUsername && turnPassword) {
|
|
752
|
+
if (!gatherIceLite && turnServer && turnUsername && turnPassword) {
|
|
678
753
|
const turnCandidatePromise = (async () => {
|
|
754
|
+
const turnTransport = this.options.turnTransport ?? "udp";
|
|
679
755
|
const protocol = await (0, protocol_2.createStunOverTurnClient)({
|
|
680
756
|
address: turnServer,
|
|
681
757
|
username: turnUsername,
|
|
@@ -683,9 +759,10 @@ class Connection {
|
|
|
683
759
|
}, {
|
|
684
760
|
portRange: this.options.portRange,
|
|
685
761
|
interfaceAddresses: this.options.interfaceAddresses,
|
|
686
|
-
transport:
|
|
762
|
+
transport: turnTransport,
|
|
763
|
+
tlsOptions: this.options.turnTlsOptions,
|
|
687
764
|
}).catch(async (e) => {
|
|
688
|
-
if (
|
|
765
|
+
if (turnTransport === "udp") {
|
|
689
766
|
return await (0, protocol_2.createStunOverTurnClient)({
|
|
690
767
|
address: turnServer,
|
|
691
768
|
username: turnUsername,
|
|
@@ -711,9 +788,6 @@ class Connection {
|
|
|
711
788
|
})().catch((error) => {
|
|
712
789
|
log("query TURN server", error);
|
|
713
790
|
});
|
|
714
|
-
if (this.options.forceTurn) {
|
|
715
|
-
candidatePromises = [];
|
|
716
|
-
}
|
|
717
791
|
candidatePromises.push(turnCandidatePromise);
|
|
718
792
|
}
|
|
719
793
|
return candidatePromises;
|
|
@@ -739,7 +813,9 @@ class Connection {
|
|
|
739
813
|
this.pairRemoteCandidate(c);
|
|
740
814
|
}
|
|
741
815
|
this.sortCheckList();
|
|
742
|
-
this.
|
|
816
|
+
if (!this.iceLite) {
|
|
817
|
+
this.unfreezeInitial();
|
|
818
|
+
}
|
|
743
819
|
log("earlyChecks", this.localPassword, this.earlyChecks.length);
|
|
744
820
|
// # handle early checks
|
|
745
821
|
for (const earlyCheck of this.earlyChecks) {
|
|
@@ -747,6 +823,23 @@ class Connection {
|
|
|
747
823
|
}
|
|
748
824
|
this.earlyChecks = [];
|
|
749
825
|
this.earlyChecksDone = true;
|
|
826
|
+
if (this.iceLite) {
|
|
827
|
+
if (!this.nominated) {
|
|
828
|
+
let res = iceBase_1.ICE_FAILED;
|
|
829
|
+
while (!this.checkListDone && this.state !== "closed") {
|
|
830
|
+
res = await this.checkListState.get();
|
|
831
|
+
log("checkListState", res);
|
|
832
|
+
if (res === iceBase_1.ICE_COMPLETED) {
|
|
833
|
+
break;
|
|
834
|
+
}
|
|
835
|
+
}
|
|
836
|
+
if (res !== iceBase_1.ICE_COMPLETED && !this.nominated) {
|
|
837
|
+
throw new Error("ICE negotiation failed");
|
|
838
|
+
}
|
|
839
|
+
}
|
|
840
|
+
this.setState("connected");
|
|
841
|
+
return;
|
|
842
|
+
}
|
|
750
843
|
// # perform checks
|
|
751
844
|
// 5.8. Scheduling Checks
|
|
752
845
|
for (;;) {
|
|
@@ -916,8 +1009,7 @@ class Connection {
|
|
|
916
1009
|
(0, iceBase_1.sortCandidatePairs)(this.checkList, this.iceControlling);
|
|
917
1010
|
}
|
|
918
1011
|
findPair(protocol, remoteCandidate) {
|
|
919
|
-
const pair = this.checkList.find((pair) =>
|
|
920
|
-
(0, fast_deep_equal_1.default)(pair.remoteCandidate, remoteCandidate));
|
|
1012
|
+
const pair = this.checkList.find((pair) => pair.protocol === protocol && pair.remoteCandidate === remoteCandidate);
|
|
921
1013
|
return pair;
|
|
922
1014
|
}
|
|
923
1015
|
switchRole(iceControlling) {
|
|
@@ -942,6 +1034,7 @@ class Connection {
|
|
|
942
1034
|
log("nominated", pair.toJSON());
|
|
943
1035
|
this.nominated = pair;
|
|
944
1036
|
this.nominating = false;
|
|
1037
|
+
this.pruneTcpConnections(pair);
|
|
945
1038
|
// 8.1.2. Updating States
|
|
946
1039
|
// The agent MUST remove all Waiting and Frozen pairs in the check
|
|
947
1040
|
// list and triggered check queue for the same component as the
|
|
@@ -1015,7 +1108,9 @@ class Connection {
|
|
|
1015
1108
|
}
|
|
1016
1109
|
if (!remoteCandidate) {
|
|
1017
1110
|
// 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,
|
|
1111
|
+
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"
|
|
1112
|
+
? (0, candidate_1.remoteTcpTypeForIncoming)(protocol.localCandidate.tcptype)
|
|
1113
|
+
: undefined, undefined, undefined);
|
|
1019
1114
|
this._remoteCandidates.push(remoteCandidate);
|
|
1020
1115
|
}
|
|
1021
1116
|
// find pair
|
|
@@ -1025,6 +1120,9 @@ class Connection {
|
|
|
1025
1120
|
pair.updateState(iceBase_1.CandidatePairState.WAITING);
|
|
1026
1121
|
this.addPair(pair);
|
|
1027
1122
|
}
|
|
1123
|
+
pair.noteIncomingRequest(message.transactionIdHex);
|
|
1124
|
+
pair.requestsReceived++;
|
|
1125
|
+
pair.responsesSent++;
|
|
1028
1126
|
pair.localCandidate.ufrag = localUsername;
|
|
1029
1127
|
log("Triggered Checks", message.toJSON(), pair.toJSON(), {
|
|
1030
1128
|
localUsername: this.localUsername,
|
|
@@ -1033,6 +1131,16 @@ class Connection {
|
|
|
1033
1131
|
remotePassword: this.remotePassword,
|
|
1034
1132
|
generation: this.generation,
|
|
1035
1133
|
});
|
|
1134
|
+
if (this.iceLite) {
|
|
1135
|
+
if (message.attributesKeys.includes("USE-CANDIDATE") &&
|
|
1136
|
+
!this.iceControlling) {
|
|
1137
|
+
pair.remoteNominated = true;
|
|
1138
|
+
pair.nominated = true;
|
|
1139
|
+
pair.updateState(iceBase_1.CandidatePairState.SUCCEEDED);
|
|
1140
|
+
this.checkComplete(pair);
|
|
1141
|
+
}
|
|
1142
|
+
return;
|
|
1143
|
+
}
|
|
1036
1144
|
// 7.2.1.4. Triggered Checks
|
|
1037
1145
|
if ([iceBase_1.CandidatePairState.WAITING, iceBase_1.CandidatePairState.FAILED].includes(pair.state)) {
|
|
1038
1146
|
pair.handle = this.checkStart(pair);
|
|
@@ -1049,6 +1157,9 @@ class Connection {
|
|
|
1049
1157
|
}
|
|
1050
1158
|
tryPair(protocol, remoteCandidate) {
|
|
1051
1159
|
if (protocol.localCandidate?.canPairWith(remoteCandidate) &&
|
|
1160
|
+
!(protocol.localCandidate.transport.toLowerCase() === "tcp" &&
|
|
1161
|
+
protocol.localCandidate.tcptype === "passive" &&
|
|
1162
|
+
remoteCandidate.type !== "prflx") &&
|
|
1052
1163
|
!this.findPair(protocol, remoteCandidate)) {
|
|
1053
1164
|
const pair = new iceBase_1.CandidatePair(protocol, remoteCandidate, this.iceControlling);
|
|
1054
1165
|
if (this.options.filterCandidatePair &&
|
|
@@ -1064,12 +1175,13 @@ class Connection {
|
|
|
1064
1175
|
this.tryPair(protocol, remoteCandidate);
|
|
1065
1176
|
}
|
|
1066
1177
|
}
|
|
1067
|
-
buildRequest({ nominate, remoteUsername, localUsername, iceControlling, }) {
|
|
1178
|
+
buildRequest({ nominate, remoteUsername, localUsername, iceControlling, localCandidate, }) {
|
|
1068
1179
|
const txUsername = encodeTxUsername({ remoteUsername, localUsername });
|
|
1069
1180
|
const request = new message_1.Message(const_1.methods.BINDING, const_1.classes.REQUEST);
|
|
1070
|
-
request
|
|
1071
|
-
|
|
1072
|
-
|
|
1181
|
+
request.setAttribute("USERNAME", txUsername).setAttribute("PRIORITY", (0, candidate_1.candidatePriority)("prflx", {
|
|
1182
|
+
transport: localCandidate?.transport,
|
|
1183
|
+
tcptype: localCandidate?.tcptype,
|
|
1184
|
+
}));
|
|
1073
1185
|
if (iceControlling) {
|
|
1074
1186
|
request.setAttribute("ICE-CONTROLLING", this.tieBreaker);
|
|
1075
1187
|
if (nominate) {
|
|
@@ -1081,6 +1193,19 @@ class Connection {
|
|
|
1081
1193
|
}
|
|
1082
1194
|
return request;
|
|
1083
1195
|
}
|
|
1196
|
+
pruneTcpConnections(selectedPair) {
|
|
1197
|
+
for (const protocol of this.protocols) {
|
|
1198
|
+
if (protocol.localCandidate?.transport.toLowerCase() !== "tcp") {
|
|
1199
|
+
continue;
|
|
1200
|
+
}
|
|
1201
|
+
if ("pruneForSelection" in protocol &&
|
|
1202
|
+
typeof protocol.pruneForSelection === "function") {
|
|
1203
|
+
void protocol.pruneForSelection(protocol === selectedPair.protocol
|
|
1204
|
+
? selectedPair.remoteAddr
|
|
1205
|
+
: undefined);
|
|
1206
|
+
}
|
|
1207
|
+
}
|
|
1208
|
+
}
|
|
1084
1209
|
respondError(request, addr, protocol, errorCode) {
|
|
1085
1210
|
const response = new message_1.Message(request.messageMethod, const_1.classes.ERROR, request.transactionId);
|
|
1086
1211
|
response
|