werift 0.20.1 → 0.21.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/lib/common/src/event.js +0 -3
- package/lib/common/src/event.js.map +1 -1
- package/lib/dtls/src/flight/server/flight2.js +5 -3
- package/lib/dtls/src/flight/server/flight2.js.map +1 -1
- package/lib/dtls/src/index.d.ts +1 -1
- package/lib/dtls/src/index.js.map +1 -1
- package/lib/dtls/src/record/receive.js +1 -1
- package/lib/dtls/src/record/receive.js.map +1 -1
- package/lib/ice/src/candidate.d.ts +2 -1
- package/lib/ice/src/candidate.js +17 -4
- package/lib/ice/src/candidate.js.map +1 -1
- package/lib/ice/src/helper.d.ts +6 -6
- package/lib/ice/src/helper.js +18 -15
- package/lib/ice/src/helper.js.map +1 -1
- package/lib/ice/src/ice.d.ts +28 -75
- package/lib/ice/src/ice.js +388 -418
- package/lib/ice/src/ice.js.map +1 -1
- package/lib/ice/src/iceBase.d.ts +109 -0
- package/lib/ice/src/iceBase.js +166 -0
- package/lib/ice/src/iceBase.js.map +1 -0
- package/lib/ice/src/index.d.ts +1 -0
- package/lib/ice/src/index.js +1 -0
- package/lib/ice/src/index.js.map +1 -1
- package/lib/ice/src/stun/message.d.ts +6 -0
- package/lib/ice/src/stun/message.js +4 -0
- package/lib/ice/src/stun/message.js.map +1 -1
- package/lib/ice/src/stun/protocol.d.ts +5 -6
- package/lib/ice/src/stun/protocol.js +18 -18
- package/lib/ice/src/stun/protocol.js.map +1 -1
- package/lib/ice/src/stun/transaction.js +6 -1
- package/lib/ice/src/stun/transaction.js.map +1 -1
- package/lib/ice/src/turn/protocol.d.ts +6 -5
- package/lib/ice/src/turn/protocol.js +54 -36
- package/lib/ice/src/turn/protocol.js.map +1 -1
- package/lib/ice/src/types/model.d.ts +4 -0
- package/lib/ice/src/types/model.js.map +1 -1
- package/lib/rtp/src/extra/container/webm/container.d.ts +3 -1
- package/lib/rtp/src/extra/container/webm/container.js +8 -2
- package/lib/rtp/src/extra/container/webm/container.js.map +1 -1
- package/lib/rtp/src/extra/container/webm/ebml/id.d.ts +6 -0
- package/lib/rtp/src/extra/container/webm/ebml/id.js +6 -0
- package/lib/rtp/src/extra/container/webm/ebml/id.js.map +1 -1
- package/lib/rtp/src/extra/processor/webm.d.ts +11 -16
- package/lib/rtp/src/extra/processor/webm.js.map +1 -1
- package/lib/rtp/src/extra/processor/webmCallback.d.ts +1 -10
- package/lib/rtp/src/extra/processor/webmCallback.js.map +1 -1
- package/lib/rtp/src/rtp/headerExtension.d.ts +45 -3
- package/lib/rtp/src/rtp/headerExtension.js +15 -0
- package/lib/rtp/src/rtp/headerExtension.js.map +1 -1
- package/lib/sctp/src/index.d.ts +1 -1
- package/lib/sctp/src/index.js.map +1 -1
- package/lib/webrtc/src/const.d.ts +2 -2
- package/lib/webrtc/src/const.js.map +1 -1
- package/lib/webrtc/src/media/extension/rtpExtension.d.ts +1 -0
- package/lib/webrtc/src/media/extension/rtpExtension.js +6 -0
- package/lib/webrtc/src/media/extension/rtpExtension.js.map +1 -1
- package/lib/webrtc/src/media/router.d.ts +0 -3
- package/lib/webrtc/src/media/router.js.map +1 -1
- package/lib/webrtc/src/media/rtpReceiver.d.ts +1 -2
- package/lib/webrtc/src/media/rtpReceiver.js +2 -2
- package/lib/webrtc/src/media/rtpReceiver.js.map +1 -1
- package/lib/webrtc/src/media/track.d.ts +2 -2
- package/lib/webrtc/src/media/track.js.map +1 -1
- package/lib/webrtc/src/nonstandard/recorder/index.d.ts +1 -0
- package/lib/webrtc/src/nonstandard/recorder/index.js.map +1 -1
- package/lib/webrtc/src/nonstandard/recorder/writer/webm.js +1 -0
- package/lib/webrtc/src/nonstandard/recorder/writer/webm.js.map +1 -1
- package/lib/webrtc/src/peerConnection.d.ts +12 -6
- package/lib/webrtc/src/peerConnection.js +94 -82
- package/lib/webrtc/src/peerConnection.js.map +1 -1
- package/lib/webrtc/src/sdp.js +15 -3
- package/lib/webrtc/src/sdp.js.map +1 -1
- package/lib/webrtc/src/transport/dtls.d.ts +5 -5
- package/lib/webrtc/src/transport/dtls.js +7 -18
- package/lib/webrtc/src/transport/dtls.js.map +1 -1
- package/lib/webrtc/src/transport/ice.d.ts +20 -9
- package/lib/webrtc/src/transport/ice.js +97 -32
- package/lib/webrtc/src/transport/ice.js.map +1 -1
- package/package.json +1 -1
- package/src/const.ts +2 -2
- package/src/media/extension/rtpExtension.ts +6 -0
- package/src/media/router.ts +2 -3
- package/src/media/rtpReceiver.ts +4 -3
- package/src/media/track.ts +7 -2
- package/src/nonstandard/recorder/index.ts +1 -0
- package/src/nonstandard/recorder/writer/webm.ts +47 -43
- package/src/peerConnection.ts +118 -88
- package/src/sdp.ts +16 -3
- package/src/transport/dtls.ts +11 -9
- package/src/transport/ice.ts +73 -26
package/src/transport/ice.ts
CHANGED
|
@@ -2,29 +2,35 @@ import debug from "debug";
|
|
|
2
2
|
import { v4 } from "uuid";
|
|
3
3
|
import { Event } from "../imports/common";
|
|
4
4
|
|
|
5
|
-
import {
|
|
5
|
+
import {
|
|
6
|
+
Candidate,
|
|
7
|
+
Connection,
|
|
8
|
+
type IceConnection,
|
|
9
|
+
type IceOptions,
|
|
10
|
+
} from "../../../ice/src";
|
|
6
11
|
import { candidateFromSdp, candidateToSdp } from "../sdp";
|
|
7
12
|
|
|
8
13
|
const log = debug("werift:packages/webrtc/src/transport/ice.ts");
|
|
9
14
|
|
|
10
15
|
export class RTCIceTransport {
|
|
11
16
|
readonly id = v4();
|
|
12
|
-
connection:
|
|
17
|
+
connection: IceConnection;
|
|
13
18
|
state: RTCIceConnectionState = "new";
|
|
19
|
+
private waitStart?: Event<[]>;
|
|
20
|
+
private renominating = false;
|
|
14
21
|
|
|
15
22
|
readonly onStateChange = new Event<[RTCIceConnectionState]>();
|
|
23
|
+
readonly onIceCandidate = new Event<[IceCandidate | undefined]>();
|
|
24
|
+
readonly onNegotiationNeeded = new Event<[]>();
|
|
16
25
|
|
|
17
|
-
private
|
|
18
|
-
|
|
19
|
-
constructor(private gather: RTCIceGatherer) {
|
|
20
|
-
this.connection = this.gather.connection;
|
|
26
|
+
constructor(private iceGather: RTCIceGatherer) {
|
|
27
|
+
this.connection = this.iceGather.connection;
|
|
21
28
|
this.connection.stateChanged.subscribe((state) => {
|
|
22
29
|
this.setState(state);
|
|
23
30
|
});
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
return this.gather;
|
|
31
|
+
this.iceGather.onIceCandidate = (candidate) => {
|
|
32
|
+
this.onIceCandidate.execute(candidate);
|
|
33
|
+
};
|
|
28
34
|
}
|
|
29
35
|
|
|
30
36
|
get role() {
|
|
@@ -32,21 +38,30 @@ export class RTCIceTransport {
|
|
|
32
38
|
else return "controlled";
|
|
33
39
|
}
|
|
34
40
|
|
|
41
|
+
get gatheringState() {
|
|
42
|
+
return this.iceGather.gatheringState;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
get localCandidates() {
|
|
46
|
+
return this.iceGather.localCandidates;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
get localParameters() {
|
|
50
|
+
return this.iceGather.localParameters;
|
|
51
|
+
}
|
|
52
|
+
|
|
35
53
|
private setState(state: RTCIceConnectionState) {
|
|
36
54
|
if (state !== this.state) {
|
|
37
55
|
this.state = state;
|
|
38
56
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
if (state === "closed") {
|
|
42
|
-
this.onStateChange.execute(state);
|
|
43
|
-
this.onStateChange.complete();
|
|
44
|
-
} else {
|
|
45
|
-
this.onStateChange.execute(state);
|
|
46
|
-
}
|
|
57
|
+
this.onStateChange.execute(state);
|
|
47
58
|
}
|
|
48
59
|
}
|
|
49
60
|
|
|
61
|
+
gather() {
|
|
62
|
+
return this.iceGather.gather();
|
|
63
|
+
}
|
|
64
|
+
|
|
50
65
|
addRemoteCandidate = (candidate?: IceCandidate) => {
|
|
51
66
|
if (!this.connection.remoteCandidatesEnd) {
|
|
52
67
|
if (!candidate) {
|
|
@@ -57,19 +72,36 @@ export class RTCIceTransport {
|
|
|
57
72
|
}
|
|
58
73
|
};
|
|
59
74
|
|
|
60
|
-
setRemoteParams(remoteParameters: RTCIceParameters) {
|
|
75
|
+
setRemoteParams(remoteParameters: RTCIceParameters, renomination = false) {
|
|
76
|
+
if (renomination) {
|
|
77
|
+
this.renominating = true;
|
|
78
|
+
}
|
|
61
79
|
if (
|
|
62
80
|
this.connection.remoteUsername &&
|
|
63
81
|
this.connection.remotePassword &&
|
|
64
82
|
(this.connection.remoteUsername !== remoteParameters.usernameFragment ||
|
|
65
83
|
this.connection.remotePassword !== remoteParameters.password)
|
|
66
84
|
) {
|
|
67
|
-
|
|
68
|
-
|
|
85
|
+
if (this.renominating) {
|
|
86
|
+
log("renomination", remoteParameters);
|
|
87
|
+
this.connection.resetNominatedPair();
|
|
88
|
+
this.renominating = false;
|
|
89
|
+
} else {
|
|
90
|
+
log("restart", remoteParameters);
|
|
91
|
+
this.restart();
|
|
92
|
+
}
|
|
69
93
|
}
|
|
70
94
|
this.connection.setRemoteParams(remoteParameters);
|
|
71
95
|
}
|
|
72
96
|
|
|
97
|
+
restart() {
|
|
98
|
+
this.connection.restart();
|
|
99
|
+
this.setState("new");
|
|
100
|
+
this.iceGather.gatheringState = "new";
|
|
101
|
+
this.waitStart = undefined;
|
|
102
|
+
this.onNegotiationNeeded.execute();
|
|
103
|
+
}
|
|
104
|
+
|
|
73
105
|
async start() {
|
|
74
106
|
if (this.state === "closed") {
|
|
75
107
|
throw new Error("RTCIceTransport is closed");
|
|
@@ -92,7 +124,9 @@ export class RTCIceTransport {
|
|
|
92
124
|
throw error;
|
|
93
125
|
}
|
|
94
126
|
|
|
127
|
+
this.waitStart.execute();
|
|
95
128
|
this.waitStart.complete();
|
|
129
|
+
this.waitStart = undefined;
|
|
96
130
|
}
|
|
97
131
|
|
|
98
132
|
async stop() {
|
|
@@ -100,6 +134,9 @@ export class RTCIceTransport {
|
|
|
100
134
|
this.setState("closed");
|
|
101
135
|
await this.connection.close();
|
|
102
136
|
}
|
|
137
|
+
this.onStateChange.complete();
|
|
138
|
+
this.onIceCandidate.complete();
|
|
139
|
+
this.onNegotiationNeeded.complete();
|
|
103
140
|
}
|
|
104
141
|
}
|
|
105
142
|
|
|
@@ -120,20 +157,21 @@ export type IceGathererState = (typeof IceGathererStates)[number];
|
|
|
120
157
|
export class RTCIceGatherer {
|
|
121
158
|
onIceCandidate: (candidate: IceCandidate | undefined) => void = () => {};
|
|
122
159
|
gatheringState: IceGathererState = "new";
|
|
160
|
+
readonly connection: IceConnection;
|
|
123
161
|
|
|
124
162
|
readonly onGatheringStateChange = new Event<[IceGathererState]>();
|
|
125
|
-
readonly connection: Connection;
|
|
126
163
|
|
|
127
164
|
constructor(private options: Partial<IceOptions> = {}) {
|
|
128
165
|
this.connection = new Connection(false, this.options);
|
|
166
|
+
this.connection.onIceCandidate.subscribe((candidate) => {
|
|
167
|
+
this.onIceCandidate(candidateFromIce(candidate));
|
|
168
|
+
});
|
|
129
169
|
}
|
|
130
170
|
|
|
131
171
|
async gather() {
|
|
132
172
|
if (this.gatheringState === "new") {
|
|
133
173
|
this.setState("gathering");
|
|
134
|
-
await this.connection.gatherCandidates(
|
|
135
|
-
this.onIceCandidate(candidateFromIce(candidate));
|
|
136
|
-
});
|
|
174
|
+
await this.connection.gatherCandidates();
|
|
137
175
|
this.onIceCandidate(undefined);
|
|
138
176
|
this.setState("complete");
|
|
139
177
|
}
|
|
@@ -145,7 +183,7 @@ export class RTCIceGatherer {
|
|
|
145
183
|
|
|
146
184
|
get localParameters() {
|
|
147
185
|
const params = new RTCIceParameters({
|
|
148
|
-
usernameFragment: this.connection.
|
|
186
|
+
usernameFragment: this.connection.localUsername,
|
|
149
187
|
password: this.connection.localPassword,
|
|
150
188
|
});
|
|
151
189
|
|
|
@@ -169,6 +207,8 @@ export function candidateFromIce(c: Candidate) {
|
|
|
169
207
|
c.priority,
|
|
170
208
|
c.transport,
|
|
171
209
|
c.type,
|
|
210
|
+
c.generation,
|
|
211
|
+
c.ufrag,
|
|
172
212
|
);
|
|
173
213
|
candidate.relatedAddress = c.relatedAddress;
|
|
174
214
|
candidate.relatedPort = c.relatedPort;
|
|
@@ -188,6 +228,8 @@ export function candidateToIce(x: IceCandidate) {
|
|
|
188
228
|
x.relatedAddress,
|
|
189
229
|
x.relatedPort,
|
|
190
230
|
x.tcpType,
|
|
231
|
+
x.generation,
|
|
232
|
+
x.ufrag,
|
|
191
233
|
);
|
|
192
234
|
}
|
|
193
235
|
|
|
@@ -195,6 +237,7 @@ export class RTCIceCandidate {
|
|
|
195
237
|
candidate!: string;
|
|
196
238
|
sdpMid?: string;
|
|
197
239
|
sdpMLineIndex?: number;
|
|
240
|
+
usernameFragment?: string;
|
|
198
241
|
|
|
199
242
|
constructor(props: Partial<RTCIceCandidate>) {
|
|
200
243
|
Object.assign(this, props);
|
|
@@ -209,6 +252,7 @@ export class RTCIceCandidate {
|
|
|
209
252
|
candidate: this.candidate,
|
|
210
253
|
sdpMid: this.sdpMid,
|
|
211
254
|
sdpMLineIndex: this.sdpMLineIndex,
|
|
255
|
+
usernameFragment: this.usernameFragment,
|
|
212
256
|
};
|
|
213
257
|
}
|
|
214
258
|
}
|
|
@@ -233,6 +277,8 @@ export class IceCandidate {
|
|
|
233
277
|
public priority: number,
|
|
234
278
|
public protocol: string,
|
|
235
279
|
public type: string,
|
|
280
|
+
public generation?: number,
|
|
281
|
+
public ufrag?: string,
|
|
236
282
|
) {}
|
|
237
283
|
|
|
238
284
|
toJSON(): RTCIceCandidate {
|
|
@@ -240,6 +286,7 @@ export class IceCandidate {
|
|
|
240
286
|
candidate: candidateToSdp(this),
|
|
241
287
|
sdpMLineIndex: this.sdpMLineIndex,
|
|
242
288
|
sdpMid: this.sdpMid,
|
|
289
|
+
usernameFragment: this.ufrag,
|
|
243
290
|
});
|
|
244
291
|
}
|
|
245
292
|
|