@libp2p/websockets 7.0.10 → 7.0.11
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 +5 -100
- package/dist/src/index.d.ts +64 -0
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +64 -0
- package/dist/src/index.js.map +1 -1
- package/package.json +5 -5
- package/src/index.ts +65 -0
package/README.md
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
# @libp2p/websockets <!-- omit in toc -->
|
|
2
|
-
|
|
3
1
|
[](http://libp2p.io/)
|
|
4
2
|
[](https://discuss.libp2p.io)
|
|
5
3
|
[](https://codecov.io/gh/libp2p/js-libp2p)
|
|
@@ -7,27 +5,13 @@
|
|
|
7
5
|
|
|
8
6
|
> JavaScript implementation of the WebSockets module that libp2p uses and that implements the interface-transport spec
|
|
9
7
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
- [Install](#install)
|
|
13
|
-
- [Browser `<script>` tag](#browser-script-tag)
|
|
14
|
-
- [Usage](#usage)
|
|
15
|
-
- [Constructor properties](#constructor-properties)
|
|
16
|
-
- [Libp2p Usage Example](#libp2p-usage-example)
|
|
17
|
-
- [API](#api)
|
|
18
|
-
- [Transport](#transport)
|
|
19
|
-
- [Connection](#connection)
|
|
20
|
-
- [API Docs](#api-docs)
|
|
21
|
-
- [License](#license)
|
|
22
|
-
- [Contribution](#contribution)
|
|
23
|
-
|
|
24
|
-
## Install
|
|
8
|
+
# Install
|
|
25
9
|
|
|
26
10
|
```console
|
|
27
11
|
$ npm i @libp2p/websockets
|
|
28
12
|
```
|
|
29
13
|
|
|
30
|
-
|
|
14
|
+
## Browser `<script>` tag
|
|
31
15
|
|
|
32
16
|
Loading this module through a script tag will make it's exports available as `Libp2pWebsockets` in the global namespace.
|
|
33
17
|
|
|
@@ -35,96 +19,17 @@ Loading this module through a script tag will make it's exports available as `Li
|
|
|
35
19
|
<script src="https://unpkg.com/@libp2p/websockets/dist/index.min.js"></script>
|
|
36
20
|
```
|
|
37
21
|
|
|
38
|
-
|
|
39
|
-
[](https://github.com/libp2p/interface-connection)
|
|
40
|
-
|
|
41
|
-
## Usage
|
|
42
|
-
|
|
43
|
-
```sh
|
|
44
|
-
> npm i @libp2p/websockets
|
|
45
|
-
```
|
|
46
|
-
|
|
47
|
-
### Constructor properties
|
|
48
|
-
|
|
49
|
-
```js
|
|
50
|
-
import { createLibp2pNode } from 'libp2p'
|
|
51
|
-
import { webSockets } from '@libp2p/webrtc-direct'
|
|
52
|
-
|
|
53
|
-
const node = await createLibp2p({
|
|
54
|
-
transports: [
|
|
55
|
-
webSockets()
|
|
56
|
-
]
|
|
57
|
-
//... other config
|
|
58
|
-
})
|
|
59
|
-
await node.start()
|
|
60
|
-
await node.dial('/ip4/127.0.0.1/tcp/9090/ws')
|
|
61
|
-
```
|
|
62
|
-
|
|
63
|
-
| Name | Type | Description | Default |
|
|
64
|
-
| -------- | -------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------- | ------------------------------------------------------------------------ |
|
|
65
|
-
| upgrader | [`Upgrader`](https://github.com/libp2p/js-libp2p-interfaces/tree/master/packages/libp2p-interfaces/src/transport#upgrader) | connection upgrader object with `upgradeOutbound` and `upgradeInbound` | **REQUIRED** |
|
|
66
|
-
| filter | `(multiaddrs: Array<Multiaddr>) => Array<Multiaddr>` | override transport addresses filter | **Browser:** DNS+WSS multiaddrs / **Node.js:** DNS+\[WS, WSS] multiaddrs |
|
|
67
|
-
|
|
68
|
-
You can create your own address filters for this transports, or rely in the filters [provided](./src/filters.js).
|
|
69
|
-
|
|
70
|
-
The available filters are:
|
|
71
|
-
|
|
72
|
-
- `filters.all`
|
|
73
|
-
- Returns all TCP and DNS based addresses, both with `ws` or `wss`.
|
|
74
|
-
- `filters.dnsWss`
|
|
75
|
-
- Returns all DNS based addresses with `wss`.
|
|
76
|
-
- `filters.dnsWsOrWss`
|
|
77
|
-
- Returns all DNS based addresses, both with `ws` or `wss`.
|
|
78
|
-
|
|
79
|
-
## Libp2p Usage Example
|
|
80
|
-
|
|
81
|
-
```js
|
|
82
|
-
import { createLibp2pNode } from 'libp2p'
|
|
83
|
-
import { websockets } from '@libp2p/websockets'
|
|
84
|
-
import filters from '@libp2p/websockets/filters'
|
|
85
|
-
import { mplex } from '@libp2p/mplex'
|
|
86
|
-
import { noise } from '@libp2p/noise'
|
|
87
|
-
|
|
88
|
-
const transportKey = Websockets.prototype[Symbol.toStringTag]
|
|
89
|
-
const node = await Libp2p.create({
|
|
90
|
-
transport: [
|
|
91
|
-
websockets({
|
|
92
|
-
// connect to all sockets, even insecure ones
|
|
93
|
-
filter: filters.all
|
|
94
|
-
})
|
|
95
|
-
],
|
|
96
|
-
streamMuxers: [
|
|
97
|
-
mplex()
|
|
98
|
-
],
|
|
99
|
-
connectionEncryption: [
|
|
100
|
-
noise()
|
|
101
|
-
]
|
|
102
|
-
})
|
|
103
|
-
```
|
|
104
|
-
|
|
105
|
-
For more information see [libp2p/js-libp2p/doc/CONFIGURATION.md#customizing-transports](https://github.com/libp2p/js-libp2p/blob/master/doc/CONFIGURATION.md#customizing-transports).
|
|
106
|
-
|
|
107
|
-
## API
|
|
108
|
-
|
|
109
|
-
### Transport
|
|
110
|
-
|
|
111
|
-
[](https://github.com/libp2p/interface-transport)
|
|
112
|
-
|
|
113
|
-
### Connection
|
|
114
|
-
|
|
115
|
-
[](https://github.com/libp2p/interface-connection)
|
|
116
|
-
|
|
117
|
-
## API Docs
|
|
22
|
+
# API Docs
|
|
118
23
|
|
|
119
24
|
- <https://libp2p.github.io/js-libp2p/modules/_libp2p_websockets.html>
|
|
120
25
|
|
|
121
|
-
|
|
26
|
+
# License
|
|
122
27
|
|
|
123
28
|
Licensed under either of
|
|
124
29
|
|
|
125
30
|
- Apache 2.0, ([LICENSE-APACHE](LICENSE-APACHE) / <http://www.apache.org/licenses/LICENSE-2.0>)
|
|
126
31
|
- MIT ([LICENSE-MIT](LICENSE-MIT) / <http://opensource.org/licenses/MIT>)
|
|
127
32
|
|
|
128
|
-
|
|
33
|
+
# Contribution
|
|
129
34
|
|
|
130
35
|
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.
|
package/dist/src/index.d.ts
CHANGED
|
@@ -1,3 +1,67 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @packageDocumentation
|
|
3
|
+
*
|
|
4
|
+
* A [libp2p transport](https://docs.libp2p.io/concepts/transports/overview/) based on [WebSockets](https://developer.mozilla.org/en-US/docs/Web/API/WebSockets_API).
|
|
5
|
+
*
|
|
6
|
+
* @example
|
|
7
|
+
*
|
|
8
|
+
* ```js
|
|
9
|
+
* import { createLibp2pNode } from 'libp2p'
|
|
10
|
+
* import { webSockets } from '@libp2p/webrtc-direct'
|
|
11
|
+
*
|
|
12
|
+
* const node = await createLibp2p({
|
|
13
|
+
* transports: [
|
|
14
|
+
* webSockets()
|
|
15
|
+
* ]
|
|
16
|
+
* //... other config
|
|
17
|
+
* })
|
|
18
|
+
* await node.start()
|
|
19
|
+
* await node.dial('/ip4/127.0.0.1/tcp/9090/ws')
|
|
20
|
+
* ```
|
|
21
|
+
*
|
|
22
|
+
* ## Filters
|
|
23
|
+
*
|
|
24
|
+
* When run in a browser by default this module will only connect to secure web socket addresses.
|
|
25
|
+
*
|
|
26
|
+
* To change this you should pass a filter to the factory function.
|
|
27
|
+
*
|
|
28
|
+
* You can create your own address filters for this transports, or rely in the filters [provided](./src/filters.js).
|
|
29
|
+
*
|
|
30
|
+
* The available filters are:
|
|
31
|
+
*
|
|
32
|
+
* - `filters.all`
|
|
33
|
+
* - Returns all TCP and DNS based addresses, both with `ws` or `wss`.
|
|
34
|
+
* - `filters.dnsWss`
|
|
35
|
+
* - Returns all DNS based addresses with `wss`.
|
|
36
|
+
* - `filters.dnsWsOrWss`
|
|
37
|
+
* - Returns all DNS based addresses, both with `ws` or `wss`.
|
|
38
|
+
*
|
|
39
|
+
* @example
|
|
40
|
+
*
|
|
41
|
+
* ```js
|
|
42
|
+
* import { createLibp2pNode } from 'libp2p'
|
|
43
|
+
* import { websockets } from '@libp2p/websockets'
|
|
44
|
+
* import filters from '@libp2p/websockets/filters'
|
|
45
|
+
* import { mplex } from '@libp2p/mplex'
|
|
46
|
+
* import { noise } from '@libp2p/noise'
|
|
47
|
+
*
|
|
48
|
+
* const transportKey = Websockets.prototype[Symbol.toStringTag]
|
|
49
|
+
* const node = await Libp2p.create({
|
|
50
|
+
* transport: [
|
|
51
|
+
* websockets({
|
|
52
|
+
* // connect to all sockets, even insecure ones
|
|
53
|
+
* filter: filters.all
|
|
54
|
+
* })
|
|
55
|
+
* ],
|
|
56
|
+
* streamMuxers: [
|
|
57
|
+
* mplex()
|
|
58
|
+
* ],
|
|
59
|
+
* connectionEncryption: [
|
|
60
|
+
* noise()
|
|
61
|
+
* ]
|
|
62
|
+
* })
|
|
63
|
+
* ```
|
|
64
|
+
*/
|
|
1
65
|
/// <reference types="node" />
|
|
2
66
|
import { type Transport, type MultiaddrFilter } from '@libp2p/interface/transport';
|
|
3
67
|
import { type WebSocketOptions } from 'it-ws/client';
|
package/dist/src/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+DG;;AAGH,OAAO,EAAE,KAAK,SAAS,EAAE,KAAK,eAAe,EAAuE,MAAM,6BAA6B,CAAA;AAGvJ,OAAO,EAAW,KAAK,gBAAgB,EAAE,MAAM,cAAc,CAAA;AAM7D,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAA;AAGrD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,MAAM,CAAA;AAElC,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,IAAI,CAAA;AAIvC,MAAM,WAAW,cAAe,SAAQ,YAAY,EAAE,gBAAgB;IACpE,MAAM,CAAC,EAAE,eAAe,CAAA;IACxB,SAAS,CAAC,EAAE,aAAa,CAAA;IACzB,MAAM,CAAC,EAAE,MAAM,CAAA;CAChB;AA+GD,wBAAgB,UAAU,CAAE,IAAI,GAAE,cAAmB,GAAG,CAAC,UAAU,CAAC,EAAE,GAAG,KAAK,SAAS,CAItF"}
|
package/dist/src/index.js
CHANGED
|
@@ -1,3 +1,67 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @packageDocumentation
|
|
3
|
+
*
|
|
4
|
+
* A [libp2p transport](https://docs.libp2p.io/concepts/transports/overview/) based on [WebSockets](https://developer.mozilla.org/en-US/docs/Web/API/WebSockets_API).
|
|
5
|
+
*
|
|
6
|
+
* @example
|
|
7
|
+
*
|
|
8
|
+
* ```js
|
|
9
|
+
* import { createLibp2pNode } from 'libp2p'
|
|
10
|
+
* import { webSockets } from '@libp2p/webrtc-direct'
|
|
11
|
+
*
|
|
12
|
+
* const node = await createLibp2p({
|
|
13
|
+
* transports: [
|
|
14
|
+
* webSockets()
|
|
15
|
+
* ]
|
|
16
|
+
* //... other config
|
|
17
|
+
* })
|
|
18
|
+
* await node.start()
|
|
19
|
+
* await node.dial('/ip4/127.0.0.1/tcp/9090/ws')
|
|
20
|
+
* ```
|
|
21
|
+
*
|
|
22
|
+
* ## Filters
|
|
23
|
+
*
|
|
24
|
+
* When run in a browser by default this module will only connect to secure web socket addresses.
|
|
25
|
+
*
|
|
26
|
+
* To change this you should pass a filter to the factory function.
|
|
27
|
+
*
|
|
28
|
+
* You can create your own address filters for this transports, or rely in the filters [provided](./src/filters.js).
|
|
29
|
+
*
|
|
30
|
+
* The available filters are:
|
|
31
|
+
*
|
|
32
|
+
* - `filters.all`
|
|
33
|
+
* - Returns all TCP and DNS based addresses, both with `ws` or `wss`.
|
|
34
|
+
* - `filters.dnsWss`
|
|
35
|
+
* - Returns all DNS based addresses with `wss`.
|
|
36
|
+
* - `filters.dnsWsOrWss`
|
|
37
|
+
* - Returns all DNS based addresses, both with `ws` or `wss`.
|
|
38
|
+
*
|
|
39
|
+
* @example
|
|
40
|
+
*
|
|
41
|
+
* ```js
|
|
42
|
+
* import { createLibp2pNode } from 'libp2p'
|
|
43
|
+
* import { websockets } from '@libp2p/websockets'
|
|
44
|
+
* import filters from '@libp2p/websockets/filters'
|
|
45
|
+
* import { mplex } from '@libp2p/mplex'
|
|
46
|
+
* import { noise } from '@libp2p/noise'
|
|
47
|
+
*
|
|
48
|
+
* const transportKey = Websockets.prototype[Symbol.toStringTag]
|
|
49
|
+
* const node = await Libp2p.create({
|
|
50
|
+
* transport: [
|
|
51
|
+
* websockets({
|
|
52
|
+
* // connect to all sockets, even insecure ones
|
|
53
|
+
* filter: filters.all
|
|
54
|
+
* })
|
|
55
|
+
* ],
|
|
56
|
+
* streamMuxers: [
|
|
57
|
+
* mplex()
|
|
58
|
+
* ],
|
|
59
|
+
* connectionEncryption: [
|
|
60
|
+
* noise()
|
|
61
|
+
* ]
|
|
62
|
+
* })
|
|
63
|
+
* ```
|
|
64
|
+
*/
|
|
1
65
|
import { AbortError, CodeError } from '@libp2p/interface/errors';
|
|
2
66
|
import { symbol } from '@libp2p/interface/transport';
|
|
3
67
|
import { logger } from '@libp2p/logger';
|
package/dist/src/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,0BAA0B,CAAA;AAChE,OAAO,EAAwC,MAAM,EAA+D,MAAM,6BAA6B,CAAA;AACvJ,OAAO,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAA;AACvC,OAAO,EAAE,cAAc,IAAI,KAAK,EAAE,MAAM,g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AAG,OAAO,EAAE,CAAC,CAAA;IACrD,CAAC;IAED;;;;OAIG;IACH,MAAM,CAAE,UAAuB;QAC7B,UAAU,GAAG,KAAK,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,CAAA;QAElE,IAAI,IAAI,CAAC,IAAI,EAAE,MAAM,IAAI,IAAI,EAAE;YAC7B,OAAO,IAAI,CAAC,IAAI,EAAE,MAAM,CAAC,UAAU,CAAC,CAAA;SACrC;QAED,UAAU;QACV,IAAI,SAAS,IAAI,WAAW,EAAE;YAC5B,OAAO,OAAO,CAAC,GAAG,CAAC,UAAU,CAAC,CAAA;SAC/B;QAED,OAAO,OAAO,CAAC,GAAG,CAAC,UAAU,CAAC,CAAA;IAChC,CAAC;CACF;AAED,MAAM,UAAU,UAAU,CAAE,OAAuB,EAAE;IACnD,OAAO,GAAG,EAAE;QACV,OAAO,IAAI,UAAU,CAAC,IAAI,CAAC,CAAA;IAC7B,CAAC,CAAA;AACH,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@libp2p/websockets",
|
|
3
|
-
"version": "7.0.
|
|
3
|
+
"version": "7.0.11",
|
|
4
4
|
"description": "JavaScript implementation of the WebSockets module that libp2p uses and that implements the interface-transport spec",
|
|
5
5
|
"license": "Apache-2.0 OR MIT",
|
|
6
6
|
"homepage": "https://github.com/libp2p/js-libp2p/tree/master/packages/transport-websockets#readme",
|
|
@@ -69,9 +69,9 @@
|
|
|
69
69
|
"test:electron-main": "aegir test -t electron-main -f ./dist/test/node.js --cov"
|
|
70
70
|
},
|
|
71
71
|
"dependencies": {
|
|
72
|
-
"@libp2p/interface": "^0.1.
|
|
73
|
-
"@libp2p/logger": "^3.0.
|
|
74
|
-
"@libp2p/utils": "^4.0.
|
|
72
|
+
"@libp2p/interface": "^0.1.5",
|
|
73
|
+
"@libp2p/logger": "^3.0.5",
|
|
74
|
+
"@libp2p/utils": "^4.0.6",
|
|
75
75
|
"@multiformats/mafmt": "^12.1.2",
|
|
76
76
|
"@multiformats/multiaddr": "^12.1.5",
|
|
77
77
|
"@multiformats/multiaddr-to-uri": "^9.0.2",
|
|
@@ -83,7 +83,7 @@
|
|
|
83
83
|
"ws": "^8.12.1"
|
|
84
84
|
},
|
|
85
85
|
"devDependencies": {
|
|
86
|
-
"@libp2p/interface-compliance-tests": "^4.1.
|
|
86
|
+
"@libp2p/interface-compliance-tests": "^4.1.3",
|
|
87
87
|
"aegir": "^41.0.2",
|
|
88
88
|
"is-loopback-addr": "^2.0.1",
|
|
89
89
|
"it-all": "^3.0.1",
|
package/src/index.ts
CHANGED
|
@@ -1,3 +1,68 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @packageDocumentation
|
|
3
|
+
*
|
|
4
|
+
* A [libp2p transport](https://docs.libp2p.io/concepts/transports/overview/) based on [WebSockets](https://developer.mozilla.org/en-US/docs/Web/API/WebSockets_API).
|
|
5
|
+
*
|
|
6
|
+
* @example
|
|
7
|
+
*
|
|
8
|
+
* ```js
|
|
9
|
+
* import { createLibp2pNode } from 'libp2p'
|
|
10
|
+
* import { webSockets } from '@libp2p/webrtc-direct'
|
|
11
|
+
*
|
|
12
|
+
* const node = await createLibp2p({
|
|
13
|
+
* transports: [
|
|
14
|
+
* webSockets()
|
|
15
|
+
* ]
|
|
16
|
+
* //... other config
|
|
17
|
+
* })
|
|
18
|
+
* await node.start()
|
|
19
|
+
* await node.dial('/ip4/127.0.0.1/tcp/9090/ws')
|
|
20
|
+
* ```
|
|
21
|
+
*
|
|
22
|
+
* ## Filters
|
|
23
|
+
*
|
|
24
|
+
* When run in a browser by default this module will only connect to secure web socket addresses.
|
|
25
|
+
*
|
|
26
|
+
* To change this you should pass a filter to the factory function.
|
|
27
|
+
*
|
|
28
|
+
* You can create your own address filters for this transports, or rely in the filters [provided](./src/filters.js).
|
|
29
|
+
*
|
|
30
|
+
* The available filters are:
|
|
31
|
+
*
|
|
32
|
+
* - `filters.all`
|
|
33
|
+
* - Returns all TCP and DNS based addresses, both with `ws` or `wss`.
|
|
34
|
+
* - `filters.dnsWss`
|
|
35
|
+
* - Returns all DNS based addresses with `wss`.
|
|
36
|
+
* - `filters.dnsWsOrWss`
|
|
37
|
+
* - Returns all DNS based addresses, both with `ws` or `wss`.
|
|
38
|
+
*
|
|
39
|
+
* @example
|
|
40
|
+
*
|
|
41
|
+
* ```js
|
|
42
|
+
* import { createLibp2pNode } from 'libp2p'
|
|
43
|
+
* import { websockets } from '@libp2p/websockets'
|
|
44
|
+
* import filters from '@libp2p/websockets/filters'
|
|
45
|
+
* import { mplex } from '@libp2p/mplex'
|
|
46
|
+
* import { noise } from '@libp2p/noise'
|
|
47
|
+
*
|
|
48
|
+
* const transportKey = Websockets.prototype[Symbol.toStringTag]
|
|
49
|
+
* const node = await Libp2p.create({
|
|
50
|
+
* transport: [
|
|
51
|
+
* websockets({
|
|
52
|
+
* // connect to all sockets, even insecure ones
|
|
53
|
+
* filter: filters.all
|
|
54
|
+
* })
|
|
55
|
+
* ],
|
|
56
|
+
* streamMuxers: [
|
|
57
|
+
* mplex()
|
|
58
|
+
* ],
|
|
59
|
+
* connectionEncryption: [
|
|
60
|
+
* noise()
|
|
61
|
+
* ]
|
|
62
|
+
* })
|
|
63
|
+
* ```
|
|
64
|
+
*/
|
|
65
|
+
|
|
1
66
|
import { AbortError, CodeError } from '@libp2p/interface/errors'
|
|
2
67
|
import { type Transport, type MultiaddrFilter, symbol, type CreateListenerOptions, type DialOptions, type Listener } from '@libp2p/interface/transport'
|
|
3
68
|
import { logger } from '@libp2p/logger'
|