@libp2p/webrtc 3.0.0 → 3.1.0-c858ca7f

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 (54) hide show
  1. package/dist/index.min.js +17 -18
  2. package/dist/src/private-to-private/handler.d.ts +1 -0
  3. package/dist/src/private-to-private/handler.d.ts.map +1 -1
  4. package/dist/src/private-to-private/handler.js +102 -85
  5. package/dist/src/private-to-private/handler.js.map +1 -1
  6. package/dist/src/private-to-private/transport.d.ts.map +1 -1
  7. package/dist/src/private-to-private/transport.js +2 -0
  8. package/dist/src/private-to-private/transport.js.map +1 -1
  9. package/dist/src/private-to-private/util.d.ts.map +1 -1
  10. package/dist/src/private-to-private/util.js +1 -0
  11. package/dist/src/private-to-private/util.js.map +1 -1
  12. package/dist/src/private-to-public/transport.d.ts.map +1 -1
  13. package/dist/src/private-to-public/transport.js +98 -91
  14. package/dist/src/private-to-public/transport.js.map +1 -1
  15. package/dist/src/webrtc/index.browser.d.ts +15 -0
  16. package/dist/src/webrtc/index.browser.d.ts.map +1 -0
  17. package/dist/src/webrtc/index.browser.js +5 -0
  18. package/dist/src/webrtc/index.browser.js.map +1 -0
  19. package/dist/src/webrtc/index.d.ts +8 -0
  20. package/dist/src/webrtc/index.d.ts.map +1 -0
  21. package/dist/src/webrtc/index.js +11 -0
  22. package/dist/src/webrtc/index.js.map +1 -0
  23. package/dist/src/webrtc/rtc-data-channel.d.ts +29 -0
  24. package/dist/src/webrtc/rtc-data-channel.d.ts.map +1 -0
  25. package/dist/src/webrtc/rtc-data-channel.js +115 -0
  26. package/dist/src/webrtc/rtc-data-channel.js.map +1 -0
  27. package/dist/src/webrtc/rtc-events.d.ts +9 -0
  28. package/dist/src/webrtc/rtc-events.d.ts.map +1 -0
  29. package/dist/src/webrtc/rtc-events.js +15 -0
  30. package/dist/src/webrtc/rtc-events.js.map +1 -0
  31. package/dist/src/webrtc/rtc-ice-candidate.d.ts +22 -0
  32. package/dist/src/webrtc/rtc-ice-candidate.d.ts.map +1 -0
  33. package/dist/src/webrtc/rtc-ice-candidate.js +47 -0
  34. package/dist/src/webrtc/rtc-ice-candidate.js.map +1 -0
  35. package/dist/src/webrtc/rtc-peer-connection.d.ts +47 -0
  36. package/dist/src/webrtc/rtc-peer-connection.d.ts.map +1 -0
  37. package/dist/src/webrtc/rtc-peer-connection.js +245 -0
  38. package/dist/src/webrtc/rtc-peer-connection.js.map +1 -0
  39. package/dist/src/webrtc/rtc-session-description.d.ts +10 -0
  40. package/dist/src/webrtc/rtc-session-description.d.ts.map +1 -0
  41. package/dist/src/webrtc/rtc-session-description.js +18 -0
  42. package/dist/src/webrtc/rtc-session-description.js.map +1 -0
  43. package/package.json +15 -10
  44. package/src/private-to-private/handler.ts +120 -102
  45. package/src/private-to-private/transport.ts +2 -0
  46. package/src/private-to-private/util.ts +1 -0
  47. package/src/private-to-public/transport.ts +109 -103
  48. package/src/webrtc/index.browser.ts +4 -0
  49. package/src/webrtc/index.ts +12 -0
  50. package/src/webrtc/rtc-data-channel.ts +140 -0
  51. package/src/webrtc/rtc-events.ts +19 -0
  52. package/src/webrtc/rtc-ice-candidate.ts +50 -0
  53. package/src/webrtc/rtc-peer-connection.ts +306 -0
  54. package/src/webrtc/rtc-session-description.ts +19 -0
