@libp2p/webrtc 5.2.24-a02cb0461 → 5.2.24-f5932c294

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 (87) hide show
  1. package/README.md +20 -10
  2. package/dist/index.min.js +14 -14
  3. package/dist/index.min.js.map +4 -4
  4. package/dist/src/constants.d.ts +15 -0
  5. package/dist/src/constants.d.ts.map +1 -1
  6. package/dist/src/constants.js +15 -0
  7. package/dist/src/constants.js.map +1 -1
  8. package/dist/src/index.d.ts +22 -12
  9. package/dist/src/index.d.ts.map +1 -1
  10. package/dist/src/index.js +22 -12
  11. package/dist/src/index.js.map +1 -1
  12. package/dist/src/maconn.d.ts +58 -0
  13. package/dist/src/maconn.d.ts.map +1 -0
  14. package/dist/src/maconn.js +56 -0
  15. package/dist/src/maconn.js.map +1 -0
  16. package/dist/src/muxer.d.ts +46 -14
  17. package/dist/src/muxer.d.ts.map +1 -1
  18. package/dist/src/muxer.js +135 -32
  19. package/dist/src/muxer.js.map +1 -1
  20. package/dist/src/private-to-private/initiate-connection.d.ts +4 -3
  21. package/dist/src/private-to-private/initiate-connection.d.ts.map +1 -1
  22. package/dist/src/private-to-private/initiate-connection.js +5 -23
  23. package/dist/src/private-to-private/initiate-connection.js.map +1 -1
  24. package/dist/src/private-to-private/signaling-stream-handler.d.ts +4 -4
  25. package/dist/src/private-to-private/signaling-stream-handler.d.ts.map +1 -1
  26. package/dist/src/private-to-private/signaling-stream-handler.js +6 -10
  27. package/dist/src/private-to-private/signaling-stream-handler.js.map +1 -1
  28. package/dist/src/private-to-private/transport.d.ts +2 -2
  29. package/dist/src/private-to-private/transport.d.ts.map +1 -1
  30. package/dist/src/private-to-private/transport.js +15 -30
  31. package/dist/src/private-to-private/transport.js.map +1 -1
  32. package/dist/src/private-to-private/util.d.ts +1 -3
  33. package/dist/src/private-to-private/util.d.ts.map +1 -1
  34. package/dist/src/private-to-private/util.js +3 -15
  35. package/dist/src/private-to-private/util.js.map +1 -1
  36. package/dist/src/private-to-public/listener.js +2 -2
  37. package/dist/src/private-to-public/listener.js.map +1 -1
  38. package/dist/src/private-to-public/transport.js +1 -1
  39. package/dist/src/private-to-public/transport.js.map +1 -1
  40. package/dist/src/private-to-public/utils/connect.d.ts +1 -1
  41. package/dist/src/private-to-public/utils/connect.d.ts.map +1 -1
  42. package/dist/src/private-to-public/utils/connect.js +14 -17
  43. package/dist/src/private-to-public/utils/connect.js.map +1 -1
  44. package/dist/src/private-to-public/utils/get-rtcpeerconnection.d.ts +4 -4
  45. package/dist/src/private-to-public/utils/get-rtcpeerconnection.d.ts.map +1 -1
  46. package/dist/src/private-to-public/utils/get-rtcpeerconnection.js +2 -13
  47. package/dist/src/private-to-public/utils/get-rtcpeerconnection.js.map +1 -1
  48. package/dist/src/private-to-public/utils/sdp.d.ts.map +1 -1
  49. package/dist/src/private-to-public/utils/sdp.js +3 -8
  50. package/dist/src/private-to-public/utils/sdp.js.map +1 -1
  51. package/dist/src/private-to-public/utils/stun-listener.js +1 -1
  52. package/dist/src/private-to-public/utils/stun-listener.js.map +1 -1
  53. package/dist/src/stream.d.ts +26 -13
  54. package/dist/src/stream.d.ts.map +1 -1
  55. package/dist/src/stream.js +166 -64
  56. package/dist/src/stream.js.map +1 -1
  57. package/dist/src/util.d.ts +1 -3
  58. package/dist/src/util.d.ts.map +1 -1
  59. package/dist/src/util.js +0 -19
  60. package/dist/src/util.js.map +1 -1
  61. package/dist/src/webrtc/index.d.ts +1 -1
  62. package/dist/src/webrtc/index.d.ts.map +1 -1
  63. package/dist/src/webrtc/index.js +1 -1
  64. package/dist/src/webrtc/index.js.map +1 -1
  65. package/package.json +29 -26
  66. package/src/constants.ts +18 -0
  67. package/src/index.ts +22 -12
  68. package/src/maconn.ts +101 -0
  69. package/src/muxer.ts +166 -43
  70. package/src/private-to-private/initiate-connection.ts +9 -31
  71. package/src/private-to-private/signaling-stream-handler.ts +9 -12
  72. package/src/private-to-private/transport.ts +17 -33
  73. package/src/private-to-private/util.ts +4 -21
  74. package/src/private-to-public/listener.ts +2 -2
  75. package/src/private-to-public/transport.ts +1 -1
  76. package/src/private-to-public/utils/connect.ts +15 -18
  77. package/src/private-to-public/utils/get-rtcpeerconnection.ts +4 -16
  78. package/src/private-to-public/utils/sdp.ts +3 -8
  79. package/src/private-to-public/utils/stun-listener.ts +1 -1
  80. package/src/stream.ts +194 -74
  81. package/src/util.ts +1 -22
  82. package/src/webrtc/index.ts +1 -1
  83. package/dist/src/rtcpeerconnection-to-conn.d.ts +0 -12
  84. package/dist/src/rtcpeerconnection-to-conn.d.ts.map +0 -1
  85. package/dist/src/rtcpeerconnection-to-conn.js +0 -43
  86. package/dist/src/rtcpeerconnection-to-conn.js.map +0 -1
  87. package/src/rtcpeerconnection-to-conn.ts +0 -62
