node-rtc-connection 1.0.19 → 2.0.4
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 +94 -85
- package/dist/index.cjs +20 -5606
- package/dist/index.mjs +25 -5598
- package/dist/types/crypto/der.d.ts +107 -0
- package/dist/types/crypto/x509.d.ts +56 -0
- package/dist/types/datachannel/RTCDataChannel.d.ts +179 -0
- package/dist/types/dtls/RTCCertificate.d.ts +163 -0
- package/dist/types/dtls/cipher.d.ts +81 -0
- package/dist/types/dtls/connection.d.ts +81 -0
- package/dist/types/dtls/prf.d.ts +29 -0
- package/dist/types/dtls/protocol.d.ts +127 -0
- package/dist/types/foundation/ByteBufferQueue.d.ts +71 -0
- package/dist/types/foundation/RTCError.d.ts +152 -0
- package/dist/types/ice/RTCIceCandidate.d.ts +161 -0
- package/dist/types/ice/ice-agent.d.ts +154 -0
- package/dist/types/ice/stun-message.d.ts +92 -0
- package/dist/types/index.d.ts +29 -0
- package/dist/types/peerconnection/RTCPeerConnection.d.ts +74 -0
- package/dist/types/sctp/association.d.ts +77 -0
- package/dist/types/sctp/chunks.d.ts +200 -0
- package/dist/types/sctp/crc32c.d.ts +24 -0
- package/dist/types/sctp/datachannel-manager.d.ts +51 -0
- package/dist/types/sctp/dcep.d.ts +56 -0
- package/dist/types/sdp/RTCSessionDescription.d.ts +73 -0
- package/dist/types/sdp/sdp-utils.d.ts +103 -0
- package/dist/types/stun/stun-client.d.ts +119 -0
- package/dist/types/transport-stack.d.ts +68 -0
- package/package.json +26 -21
- package/src/crypto/der.ts +205 -0
- package/src/crypto/x509.ts +146 -0
- package/src/datachannel/RTCDataChannel.ts +388 -0
- package/src/dtls/RTCCertificate.ts +396 -0
- package/src/dtls/cipher.ts +198 -0
- package/src/dtls/connection.ts +974 -0
- package/src/dtls/prf.ts +62 -0
- package/src/dtls/protocol.ts +204 -0
- package/src/foundation/{ByteBufferQueue.js → ByteBufferQueue.ts} +74 -72
- package/src/foundation/{RTCError.js → RTCError.ts} +110 -60
- package/src/ice/{RTCIceCandidate.js → RTCIceCandidate.ts} +140 -92
- package/src/ice/ice-agent.ts +609 -0
- package/src/ice/stun-message.ts +260 -0
- package/src/index.ts +72 -0
- package/src/peerconnection/RTCPeerConnection.ts +430 -0
- package/src/sctp/association.ts +523 -0
- package/src/sctp/chunks.ts +350 -0
- package/src/sctp/crc32c.ts +57 -0
- package/src/sctp/datachannel-manager.ts +187 -0
- package/src/sctp/dcep.ts +94 -0
- package/src/sdp/{RTCSessionDescription.js → RTCSessionDescription.ts} +42 -29
- package/src/sdp/sdp-utils.ts +229 -0
- package/src/stun/{stun-client.js → stun-client.ts} +346 -187
- package/src/transport-stack.ts +165 -0
- package/dist/index.cjs.map +0 -1
- package/dist/index.mjs.map +0 -1
- package/src/datachannel/RTCDataChannel.js +0 -354
- package/src/dtls/RTCCertificate.js +0 -310
- package/src/dtls/RTCDtlsTransport.js +0 -247
- package/src/ice/RTCIceTransport.js +0 -1018
- package/src/index.d.ts +0 -400
- package/src/index.js +0 -92
- package/src/network/network-transport.js +0 -478
- package/src/peerconnection/RTCPeerConnection.js +0 -875
- package/src/sctp/RTCSctpTransport.js +0 -253
- package/src/sdp/sdp-utils.js +0 -224
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @
|
|
3
|
-
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
2
|
+
* @file RTCError - WebRTC-specific error types.
|
|
3
|
+
*
|
|
4
|
+
* Implements the W3C RTCError interface
|
|
5
|
+
* (https://www.w3.org/TR/webrtc/#rtcerror-interface).
|
|
6
|
+
*
|
|
7
7
|
* Provides WebRTC-specific error types extending the standard Error class
|
|
8
8
|
* with additional error detail types and metadata fields.
|
|
9
|
-
*
|
|
10
|
-
* @license
|
|
9
|
+
*
|
|
10
|
+
* @license MIT
|
|
11
11
|
* @author nmhung1210
|
|
12
12
|
*/
|
|
13
13
|
|
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
/**
|
|
17
17
|
* RTCErrorDetailType enum - Standardized WebRTC error details.
|
|
18
18
|
* Maps to RTCErrorDetailType from the WebRTC spec.
|
|
19
|
-
*
|
|
19
|
+
*
|
|
20
20
|
* @readonly
|
|
21
21
|
* @enum {string}
|
|
22
22
|
*/
|
|
@@ -32,18 +32,73 @@ const RTCErrorDetailType = Object.freeze({
|
|
|
32
32
|
INVALID_STATE: 'invalid-state',
|
|
33
33
|
INVALID_MODIFICATION: 'invalid-modification',
|
|
34
34
|
INVALID_ACCESS_ERROR: 'invalid-access-error',
|
|
35
|
-
OPERATION_ERROR: 'operation-error'
|
|
36
|
-
});
|
|
35
|
+
OPERATION_ERROR: 'operation-error',
|
|
36
|
+
} as const);
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Error detail type string union.
|
|
40
|
+
*/
|
|
41
|
+
type RTCErrorDetail = typeof RTCErrorDetailType[keyof typeof RTCErrorDetailType];
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Error initialization dictionary.
|
|
45
|
+
*/
|
|
46
|
+
interface RTCErrorInit {
|
|
47
|
+
errorDetail?: string;
|
|
48
|
+
sdpLineNumber?: number | null;
|
|
49
|
+
httpRequestStatusCode?: number | null;
|
|
50
|
+
sctpCauseCode?: number | null;
|
|
51
|
+
receivedAlert?: number | null;
|
|
52
|
+
sentAlert?: number | null;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Native WebRTC error object shape.
|
|
57
|
+
*/
|
|
58
|
+
interface NativeRTCError {
|
|
59
|
+
error_detail?: string;
|
|
60
|
+
sctp_cause_code?: number;
|
|
61
|
+
message?: string;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* JSON representation of an RTCError.
|
|
66
|
+
*/
|
|
67
|
+
interface RTCErrorJSON {
|
|
68
|
+
name: string;
|
|
69
|
+
message: string;
|
|
70
|
+
errorDetail: string;
|
|
71
|
+
sdpLineNumber?: number;
|
|
72
|
+
httpRequestStatusCode?: number;
|
|
73
|
+
sctpCauseCode?: number;
|
|
74
|
+
receivedAlert?: number;
|
|
75
|
+
sentAlert?: number;
|
|
76
|
+
}
|
|
37
77
|
|
|
38
78
|
/**
|
|
39
79
|
* RTCError extends Error with WebRTC-specific error details.
|
|
40
|
-
*
|
|
80
|
+
*
|
|
41
81
|
* @extends Error
|
|
42
82
|
*/
|
|
43
83
|
class RTCError extends Error {
|
|
84
|
+
/** Export error detail types as static property */
|
|
85
|
+
static readonly DetailType = RTCErrorDetailType;
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* Specific error category.
|
|
89
|
+
* @private {string}
|
|
90
|
+
*/
|
|
91
|
+
#errorDetail: string;
|
|
92
|
+
|
|
93
|
+
#sdpLineNumber: number | null;
|
|
94
|
+
#httpRequestStatusCode: number | null;
|
|
95
|
+
#sctpCauseCode: number | null;
|
|
96
|
+
#receivedAlert: number | null;
|
|
97
|
+
#sentAlert: number | null;
|
|
98
|
+
|
|
44
99
|
/**
|
|
45
100
|
* Creates a new RTCError.
|
|
46
|
-
*
|
|
101
|
+
*
|
|
47
102
|
* @param {RTCErrorInit} [init={}] - Error initialization dictionary
|
|
48
103
|
* @param {string} [init.errorDetail='none'] - Error detail type
|
|
49
104
|
* @param {number} [init.sdpLineNumber] - SDP line number where error occurred
|
|
@@ -53,11 +108,11 @@ class RTCError extends Error {
|
|
|
53
108
|
* @param {number} [init.sentAlert] - TLS alert sent
|
|
54
109
|
* @param {string} [message=''] - Error message
|
|
55
110
|
*/
|
|
56
|
-
constructor(init = {}, message = '') {
|
|
111
|
+
constructor(init: RTCErrorInit = {}, message = '') {
|
|
57
112
|
super(message);
|
|
58
|
-
|
|
113
|
+
|
|
59
114
|
this.name = 'RTCError';
|
|
60
|
-
|
|
115
|
+
|
|
61
116
|
// Maintain stack trace in V8
|
|
62
117
|
if (Error.captureStackTrace) {
|
|
63
118
|
Error.captureStackTrace(this, RTCError);
|
|
@@ -68,19 +123,15 @@ class RTCError extends Error {
|
|
|
68
123
|
if (typeof errorDetail !== 'string') {
|
|
69
124
|
throw new TypeError('errorDetail must be a string');
|
|
70
125
|
}
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
* Specific error category.
|
|
74
|
-
* @private {string}
|
|
75
|
-
*/
|
|
76
|
-
this._errorDetail = errorDetail;
|
|
126
|
+
|
|
127
|
+
this.#errorDetail = errorDetail;
|
|
77
128
|
|
|
78
129
|
// Optional numeric fields with validation
|
|
79
|
-
this
|
|
80
|
-
this
|
|
81
|
-
this
|
|
82
|
-
this
|
|
83
|
-
this
|
|
130
|
+
this.#sdpLineNumber = this.#validateInteger(init.sdpLineNumber, 'sdpLineNumber');
|
|
131
|
+
this.#httpRequestStatusCode = this.#validateInteger(init.httpRequestStatusCode, 'httpRequestStatusCode');
|
|
132
|
+
this.#sctpCauseCode = this.#validateInteger(init.sctpCauseCode, 'sctpCauseCode');
|
|
133
|
+
this.#receivedAlert = this.#validateUnsignedInteger(init.receivedAlert, 'receivedAlert');
|
|
134
|
+
this.#sentAlert = this.#validateUnsignedInteger(init.sentAlert, 'sentAlert');
|
|
84
135
|
}
|
|
85
136
|
|
|
86
137
|
/**
|
|
@@ -91,7 +142,7 @@ class RTCError extends Error {
|
|
|
91
142
|
* @returns {number|null}
|
|
92
143
|
* @throws {TypeError} If value is not an integer
|
|
93
144
|
*/
|
|
94
|
-
|
|
145
|
+
#validateInteger(value: number | null | undefined, fieldName: string): number | null {
|
|
95
146
|
if (value === undefined || value === null) {
|
|
96
147
|
return null;
|
|
97
148
|
}
|
|
@@ -110,7 +161,7 @@ class RTCError extends Error {
|
|
|
110
161
|
* @returns {number|null}
|
|
111
162
|
* @throws {TypeError} If value is not an unsigned integer
|
|
112
163
|
*/
|
|
113
|
-
|
|
164
|
+
#validateUnsignedInteger(value: number | null | undefined, fieldName: string): number | null {
|
|
114
165
|
if (value === undefined || value === null) {
|
|
115
166
|
return null;
|
|
116
167
|
}
|
|
@@ -125,75 +176,75 @@ class RTCError extends Error {
|
|
|
125
176
|
* RTCErrorDetailType - specific error category.
|
|
126
177
|
* @type {string}
|
|
127
178
|
*/
|
|
128
|
-
get errorDetail() {
|
|
129
|
-
return this
|
|
179
|
+
get errorDetail(): string {
|
|
180
|
+
return this.#errorDetail;
|
|
130
181
|
}
|
|
131
182
|
|
|
132
183
|
/**
|
|
133
184
|
* SDP line number where the error occurred (if applicable).
|
|
134
185
|
* @type {number|null}
|
|
135
186
|
*/
|
|
136
|
-
get sdpLineNumber() {
|
|
137
|
-
return this
|
|
187
|
+
get sdpLineNumber(): number | null {
|
|
188
|
+
return this.#sdpLineNumber;
|
|
138
189
|
}
|
|
139
190
|
|
|
140
191
|
/**
|
|
141
192
|
* HTTP request status code (if applicable).
|
|
142
193
|
* @type {number|null}
|
|
143
194
|
*/
|
|
144
|
-
get httpRequestStatusCode() {
|
|
145
|
-
return this
|
|
195
|
+
get httpRequestStatusCode(): number | null {
|
|
196
|
+
return this.#httpRequestStatusCode;
|
|
146
197
|
}
|
|
147
198
|
|
|
148
199
|
/**
|
|
149
200
|
* SCTP cause code (if applicable).
|
|
150
201
|
* @type {number|null}
|
|
151
202
|
*/
|
|
152
|
-
get sctpCauseCode() {
|
|
153
|
-
return this
|
|
203
|
+
get sctpCauseCode(): number | null {
|
|
204
|
+
return this.#sctpCauseCode;
|
|
154
205
|
}
|
|
155
206
|
|
|
156
207
|
/**
|
|
157
208
|
* TLS alert value received (if applicable).
|
|
158
209
|
* @type {number|null}
|
|
159
210
|
*/
|
|
160
|
-
get receivedAlert() {
|
|
161
|
-
return this
|
|
211
|
+
get receivedAlert(): number | null {
|
|
212
|
+
return this.#receivedAlert;
|
|
162
213
|
}
|
|
163
214
|
|
|
164
215
|
/**
|
|
165
216
|
* TLS alert value sent (if applicable).
|
|
166
217
|
* @type {number|null}
|
|
167
218
|
*/
|
|
168
|
-
get sentAlert() {
|
|
169
|
-
return this
|
|
219
|
+
get sentAlert(): number | null {
|
|
220
|
+
return this.#sentAlert;
|
|
170
221
|
}
|
|
171
222
|
|
|
172
223
|
/**
|
|
173
224
|
* Converts error to JSON representation.
|
|
174
225
|
* @returns {Object} JSON representation of the error
|
|
175
226
|
*/
|
|
176
|
-
toJSON() {
|
|
177
|
-
const json = {
|
|
227
|
+
toJSON(): RTCErrorJSON {
|
|
228
|
+
const json: RTCErrorJSON = {
|
|
178
229
|
name: this.name,
|
|
179
230
|
message: this.message,
|
|
180
|
-
errorDetail: this
|
|
231
|
+
errorDetail: this.#errorDetail,
|
|
181
232
|
};
|
|
182
233
|
|
|
183
|
-
if (this
|
|
184
|
-
json.sdpLineNumber = this
|
|
234
|
+
if (this.#sdpLineNumber !== null) {
|
|
235
|
+
json.sdpLineNumber = this.#sdpLineNumber;
|
|
185
236
|
}
|
|
186
|
-
if (this
|
|
187
|
-
json.httpRequestStatusCode = this
|
|
237
|
+
if (this.#httpRequestStatusCode !== null) {
|
|
238
|
+
json.httpRequestStatusCode = this.#httpRequestStatusCode;
|
|
188
239
|
}
|
|
189
|
-
if (this
|
|
190
|
-
json.sctpCauseCode = this
|
|
240
|
+
if (this.#sctpCauseCode !== null) {
|
|
241
|
+
json.sctpCauseCode = this.#sctpCauseCode;
|
|
191
242
|
}
|
|
192
|
-
if (this
|
|
193
|
-
json.receivedAlert = this
|
|
243
|
+
if (this.#receivedAlert !== null) {
|
|
244
|
+
json.receivedAlert = this.#receivedAlert;
|
|
194
245
|
}
|
|
195
|
-
if (this
|
|
196
|
-
json.sentAlert = this
|
|
246
|
+
if (this.#sentAlert !== null) {
|
|
247
|
+
json.sentAlert = this.#sentAlert;
|
|
197
248
|
}
|
|
198
249
|
|
|
199
250
|
return json;
|
|
@@ -207,9 +258,9 @@ class RTCError extends Error {
|
|
|
207
258
|
* @param {string} [nativeError.message] - Error message
|
|
208
259
|
* @returns {RTCError}
|
|
209
260
|
*/
|
|
210
|
-
static fromNative(nativeError) {
|
|
211
|
-
const init = {
|
|
212
|
-
errorDetail: nativeError.error_detail || RTCErrorDetailType.NONE
|
|
261
|
+
static fromNative(nativeError: NativeRTCError): RTCError {
|
|
262
|
+
const init: RTCErrorInit = {
|
|
263
|
+
errorDetail: nativeError.error_detail || RTCErrorDetailType.NONE,
|
|
213
264
|
};
|
|
214
265
|
|
|
215
266
|
if (nativeError.sctp_cause_code !== undefined) {
|
|
@@ -220,7 +271,6 @@ class RTCError extends Error {
|
|
|
220
271
|
}
|
|
221
272
|
}
|
|
222
273
|
|
|
223
|
-
|
|
224
|
-
RTCError
|
|
225
|
-
|
|
226
|
-
module.exports = RTCError;
|
|
274
|
+
export default RTCError;
|
|
275
|
+
export { RTCError, RTCErrorDetailType };
|
|
276
|
+
export type { RTCErrorInit, RTCErrorDetail, NativeRTCError, RTCErrorJSON };
|