@@ -0,0 +1,15 @@
1
+ export declare const RTCPeerConnection: {
2
+ new (configuration?: RTCConfiguration | undefined): RTCPeerConnection;
3
+ prototype: RTCPeerConnection;
4
+ generateCertificate(keygenAlgorithm: AlgorithmIdentifier): Promise<RTCCertificate>;
5
+ };
6
+ export declare const RTCSessionDescription: {
7
+ new (descriptionInitDict: RTCSessionDescriptionInit): RTCSessionDescription;
8
+ prototype: RTCSessionDescription;
9
+ };
10
+ export declare const RTCIceCandidate: {
11
+ new (candidateInitDict?: RTCIceCandidateInit | undefined): RTCIceCandidate;
12
+ prototype: RTCIceCandidate;
13
+ };
14
+ export declare function cleanup(): void;
15
+ //# sourceMappingURL=index.browser.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.browser.d.ts","sourceRoot":"","sources":["../../../src/webrtc/index.browser.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,iBAAiB;;;;CAA+B,CAAA;AAC7D,eAAO,MAAM,qBAAqB;;;CAAmC,CAAA;AACrE,eAAO,MAAM,eAAe;;;CAA6B,CAAA;AACzD,wBAAgB,OAAO,IAAK,IAAI,CAAG"}
@@ -0,0 +1,5 @@
1
+ export const RTCPeerConnection = globalThis.RTCPeerConnection;
2
+ export const RTCSessionDescription = globalThis.RTCSessionDescription;
3
+ export const RTCIceCandidate = globalThis.RTCIceCandidate;
4
+ export function cleanup() { }
5
+ //# sourceMappingURL=index.browser.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.browser.js","sourceRoot":"","sources":["../../../src/webrtc/index.browser.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,iBAAiB,GAAG,UAAU,CAAC,iBAAiB,CAAA;AAC7D,MAAM,CAAC,MAAM,qBAAqB,GAAG,UAAU,CAAC,qBAAqB,CAAA;AACrE,MAAM,CAAC,MAAM,eAAe,GAAG,UAAU,CAAC,eAAe,CAAA;AACzD,MAAM,UAAU,OAAO,KAAW,CAAC"}
@@ -0,0 +1,8 @@
1
+ import { IceCandidate } from './rtc-ice-candidate.js';
2
+ import { PeerConnection } from './rtc-peer-connection.js';
3
+ import { SessionDescription } from './rtc-session-description.js';
4
+ export { SessionDescription as RTCSessionDescription };
5
+ export { IceCandidate as RTCIceCandidate };
6
+ export { PeerConnection as RTCPeerConnection };
7
+ export declare function cleanup(): void;
8
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/webrtc/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAA;AACrD,OAAO,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAA;AACzD,OAAO,EAAE,kBAAkB,EAAE,MAAM,8BAA8B,CAAA;AAEjE,OAAO,EAAE,kBAAkB,IAAI,qBAAqB,EAAE,CAAA;AACtD,OAAO,EAAE,YAAY,IAAI,eAAe,EAAE,CAAA;AAC1C,OAAO,EAAE,cAAc,IAAI,iBAAiB,EAAE,CAAA;AAE9C,wBAAgB,OAAO,IAAK,IAAI,CAE/B"}
@@ -0,0 +1,11 @@
1
+ import node from 'node-datachannel';
2
+ import { IceCandidate } from './rtc-ice-candidate.js';
3
+ import { PeerConnection } from './rtc-peer-connection.js';
4
+ import { SessionDescription } from './rtc-session-description.js';
5
+ export { SessionDescription as RTCSessionDescription };
6
+ export { IceCandidate as RTCIceCandidate };
7
+ export { PeerConnection as RTCPeerConnection };
8
+ export function cleanup() {
9
+ node.cleanup();
10
+ }
11
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/webrtc/index.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,kBAAkB,CAAA;AACnC,OAAO,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAA;AACrD,OAAO,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAA;AACzD,OAAO,EAAE,kBAAkB,EAAE,MAAM,8BAA8B,CAAA;AAEjE,OAAO,EAAE,kBAAkB,IAAI,qBAAqB,EAAE,CAAA;AACtD,OAAO,EAAE,YAAY,IAAI,eAAe,EAAE,CAAA;AAC1C,OAAO,EAAE,cAAc,IAAI,iBAAiB,EAAE,CAAA;AAE9C,MAAM,UAAU,OAAO;IACrB,IAAI,CAAC,OAAO,EAAE,CAAA;AAChB,CAAC"}
@@ -0,0 +1,29 @@
1
+ import type node from 'node-datachannel';
2
+ export declare class DataChannel extends EventTarget implements RTCDataChannel {
3
+ #private;
4
+ binaryType: BinaryType;
5
+ readonly maxPacketLifeTime: number | null;
6
+ readonly maxRetransmits: number | null;
7
+ readonly negotiated: boolean;
8
+ readonly ordered: boolean;
9
+ onbufferedamountlow: ((this: RTCDataChannel, ev: Event) => any) | null;
10
+ onclose: ((this: RTCDataChannel, ev: Event) => any) | null;
11
+ onclosing: ((this: RTCDataChannel, ev: Event) => any) | null;
12
+ onerror: ((this: RTCDataChannel, ev: Event) => any) | null;
13
+ onmessage: ((this: RTCDataChannel, ev: MessageEvent) => any) | null;
14
+ onopen: ((this: RTCDataChannel, ev: Event) => any) | null;
15
+ constructor(dataChannel: node.DataChannel, dataChannelDict?: RTCDataChannelInit);
16
+ get id(): number;
17
+ get label(): string;
18
+ get protocol(): string;
19
+ get bufferedAmount(): number;
20
+ set bufferedAmountLowThreshold(threshold: number);
21
+ get bufferedAmountLowThreshold(): number;
22
+ get readyState(): RTCDataChannelState;
23
+ close(): void;
24
+ send(data: string): void;
25
+ send(data: Blob): void;
26
+ send(data: ArrayBuffer): void;
27
+ send(data: ArrayBufferView): void;
28
+ }
29
+ //# sourceMappingURL=rtc-data-channel.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rtc-data-channel.d.ts","sourceRoot":"","sources":["../../../src/webrtc/rtc-data-channel.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,IAAI,MAAM,kBAAkB,CAAA;AAExC,qBAAa,WAAY,SAAQ,WAAY,YAAW,cAAc;;IACpE,UAAU,EAAE,UAAU,CAAA;IAEtB,QAAQ,CAAC,iBAAiB,EAAE,MAAM,GAAG,IAAI,CAAA;IACzC,QAAQ,CAAC,cAAc,EAAE,MAAM,GAAG,IAAI,CAAA;IACtC,QAAQ,CAAC,UAAU,EAAE,OAAO,CAAA;IAC5B,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAA;IAEzB,mBAAmB,EAAE,CAAC,CAAC,IAAI,EAAE,cAAc,EAAE,EAAE,EAAE,KAAK,KAAK,GAAG,CAAC,GAAG,IAAI,CAAA;IACtE,OAAO,EAAE,CAAC,CAAC,IAAI,EAAE,cAAc,EAAE,EAAE,EAAE,KAAK,KAAK,GAAG,CAAC,GAAG,IAAI,CAAA;IAC1D,SAAS,EAAE,CAAC,CAAC,IAAI,EAAE,cAAc,EAAE,EAAE,EAAE,KAAK,KAAK,GAAG,CAAC,GAAG,IAAI,CAAA;IAC5D,OAAO,EAAE,CAAC,CAAC,IAAI,EAAE,cAAc,EAAE,EAAE,EAAE,KAAK,KAAK,GAAG,CAAC,GAAG,IAAI,CAAA;IAC1D,SAAS,EAAE,CAAC,CAAC,IAAI,EAAE,cAAc,EAAE,EAAE,EAAE,YAAY,KAAK,GAAG,CAAC,GAAG,IAAI,CAAA;IACnE,MAAM,EAAE,CAAC,CAAC,IAAI,EAAE,cAAc,EAAE,EAAE,EAAE,KAAK,KAAK,GAAG,CAAC,GAAG,IAAI,CAAA;gBAM5C,WAAW,EAAE,IAAI,CAAC,WAAW,EAAE,eAAe,GAAE,kBAAuB;IAqEpF,IAAI,EAAE,IAAK,MAAM,CAEhB;IAED,IAAI,KAAK,IAAK,MAAM,CAEnB;IAED,IAAI,QAAQ,IAAK,MAAM,CAEtB;IAED,IAAI,cAAc,IAAK,MAAM,CAE5B;IAED,IAAI,0BAA0B,CAAE,SAAS,EAAE,MAAM,EAGhD;IAED,IAAI,0BAA0B,IAAK,MAAM,CAExC;IAED,IAAI,UAAU,IAAK,mBAAmB,CAErC;IAED,KAAK,IAAK,IAAI;IAOd,IAAI,CAAE,IAAI,EAAE,MAAM,GAAG,IAAI;IACzB,IAAI,CAAE,IAAI,EAAE,IAAI,GAAG,IAAI;IACvB,IAAI,CAAE,IAAI,EAAE,WAAW,GAAG,IAAI;IAC9B,IAAI,CAAE,IAAI,EAAE,eAAe,GAAG,IAAI;CASnC"}
@@ -0,0 +1,115 @@
1
+ import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string';
2
+ export class DataChannel extends EventTarget {
3
+ binaryType;
4
+ maxPacketLifeTime;
5
+ maxRetransmits;
6
+ negotiated;
7
+ ordered;
8
+ onbufferedamountlow;
9
+ onclose;
10
+ onclosing;
11
+ onerror;
12
+ onmessage;
13
+ onopen;
14
+ #dataChannel;
15
+ #bufferedAmountLowThreshold;
16
+ #readyState;
17
+ constructor(dataChannel, dataChannelDict = {}) {
18
+ super();
19
+ this.#dataChannel = dataChannel;
20
+ this.#readyState = 'connecting';
21
+ this.#bufferedAmountLowThreshold = 0;
22
+ this.binaryType = 'arraybuffer';
23
+ this.#dataChannel.onOpen(() => {
24
+ this.#readyState = 'open';
25
+ this.dispatchEvent(new Event('open'));
26
+ });
27
+ this.#dataChannel.onClosed(() => {
28
+ this.#readyState = 'closed';
29
+ this.dispatchEvent(new Event('close'));
30
+ });
31
+ this.#dataChannel.onError((msg) => {
32
+ this.#readyState = 'closed';
33
+ this.dispatchEvent(new RTCErrorEvent('error', {
34
+ error: new RTCError({
35
+ errorDetail: 'data-channel-failure'
36
+ }, msg)
37
+ }));
38
+ });
39
+ this.#dataChannel.onBufferedAmountLow(() => {
40
+ this.dispatchEvent(new Event('bufferedamountlow'));
41
+ });
42
+ this.#dataChannel.onMessage((data) => {
43
+ if (typeof data === 'string') {
44
+ data = uint8ArrayFromString(data);
45
+ }
46
+ this.dispatchEvent(new MessageEvent('message', { data }));
47
+ });
48
+ // forward events to properties
49
+ this.addEventListener('message', event => {
50
+ this.onmessage?.(event);
51
+ });
52
+ this.addEventListener('bufferedamountlow', event => {
53
+ this.onbufferedamountlow?.(event);
54
+ });
55
+ this.addEventListener('error', event => {
56
+ this.onerror?.(event);
57
+ });
58
+ this.addEventListener('close', event => {
59
+ this.onclose?.(event);
60
+ });
61
+ this.addEventListener('closing', event => {
62
+ this.onclosing?.(event);
63
+ });
64
+ this.addEventListener('open', event => {
65
+ this.onopen?.(event);
66
+ });
67
+ this.onbufferedamountlow = null;
68
+ this.onclose = null;
69
+ this.onclosing = null;
70
+ this.onerror = null;
71
+ this.onmessage = null;
72
+ this.onopen = null;
73
+ this.maxPacketLifeTime = dataChannelDict.maxPacketLifeTime ?? null;
74
+ this.maxRetransmits = dataChannelDict.maxRetransmits ?? null;
75
+ this.negotiated = dataChannelDict.negotiated ?? false;
76
+ this.ordered = dataChannelDict.ordered ?? true;
77
+ }
78
+ get id() {
79
+ return this.#dataChannel.getId();
80
+ }
81
+ get label() {
82
+ return this.#dataChannel.getLabel();
83
+ }
84
+ get protocol() {
85
+ return this.#dataChannel.getProtocol();
86
+ }
87
+ get bufferedAmount() {
88
+ return this.#dataChannel.bufferedAmount();
89
+ }
90
+ set bufferedAmountLowThreshold(threshold) {
91
+ this.#bufferedAmountLowThreshold = threshold;
92
+ this.#dataChannel.setBufferedAmountLowThreshold(threshold);
93
+ }
94
+ get bufferedAmountLowThreshold() {
95
+ return this.#bufferedAmountLowThreshold;
96
+ }
97
+ get readyState() {
98
+ return this.#readyState;
99
+ }
100
+ close() {
101
+ this.#readyState = 'closing';
102
+ this.dispatchEvent(new Event('closing'));
103
+ this.#dataChannel.close();
104
+ }
105
+ send(data) {
106
+ // TODO: sending Blobs
107
+ if (typeof data === 'string') {
108
+ this.#dataChannel.sendMessage(data);
109
+ }
110
+ else {
111
+ this.#dataChannel.sendMessageBinary(data);
112
+ }
113
+ }
114
+ }
115
+ //# sourceMappingURL=rtc-data-channel.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rtc-data-channel.js","sourceRoot":"","sources":["../../../src/webrtc/rtc-data-channel.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,IAAI,oBAAoB,EAAE,MAAM,yBAAyB,CAAA;AAG5E,MAAM,OAAO,WAAY,SAAQ,WAAW;IAC1C,UAAU,CAAY;IAEb,iBAAiB,CAAe;IAChC,cAAc,CAAe;IAC7B,UAAU,CAAS;IACnB,OAAO,CAAS;IAEzB,mBAAmB,CAAmD;IACtE,OAAO,CAAmD;IAC1D,SAAS,CAAmD;IAC5D,OAAO,CAAmD;IAC1D,SAAS,CAA0D;IACnE,MAAM,CAAmD;IAEzD,YAAY,CAAkB;IAC9B,2BAA2B,CAAQ;IACnC,WAAW,CAAqB;IAEhC,YAAa,WAA6B,EAAE,kBAAsC,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A;SACpC;aAAM;YACL,IAAI,CAAC,YAAY,CAAC,iBAAiB,CAAC,IAAI,CAAC,CAAA;SAC1C;IACH,CAAC;CACF"}
@@ -0,0 +1,9 @@
1
+ export declare class PeerConnectionIceEvent extends Event implements RTCPeerConnectionIceEvent {
2
+ readonly candidate: RTCIceCandidate | null;
3
+ constructor(candidate: RTCIceCandidate);
4
+ }
5
+ export declare class DataChannelEvent extends Event implements RTCDataChannelEvent {
6
+ readonly channel: RTCDataChannel;
7
+ constructor(channel: RTCDataChannel);
8
+ }
9
+ //# sourceMappingURL=rtc-events.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rtc-events.d.ts","sourceRoot":"","sources":["../../../src/webrtc/rtc-events.ts"],"names":[],"mappings":"AAAA,qBAAa,sBAAuB,SAAQ,KAAM,YAAW,yBAAyB;IACpF,QAAQ,CAAC,SAAS,EAAE,eAAe,GAAG,IAAI,CAAA;gBAE7B,SAAS,EAAE,eAAe;CAKxC;AAED,qBAAa,gBAAiB,SAAQ,KAAM,YAAW,mBAAmB;IACxE,QAAQ,CAAC,OAAO,EAAE,cAAc,CAAA;gBAEnB,OAAO,EAAE,cAAc;CAKrC"}
@@ -0,0 +1,15 @@
1
+ export class PeerConnectionIceEvent extends Event {
2
+ candidate;
3
+ constructor(candidate) {
4
+ super('icecandidate');
5
+ this.candidate = candidate;
6
+ }
7
+ }
8
+ export class DataChannelEvent extends Event {
9
+ channel;
10
+ constructor(channel) {
11
+ super('datachannel');
12
+ this.channel = channel;
13
+ }
14
+ }
15
+ //# sourceMappingURL=rtc-events.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rtc-events.js","sourceRoot":"","sources":["../../../src/webrtc/rtc-events.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,sBAAuB,SAAQ,KAAK;IACtC,SAAS,CAAwB;IAE1C,YAAa,SAA0B;QACrC,KAAK,CAAC,cAAc,CAAC,CAAA;QAErB,IAAI,CAAC,SAAS,GAAG,SAAS,CAAA;IAC5B,CAAC;CACF;AAED,MAAM,OAAO,gBAAiB,SAAQ,KAAK;IAChC,OAAO,CAAgB;IAEhC,YAAa,OAAuB;QAClC,KAAK,CAAC,aAAa,CAAC,CAAA;QAEpB,IAAI,CAAC,OAAO,GAAG,OAAO,CAAA;IACxB,CAAC;CACF"}
@@ -0,0 +1,22 @@
1
+ /**
2
+ * @see https://developer.mozilla.org/docs/Web/API/RTCIceCandidate
3
+ */
4
+ export declare 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
+ constructor(init: RTCIceCandidateInit);
20
+ toJSON(): RTCIceCandidateInit;
21
+ }
22
+ //# sourceMappingURL=rtc-ice-candidate.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rtc-ice-candidate.d.ts","sourceRoot":"","sources":["../../../src/webrtc/rtc-ice-candidate.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,qBAAa,YAAa,YAAW,eAAe;IAClD,QAAQ,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI,CAAA;IAC/B,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAA;IAC1B,QAAQ,CAAC,SAAS,EAAE,eAAe,GAAG,IAAI,CAAA;IAC1C,QAAQ,CAAC,UAAU,EAAE,MAAM,GAAG,IAAI,CAAA;IAClC,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAAA;IAC5B,QAAQ,CAAC,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAA;IAChC,QAAQ,CAAC,QAAQ,EAAE,cAAc,GAAG,IAAI,CAAA;IACxC,QAAQ,CAAC,cAAc,EAAE,MAAM,GAAG,IAAI,CAAA;IACtC,QAAQ,CAAC,WAAW,EAAE,MAAM,GAAG,IAAI,CAAA;IACnC,QAAQ,CAAC,aAAa,EAAE,MAAM,GAAG,IAAI,CAAA;IACrC,QAAQ,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,CAAA;IAC9B,QAAQ,CAAC,OAAO,EAAE,sBAAsB,GAAG,IAAI,CAAA;IAC/C,QAAQ,CAAC,IAAI,EAAE,mBAAmB,GAAG,IAAI,CAAA;IACzC,QAAQ,CAAC,gBAAgB,EAAE,MAAM,GAAG,IAAI,CAAA;gBAE3B,IAAI,EAAE,mBAAmB;IAsBtC,MAAM,IAAK,mBAAmB;CAQ/B"}
@@ -0,0 +1,47 @@
1
+ /**
2
+ * @see https://developer.mozilla.org/docs/Web/API/RTCIceCandidate
3
+ */
4
+ export class IceCandidate {
5
+ address;
6
+ candidate;
7
+ component;
8
+ foundation;
9
+ port;
10
+ priority;
11
+ protocol;
12
+ relatedAddress;
13
+ relatedPort;
14
+ sdpMLineIndex;
15
+ sdpMid;
16
+ tcpType;
17
+ type;
18
+ usernameFragment;
19
+ constructor(init) {
20
+ if (init.candidate == null) {
21
+ throw new DOMException('candidate must be specified');
22
+ }
23
+ this.candidate = init.candidate;
24
+ this.sdpMLineIndex = init.sdpMLineIndex ?? null;
25
+ this.sdpMid = init.sdpMid ?? null;
26
+ this.usernameFragment = init.usernameFragment ?? null;
27
+ this.address = null;
28
+ this.component = null;
29
+ this.foundation = null;
30
+ this.port = null;
31
+ this.priority = null;
32
+ this.protocol = null;
33
+ this.relatedAddress = null;
34
+ this.relatedPort = null;
35
+ this.tcpType = null;
36
+ this.type = null;
37
+ }
38
+ toJSON() {
39
+ return {
40
+ candidate: this.candidate,
41
+ sdpMLineIndex: this.sdpMLineIndex,
42
+ sdpMid: this.sdpMid,
43
+ usernameFragment: this.usernameFragment
44
+ };
45
+ }
46
+ }
47
+ //# sourceMappingURL=rtc-ice-candidate.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rtc-ice-candidate.js","sourceRoot":"","sources":["../../../src/webrtc/rtc-ice-candidate.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,OAAO,YAAY;IACd,OAAO,CAAe;IACtB,SAAS,CAAQ;IACjB,SAAS,CAAwB;IACjC,UAAU,CAAe;IACzB,IAAI,CAAe;IACnB,QAAQ,CAAe;IACvB,QAAQ,CAAuB;IAC/B,cAAc,CAAe;IAC7B,WAAW,CAAe;IAC1B,aAAa,CAAe;IAC5B,MAAM,CAAe;IACrB,OAAO,CAA+B;IACtC,IAAI,CAA4B;IAChC,gBAAgB,CAAe;IAExC,YAAa,IAAyB;QACpC,IAAI,IAAI,CAAC,SAAS,IAAI,IAAI,EAAE;YAC1B,MAAM,IAAI,YAAY,CAAC,6BAA6B,CAAC,CAAA;SACtD;QAED,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC,SAAS,CAAA;QAC/B,IAAI,CAAC,aAAa,GAAG,IAAI,CAAC,aAAa,IAAI,IAAI,CAAA;QAC/C,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,MAAM,IAAI,IAAI,CAAA;QACjC,IAAI,CAAC,gBAAgB,GAAG,IAAI,CAAC,gBAAgB,IAAI,IAAI,CAAA;QAErD,IAAI,CAAC,OAAO,GAAG,IAAI,CAAA;QACnB,IAAI,CAAC,SAAS,GAAG,IAAI,CAAA;QACrB,IAAI,CAAC,UAAU,GAAG,IAAI,CAAA;QACtB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAA;QAChB,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAA;QACpB,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAA;QACpB,IAAI,CAAC,cAAc,GAAG,IAAI,CAAA;QAC1B,IAAI,CAAC,WAAW,GAAG,IAAI,CAAA;QACvB,IAAI,CAAC,OAAO,GAAG,IAAI,CAAA;QACnB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAA;IAClB,CAAC;IAED,MAAM;QACJ,OAAO;YACL,SAAS,EAAE,IAAI,CAAC,SAAS;YACzB,aAAa,EAAE,IAAI,CAAC,aAAa;YACjC,MAAM,EAAE,IAAI,CAAC,MAAM;YACnB,gBAAgB,EAAE,IAAI,CAAC,gBAAgB;SACxC,CAAA;IACH,CAAC;CACF"}
@@ -0,0 +1,47 @@
1
+ export declare class PeerConnection extends EventTarget implements RTCPeerConnection {
2
+ #private;
3
+ static generateCertificate(keygenAlgorithm: AlgorithmIdentifier): Promise<RTCCertificate>;
4
+ canTrickleIceCandidates: boolean | null;
5
+ sctp: RTCSctpTransport | null;
6
+ onconnectionstatechange: ((this: RTCPeerConnection, ev: Event) => any) | null;
7
+ ondatachannel: ((this: RTCPeerConnection, ev: RTCDataChannelEvent) => any) | null;
8
+ onicecandidate: ((this: RTCPeerConnection, ev: RTCPeerConnectionIceEvent) => any) | null;
9
+ onicecandidateerror: ((this: RTCPeerConnection, ev: Event) => any) | null;
10
+ oniceconnectionstatechange: ((this: RTCPeerConnection, ev: Event) => any) | null;
11
+ onicegatheringstatechange: ((this: RTCPeerConnection, ev: Event) => any) | null;
12
+ onnegotiationneeded: ((this: RTCPeerConnection, ev: Event) => any) | null;
13
+ onsignalingstatechange: ((this: RTCPeerConnection, ev: Event) => any) | null;
14
+ ontrack: ((this: RTCPeerConnection, ev: RTCTrackEvent) => any) | null;
15
+ constructor(init?: RTCConfiguration);
16
+ get connectionState(): RTCPeerConnectionState;
17
+ get iceConnectionState(): RTCIceConnectionState;
18
+ get iceGatheringState(): RTCIceGatheringState;
19
+ get signalingState(): RTCSignalingState;
20
+ get currentLocalDescription(): RTCSessionDescription | null;
21
+ get localDescription(): RTCSessionDescription | null;
22
+ get pendingLocalDescription(): RTCSessionDescription | null;
23
+ get currentRemoteDescription(): RTCSessionDescription | null;
24
+ get pendingRemoteDescription(): RTCSessionDescription | null;
25
+ get remoteDescription(): RTCSessionDescription | null;
26
+ addIceCandidate(candidate?: RTCIceCandidateInit): Promise<void>;
27
+ addTrack(track: MediaStreamTrack, ...streams: MediaStream[]): RTCRtpSender;
28
+ addTransceiver(trackOrKind: MediaStreamTrack | string, init?: RTCRtpTransceiverInit): RTCRtpTransceiver;
29
+ close(): void;
30
+ createDataChannel(label: string, dataChannelDict?: RTCDataChannelInit): RTCDataChannel;
31
+ createOffer(options?: RTCOfferOptions): Promise<RTCSessionDescriptionInit>;
32
+ createOffer(successCallback: RTCSessionDescriptionCallback, failureCallback: RTCPeerConnectionErrorCallback, options?: RTCOfferOptions): Promise<void>;
33
+ createAnswer(options?: RTCAnswerOptions): Promise<RTCSessionDescriptionInit>;
34
+ createAnswer(successCallback: RTCSessionDescriptionCallback, failureCallback: RTCPeerConnectionErrorCallback): Promise<void>;
35
+ getConfiguration(): RTCConfiguration;
36
+ getReceivers(): RTCRtpReceiver[];
37
+ getSenders(): RTCRtpSender[];
38
+ getStats(selector?: MediaStreamTrack | null): Promise<RTCStatsReport>;
39
+ getTransceivers(): RTCRtpTransceiver[];
40
+ removeTrack(sender: RTCRtpSender): void;
41
+ restartIce(): void;
42
+ setConfiguration(configuration?: RTCConfiguration): void;
43
+ setLocalDescription(description?: RTCLocalSessionDescriptionInit): Promise<void>;
44
+ setRemoteDescription(description: RTCSessionDescriptionInit): Promise<void>;
45
+ }
46
+ export { PeerConnection as RTCPeerConnection };
47
+ //# sourceMappingURL=rtc-peer-connection.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rtc-peer-connection.d.ts","sourceRoot":"","sources":["../../../src/webrtc/rtc-peer-connection.ts"],"names":[],"mappings":"AAOA,qBAAa,cAAe,SAAQ,WAAY,YAAW,iBAAiB;;WAC7D,mBAAmB,CAAE,eAAe,EAAE,mBAAmB,GAAG,OAAO,CAAC,cAAc,CAAC;IAIhG,uBAAuB,EAAE,OAAO,GAAG,IAAI,CAAA;IACvC,IAAI,EAAE,gBAAgB,GAAG,IAA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I5E,eAAe,IAAK,iBAAiB,EAAE;IAIvC,WAAW,CAAE,MAAM,EAAE,YAAY,GAAG,IAAI;IAIxC,UAAU,IAAK,IAAI;IAInB,gBAAgB,CAAE,aAAa,GAAE,gBAAqB,GAAG,IAAI;IAIvD,mBAAmB,CAAE,WAAW,CAAC,EAAE,8BAA8B,GAAG,OAAO,CAAC,IAAI,CAAC;IAcjF,oBAAoB,CAAE,WAAW,EAAE,yBAAyB,GAAG,OAAO,CAAC,IAAI,CAAC;CAQnF;AAED,OAAO,EAAE,cAAc,IAAI,iBAAiB,EAAE,CAAA"}
@@ -0,0 +1,245 @@
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