@@ -27,6 +27,10 @@ export declare const CODEC_CERTHASH = 466;
27
27
  * How much can be buffered to the DataChannel at once
28
28
  */
29
29
  export declare const MAX_BUFFERED_AMOUNT: number;
30
+ /**
31
+ * How long time we wait for the 'bufferedamountlow' event to be emitted
32
+ */
33
+ export declare const BUFFERED_AMOUNT_LOW_TIMEOUT: number;
30
34
  /**
31
35
  * Max message size that can be sent to the DataChannel. In browsers this is
32
36
  * 256KiB but go-libp2p and rust-libp2p only support 16KiB at the time of
@@ -41,6 +45,17 @@ export declare const MAX_MESSAGE_SIZE: number;
41
45
  * protobuf that aren't message field bytes
42
46
  */
43
47
  export declare const PROTOBUF_OVERHEAD: number;
48
+ /**
49
+ * When closing streams we send a FIN then wait for the remote to
50
+ * reply with a FIN_ACK. If that does not happen within this timeout
51
+ * we close the stream anyway.
52
+ */
53
+ export declare const FIN_ACK_TIMEOUT = 5000;
54
+ /**
55
+ * When sending data messages, if the channel is not in the "open" state, wait
56
+ * this long for the "open" event to fire.
57
+ */
58
+ export declare const OPEN_TIMEOUT = 5000;
44
59
  /**
45
60
  * When closing a stream, we wait for `bufferedAmount` to become 0 before
46
61
  * closing the underlying RTCDataChannel - this controls how long we wait in ms
@@ -1 +1 @@
1
- {"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../src/constants.ts"],"names":[],"mappings":"AAGA;;;;;;;GAOG;AACH,eAAO,MAAM,mBAAmB,UAK/B,CAAA;AAED;;GAEG;AACH,eAAO,MAAM,cAAc,UAA+E,CAAA;AAE1G;;GAEG;AACH,eAAO,MAAM,YAAY,sBAAsB,CAAA;AAE/C;;GAEG;AACH,eAAO,MAAM,mBAAmB,MAAS,CAAA;AAEzC;;GAEG;AACH,eAAO,MAAM,cAAc,MAAS,CAAA;AAEpC;;GAEG;AACH,eAAO,MAAM,mBAAmB,QAAkB,CAAA;AAElD;;;;;;;GAOG;AACH,eAAO,MAAM,gBAAgB,QAAY,CAAA;AAsBzC;;;GAGG;AACH,eAAO,MAAM,iBAAiB,QAA8B,CAAA;AAE5D;;;GAGG;AACH,eAAO,MAAM,0BAA0B,QAAS,CAAA;AAEhD;;GAEG;AACH,eAAO,MAAM,cAAc,YAAY,CAAA;AAEvC;;GAEG;AACH,eAAO,MAAM,kBAAkB,4BAA4B,CAAA;AAE3D;;GAEG;AACH,eAAO,MAAM,iCAAiC,sCAAsC,CAAA;AAEpF;;GAEG;AACH,eAAO,MAAM,oCAAoC,0CAA0C,CAAA;AAE3F;;GAEG;AACH,eAAO,MAAM,oCAAoC,UAAU,CAAA;AAE3D;;GAEG;AACH,eAAO,MAAM,4BAA4B,aAAgB,CAAA;AAEzD;;GAEG;AACH,eAAO,MAAM,qCAAqC,WAAa,CAAA"}
1
+ {"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../src/constants.ts"],"names":[],"mappings":"AAGA;;;;;;;GAOG;AACH,eAAO,MAAM,mBAAmB,UAK/B,CAAA;AAED;;GAEG;AACH,eAAO,MAAM,cAAc,UAA+E,CAAA;AAE1G;;GAEG;AACH,eAAO,MAAM,YAAY,sBAAsB,CAAA;AAE/C;;GAEG;AACH,eAAO,MAAM,mBAAmB,MAAS,CAAA;AAEzC;;GAEG;AACH,eAAO,MAAM,cAAc,MAAS,CAAA;AAEpC;;GAEG;AACH,eAAO,MAAM,mBAAmB,QAAkB,CAAA;AAElD;;GAEG;AACH,eAAO,MAAM,2BAA2B,QAAY,CAAA;AAEpD;;;;;;;GAOG;AACH,eAAO,MAAM,gBAAgB,QAAY,CAAA;AAsBzC;;;GAGG;AACH,eAAO,MAAM,iBAAiB,QAA8B,CAAA;AAE5D;;;;GAIG;AACH,eAAO,MAAM,eAAe,OAAQ,CAAA;AAEpC;;;GAGG;AACH,eAAO,MAAM,YAAY,OAAQ,CAAA;AAEjC;;;GAGG;AACH,eAAO,MAAM,0BAA0B,QAAS,CAAA;AAEhD;;GAEG;AACH,eAAO,MAAM,cAAc,YAAY,CAAA;AAEvC;;GAEG;AACH,eAAO,MAAM,kBAAkB,4BAA4B,CAAA;AAE3D;;GAEG;AACH,eAAO,MAAM,iCAAiC,sCAAsC,CAAA;AAEpF;;GAEG;AACH,eAAO,MAAM,oCAAoC,0CAA0C,CAAA;AAE3F;;GAEG;AACH,eAAO,MAAM,oCAAoC,UAAU,CAAA;AAE3D;;GAEG;AACH,eAAO,MAAM,4BAA4B,aAAgB,CAAA;AAEzD;;GAEG;AACH,eAAO,MAAM,qCAAqC,WAAa,CAAA"}
@@ -34,6 +34,10 @@ export const CODEC_CERTHASH = 0x01d2;
34
34
  * How much can be buffered to the DataChannel at once
35
35
  */
