node-rtc-connection 2.0.4 → 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.
Files changed (53) hide show
  1. package/index.cjs +1 -0
  2. package/index.mjs +1 -0
  3. package/package.json +10 -47
  4. package/dist/index.cjs +0 -32
  5. package/dist/index.mjs +0 -43
  6. package/src/crypto/der.ts +0 -205
  7. package/src/crypto/x509.ts +0 -146
  8. package/src/datachannel/RTCDataChannel.ts +0 -388
  9. package/src/dtls/RTCCertificate.ts +0 -396
  10. package/src/dtls/cipher.ts +0 -198
  11. package/src/dtls/connection.ts +0 -974
  12. package/src/dtls/prf.ts +0 -62
  13. package/src/dtls/protocol.ts +0 -204
  14. package/src/foundation/ByteBufferQueue.ts +0 -237
  15. package/src/foundation/RTCError.ts +0 -276
  16. package/src/ice/RTCIceCandidate.ts +0 -349
  17. package/src/ice/ice-agent.ts +0 -609
  18. package/src/ice/stun-message.ts +0 -260
  19. package/src/index.ts +0 -72
  20. package/src/peerconnection/RTCPeerConnection.ts +0 -430
  21. package/src/sctp/association.ts +0 -523
  22. package/src/sctp/chunks.ts +0 -350
  23. package/src/sctp/crc32c.ts +0 -57
  24. package/src/sctp/datachannel-manager.ts +0 -187
  25. package/src/sctp/dcep.ts +0 -94
  26. package/src/sdp/RTCSessionDescription.ts +0 -115
  27. package/src/sdp/sdp-utils.ts +0 -229
  28. package/src/stun/stun-client.ts +0 -936
  29. package/src/transport-stack.ts +0 -165
  30. /package/{dist/types → types}/crypto/der.d.ts +0 -0
  31. /package/{dist/types → types}/crypto/x509.d.ts +0 -0
  32. /package/{dist/types → types}/datachannel/RTCDataChannel.d.ts +0 -0
  33. /package/{dist/types → types}/dtls/RTCCertificate.d.ts +0 -0
  34. /package/{dist/types → types}/dtls/cipher.d.ts +0 -0
  35. /package/{dist/types → types}/dtls/connection.d.ts +0 -0
  36. /package/{dist/types → types}/dtls/prf.d.ts +0 -0
  37. /package/{dist/types → types}/dtls/protocol.d.ts +0 -0
  38. /package/{dist/types → types}/foundation/ByteBufferQueue.d.ts +0 -0
  39. /package/{dist/types → types}/foundation/RTCError.d.ts +0 -0
  40. /package/{dist/types → types}/ice/RTCIceCandidate.d.ts +0 -0
  41. /package/{dist/types → types}/ice/ice-agent.d.ts +0 -0
  42. /package/{dist/types → types}/ice/stun-message.d.ts +0 -0
  43. /package/{dist/types → types}/index.d.ts +0 -0
  44. /package/{dist/types → types}/peerconnection/RTCPeerConnection.d.ts +0 -0
  45. /package/{dist/types → types}/sctp/association.d.ts +0 -0
  46. /package/{dist/types → types}/sctp/chunks.d.ts +0 -0
  47. /package/{dist/types → types}/sctp/crc32c.d.ts +0 -0
  48. /package/{dist/types → types}/sctp/datachannel-manager.d.ts +0 -0
  49. /package/{dist/types → types}/sctp/dcep.d.ts +0 -0
  50. /package/{dist/types → types}/sdp/RTCSessionDescription.d.ts +0 -0
  51. /package/{dist/types → types}/sdp/sdp-utils.d.ts +0 -0
  52. /package/{dist/types → types}/stun/stun-client.d.ts +0 -0
  53. /package/{dist/types → types}/transport-stack.d.ts +0 -0
