node-rtc-connection 1.0.19 → 2.0.5
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/index.cjs +1 -0
- package/index.mjs +1 -0
- package/package.json +14 -46
- package/types/crypto/der.d.ts +107 -0
- package/types/crypto/x509.d.ts +56 -0
- package/types/datachannel/RTCDataChannel.d.ts +179 -0
- package/types/dtls/RTCCertificate.d.ts +163 -0
- package/types/dtls/cipher.d.ts +81 -0
- package/types/dtls/connection.d.ts +81 -0
- package/types/dtls/prf.d.ts +29 -0
- package/types/dtls/protocol.d.ts +127 -0
- package/types/foundation/ByteBufferQueue.d.ts +71 -0
- package/types/foundation/RTCError.d.ts +152 -0
- package/types/ice/RTCIceCandidate.d.ts +161 -0
- package/types/ice/ice-agent.d.ts +154 -0
- package/types/ice/stun-message.d.ts +92 -0
- package/types/index.d.ts +29 -0
- package/types/peerconnection/RTCPeerConnection.d.ts +74 -0
- package/types/sctp/association.d.ts +77 -0
- package/types/sctp/chunks.d.ts +200 -0
- package/types/sctp/crc32c.d.ts +24 -0
- package/types/sctp/datachannel-manager.d.ts +51 -0
- package/types/sctp/dcep.d.ts +56 -0
- package/types/sdp/RTCSessionDescription.d.ts +73 -0
- package/types/sdp/sdp-utils.d.ts +103 -0
- package/types/stun/stun-client.d.ts +119 -0
- package/types/transport-stack.d.ts +68 -0
- package/dist/index.cjs +0 -5618
- package/dist/index.cjs.map +0 -1
- package/dist/index.mjs +0 -5616
- 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/foundation/ByteBufferQueue.js +0 -235
- package/src/foundation/RTCError.js +0 -226
- package/src/ice/RTCIceCandidate.js +0 -301
- 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/RTCSessionDescription.js +0 -102
- package/src/sdp/sdp-utils.js +0 -224
- package/src/stun/stun-client.js +0 -777
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file datachannel-manager.ts
|
|
3
|
+
* @description Bridges SCTP streams + DCEP to RTCDataChannel instances.
|
|
4
|
+
* @module sctp/datachannel-manager
|
|
5
|
+
*
|
|
6
|
+
* Responsibilities:
|
|
7
|
+
* - Allocate SCTP stream IDs per RFC 8832 §6: the DTLS client (a=setup:active)
|
|
8
|
+
* uses even stream IDs, the DTLS server uses odd.
|
|
9
|
+
* - Send DATA_CHANNEL_OPEN and await DATA_CHANNEL_ACK; respond to inbound OPEN.
|
|
10
|
+
* - Map outgoing string/binary sends to the correct PPID, and incoming PPIDs
|
|
11
|
+
* back to string/binary, including the EMPTY variants for zero-length data.
|
|
12
|
+
*/
|
|
13
|
+
import { EventEmitter } from 'events';
|
|
14
|
+
import type { SctpAssociation } from './association';
|
|
15
|
+
import { RTCDataChannel } from '../datachannel/RTCDataChannel';
|
|
16
|
+
/** Subset of RTCDataChannelInit used when opening/accepting channels. */
|
|
17
|
+
interface ChannelInit {
|
|
18
|
+
ordered?: boolean;
|
|
19
|
+
maxRetransmits?: number | null;
|
|
20
|
+
maxPacketLifeTime?: number | null;
|
|
21
|
+
protocol?: string;
|
|
22
|
+
}
|
|
23
|
+
/** Information surfaced on the 'open-request' event for an inbound channel. */
|
|
24
|
+
export interface OpenRequestInfo {
|
|
25
|
+
streamId: number;
|
|
26
|
+
label: string;
|
|
27
|
+
protocol: string;
|
|
28
|
+
ordered: boolean;
|
|
29
|
+
channelType: number;
|
|
30
|
+
reliabilityParameter: number;
|
|
31
|
+
}
|
|
32
|
+
declare class DataChannelManager extends EventEmitter {
|
|
33
|
+
#private;
|
|
34
|
+
/**
|
|
35
|
+
* @param {import('./association').SctpAssociation} association
|
|
36
|
+
* @param {boolean} isDtlsClient - true if we are the DTLS client (even IDs)
|
|
37
|
+
*/
|
|
38
|
+
constructor(association: SctpAssociation, isDtlsClient: boolean);
|
|
39
|
+
/**
|
|
40
|
+
* Open a channel initiated locally.
|
|
41
|
+
* @param {import('../datachannel/RTCDataChannel').RTCDataChannel} channel
|
|
42
|
+
* @param {Object} init - { ordered, maxRetransmits, maxPacketLifeTime, protocol }
|
|
43
|
+
*/
|
|
44
|
+
openChannel(channel: RTCDataChannel, init?: ChannelInit): void;
|
|
45
|
+
/**
|
|
46
|
+
* Register an inbound channel (created in response to 'open-request') and
|
|
47
|
+
* attach its sender.
|
|
48
|
+
*/
|
|
49
|
+
acceptChannel(channel: RTCDataChannel, info: OpenRequestInfo): void;
|
|
50
|
+
}
|
|
51
|
+
export { DataChannelManager };
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file dcep.ts
|
|
3
|
+
* @description Data Channel Establishment Protocol (RFC 8832) message codec.
|
|
4
|
+
* @module sctp/dcep
|
|
5
|
+
*
|
|
6
|
+
* DCEP runs on PPID 50 and negotiates a data channel on an SCTP stream:
|
|
7
|
+
* DATA_CHANNEL_OPEN (0x03) -> DATA_CHANNEL_ACK (0x02)
|
|
8
|
+
*/
|
|
9
|
+
export declare const MESSAGE_TYPE: Readonly<{
|
|
10
|
+
DATA_CHANNEL_ACK: 2;
|
|
11
|
+
DATA_CHANNEL_OPEN: 3;
|
|
12
|
+
}>;
|
|
13
|
+
export declare const CHANNEL_TYPE: Readonly<{
|
|
14
|
+
RELIABLE: 0;
|
|
15
|
+
RELIABLE_UNORDERED: 128;
|
|
16
|
+
PARTIAL_RELIABLE_REXMIT: 1;
|
|
17
|
+
PARTIAL_RELIABLE_REXMIT_UNORDERED: 129;
|
|
18
|
+
PARTIAL_RELIABLE_TIMED: 2;
|
|
19
|
+
PARTIAL_RELIABLE_TIMED_UNORDERED: 130;
|
|
20
|
+
}>;
|
|
21
|
+
export interface OpenParams {
|
|
22
|
+
channelType: number;
|
|
23
|
+
priority?: number;
|
|
24
|
+
reliabilityParameter?: number;
|
|
25
|
+
label?: string;
|
|
26
|
+
protocol?: string;
|
|
27
|
+
}
|
|
28
|
+
export interface DecodedOpen {
|
|
29
|
+
channelType: number;
|
|
30
|
+
priority: number;
|
|
31
|
+
reliabilityParameter: number;
|
|
32
|
+
label: string;
|
|
33
|
+
protocol: string;
|
|
34
|
+
unordered: boolean;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Encode a DATA_CHANNEL_OPEN message.
|
|
38
|
+
* @param {Object} p
|
|
39
|
+
* @param {number} p.channelType
|
|
40
|
+
* @param {number} p.priority
|
|
41
|
+
* @param {number} p.reliabilityParameter
|
|
42
|
+
* @param {string} p.label
|
|
43
|
+
* @param {string} p.protocol
|
|
44
|
+
* @returns {Buffer}
|
|
45
|
+
*/
|
|
46
|
+
export declare function encodeOpen({ channelType, priority, reliabilityParameter, label, protocol }: OpenParams): Buffer;
|
|
47
|
+
/**
|
|
48
|
+
* Decode a DATA_CHANNEL_OPEN message.
|
|
49
|
+
* @param {Buffer} buf
|
|
50
|
+
* @returns {Object}
|
|
51
|
+
*/
|
|
52
|
+
export declare function decodeOpen(buf: Buffer): DecodedOpen;
|
|
53
|
+
/** Encode a DATA_CHANNEL_ACK message. */
|
|
54
|
+
export declare function encodeAck(): Buffer;
|
|
55
|
+
/** Return the message type of a DCEP buffer. */
|
|
56
|
+
export declare function messageType(buf: Buffer): number;
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file RTCSessionDescription.ts
|
|
3
|
+
* @description Session Description Protocol (SDP) representation
|
|
4
|
+
* @module sdp/RTCSessionDescription
|
|
5
|
+
*
|
|
6
|
+
* Implements the W3C RTCSessionDescription interface
|
|
7
|
+
* (https://www.w3.org/TR/webrtc/#rtcsessiondescription-class).
|
|
8
|
+
*/
|
|
9
|
+
/**
|
|
10
|
+
* RTCSdpType - Types of session descriptions
|
|
11
|
+
* @readonly
|
|
12
|
+
* @enum {string}
|
|
13
|
+
*/
|
|
14
|
+
export declare const RTCSdpType: Readonly<Record<string, string>>;
|
|
15
|
+
/**
|
|
16
|
+
* Session description init object.
|
|
17
|
+
*/
|
|
18
|
+
export interface RTCSessionDescriptionInit {
|
|
19
|
+
type?: string;
|
|
20
|
+
sdp?: string;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* JSON representation of an RTCSessionDescription.
|
|
24
|
+
*/
|
|
25
|
+
export interface RTCSessionDescriptionJSON {
|
|
26
|
+
type: string | null;
|
|
27
|
+
sdp: string | null;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* @class RTCSessionDescription
|
|
31
|
+
* @description Represents a WebRTC session description (offer/answer)
|
|
32
|
+
*
|
|
33
|
+
* @example
|
|
34
|
+
* const desc = new RTCSessionDescription({
|
|
35
|
+
* type: 'offer',
|
|
36
|
+
* sdp: 'v=0\r\no=- 123456 2 IN IP4 127.0.0.1\r\n...'
|
|
37
|
+
* });
|
|
38
|
+
*/
|
|
39
|
+
export declare class RTCSessionDescription {
|
|
40
|
+
#private;
|
|
41
|
+
/**
|
|
42
|
+
* Create an RTCSessionDescription instance.
|
|
43
|
+
* @param {Object} [init] - Session description init
|
|
44
|
+
* @param {string} [init.type] - SDP type (offer/answer/pranswer/rollback)
|
|
45
|
+
* @param {string} [init.sdp] - SDP string
|
|
46
|
+
*/
|
|
47
|
+
constructor(init?: RTCSessionDescriptionInit);
|
|
48
|
+
/**
|
|
49
|
+
* Get the SDP type.
|
|
50
|
+
* @returns {string|null} SDP type
|
|
51
|
+
*/
|
|
52
|
+
get type(): string | null;
|
|
53
|
+
/**
|
|
54
|
+
* Set the SDP type.
|
|
55
|
+
* @param {string} value - SDP type
|
|
56
|
+
*/
|
|
57
|
+
set type(value: string | null);
|
|
58
|
+
/**
|
|
59
|
+
* Get the SDP string.
|
|
60
|
+
* @returns {string|null} SDP string
|
|
61
|
+
*/
|
|
62
|
+
get sdp(): string | null;
|
|
63
|
+
/**
|
|
64
|
+
* Set the SDP string.
|
|
65
|
+
* @param {string} value - SDP string
|
|
66
|
+
*/
|
|
67
|
+
set sdp(value: string | null);
|
|
68
|
+
/**
|
|
69
|
+
* Convert to JSON representation.
|
|
70
|
+
* @returns {Object} JSON representation
|
|
71
|
+
*/
|
|
72
|
+
toJSON(): RTCSessionDescriptionJSON;
|
|
73
|
+
}
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file sdp-utils.ts
|
|
3
|
+
* @description SDP generation/parsing for a WebRTC data-channel m-section.
|
|
4
|
+
* @module sdp/sdp-utils
|
|
5
|
+
*
|
|
6
|
+
* Emits the standard application m-line with the SCTP-over-DTLS profile and
|
|
7
|
+
* conveys transport addresses through ICE candidates (not the c=/m= lines, per
|
|
8
|
+
* the WebRTC JSEP/SDP rules). This is what browsers expect.
|
|
9
|
+
*/
|
|
10
|
+
/** ICE credentials. */
|
|
11
|
+
export interface IceCredentials {
|
|
12
|
+
usernameFragment: string;
|
|
13
|
+
password: string;
|
|
14
|
+
}
|
|
15
|
+
/** DTLS certificate fingerprint. */
|
|
16
|
+
export interface Fingerprint {
|
|
17
|
+
algorithm: string;
|
|
18
|
+
value: string;
|
|
19
|
+
}
|
|
20
|
+
/** A candidate descriptor as accepted by {@link buildSdp}. */
|
|
21
|
+
export interface CandidateInput {
|
|
22
|
+
sdp?: string;
|
|
23
|
+
candidate?: string;
|
|
24
|
+
}
|
|
25
|
+
/** Options accepted by {@link buildSdp}. */
|
|
26
|
+
export interface BuildSdpOptions {
|
|
27
|
+
kind?: 'offer' | 'answer';
|
|
28
|
+
iceUfrag: string;
|
|
29
|
+
icePwd: string;
|
|
30
|
+
fingerprint?: Fingerprint;
|
|
31
|
+
setup?: string;
|
|
32
|
+
candidates?: CandidateInput[];
|
|
33
|
+
sctpPort?: number;
|
|
34
|
+
maxMessageSize?: number;
|
|
35
|
+
}
|
|
36
|
+
/** Options accepted by {@link generateOffer} / {@link generateAnswer}. */
|
|
37
|
+
export interface GenerateOptions extends BuildSdpOptions {
|
|
38
|
+
}
|
|
39
|
+
/** Parsed ICE parameters. */
|
|
40
|
+
export interface IceParameters {
|
|
41
|
+
usernameFragment: string | null;
|
|
42
|
+
password: string | null;
|
|
43
|
+
}
|
|
44
|
+
/** Parsed DTLS parameters. */
|
|
45
|
+
export interface DtlsParameters {
|
|
46
|
+
role: string;
|
|
47
|
+
fingerprints: Fingerprint[];
|
|
48
|
+
setup?: string;
|
|
49
|
+
}
|
|
50
|
+
/** Parsed SCTP parameters. */
|
|
51
|
+
export interface SctpParameters {
|
|
52
|
+
port: number;
|
|
53
|
+
maxMessageSize: number;
|
|
54
|
+
}
|
|
55
|
+
/** A parsed ICE candidate. */
|
|
56
|
+
export interface ParsedCandidate {
|
|
57
|
+
candidate: string;
|
|
58
|
+
foundation: string;
|
|
59
|
+
component: number;
|
|
60
|
+
protocol: string;
|
|
61
|
+
priority: number;
|
|
62
|
+
address: string;
|
|
63
|
+
port: number;
|
|
64
|
+
type: string;
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Generate ICE credentials (ufrag >= 4 chars, pwd >= 22 chars per RFC 8445).
|
|
68
|
+
* @returns {{usernameFragment:string, password:string}}
|
|
69
|
+
*/
|
|
70
|
+
export declare function generateIceCredentials(): IceCredentials;
|
|
71
|
+
/**
|
|
72
|
+
* Build the SDP for a data-channel-only session.
|
|
73
|
+
* @param {Object} o
|
|
74
|
+
* @param {'offer'|'answer'} o.kind
|
|
75
|
+
* @param {string} o.iceUfrag
|
|
76
|
+
* @param {string} o.icePwd
|
|
77
|
+
* @param {{algorithm:string,value:string}} o.fingerprint - DTLS cert fingerprint
|
|
78
|
+
* @param {string} o.setup - 'actpass' | 'active' | 'passive'
|
|
79
|
+
* @param {Array<{sdp?:string,candidate?:string}>} [o.candidates]
|
|
80
|
+
* @param {number} [o.sctpPort=5000]
|
|
81
|
+
* @param {number} [o.maxMessageSize=262144]
|
|
82
|
+
* @returns {string}
|
|
83
|
+
*/
|
|
84
|
+
export declare function buildSdp(o: BuildSdpOptions): string;
|
|
85
|
+
export declare function generateOffer(opts: GenerateOptions): string;
|
|
86
|
+
export declare function generateAnswer(opts: GenerateOptions): string;
|
|
87
|
+
/** Parse ICE ufrag/pwd. */
|
|
88
|
+
export declare function parseIceParameters(sdp: string): IceParameters;
|
|
89
|
+
/** Parse DTLS setup role + fingerprints. */
|
|
90
|
+
export declare function parseDtlsParameters(sdp: string): DtlsParameters;
|
|
91
|
+
/** Parse SCTP port / max message size. */
|
|
92
|
+
export declare function parseSctpParameters(sdp: string): SctpParameters;
|
|
93
|
+
/**
|
|
94
|
+
* Parse ICE candidate lines into structured objects.
|
|
95
|
+
* @param {string} sdp
|
|
96
|
+
* @returns {Array<{candidate:string,foundation:string,component:number,protocol:string,priority:number,address:string,port:number,type:string}>}
|
|
97
|
+
*/
|
|
98
|
+
export declare function parseCandidates(sdp: string): ParsedCandidate[];
|
|
99
|
+
/**
|
|
100
|
+
* Parse a single "candidate:..." string.
|
|
101
|
+
* @param {string} str
|
|
102
|
+
*/
|
|
103
|
+
export declare function parseCandidateLine(str: string): ParsedCandidate | null;
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file stun-client.ts
|
|
3
|
+
* @description STUN (Session Traversal Utilities for NAT) client implementation
|
|
4
|
+
* @module stun/stun-client
|
|
5
|
+
*
|
|
6
|
+
* STUN Protocol: RFC 5389
|
|
7
|
+
* TURN Protocol: RFC 5766
|
|
8
|
+
*/
|
|
9
|
+
import { EventEmitter } from 'events';
|
|
10
|
+
/**
|
|
11
|
+
* Constructor options for {@link STUNClient}.
|
|
12
|
+
*/
|
|
13
|
+
interface STUNClientOptions {
|
|
14
|
+
/** STUN/TURN server address */
|
|
15
|
+
server: string;
|
|
16
|
+
/** Server port */
|
|
17
|
+
port: number;
|
|
18
|
+
/** TURN username */
|
|
19
|
+
username?: string;
|
|
20
|
+
/** TURN password */
|
|
21
|
+
credential?: string;
|
|
22
|
+
/** Transport protocol (udp/tcp) */
|
|
23
|
+
transport?: string;
|
|
24
|
+
/** Additional query parameters from URL */
|
|
25
|
+
params?: Record<string, unknown>;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Reflexive address info resolved from a STUN Binding response.
|
|
29
|
+
*/
|
|
30
|
+
interface ReflexiveAddress {
|
|
31
|
+
address: string;
|
|
32
|
+
port: number;
|
|
33
|
+
family: string;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Relay address info resolved from a TURN Allocate response.
|
|
37
|
+
*/
|
|
38
|
+
interface RelayAddress {
|
|
39
|
+
relayedAddress: string;
|
|
40
|
+
relayedPort: number;
|
|
41
|
+
lifetime: number;
|
|
42
|
+
type: 'relay';
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Result of a TURN Refresh response.
|
|
46
|
+
*/
|
|
47
|
+
interface RefreshResult {
|
|
48
|
+
lifetime: number;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Result of a generic success response (CreatePermission / ChannelBind).
|
|
52
|
+
*/
|
|
53
|
+
interface OkResult {
|
|
54
|
+
ok: true;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Union of every result shape a transaction may resolve with.
|
|
58
|
+
*/
|
|
59
|
+
type TransactionResult = ReflexiveAddress | RelayAddress | RefreshResult | OkResult;
|
|
60
|
+
/**
|
|
61
|
+
* @class STUNClient
|
|
62
|
+
* @description STUN/TURN client for NAT traversal
|
|
63
|
+
*/
|
|
64
|
+
declare class STUNClient extends EventEmitter {
|
|
65
|
+
#private;
|
|
66
|
+
/**
|
|
67
|
+
* Create a STUN client
|
|
68
|
+
* @param {Object} options - Client options
|
|
69
|
+
* @param {string} options.server - STUN/TURN server address
|
|
70
|
+
* @param {number} options.port - Server port
|
|
71
|
+
* @param {string} [options.username] - TURN username
|
|
72
|
+
* @param {string} [options.credential] - TURN password
|
|
73
|
+
* @param {string} [options.transport='udp'] - Transport protocol (udp/tcp)
|
|
74
|
+
* @param {Object} [options.params={}] - Additional query parameters from URL
|
|
75
|
+
*/
|
|
76
|
+
constructor(options: STUNClientOptions);
|
|
77
|
+
/**
|
|
78
|
+
* Connect to the STUN/TURN server
|
|
79
|
+
* @returns {Promise<void>}
|
|
80
|
+
*/
|
|
81
|
+
connect(): Promise<void>;
|
|
82
|
+
/**
|
|
83
|
+
* Send a STUN Binding Request to get reflexive address
|
|
84
|
+
* @returns {Promise<Object>} Reflexive address info
|
|
85
|
+
*/
|
|
86
|
+
getReflexiveAddress(): Promise<TransactionResult>;
|
|
87
|
+
/**
|
|
88
|
+
* Send a TURN Allocate Request to get relay address
|
|
89
|
+
* @param {number} [lifetime=600] - Allocation lifetime in seconds
|
|
90
|
+
* @returns {Promise<Object>} Relay address info
|
|
91
|
+
*/
|
|
92
|
+
allocateRelay(lifetime?: number): Promise<TransactionResult>;
|
|
93
|
+
/**
|
|
94
|
+
* Send a TURN Refresh Request to keep allocation alive
|
|
95
|
+
* @param {number} [lifetime=600] - Allocation lifetime in seconds
|
|
96
|
+
* @returns {Promise<Object>} Updated allocation info
|
|
97
|
+
*/
|
|
98
|
+
refreshAllocation(lifetime?: number): Promise<TransactionResult>;
|
|
99
|
+
/**
|
|
100
|
+
* Create a TURN Permission for a peer
|
|
101
|
+
* @param {string} peerAddress - Peer IP address
|
|
102
|
+
* @returns {Promise<void>}
|
|
103
|
+
*/
|
|
104
|
+
createPermission(peerAddress: string): Promise<void>;
|
|
105
|
+
/**
|
|
106
|
+
* Send data to a peer via TURN Send Indication
|
|
107
|
+
* @param {string} peerAddress - Peer IP address
|
|
108
|
+
* @param {number} peerPort - Peer port
|
|
109
|
+
* @param {Buffer} data - Data to send
|
|
110
|
+
* @returns {Promise<void>}
|
|
111
|
+
*/
|
|
112
|
+
sendIndication(peerAddress: string, peerPort: number, data: Buffer): Promise<void>;
|
|
113
|
+
/**
|
|
114
|
+
* Close the client
|
|
115
|
+
*/
|
|
116
|
+
close(): void;
|
|
117
|
+
}
|
|
118
|
+
export default STUNClient;
|
|
119
|
+
export { STUNClient };
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file transport-stack.ts
|
|
3
|
+
* @description Composes ICE -> DTLS -> SCTP -> DCEP into one transport, the
|
|
4
|
+
* real WebRTC data-channel pipeline.
|
|
5
|
+
* @module transport-stack
|
|
6
|
+
*
|
|
7
|
+
* Wiring:
|
|
8
|
+
* IceAgent emits 'data' (non-STUN datagrams) -> DtlsConnection.handlePacket
|
|
9
|
+
* DtlsConnection.output -> IceAgent.send
|
|
10
|
+
* DtlsConnection 'data' (app records) -> SctpAssociation.receivePacket
|
|
11
|
+
* SctpAssociation 'output' -> DtlsConnection.send
|
|
12
|
+
* SctpAssociation + DataChannelManager -> RTCDataChannel
|
|
13
|
+
*
|
|
14
|
+
* The DTLS client/server role follows the negotiated a=setup; the SCTP client
|
|
15
|
+
* (INIT initiator) is the DTLS client, per RFC 8832.
|
|
16
|
+
*/
|
|
17
|
+
import { EventEmitter } from 'events';
|
|
18
|
+
import { IceAgent } from './ice/ice-agent';
|
|
19
|
+
import { DtlsConnection } from './dtls/connection';
|
|
20
|
+
import { SctpAssociation } from './sctp/association';
|
|
21
|
+
import { DataChannelManager, OpenRequestInfo } from './sctp/datachannel-manager';
|
|
22
|
+
import type { RTCDataChannel, RTCDataChannelInit } from './datachannel/RTCDataChannel';
|
|
23
|
+
import type { KeyObject } from 'crypto';
|
|
24
|
+
export interface TransportStackOptions {
|
|
25
|
+
/** ICE controlling vs controlled (offerer is controlling). */
|
|
26
|
+
iceRole: 'controlling' | 'controlled';
|
|
27
|
+
/** DTLS role from a=setup (active=client). */
|
|
28
|
+
dtlsRole: 'client' | 'server';
|
|
29
|
+
localUfrag: string;
|
|
30
|
+
localPwd: string;
|
|
31
|
+
certDer: Buffer;
|
|
32
|
+
privateKey: KeyObject;
|
|
33
|
+
verifyFingerprint?: (fp: {
|
|
34
|
+
algorithm: string;
|
|
35
|
+
value: string;
|
|
36
|
+
}) => boolean;
|
|
37
|
+
}
|
|
38
|
+
export declare class TransportStack extends EventEmitter {
|
|
39
|
+
#private;
|
|
40
|
+
ice: IceAgent;
|
|
41
|
+
dtls: DtlsConnection | null;
|
|
42
|
+
sctp: SctpAssociation | null;
|
|
43
|
+
dcm: DataChannelManager | null;
|
|
44
|
+
constructor(opts: TransportStackOptions);
|
|
45
|
+
/**
|
|
46
|
+
* Begin gathering local candidates.
|
|
47
|
+
* @param opts - { iceServers, iceTransportPolicy } forwarded to ICE.
|
|
48
|
+
*/
|
|
49
|
+
gather(opts?: {
|
|
50
|
+
iceServers?: unknown[];
|
|
51
|
+
iceTransportPolicy?: 'all' | 'relay';
|
|
52
|
+
}): Promise<void>;
|
|
53
|
+
getLocalCandidates(): ReturnType<IceAgent['getLocalCandidates']>;
|
|
54
|
+
/** Provide the peer's ICE credentials and start checks when ready. */
|
|
55
|
+
setRemote(ufrag: string, pwd: string): void;
|
|
56
|
+
addRemoteCandidate(cand: {
|
|
57
|
+
address: string;
|
|
58
|
+
port: number;
|
|
59
|
+
type?: string;
|
|
60
|
+
priority?: number;
|
|
61
|
+
}): void;
|
|
62
|
+
/** Open a locally-initiated data channel once SCTP is established. */
|
|
63
|
+
openChannel(channel: RTCDataChannel, init: RTCDataChannelInit): void;
|
|
64
|
+
/** Accept an inbound channel created from a 'datachannel-request'. */
|
|
65
|
+
acceptChannel(channel: RTCDataChannel, info: OpenRequestInfo): void;
|
|
66
|
+
isReady(): boolean;
|
|
67
|
+
close(): void;
|
|
68
|
+
}
|