36
36
  export const MAX_BUFFERED_AMOUNT = 2 * 1024 * 1024;
37
+ /**
38
+ * How long time we wait for the 'bufferedamountlow' event to be emitted
39
+ */
40
+ export const BUFFERED_AMOUNT_LOW_TIMEOUT = 30 * 1000;
37
41
  /**
38
42
  * Max message size that can be sent to the DataChannel. In browsers this is
39
43
  * 256KiB but go-libp2p and rust-libp2p only support 16KiB at the time of
@@ -65,6 +69,17 @@ function calculateProtobufOverhead(maxMessageSize = MAX_MESSAGE_SIZE) {
65
69
  * protobuf that aren't message field bytes
66
70
  */
67
71
  export const PROTOBUF_OVERHEAD = calculateProtobufOverhead();
72
+ /**
73
+ * When closing streams we send a FIN then wait for the remote to
74
+ * reply with a FIN_ACK. If that does not happen within this timeout
75
+ * we close the stream anyway.
76
+ */
77
+ export const FIN_ACK_TIMEOUT = 5_000;
78
+ /**
79
+ * When sending data messages, if the channel is not in the "open" state, wait
80
+ * this long for the "open" event to fire.
81
+ */
82
+ export const OPEN_TIMEOUT = 5_000;
68
83
  /**
69
84
  * When closing a stream, we wait for `bufferedAmount` to become 0 before
70
85
  * closing the underlying RTCDataChannel - this controls how long we wait in ms
@@ -1 +1 @@
1
- {"version":3,"file":"constants.js","sourceRoot":"","sources":["../../src/constants.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAA;AAC7C,OAAO,EAAE,OAAO,EAAE,MAAM,mCAAmC,CAAA;AAE3D;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAAG;IACjC,8BAA8B;IAC9B,kCAAkC;IAClC,+BAA+B;IAC/B,qCAAqC;CACtC,CAAA;AAED;;GAEG;AACH,MAAM,CAAC,MAAM,cAAc,GAAG,KAAK,CAAC,IAAI,CAAC,gEAAgE,CAAC,CAAA;AAE1G;;GAEG;AACH,MAAM,CAAC,MAAM,YAAY,GAAG,mBAAmB,CAAA;AAE/C;;GAEG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAAG,MAAM,CAAA;AAEzC;;GAEG;AACH,MAAM,CAAC,MAAM,cAAc,GAAG,MAAM,CAAA;AAEpC;;GAEG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAAG,CAAC,GAAG,IAAI,GAAG,IAAI,CAAA;AAElD;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAG,EAAE,GAAG,IAAI,CAAA;AAEzC;;;;;;GAMG;AACH,SAAS,yBAAyB,CAAE,cAAc,GAAG,gBAAgB;IACnE,0BAA0B;IAC1B,MAAM,aAAa,GAAG,cAAc,CAAC,cAAc,GAAG,cAAc,CAAC,cAAc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M,CAAC,MAAM,iBAAiB,GAAG,yBAAyB,EAAE,CAAA;AAE5D;;;;GAIG;AACH,MAAM,CAAC,MAAM,eAAe,GAAG,KAAK,CAAA;AAEpC;;;GAGG;AACH,MAAM,CAAC,MAAM,YAAY,GAAG,KAAK,CAAA;AAEjC;;;GAGG;AACH,MAAM,CAAC,MAAM,0BAA0B,GAAG,MAAM,CAAA;AAEhD;;GAEG;AACH,MAAM,CAAC,MAAM,cAAc,GAAG,SAAS,CAAA;AAEvC;;GAEG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAAG,yBAAyB,CAAA;AAE3D;;GAEG;AACH,MAAM,CAAC,MAAM,iCAAiC,GAAG,mCAAmC,CAAA;AAEpF;;GAEG;AACH,MAAM,CAAC,MAAM,oCAAoC,GAAG,uCAAuC,CAAA;AAE3F;;GAEG;AACH,MAAM,CAAC,MAAM,oCAAoC,GAAG,OAAO,CAAA;AAE3D;;GAEG;AACH,MAAM,CAAC,MAAM,4BAA4B,GAAG,aAAa,CAAA;AAEzD;;GAEG;AACH,MAAM,CAAC,MAAM,qCAAqC,GAAG,UAAU,CAAA"}
@@ -26,8 +26,8 @@
26
26
  * WebRTC requires use of a relay to connect two nodes. The listener first discovers a relay server and makes a reservation, then the dialer can connect via the relayed address.
27
27
  *
28
28
  * ```TypeScript
29
- * import { noise } from '@libp2p/noise'
30
- * import { yamux } from '@libp2p/yamux'
29
+ * import { noise } from '@chainsafe/libp2p-noise'
30
+ * import { yamux } from '@chainsafe/libp2p-yamux'
31
31
  * import { echo } from '@libp2p/echo'
32
32
  * import { circuitRelayTransport, circuitRelayServer } from '@libp2p/circuit-relay-v2'
33
33
  * import { identify } from '@libp2p/identify'
@@ -35,6 +35,7 @@
35
35
  * import { webSockets } from '@libp2p/websockets'
36
36
  * import { WebRTC } from '@multiformats/multiaddr-matcher'
37
37
  * import delay from 'delay'
38
+ * import { pipe } from 'it-pipe'
38
39
  * import { createLibp2p } from 'libp2p'
39
40
  * import type { Multiaddr } from '@multiformats/multiaddr'
40
41
  *
@@ -133,11 +134,15 @@
133
134
  * await relay.stop()
134
135
  *
135
136
  * // send/receive some data from the remote peer via a direct connection
136
- * stream.send(new TextEncoder().encode('hello world'))
137
- *
138
- * stream.addEventListener('message', (evt) => {
139
- * console.info(new TextDecoder().decode(evt.data.subarray()))
140
- * })
137
+ * await pipe(
138
+ * [new TextEncoder().encode('hello world')],
139
+ * stream,
140
+ * async source => {
141
+ * for await (const buf of source) {
142
+ * console.info(new TextDecoder().decode(buf.subarray()))
143
+ * }
144
+ * }
145
+ * )
141
146
  * ```
142
147
  *
143
148
  * @example WebRTC Direct
@@ -162,6 +167,7 @@
162
167
  * ```TypeScript
163
168
  * import { createLibp2p } from 'libp2p'
164
169
  * import { multiaddr } from '@multiformats/multiaddr'
170
+ * import { pipe } from 'it-pipe'
165
171
  * import { fromString, toString } from 'uint8arrays'
166
172
  * import { webRTCDirect } from '@libp2p/webrtc'
167
173
  *
@@ -190,11 +196,15 @@
190
196
  * signal: AbortSignal.timeout(10_000)
191
197
  * })
192
198
  *
193
- * stream.send(new TextEncoder().encode('hello world'))
194
- *
195
- * stream.addEventListener('message', (evt) => {
196
- * console.info(new TextDecoder().decode(evt.data.subarray()))
197
- * })
199
+ * await pipe(
200
+ * [fromString(`Hello js-libp2p-webrtc\n`)],
201
+ * stream,
202
+ * async function (source) {
203
+ * for await (const buf of source) {
204
+ * console.info(toString(buf.subarray()))
205
+ * }
206
+ * }
207
+ * )
198
208
  * ```
199
209
  *
200
210
  * ## WebRTC Direct certificate hashes
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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+B,KAAK,SAAS,CAEnH;AAED,YAAY,EAAE,mBAAmB,EAAE,yBAAyB,EAAE,CAAA;AAE9D,iBAAS,MAAM,CAAE,IAAI,CAAC,EAAE,mBAAmB,GAAG,CAAC,UAAU,EAAE,yBAAyB,KAAK,SAAS,CAEjG;AAED,OAAO,EAAE,MAAM,EAAE,YAAY,EAAE,CAAA"}
package/dist/src/index.js CHANGED
@@ -26,8 +26,8 @@
26
26
  * WebRTC requires use of a relay to connect two nodes. The listener first discovers a relay server and makes a reservation, then the dialer can connect via the relayed address.
27
27
  *
28
28
  * ```TypeScript
29
- * import { noise } from '@libp2p/noise'
30
- * import { yamux } from '@libp2p/yamux'
29
+ * import { noise } from '@chainsafe/libp2p-noise'
30
+ * import { yamux } from '@chainsafe/libp2p-yamux'
31
31
  * import { echo } from '@libp2p/echo'
32
32
  * import { circuitRelayTransport, circuitRelayServer } from '@libp2p/circuit-relay-v2'
33
33
  * import { identify } from '@libp2p/identify'
@@ -35,6 +35,7 @@
35
35
  * import { webSockets } from '@libp2p/websockets'
36
36
  * import { WebRTC } from '@multiformats/multiaddr-matcher'
37
37
  * import delay from 'delay'
38
+ * import { pipe } from 'it-pipe'
38
39
  * import { createLibp2p } from 'libp2p'
39
40
  * import type { Multiaddr } from '@multiformats/multiaddr'
40
41
  *
@@ -133,11 +134,15 @@
133
134
  * await relay.stop()
134
135
  *
135
136
  * // send/receive some data from the remote peer via a direct connection
136
- * stream.send(new TextEncoder().encode('hello world'))
137
- *
138
- * stream.addEventListener('message', (evt) => {
139
- * console.info(new TextDecoder().decode(evt.data.subarray()))
140
- * })
137
+ * await pipe(
138
+ * [new TextEncoder().encode('hello world')],
139
+ * stream,
140
+ * async source => {
141
+ * for await (const buf of source) {
142
+ * console.info(new TextDecoder().decode(buf.subarray()))
143
+ * }
144
+ * }
145
+ * )
141
146
  * ```
142
147
  *
143
148
  * @example WebRTC Direct
@@ -162,6 +167,7 @@
162
167
  * ```TypeScript
163
168
  * import { createLibp2p } from 'libp2p'
164
169
  * import { multiaddr } from '@multiformats/multiaddr'
170
+ * import { pipe } from 'it-pipe'
165
171
  * import { fromString, toString } from 'uint8arrays'
166
172
  * import { webRTCDirect } from '@libp2p/webrtc'
167
173
  *
@@ -190,11 +196,15 @@
190
196
  * signal: AbortSignal.timeout(10_000)
191
197
  * })
192
198
  *
193
- * stream.send(new TextEncoder().encode('hello world'))
194
- *
195
- * stream.addEventListener('message', (evt) => {
196
- * console.info(new TextDecoder().decode(evt.data.subarray()))
197
- * })
199
+ * await pipe(
200
+ * [fromString(`Hello js-libp2p-webrtc\n`)],
201
+ * stream,
202
+ * async function (source) {
203
+ * for await (const buf of source) {
204
+ * console.info(toString(buf.subarray()))
205
+ * }
206
+ * }
207
+ * )
198
208
  * ```
199
209
  *
200
210
  * ## WebRTC Direct certificate hashes
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4PG;AAEH,OAAO,EAAE,eAAe,EAAE,MAAM,mCAAmC,CAAA;AACnE,OAAO,EAAE,qBAAqB,EAAE,MAAM,kCAAkC,CAAA;AA+ExE,SAAS,YAAY,CAAE,IAAgC;IACrD,OAAO,CAAC,UAA2C,EAAE,EAAE,CAAC,IAAI,qBAAqB,CAAC,UAAU,EAAE,IAAI,CAAC,CAAA;AACrG,CAAC;AAID,SAAS,MAAM,CAAE,IAA0B;IACzC,OAAO,CAAC,UAAqC,EAAE,EAAE,CAAC,IAAI,eAAe,CAAC,UAAU,EAAE,IAAI,CAAC,CAAA;AACzF,CAAC;AAED,OAAO,EAAE,MAAM,EAAE,YAAY,EAAE,CAAA"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsQG;AAEH,OAAO,EAAE,eAAe,EAAE,MAAM,mCAAmC,CAAA;AACnE,OAAO,EAAE,qBAAqB,EAAE,MAAM,kCAAkC,CAAA;AA+ExE,SAAS,YAAY,CAAE,IAAgC;IACrD,OAAO,CAAC,UAA2C,EAAE,EAAE,CAAC,IAAI,qBAAqB,CAAC,UAAU,EAAE,IAAI,CAAC,CAAA;AACrG,CAAC;AAID,SAAS,MAAM,CAAE,IAA0B;IACzC,OAAO,CAAC,UAAqC,EAAE,EAAE,CAAC,IAAI,eAAe,CAAC,UAAU,EAAE,IAAI,CAAC,CAAA;AACzF,CAAC;AAED,OAAO,EAAE,MAAM,EAAE,YAAY,EAAE,CAAA"}
@@ -0,0 +1,58 @@
1
+ import type { RTCPeerConnection } from './webrtc/index.js';
2
+ import type { ComponentLogger, Logger, MultiaddrConnection, MultiaddrConnectionTimeline, CounterGroup } from '@libp2p/interface';
3
+ import type { AbortOptions, Multiaddr } from '@multiformats/multiaddr';
4
+ import type { Source, Sink } from 'it-stream-types';
5
+ import type { Uint8ArrayList } from 'uint8arraylist';
6
+ interface WebRTCMultiaddrConnectionInit {
7
+ /**
8
+ * WebRTC Peer Connection
9
+ */
10
+ peerConnection: RTCPeerConnection;
11
+ /**
12
+ * The multiaddr address used to communicate with the remote peer
13
+ */
14
+ remoteAddr: Multiaddr;
15
+ /**
16
+ * Holds the relevant events timestamps of the connection
17
+ */
18
+ timeline: MultiaddrConnectionTimeline;
19
+ /**
20
+ * Optional metrics counter group for this connection
21
+ */
22
+ metrics?: CounterGroup;
23
+ }
24
+ export interface WebRTCMultiaddrConnectionComponents {
25
+ logger: ComponentLogger;
26
+ }
27
+ export declare class WebRTCMultiaddrConnection implements MultiaddrConnection {
28
+ readonly log: Logger;
29
+ /**
30
+ * WebRTC Peer Connection
31
+ */
32
+ readonly peerConnection: RTCPeerConnection;
33
+ /**
34
+ * The multiaddr address used to communicate with the remote peer
35
+ */
36
+ remoteAddr: Multiaddr;
37
+ /**
38
+ * Holds the life cycle times of the connection
39
+ */
40
+ timeline: MultiaddrConnectionTimeline;
41
+ /**
42
+ * Optional metrics counter group for this connection
43
+ */
44
+ metrics?: CounterGroup;
45
+ /**
46
+ * The stream source, a no-op as the transport natively supports multiplexing
47
+ */
48
+ source: AsyncGenerator<Uint8Array, any, unknown>;
49
+ /**
50
+ * The stream destination, a no-op as the transport natively supports multiplexing
51
+ */
52
+ sink: Sink<Source<Uint8Array | Uint8ArrayList>, Promise<void>>;
53
+ constructor(components: WebRTCMultiaddrConnectionComponents, init: WebRTCMultiaddrConnectionInit);
54
+ close(options?: AbortOptions): Promise<void>;
55
+ abort(err: Error): void;
56
+ }
57
+ export {};
58
+ //# sourceMappingURL=maconn.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"maconn.d.ts","sourceRoot":"","sources":["../../src/maconn.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAA;AAC1D,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,EAAE,mBAAmB,EAAE,2BAA2B,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAA;AAChI,OAAO,KAAK,EAAE,YAAY,EAAE,SAAS,EAA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 * The multiaddr address used to communicate with the remote peer
10
+ */
11
+ remoteAddr;
12
+ /**
13
+ * Holds the life cycle times of the connection
14
+ */
15
+ timeline;
16
+ /**
17
+ * Optional metrics counter group for this connection
18
+ */
19
+ metrics;
20
+ /**
21
+ * The stream source, a no-op as the transport natively supports multiplexing
22
+ */
23
+ source = nopSource();
24
+ /**
25
+ * The stream destination, a no-op as the transport natively supports multiplexing
26
+ */
27
+ sink = nopSink;
28
+ constructor(components, init) {
29
+ this.log = components.logger.forComponent('libp2p:webrtc:maconn');
30
+ this.remoteAddr = init.remoteAddr;
31
+ this.timeline = init.timeline;
32
+ this.peerConnection = init.peerConnection;
33
+ const peerConnection = this.peerConnection;
34
+ const initialState = peerConnection.connectionState;
35
+ this.peerConnection.onconnectionstatechange = () => {
36
+ this.log.trace('peer connection state change', peerConnection.connectionState, 'initial state', initialState);
37
+ if (peerConnection.connectionState === 'disconnected' || peerConnection.connectionState === 'failed' || peerConnection.connectionState === 'closed') {
38
+ // nothing else to do but close the connection
39
+ this.timeline.close = Date.now();
40
+ }
41
+ };
42
+ }
43
+ async close(options) {
44
+ this.log.trace('closing connection');
45
+ this.peerConnection.close();
46
+ this.timeline.close = Date.now();
47
+ this.metrics?.increment({ close: true });
48
+ }
49
+ abort(err) {
50
+ this.log.error('closing connection due to error', err);
51
+ this.peerConnection.close();
52
+ this.timeline.close = Date.now();
53
+ this.metrics?.increment({ abort: true });
54
+ }
55
+ }
56
+ //# sourceMappingURL=maconn.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"maconn.js","sourceRoot":"","sources":["../../src/maconn.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAA;AAiC9C,MAAM,OAAO,yBAAyB;IAC3B,GAAG,CAAQ;IAEpB;;OAEG;IACM,cAAc,CAAmB;IAE1C;;OAEG;IACH,UAAU,CAAW;IAErB;;OAEG;IACH,QAAQ,CAA6B;IAErC;;OAEG;IACH,OAA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,CAAC;IAED,KAAK,CAAE,GAAU;QACf,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,iCAAiC,EAAE,GAAG,CAAC,CAAA;QAEtD,IAAI,CAAC,cAAc,CAAC,KAAK,EAAE,CAAA;QAC3B,IAAI,CAAC,QAAQ,CAAC,KAAK,GAAG,IAAI,CAAC,GAAG,EAAE,CAAA;QAChC,IAAI,CAAC,OAAO,EAAE,SAAS,CAAC,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAA;IAC1C,CAAC;CACF"}
@@ -1,7 +1,8 @@
1
- import { AbstractStreamMuxer } from '@libp2p/utils';
2
- import { WebRTCStream } from './stream.js';
3
1
  import type { DataChannelOptions } from './index.js';