@@ -1,165 +0,0 @@
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
-
18
- import { EventEmitter } from 'events';
19
- import { IceAgent } from './ice/ice-agent';
20
- import { DtlsConnection, ROLE as DTLS_ROLE } from './dtls/connection';
21
- import { SctpAssociation } from './sctp/association';
22
- import { DataChannelManager, OpenRequestInfo } from './sctp/datachannel-manager';
23
- import type { RTCDataChannel, RTCDataChannelInit } from './datachannel/RTCDataChannel';
24
- import type { KeyObject } from 'crypto';
25
-
26
- export interface TransportStackOptions {
27
- /** ICE controlling vs controlled (offerer is controlling). */
28
- iceRole: 'controlling' | 'controlled';
29
- /** DTLS role from a=setup (active=client). */
30
- dtlsRole: 'client' | 'server';
31
- localUfrag: string;
32
- localPwd: string;
33
- certDer: Buffer;
34
- privateKey: KeyObject;
35
- verifyFingerprint?: (fp: { algorithm: string; value: string }) => boolean;
36
- }
37
-
38
- export class TransportStack extends EventEmitter {
39
- #opts: TransportStackOptions;
40
- ice: IceAgent;
41
- dtls: DtlsConnection | null;
42
- sctp: SctpAssociation | null;
43
- dcm: DataChannelManager | null;
44
- #dtlsStarted: boolean;
45
-
46
- constructor(opts: TransportStackOptions) {
47
- super();
48
- this.#opts = opts;
49
- this.ice = new IceAgent({
50
- role: opts.iceRole,
51
- localUfrag: opts.localUfrag,
52
- localPwd: opts.localPwd,
53
- });
54
- this.dtls = null;
55
- this.sctp = null;
56
- this.dcm = null;
57
- this.#dtlsStarted = false;
58
-
59
- this.ice.on('candidate', (c) => this.emit('candidate', c));
60
- this.ice.on('error', (e) => this.emit('error', e));
61
- this.ice.on('failed', () => this.emit('error', new Error('ICE failed')));
62
-
63
- // Inbound DTLS datagrams from the selected/learned path.
64
- this.ice.on('data', (msg: Buffer) => {
65
- if (this.dtls) this.dtls.handlePacket(msg);
66
- });
67
-
68
- this.ice.on('connected', () => {
69
- this.emit('iceconnected');
70
- this.#startDtls();
71
- });
72
- }
73
-
74
- /**
75
- * Begin gathering local candidates.
76
- * @param opts - { iceServers, iceTransportPolicy } forwarded to ICE.
77
- */
78
- async gather(opts: { iceServers?: unknown[]; iceTransportPolicy?: 'all' | 'relay' } = {}): Promise<void> {
79
- await this.ice.gather(opts as any);
80
- }
81
-
82
- getLocalCandidates(): ReturnType<IceAgent['getLocalCandidates']> {
83
- return this.ice.getLocalCandidates();
84
- }
85
-
86
- /** Provide the peer's ICE credentials and start checks when ready. */
87
- setRemote(ufrag: string, pwd: string): void {
88
- this.ice.setRemoteCredentials(ufrag, pwd);
89
- this.ice.start();
90
- }
91
-
92
- addRemoteCandidate(cand: { address: string; port: number; type?: string; priority?: number }): void {
93
- this.ice.addRemoteCandidate(cand);
94
- }
95
-
96
- #startDtls(): void {
97
- if (this.#dtlsStarted) return;
98
- this.#dtlsStarted = true;
99
-
100
- this.dtls = new DtlsConnection({
101
- role: this.#opts.dtlsRole === 'client' ? DTLS_ROLE.CLIENT : DTLS_ROLE.SERVER,
102
- certDer: this.#opts.certDer,
103
- privateKey: this.#opts.privateKey,
104
- verifyFingerprint: this.#opts.verifyFingerprint,
105
- output: (datagram: Buffer) => {
106
- try { this.ice.send(datagram); } catch (e) { this.emit('error', e); }
107
- },
108
- });
109
-
110
- this.dtls.on('connect', () => {
111
- this.emit('dtlsconnected');
112
- this.#startSctp();
113
- });
114
- this.dtls.on('data', (record: Buffer) => {
115
- if (this.sctp) this.sctp.receivePacket(record);
116
- });
117
- this.dtls.on('error', (e) => this.emit('error', e));
118
- this.dtls.on('close', () => this.emit('close'));
119
-
120
- this.dtls.start();
121
- }
122
-
123
- #startSctp(): void {
124
- const isClient = this.#opts.dtlsRole === 'client';
125
- const sctp = new SctpAssociation({ isClient });
126
- this.sctp = sctp;
127
- sctp.on('output', (pkt: Buffer) => {
128
- try { if (this.dtls) this.dtls.send(pkt); } catch (e) { this.emit('error', e); }
129
- });
130
- sctp.on('error', (e) => this.emit('error', e));
131
- sctp.on('close', () => this.emit('close'));
132
-
133
- this.dcm = new DataChannelManager(sctp, isClient);
134
- this.dcm.on('open-request', (info: OpenRequestInfo) => this.emit('datachannel-request', info));
135
-
136
- sctp.on('established', () => {
137
- this.emit('sctpconnected');
138
- this.emit('ready');
139
- });
140
-
141
- sctp.start();
142
- }
143
-
144
- /** Open a locally-initiated data channel once SCTP is established. */
145
- openChannel(channel: RTCDataChannel, init: RTCDataChannelInit): void {
146
- if (!this.dcm) throw new Error('SCTP not ready');
147
- this.dcm.openChannel(channel, init);
148
- }
149
-
150
- /** Accept an inbound channel created from a 'datachannel-request'. */
151
- acceptChannel(channel: RTCDataChannel, info: OpenRequestInfo): void {
152
- if (!this.dcm) throw new Error('SCTP not ready');
153
- this.dcm.acceptChannel(channel, info);
154
- }
155
-
156
- isReady(): boolean {
157
- return !!this.sctp && this.sctp.state === 'established';
158
- }
159
-
160
- close(): void {
161
- if (this.sctp) try { this.sctp.shutdown(); } catch { /* best-effort */ }
162
- if (this.dtls) try { this.dtls.close(); } catch { /* best-effort */ }
163
- if (this.ice) try { this.ice.close(); } catch { /* best-effort */ }
164
- }
165
- }
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes