@libp2p/webrtc 4.0.10 → 4.0.11
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/dist/index.min.js +12 -12
- package/dist/src/webrtc/index.d.ts +1 -6
- package/dist/src/webrtc/index.d.ts.map +1 -1
- package/dist/src/webrtc/index.js +1 -6
- package/dist/src/webrtc/index.js.map +1 -1
- package/package.json +7 -7
- package/src/webrtc/index.ts +1 -6
- package/dist/src/webrtc/rtc-data-channel.d.ts +0 -29
- package/dist/src/webrtc/rtc-data-channel.d.ts.map +0 -1
- package/dist/src/webrtc/rtc-data-channel.js +0 -115
- package/dist/src/webrtc/rtc-data-channel.js.map +0 -1
- package/dist/src/webrtc/rtc-events.d.ts +0 -9
- package/dist/src/webrtc/rtc-events.d.ts.map +0 -1
- package/dist/src/webrtc/rtc-events.js +0 -15
- package/dist/src/webrtc/rtc-events.js.map +0 -1
- package/dist/src/webrtc/rtc-ice-candidate.d.ts +0 -22
- package/dist/src/webrtc/rtc-ice-candidate.d.ts.map +0 -1
- package/dist/src/webrtc/rtc-ice-candidate.js +0 -47
- package/dist/src/webrtc/rtc-ice-candidate.js.map +0 -1
- package/dist/src/webrtc/rtc-peer-connection.d.ts +0 -47
- package/dist/src/webrtc/rtc-peer-connection.d.ts.map +0 -1
- package/dist/src/webrtc/rtc-peer-connection.js +0 -245
- package/dist/src/webrtc/rtc-peer-connection.js.map +0 -1
- package/dist/src/webrtc/rtc-session-description.d.ts +0 -10
- package/dist/src/webrtc/rtc-session-description.d.ts.map +0 -1
- package/dist/src/webrtc/rtc-session-description.js +0 -18
- package/dist/src/webrtc/rtc-session-description.js.map +0 -1
- package/src/webrtc/rtc-data-channel.ts +0 -140
- package/src/webrtc/rtc-events.ts +0 -19
- package/src/webrtc/rtc-ice-candidate.ts +0 -50
- package/src/webrtc/rtc-peer-connection.ts +0 -306
- package/src/webrtc/rtc-session-description.ts +0 -19
|
@@ -1,245 +0,0 @@
|
|
|
1
|
-
import node from 'node-datachannel';
|
|
2
|
-
import defer, {} from 'p-defer';
|
|
3
|
-
import { DataChannel } from './rtc-data-channel.js';
|
|
4
|
-
import { DataChannelEvent, PeerConnectionIceEvent } from './rtc-events.js';
|
|
5
|
-
import { IceCandidate } from './rtc-ice-candidate.js';
|
|
6
|
-
import { SessionDescription } from './rtc-session-description.js';
|
|
7
|
-
export class PeerConnection extends EventTarget {
|
|
8
|
-
static async generateCertificate(keygenAlgorithm) {
|
|
9
|
-
throw new Error('Not implemented');
|
|
10
|
-
}
|
|
11
|
-
canTrickleIceCandidates;
|
|
12
|
-
sctp;
|
|
13
|
-
onconnectionstatechange;
|
|
14
|
-
ondatachannel;
|
|
15
|
-
onicecandidate;
|
|
16
|
-
onicecandidateerror;
|
|
17
|
-
oniceconnectionstatechange;
|
|
18
|
-
onicegatheringstatechange;
|
|
19
|
-
onnegotiationneeded;
|
|
20
|
-
onsignalingstatechange;
|
|
21
|
-
ontrack;
|
|
22
|
-
#peerConnection;
|
|
23
|
-
#config;
|
|
24
|
-
#localOffer;
|
|
25
|
-
#localAnswer;
|
|
26
|
-
#dataChannels;
|
|
27
|
-
constructor(init = {}) {
|
|
28
|
-
super();
|
|
29
|
-
this.#config = init;
|
|
30
|
-
this.#localOffer = defer();
|
|
31
|
-
this.#localAnswer = defer();
|
|
32
|
-
this.#dataChannels = new Set();
|
|
33
|
-
const iceServers = init.iceServers ?? [];
|
|
34
|
-
this.#peerConnection = new node.PeerConnection(`peer-${Math.random()}`, {
|
|
35
|
-
iceServers: iceServers.map(server => {
|
|
36
|
-
const urls = (Array.isArray(server.urls) ? server.urls : [server.urls]).map(str => new URL(str));
|
|
37
|
-
return urls.map(url => {
|
|
38
|
-
/** @type {import('../lib/index.js').IceServer} */
|
|
39
|
-
const iceServer = {
|
|
40
|
-
hostname: url.hostname,
|
|
41
|
-
port: parseInt(url.port, 10),
|
|
42
|
-
username: server.username,
|
|
43
|
-
password: server.credential
|
|
44
|
-
// relayType - how to specify?
|
|
45
|
-
};
|
|
46
|
-
return iceServer;
|
|
47
|
-
});
|
|
48
|
-
})
|
|
49
|
-
.flat(),
|
|
50
|
-
iceTransportPolicy: init?.iceTransportPolicy
|
|
51
|
-
});
|
|
52
|
-
this.#peerConnection.onStateChange(() => {
|
|
53
|
-
this.dispatchEvent(new Event('connectionstatechange'));
|
|
54
|
-
});
|
|
55
|
-
// https://github.com/murat-dogan/node-datachannel/pull/171
|
|
56
|
-
// this.#peerConnection.onSignalingStateChange(() => {
|
|
57
|
-
// this.dispatchEvent(new Event('signalingstatechange'))
|
|
58
|
-
// })
|
|
59
|
-
this.#peerConnection.onGatheringStateChange(() => {
|
|
60
|
-
this.dispatchEvent(new Event('icegatheringstatechange'));
|
|
61
|
-
});
|
|
62
|
-
this.#peerConnection.onDataChannel(channel => {
|
|
63
|
-
this.dispatchEvent(new DataChannelEvent(new DataChannel(channel)));
|
|
64
|
-
});
|
|
65
|
-
// forward events to properties
|
|
66
|
-
this.addEventListener('connectionstatechange', event => {
|
|
67
|
-
this.onconnectionstatechange?.(event);
|
|
68
|
-
});
|
|
69
|
-
this.addEventListener('signalingstatechange', event => {
|
|
70
|
-
this.onsignalingstatechange?.(event);
|
|
71
|
-
});
|
|
72
|
-
this.addEventListener('icegatheringstatechange', event => {
|
|
73
|
-
this.onicegatheringstatechange?.(event);
|
|
74
|
-
});
|
|
75
|
-
this.addEventListener('datachannel', event => {
|
|
76
|
-
this.ondatachannel?.(event);
|
|
77
|
-
});
|
|
78
|
-
this.#peerConnection.onLocalDescription((sdp, type) => {
|
|
79
|
-
if (type === 'offer') {
|
|
80
|
-
this.#localOffer.resolve({
|
|
81
|
-
sdp,
|
|
82
|
-
type
|
|
83
|
-
});
|
|
84
|
-
}
|
|
85
|
-
if (type === 'answer') {
|
|
86
|
-
this.#localAnswer.resolve({
|
|
87
|
-
sdp,
|
|
88
|
-
type
|
|
89
|
-
});
|
|
90
|
-
}
|
|
91
|
-
});
|
|
92
|
-
this.#peerConnection.onLocalCandidate((candidate, mid) => {
|
|
93
|
-
if (mid === 'unspec') {
|
|
94
|
-
this.#localAnswer.reject(new Error(`Invalid description type ${mid}`));
|
|
95
|
-
return;
|
|
96
|
-
}
|
|
97
|
-
const event = new PeerConnectionIceEvent(new IceCandidate({ candidate }));
|
|
98
|
-
this.onicecandidate?.(event);
|
|
99
|
-
});
|
|
100
|
-
this.canTrickleIceCandidates = null;
|
|
101
|
-
this.sctp = null;
|
|
102
|
-
this.onconnectionstatechange = null;
|
|
103
|
-
this.ondatachannel = null;
|
|
104
|
-
this.onicecandidate = null;
|
|
105
|
-
this.onicecandidateerror = null;
|
|
106
|
-
this.oniceconnectionstatechange = null;
|
|
107
|
-
this.onicegatheringstatechange = null;
|
|
108
|
-
this.onnegotiationneeded = null;
|
|
109
|
-
this.onsignalingstatechange = null;
|
|
110
|
-
this.ontrack = null;
|
|
111
|
-
}
|
|
112
|
-
get connectionState() {
|
|
113
|
-
return assertState(this.#peerConnection.state(), RTCPeerConnectionStates);
|
|
114
|
-
}
|
|
115
|
-
get iceConnectionState() {
|
|
116
|
-
return assertState(this.#peerConnection.state(), RTCIceConnectionStates);
|
|
117
|
-
}
|
|
118
|
-
get iceGatheringState() {
|
|
119
|
-
return assertState(this.#peerConnection.gatheringState(), RTCIceGatheringStates);
|
|
120
|
-
}
|
|
121
|
-
get signalingState() {
|
|
122
|
-
return assertState(this.#peerConnection.signalingState(), RTCSignalingStates);
|
|
123
|
-
}
|
|
124
|
-
get currentLocalDescription() {
|
|
125
|
-
return toSessionDescription(this.#peerConnection.localDescription());
|
|
126
|
-
}
|
|
127
|
-
get localDescription() {
|
|
128
|
-
return toSessionDescription(this.#peerConnection.localDescription());
|
|
129
|
-
}
|
|
130
|
-
get pendingLocalDescription() {
|
|
131
|
-
return toSessionDescription(this.#peerConnection.localDescription());
|
|
132
|
-
}
|
|
133
|
-
get currentRemoteDescription() {
|
|
134
|
-
// not exposed by node-datachannel
|
|
135
|
-
return toSessionDescription(null);
|
|
136
|
-
}
|
|
137
|
-
get pendingRemoteDescription() {
|
|
138
|
-
// not exposed by node-datachannel
|
|
139
|
-
return toSessionDescription(null);
|
|
140
|
-
}
|
|
141
|
-
get remoteDescription() {
|
|
142
|
-
// not exposed by node-datachannel
|
|
143
|
-
return toSessionDescription(null);
|
|
144
|
-
}
|
|
145
|
-
async addIceCandidate(candidate) {
|
|
146
|
-
if (candidate == null || candidate.candidate == null) {
|
|
147
|
-
throw new Error('Candidate invalid');
|
|
148
|
-
}
|
|
149
|
-
this.#peerConnection.addRemoteCandidate(candidate.candidate, candidate.sdpMid ?? '0');
|
|
150
|
-
}
|
|
151
|
-
addTrack(track, ...streams) {
|
|
152
|
-
throw new Error('Not implemented');
|
|
153
|
-
}
|
|
154
|
-
addTransceiver(trackOrKind, init) {
|
|
155
|
-
throw new Error('Not implemented');
|
|
156
|
-
}
|
|
157
|
-
close() {
|
|
158
|
-
// close all channels before shutting down
|
|
159
|
-
this.#dataChannels.forEach(channel => {
|
|
160
|
-
channel.close();
|
|
161
|
-
});
|
|
162
|
-
this.#peerConnection.close();
|
|
163
|
-
this.#peerConnection.destroy();
|
|
164
|
-
}
|
|
165
|
-
createDataChannel(label, dataChannelDict = {}) {
|
|
166
|
-
const channel = this.#peerConnection.createDataChannel(label, dataChannelDict);
|
|
167
|
-
const dataChannel = new DataChannel(channel, dataChannelDict);
|
|
168
|
-
// ensure we can close all channels when shutting down
|
|
169
|
-
this.#dataChannels.add(dataChannel);
|
|
170
|
-
dataChannel.addEventListener('close', () => {
|
|
171
|
-
this.#dataChannels.delete(dataChannel);
|
|
172
|
-
});
|
|
173
|
-
return dataChannel;
|
|
174
|
-
}
|
|
175
|
-
async createOffer(...args) {
|
|
176
|
-
return this.#localOffer.promise;
|
|
177
|
-
}
|
|
178
|
-
async createAnswer(...args) {
|
|
179
|
-
return this.#localAnswer.promise;
|
|
180
|
-
}
|
|
181
|
-
getConfiguration() {
|
|
182
|
-
return this.#config;
|
|
183
|
-
}
|
|
184
|
-
getReceivers() {
|
|
185
|
-
throw new Error('Not implemented');
|
|
186
|
-
}
|
|
187
|
-
getSenders() {
|
|
188
|
-
throw new Error('Not implemented');
|
|
189
|
-
}
|
|
190
|
-
async getStats(selector) {
|
|
191
|
-
throw new Error('Not implemented');
|
|
192
|
-
}
|
|
193
|
-
getTransceivers() {
|
|
194
|
-
throw new Error('Not implemented');
|
|
195
|
-
}
|
|
196
|
-
removeTrack(sender) {
|
|
197
|
-
throw new Error('Not implemented');
|
|
198
|
-
}
|
|
199
|
-
restartIce() {
|
|
200
|
-
throw new Error('Not implemented');
|
|
201
|
-
}
|
|
202
|
-
setConfiguration(configuration = {}) {
|
|
203
|
-
this.#config = configuration;
|
|
204
|
-
}
|
|
205
|
-
async setLocalDescription(description) {
|
|
206
|
-
if (description == null || description.type == null) {
|
|
207
|
-
throw new Error('Local description type must be set');
|
|
208
|
-
}
|
|
209
|
-
if (description.type !== 'offer') {
|
|
210
|
-
// any other type causes libdatachannel to throw
|
|
211
|
-
return;
|
|
212
|
-
}
|
|
213
|
-
// @ts-expect-error types are wrong
|
|
214
|
-
this.#peerConnection.setLocalDescription(description.type);
|
|
215
|
-
}
|
|
216
|
-
async setRemoteDescription(description) {
|
|
217
|
-
if (description.sdp == null) {
|
|
218
|
-
throw new Error('Remote SDP must be set');
|
|
219
|
-
}
|
|
220
|
-
// @ts-expect-error types are wrong
|
|
221
|
-
this.#peerConnection.setRemoteDescription(description.sdp, description.type);
|
|
222
|
-
}
|
|
223
|
-
}
|
|
224
|
-
export { PeerConnection as RTCPeerConnection };
|
|
225
|
-
function assertState(state, states) {
|
|
226
|
-
if (state != null && !states.includes(state)) {
|
|
227
|
-
throw new Error(`Invalid value encountered - "${state}" must be one of ${states}`);
|
|
228
|
-
}
|
|
229
|
-
return state;
|
|
230
|
-
}
|
|
231
|
-
function toSessionDescription(description) {
|
|
232
|
-
if (description == null) {
|
|
233
|
-
return null;
|
|
234
|
-
}
|
|
235
|
-
return new SessionDescription({
|
|
236
|
-
sdp: description.sdp,
|
|
237
|
-
type: assertState(description.type, RTCSdpTypes)
|
|
238
|
-
});
|
|
239
|
-
}
|
|
240
|
-
const RTCPeerConnectionStates = ['closed', 'connected', 'connecting', 'disconnected', 'failed', 'new'];
|
|
241
|
-
const RTCSdpTypes = ['answer', 'offer', 'pranswer', 'rollback'];
|
|
242
|
-
const RTCIceConnectionStates = ['checking', 'closed', 'completed', 'connected', 'disconnected', 'failed', 'new'];
|
|
243
|
-
const RTCIceGatheringStates = ['complete', 'gathering', 'new'];
|
|
244
|
-
const RTCSignalingStates = ['closed', 'have-local-offer', 'have-local-pranswer', 'have-remote-offer', 'have-remote-pranswer', 'stable'];
|
|
245
|
-
//# sourceMappingURL=rtc-peer-connection.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"rtc-peer-connection.js","sourceRoot":"","sources":["../../../src/webrtc/rtc-peer-connection.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,kBAAkB,CAAA;AACnC,OAAO,KAAK,EAAE,EAAwB,MAAM,SAAS,CAAA;AACrD,OAAO,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAA;AACnD,OAAO,EAAE,gBAAgB,EAAE,sBAAsB,EAAE,MAAM,iBAAiB,CAAA;AAC1E,OAAO,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAA;AACrD,OAAO,EAAE,kBAAkB,EAAE,MAAM,8BAA8B,CAAA;AAEjE,MAAM,OAAO,cAAe,SAAQ,WAAW;IAC7C,MAAM,CAAC,KAAK,CAAC,mBAAmB,CAAE,eAAoC;QACpE,MAAM,IAAI,KAAK,CAAC,iBAAiB,CAAC,CAAA;IACpC,CAAC;IAED,uBAAuB,CAAgB;IACvC,IAAI,CAAyB;IAE7B,uBAAuB,CAAsD;IAC7E,aAAa,CAAoE;IACjF,cAAc,CAA0E;IACxF,mBAAmB,CAAsD;IACzE,0BAA0B,CAAsD;IAChF,yBAAyB,CAAsD;IAC/E,mBAA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E,mBAAmB,EAAE,sBAAsB,EAAE,QAAQ,CAAC,CAAA"}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @see https://developer.mozilla.org/docs/Web/API/RTCSessionDescription
|
|
3
|
-
*/
|
|
4
|
-
export declare class SessionDescription implements RTCSessionDescription {
|
|
5
|
-
readonly sdp: string;
|
|
6
|
-
readonly type: RTCSdpType;
|
|
7
|
-
constructor(init: RTCSessionDescriptionInit);
|
|
8
|
-
toJSON(): RTCSessionDescriptionInit;
|
|
9
|
-
}
|
|
10
|
-
//# sourceMappingURL=rtc-session-description.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"rtc-session-description.d.ts","sourceRoot":"","sources":["../../../src/webrtc/rtc-session-description.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,qBAAa,kBAAmB,YAAW,qBAAqB;IAC9D,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAA;IACpB,QAAQ,CAAC,IAAI,EAAE,UAAU,CAAA;gBAEZ,IAAI,EAAE,yBAAyB;IAK5C,MAAM,IAAK,yBAAyB;CAMrC"}
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @see https://developer.mozilla.org/docs/Web/API/RTCSessionDescription
|
|
3
|
-
*/
|
|
4
|
-
export class SessionDescription {
|
|
5
|
-
sdp;
|
|
6
|
-
type;
|
|
7
|
-
constructor(init) {
|
|
8
|
-
this.sdp = init.sdp ?? '';
|
|
9
|
-
this.type = init.type;
|
|
10
|
-
}
|
|
11
|
-
toJSON() {
|
|
12
|
-
return {
|
|
13
|
-
sdp: this.sdp,
|
|
14
|
-
type: this.type
|
|
15
|
-
};
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
//# sourceMappingURL=rtc-session-description.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"rtc-session-description.js","sourceRoot":"","sources":["../../../src/webrtc/rtc-session-description.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,OAAO,kBAAkB;IACpB,GAAG,CAAQ;IACX,IAAI,CAAY;IAEzB,YAAa,IAA+B;QAC1C,IAAI,CAAC,GAAG,GAAG,IAAI,CAAC,GAAG,IAAI,EAAE,CAAA;QACzB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC,IAAI,CAAA;IACvB,CAAC;IAED,MAAM;QACJ,OAAO;YACL,GAAG,EAAE,IAAI,CAAC,GAAG;YACb,IAAI,EAAE,IAAI,CAAC,IAAI;SAChB,CAAA;IACH,CAAC;CACF"}
|
|
@@ -1,140 +0,0 @@
|
|
|
1
|
-
import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string'
|
|
2
|
-
import type node from 'node-datachannel'
|
|
3
|
-
|
|
4
|
-
export class DataChannel extends EventTarget implements RTCDataChannel {
|
|
5
|
-
binaryType: BinaryType
|
|
6
|
-
|
|
7
|
-
readonly maxPacketLifeTime: number | null
|
|
8
|
-
readonly maxRetransmits: number | null
|
|
9
|
-
readonly negotiated: boolean
|
|
10
|
-
readonly ordered: boolean
|
|
11
|
-
|
|
12
|
-
onbufferedamountlow: ((this: RTCDataChannel, ev: Event) => any) | null
|
|
13
|
-
onclose: ((this: RTCDataChannel, ev: Event) => any) | null
|
|
14
|
-
onclosing: ((this: RTCDataChannel, ev: Event) => any) | null
|
|
15
|
-
onerror: ((this: RTCDataChannel, ev: Event) => any) | null
|
|
16
|
-
onmessage: ((this: RTCDataChannel, ev: MessageEvent) => any) | null
|
|
17
|
-
onopen: ((this: RTCDataChannel, ev: Event) => any) | null
|
|
18
|
-
|
|
19
|
-
#dataChannel: node.DataChannel
|
|
20
|
-
#bufferedAmountLowThreshold: number
|
|
21
|
-
#readyState: RTCDataChannelState
|
|
22
|
-
|
|
23
|
-
constructor (dataChannel: node.DataChannel, dataChannelDict: RTCDataChannelInit = {}) {
|
|
24
|
-
super()
|
|
25
|
-
|
|
26
|
-
this.#dataChannel = dataChannel
|
|
27
|
-
this.#readyState = 'connecting'
|
|
28
|
-
this.#bufferedAmountLowThreshold = 0
|
|
29
|
-
|
|
30
|
-
this.binaryType = 'arraybuffer'
|
|
31
|
-
|
|
32
|
-
this.#dataChannel.onOpen(() => {
|
|
33
|
-
this.#readyState = 'open'
|
|
34
|
-
this.dispatchEvent(new Event('open'))
|
|
35
|
-
})
|
|
36
|
-
this.#dataChannel.onClosed(() => {
|
|
37
|
-
this.#readyState = 'closed'
|
|
38
|
-
this.dispatchEvent(new Event('close'))
|
|
39
|
-
})
|
|
40
|
-
this.#dataChannel.onError((msg) => {
|
|
41
|
-
this.#readyState = 'closed'
|
|
42
|
-
this.dispatchEvent(new RTCErrorEvent('error', {
|
|
43
|
-
error: new RTCError({
|
|
44
|
-
errorDetail: 'data-channel-failure'
|
|
45
|
-
}, msg)
|
|
46
|
-
}))
|
|
47
|
-
})
|
|
48
|
-
this.#dataChannel.onBufferedAmountLow(() => {
|
|
49
|
-
this.dispatchEvent(new Event('bufferedamountlow'))
|
|
50
|
-
})
|
|
51
|
-
this.#dataChannel.onMessage((data: string | Uint8Array) => {
|
|
52
|
-
if (typeof data === 'string') {
|
|
53
|
-
data = uint8ArrayFromString(data)
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
this.dispatchEvent(new MessageEvent('message', { data }))
|
|
57
|
-
})
|
|
58
|
-
|
|
59
|
-
// forward events to properties
|
|
60
|
-
this.addEventListener('message', event => {
|
|
61
|
-
this.onmessage?.(event as MessageEvent<ArrayBuffer>)
|
|
62
|
-
})
|
|
63
|
-
this.addEventListener('bufferedamountlow', event => {
|
|
64
|
-
this.onbufferedamountlow?.(event)
|
|
65
|
-
})
|
|
66
|
-
this.addEventListener('error', event => {
|
|
67
|
-
this.onerror?.(event)
|
|
68
|
-
})
|
|
69
|
-
this.addEventListener('close', event => {
|
|
70
|
-
this.onclose?.(event)
|
|
71
|
-
})
|
|
72
|
-
this.addEventListener('closing', event => {
|
|
73
|
-
this.onclosing?.(event)
|
|
74
|
-
})
|
|
75
|
-
this.addEventListener('open', event => {
|
|
76
|
-
this.onopen?.(event)
|
|
77
|
-
})
|
|
78
|
-
|
|
79
|
-
this.onbufferedamountlow = null
|
|
80
|
-
this.onclose = null
|
|
81
|
-
this.onclosing = null
|
|
82
|
-
this.onerror = null
|
|
83
|
-
this.onmessage = null
|
|
84
|
-
this.onopen = null
|
|
85
|
-
|
|
86
|
-
this.maxPacketLifeTime = dataChannelDict.maxPacketLifeTime ?? null
|
|
87
|
-
this.maxRetransmits = dataChannelDict.maxRetransmits ?? null
|
|
88
|
-
this.negotiated = dataChannelDict.negotiated ?? false
|
|
89
|
-
this.ordered = dataChannelDict.ordered ?? true
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
get id (): number {
|
|
93
|
-
return this.#dataChannel.getId()
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
get label (): string {
|
|
97
|
-
return this.#dataChannel.getLabel()
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
get protocol (): string {
|
|
101
|
-
return this.#dataChannel.getProtocol()
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
get bufferedAmount (): number {
|
|
105
|
-
return this.#dataChannel.bufferedAmount()
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
set bufferedAmountLowThreshold (threshold: number) {
|
|
109
|
-
this.#bufferedAmountLowThreshold = threshold
|
|
110
|
-
this.#dataChannel.setBufferedAmountLowThreshold(threshold)
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
get bufferedAmountLowThreshold (): number {
|
|
114
|
-
return this.#bufferedAmountLowThreshold
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
get readyState (): RTCDataChannelState {
|
|
118
|
-
return this.#readyState
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
close (): void {
|
|
122
|
-
this.#readyState = 'closing'
|
|
123
|
-
this.dispatchEvent(new Event('closing'))
|
|
124
|
-
|
|
125
|
-
this.#dataChannel.close()
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
send (data: string): void
|
|
129
|
-
send (data: Blob): void
|
|
130
|
-
send (data: ArrayBuffer): void
|
|
131
|
-
send (data: ArrayBufferView): void
|
|
132
|
-
send (data: any): void {
|
|
133
|
-
// TODO: sending Blobs
|
|
134
|
-
if (typeof data === 'string') {
|
|
135
|
-
this.#dataChannel.sendMessage(data)
|
|
136
|
-
} else {
|
|
137
|
-
this.#dataChannel.sendMessageBinary(data)
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
}
|
package/src/webrtc/rtc-events.ts
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
export class PeerConnectionIceEvent extends Event implements RTCPeerConnectionIceEvent {
|
|
2
|
-
readonly candidate: RTCIceCandidate | null
|
|
3
|
-
|
|
4
|
-
constructor (candidate: RTCIceCandidate) {
|
|
5
|
-
super('icecandidate')
|
|
6
|
-
|
|
7
|
-
this.candidate = candidate
|
|
8
|
-
}
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
export class DataChannelEvent extends Event implements RTCDataChannelEvent {
|
|
12
|
-
readonly channel: RTCDataChannel
|
|
13
|
-
|
|
14
|
-
constructor (channel: RTCDataChannel) {
|
|
15
|
-
super('datachannel')
|
|
16
|
-
|
|
17
|
-
this.channel = channel
|
|
18
|
-
}
|
|
19
|
-
}
|
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @see https://developer.mozilla.org/docs/Web/API/RTCIceCandidate
|
|
3
|
-
*/
|
|
4
|
-
export class IceCandidate implements RTCIceCandidate {
|
|
5
|
-
readonly address: string | null
|
|
6
|
-
readonly candidate: string
|
|
7
|
-
readonly component: RTCIceComponent | null
|
|
8
|
-
readonly foundation: string | null
|
|
9
|
-
readonly port: number | null
|
|
10
|
-
readonly priority: number | null
|
|
11
|
-
readonly protocol: RTCIceProtocol | null
|
|
12
|
-
readonly relatedAddress: string | null
|
|
13
|
-
readonly relatedPort: number | null
|
|
14
|
-
readonly sdpMLineIndex: number | null
|
|
15
|
-
readonly sdpMid: string | null
|
|
16
|
-
readonly tcpType: RTCIceTcpCandidateType | null
|
|
17
|
-
readonly type: RTCIceCandidateType | null
|
|
18
|
-
readonly usernameFragment: string | null
|
|
19
|
-
|
|
20
|
-
constructor (init: RTCIceCandidateInit) {
|
|
21
|
-
if (init.candidate == null) {
|
|
22
|
-
throw new DOMException('candidate must be specified')
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
this.candidate = init.candidate
|
|
26
|
-
this.sdpMLineIndex = init.sdpMLineIndex ?? null
|
|
27
|
-
this.sdpMid = init.sdpMid ?? null
|
|
28
|
-
this.usernameFragment = init.usernameFragment ?? null
|
|
29
|
-
|
|
30
|
-
this.address = null
|
|
31
|
-
this.component = null
|
|
32
|
-
this.foundation = null
|
|
33
|
-
this.port = null
|
|
34
|
-
this.priority = null
|
|
35
|
-
this.protocol = null
|
|
36
|
-
this.relatedAddress = null
|
|
37
|
-
this.relatedPort = null
|
|
38
|
-
this.tcpType = null
|
|
39
|
-
this.type = null
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
toJSON (): RTCIceCandidateInit {
|
|
43
|
-
return {
|
|
44
|
-
candidate: this.candidate,
|
|
45
|
-
sdpMLineIndex: this.sdpMLineIndex,
|
|
46
|
-
sdpMid: this.sdpMid,
|
|
47
|
-
usernameFragment: this.usernameFragment
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
}
|