4
- import type { ComponentLogger, CounterGroup, StreamMuxer, StreamMuxerFactory, CreateStreamOptions, MultiaddrConnection } from '@libp2p/interface';
2
+ import type { ComponentLogger, Stream, CounterGroup, StreamMuxer, StreamMuxerFactory, StreamMuxerInit } from '@libp2p/interface';
3
+ import type { AbortOptions } from '@multiformats/multiaddr';
4
+ import type { Source, Sink } from 'it-stream-types';
5
+ import type { Uint8ArrayList } from 'uint8arraylist';
5
6
  export interface DataChannelMuxerFactoryInit {
6
7
  /**
7
8
  * WebRTC Peer Connection
@@ -15,27 +16,32 @@ export interface DataChannelMuxerFactoryInit {
15
16
  * Optional metrics for this data channel muxer
16
17
  */
17
18
  metrics?: CounterGroup;
18
- /**
19
- * Options used to create data channels
20
- */
21
19
  dataChannelOptions?: DataChannelOptions;
22
20
  }
23
21
  export interface DataChannelMuxerFactoryComponents {
24
22
  logger: ComponentLogger;
25
23
  }
24
+ interface BufferedStream {
25
+ stream: Stream;
26
+ channel: RTCDataChannel;
27
+ onEnd(err?: Error): void;
28
+ }
26
29
  export declare class DataChannelMuxerFactory implements StreamMuxerFactory {
27
30
  readonly protocol: string;
28
31
  /**
29
32
  * WebRTC Peer Connection
30
33
  */
31
34
  private readonly peerConnection;
35
+ private bufferedStreams;
32
36
  private readonly metrics?;
33
37
  private readonly dataChannelOptions?;
34
- constructor(init: DataChannelMuxerFactoryInit);
35
- createStreamMuxer(maConn: MultiaddrConnection): StreamMuxer;
38
+ private readonly components;
39
+ private readonly log;
40
+ constructor(components: DataChannelMuxerFactoryComponents, init: DataChannelMuxerFactoryInit);
41
+ createStreamMuxer(init?: StreamMuxerInit): StreamMuxer;
36
42
  }
37
- export interface DataChannelMuxerInit extends DataChannelMuxerFactoryInit {
38
- protocol: string;
43
+ export interface DataChannelMuxerInit extends DataChannelMuxerFactoryInit, StreamMuxerInit {
44
+ streams: BufferedStream[];
39
45
  }
40
46
  export interface DataChannelMuxerComponents {
41
47
  logger: ComponentLogger;
@@ -43,11 +49,37 @@ export interface DataChannelMuxerComponents {
43
49
  /**
44
50
  * A libp2p data channel stream muxer
45
51
  */
46
- export declare class DataChannelMuxer extends AbstractStreamMuxer<WebRTCStream> implements StreamMuxer<WebRTCStream> {
52
+ export declare class DataChannelMuxer implements StreamMuxer {
53
+ #private;
54
+ readonly init: DataChannelMuxerInit;
55
+ /**
56
+ * Array of streams in the data channel
57
+ */
58
+ streams: Stream[];
59
+ protocol: string;
60
+ private readonly log;
47
61
  private readonly peerConnection;
48
62
  private readonly dataChannelOptions;
49
- constructor(maConn: MultiaddrConnection, init: DataChannelMuxerInit);
50
- onCreateStream(options?: CreateStreamOptions): Promise<WebRTCStream>;
51
- onData(): void;
63
+ private readonly metrics?;
64
+ private readonly logger;
65
+ constructor(components: DataChannelMuxerComponents, init: DataChannelMuxerInit);
66
+ /**
67
+ * Gracefully close all tracked streams and stop the muxer
68
+ */
69
+ close(options?: AbortOptions): Promise<void>;
70
+ /**
71
+ * Abort all tracked streams and stop the muxer
72
+ */
73
+ abort(err: Error): void;
74
+ /**
75
+ * The stream source, a no-op as the transport natively supports multiplexing
76
+ */
77
+ source: AsyncGenerator<Uint8Array, any, unknown>;
78
+ /**
79
+ * The stream destination, a no-op as the transport natively supports multiplexing
80
+ */
81
+ sink: Sink<Source<Uint8Array | Uint8ArrayList>, Promise<void>>;
82
+ newStream(): Stream;
52
83
  }
84
+ export {};
53
85
  //# sourceMappingURL=muxer.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"muxer.d.ts","sourceRoot":"","sources":["../../src/muxer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,eAAe,CAAA;AAGnD,OAAO,EAAgB,YAAY,EAAE,MAAM,aAAa,CAAA;AACxD,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAA;AACpD,OAAO,KAAK,EAAE,eAAe,EAAE,YAAY,EAAE,WAAW,EAAE,kBAAkB,EAAE,mBAAmB,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAA;AAEjJ,MAAM,WAAW,2BAA2B;IAC1C;;OAEG;IACH,cAAc,EAAE,iBAAiB,CAAA;IAEjC;;OAEG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAA;IAEjB;;OAEG;IACH,OAAO,CAAC,EAAE,YAAY,CAAA;IAEtB;;OAEG;IACH,kBAAkB,CAAC,EAAE,kBAAkB,CAAA;CACxC;AAED,MAAM,WAAW,iCAAiC;IAChD,MAAM,EAAE,eAAe,CAAA;CACxB;AAED,qBAAa,uBAAwB,YAAW,kBAAkB;IAChE,SAAgB,QAAQ,EAAE,MAAM,CAAA;IAEhC;;OAEG;IACH,OAAO,CAAC,QAAQ,CAAC,cAAc,CAAmB;IAClD,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAc;IACvC,OAAO,CAAC,QAAQ,CAAC,kBAAkB,CAAC,CAAoB;gBAE3C,IAAI,EAAE,2BAA2B;IAO9C,iBAAiB,CAAE,MAAM,EAAE,mBAAmB,GAAG,WAAW;CAQ7D;AAED,MAAM,WAAW,oBAAqB,SAAQ,2BAA2B;IACvE,QAAQ,EAAE,MAAM,CAAA;CACjB;AAED,MAAM,WAAW,0BAA0B;IACzC,MAAM,EAAE,eAAe,CAAA;CACxB;AAED;;GAEG;AACH,qB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