@libp2p/webrtc 0.0.0
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/LICENSE +4 -0
- package/README.md +210 -0
- package/dist/index.min.js +54 -0
- package/dist/index.min.js.map +7 -0
- package/dist/proto_ts/message.d.ts +56 -0
- package/dist/proto_ts/message.d.ts.map +1 -0
- package/dist/proto_ts/message.js +86 -0
- package/dist/proto_ts/message.js.map +1 -0
- package/dist/src/error.d.ts +54 -0
- package/dist/src/error.d.ts.map +1 -0
- package/dist/src/error.js +105 -0
- package/dist/src/error.js.map +1 -0
- package/dist/src/index.d.ts +4 -0
- package/dist/src/index.d.ts.map +1 -0
- package/dist/src/index.js +6 -0
- package/dist/src/index.js.map +1 -0
- package/dist/src/maconn.d.ts +43 -0
- package/dist/src/maconn.d.ts.map +1 -0
- package/dist/src/maconn.js +29 -0
- package/dist/src/maconn.js.map +1 -0
- package/dist/src/muxer.d.ts +55 -0
- package/dist/src/muxer.d.ts.map +1 -0
- package/dist/src/muxer.js +92 -0
- package/dist/src/muxer.js.map +1 -0
- package/dist/src/options.d.ts +6 -0
- package/dist/src/options.d.ts.map +1 -0
- package/dist/src/options.js +2 -0
- package/dist/src/options.js.map +1 -0
- package/dist/src/sdp.d.ts +33 -0
- package/dist/src/sdp.d.ts.map +1 -0
- package/dist/src/sdp.js +118 -0
- package/dist/src/sdp.js.map +1 -0
- package/dist/src/stream.d.ts +141 -0
- package/dist/src/stream.d.ts.map +1 -0
- package/dist/src/stream.js +290 -0
- package/dist/src/stream.js.map +1 -0
- package/dist/src/transport.d.ts +60 -0
- package/dist/src/transport.d.ts.map +1 -0
- package/dist/src/transport.js +193 -0
- package/dist/src/transport.js.map +1 -0
- package/dist/src/util.d.ts +5 -0
- package/dist/src/util.d.ts.map +1 -0
- package/dist/src/util.js +5 -0
- package/dist/src/util.js.map +1 -0
- package/dist/stats.json +1 -0
- package/package.json +170 -0
- package/proto_ts/message.ts +105 -0
- package/src/error.ts +123 -0
- package/src/index.ts +6 -0
- package/src/maconn.ts +67 -0
- package/src/message.proto +22 -0
- package/src/muxer.ts +120 -0
- package/src/options.ts +4 -0
- package/src/sdp.ts +136 -0
- package/src/stream.ts +422 -0
- package/src/transport.ts +243 -0
- package/src/util.ts +5 -0
package/LICENSE
ADDED
package/README.md
ADDED
|
@@ -0,0 +1,210 @@
|
|
|
1
|
+
# js-libp2p-webrtc <!-- omit in toc -->
|
|
2
|
+
|
|
3
|
+
[](http://libp2p.io/)
|
|
4
|
+
[](https://discuss.libp2p.io)
|
|
5
|
+
[](https://codecov.io/gh/libp2p/js-libp2p-webrtc)
|
|
6
|
+
[](https://github.com/libp2p/js-libp2p-webrtc/actions/workflows/js-test-and-release.yml)
|
|
7
|
+
|
|
8
|
+
> A libp2p transport using WebRTC connections
|
|
9
|
+
|
|
10
|
+
## Table of contents <!-- omit in toc -->
|
|
11
|
+
|
|
12
|
+
- [Install](#install)
|
|
13
|
+
- [Browser `<script>` tag](#browser-script-tag)
|
|
14
|
+
- [Usage](#usage)
|
|
15
|
+
- [Examples](#examples)
|
|
16
|
+
- [Interfaces](#interfaces)
|
|
17
|
+
- [Transport](#transport)
|
|
18
|
+
- [Connection](#connection)
|
|
19
|
+
- [Contribute](#contribute)
|
|
20
|
+
- [Build](#build)
|
|
21
|
+
- [Protocol Buffers](#protocol-buffers)
|
|
22
|
+
- [Test](#test)
|
|
23
|
+
- [Lint](#lint)
|
|
24
|
+
- [Clean](#clean)
|
|
25
|
+
- [Check Dependencies](#check-dependencies)
|
|
26
|
+
- [Build a Release](#build-a-release)
|
|
27
|
+
- [License](#license)
|
|
28
|
+
- [Contribute](#contribute-1)
|
|
29
|
+
|
|
30
|
+
## Install
|
|
31
|
+
|
|
32
|
+
```console
|
|
33
|
+
$ npm i js-libp2p-webrtc
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
### Browser `<script>` tag
|
|
37
|
+
|
|
38
|
+
Loading this module through a script tag will make it's exports available as `JsLibp2pWebrtc` in the global namespace.
|
|
39
|
+
|
|
40
|
+
```html
|
|
41
|
+
<script src="https://unpkg.com/js-libp2p-webrtc/dist/index.min.js"></script>
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
## Usage
|
|
45
|
+
|
|
46
|
+
```js
|
|
47
|
+
import { createLibp2p } from 'libp2p'
|
|
48
|
+
import { Noise } from '@chainsafe/libp2p-noise'
|
|
49
|
+
import { multiaddr } from '@multiformats/multiaddr'
|
|
50
|
+
import first from "it-first";
|
|
51
|
+
import { pipe } from "it-pipe";
|
|
52
|
+
import { fromString, toString } from "uint8arrays";
|
|
53
|
+
import { webRTC } from 'js-libp2p-webrtc'
|
|
54
|
+
|
|
55
|
+
const node = await createLibp2p({
|
|
56
|
+
transports: [webRTC()],
|
|
57
|
+
connectionEncryption: [() => new Noise()],
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
await node.start()
|
|
61
|
+
|
|
62
|
+
const ma = multiaddr('/ip4/0.0.0.0/udp/56093/webrtc/certhash/uEiByaEfNSLBexWBNFZy_QB1vAKEj7JAXDizRs4_SnTflsQ')
|
|
63
|
+
const stream = await node.dialProtocol(ma, ['/my-protocol/1.0.0'])
|
|
64
|
+
const message = `Hello js-libp2p-webrtc\n`
|
|
65
|
+
const response = await pipe([fromString(message)], stream, async (source) => await first(source))
|
|
66
|
+
const responseDecoded = toString(response.slice(0, response.length))
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
## Examples
|
|
70
|
+
|
|
71
|
+
Examples can be found in the [examples folder](examples/README.md).
|
|
72
|
+
|
|
73
|
+
## Interfaces
|
|
74
|
+
|
|
75
|
+
### Transport
|
|
76
|
+
|
|
77
|
+

|
|
78
|
+
|
|
79
|
+
Browsers can only `dial`, so `listen` is not supported.
|
|
80
|
+
|
|
81
|
+
```js
|
|
82
|
+
interface Transport {
|
|
83
|
+
[Symbol.toStringTag]: string
|
|
84
|
+
[symbol]: true
|
|
85
|
+
dial: (ma: Multiaddr, options: DialOptions) => Promise<Connection>
|
|
86
|
+
createListener: (options: CreateListenerOptions) => Listener
|
|
87
|
+
filter: MultiaddrFilter
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
class WebRTCTransport implements Transport {
|
|
91
|
+
|
|
92
|
+
async dial (ma: Multiaddr, options: WebRTCDialOptions): Promise<Connection> {
|
|
93
|
+
const rawConn = await this._connect(ma, options)
|
|
94
|
+
log(`dialing address - ${ma.toString()}`)
|
|
95
|
+
return rawConn
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
createListener (options: CreateListenerOptions): Listener {
|
|
99
|
+
throw unimplemented('WebRTCTransport.createListener')
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
### Connection
|
|
105
|
+
|
|
106
|
+

|
|
107
|
+
|
|
108
|
+
```js
|
|
109
|
+
interface MultiaddrConnection extends Duplex<Uint8Array> {
|
|
110
|
+
close: (err?: Error) => Promise<void>
|
|
111
|
+
remoteAddr: Multiaddr
|
|
112
|
+
timeline: MultiaddrConnectionTimeline
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
class WebRTCMultiaddrConnection implements MultiaddrConnection { }
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
## Contribute
|
|
119
|
+
|
|
120
|
+
Contributions are welcome! The libp2p implementation in JavaScript is a work in progress. As such, there's a few things you can do right now to help out:
|
|
121
|
+
|
|
122
|
+
- [Check out the existing issues](//github.com/little-bear-labs/js-libp2p-webrtc/issues).
|
|
123
|
+
- **Perform code reviews**.
|
|
124
|
+
- **Add tests**. There can never be enough tests.
|
|
125
|
+
- Go through the modules and **check out existing issues**. This is especially useful for modules in active development. Some knowledge of IPFS/libp2p may be required, as well as the infrastructure behind it - for instance, you may need to read up on p2p and more complex operations like muxing to be able to help technically.
|
|
126
|
+
|
|
127
|
+
Please be aware that all interactions related to libp2p are subject to the IPFS [Code of Conduct](https://github.com/ipfs/community/blob/master/code-of-conduct.md).
|
|
128
|
+
|
|
129
|
+
Small note: If editing the README, please conform to the [standard-readme](https://github.com/RichardLitt/standard-readme) specification.
|
|
130
|
+
|
|
131
|
+
This module leans heavily on (Aegir)\[<https://github.com/ipfs/aegir>] for most of the `package.json` scripts.
|
|
132
|
+
|
|
133
|
+
### Build
|
|
134
|
+
|
|
135
|
+
The build script is a wrapper to `aegir build`. To build this package:
|
|
136
|
+
|
|
137
|
+
```shell
|
|
138
|
+
npm run build
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
The build will be located in the `/dist` folder.
|
|
142
|
+
|
|
143
|
+
### Protocol Buffers
|
|
144
|
+
|
|
145
|
+
There is also `npm run generate:proto` script that uses protoc to populate the generated code directory `proto_ts` based on `*.proto` files in src. Don't forget to run this step before `build` any time you make a change to any of the `*.proto` files.
|
|
146
|
+
|
|
147
|
+
### Test
|
|
148
|
+
|
|
149
|
+
To run all tests:
|
|
150
|
+
|
|
151
|
+
```shell
|
|
152
|
+
npm test
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
To run tests for Chome only:
|
|
156
|
+
|
|
157
|
+
```shell
|
|
158
|
+
npm run test:chrome
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
To run tests for Firefox only:
|
|
162
|
+
|
|
163
|
+
```shell
|
|
164
|
+
npm run test:firefox
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
### Lint
|
|
168
|
+
|
|
169
|
+
Aegir is also used to lint the code, which follows the [Standard](https://github.com/standard/standard) JS linter.
|
|
170
|
+
The VS Code plugin for this standard is located at <https://marketplace.visualstudio.com/items?itemName=standard.vscode-standard>.
|
|
171
|
+
To lint this repo:
|
|
172
|
+
|
|
173
|
+
```shell
|
|
174
|
+
npm run lint
|
|
175
|
+
```
|
|
176
|
+
|
|
177
|
+
You can also auto-fix when applicable:
|
|
178
|
+
|
|
179
|
+
```shell
|
|
180
|
+
npm run lint:fix
|
|
181
|
+
```
|
|
182
|
+
|
|
183
|
+
### Clean
|
|
184
|
+
|
|
185
|
+
```shell
|
|
186
|
+
npm run clean
|
|
187
|
+
```
|
|
188
|
+
|
|
189
|
+
### Check Dependencies
|
|
190
|
+
|
|
191
|
+
```shell
|
|
192
|
+
npm run deps-check
|
|
193
|
+
```
|
|
194
|
+
|
|
195
|
+
### Build a Release
|
|
196
|
+
|
|
197
|
+
```shell
|
|
198
|
+
npm run release
|
|
199
|
+
```
|
|
200
|
+
|
|
201
|
+
## License
|
|
202
|
+
|
|
203
|
+
Licensed under either of
|
|
204
|
+
|
|
205
|
+
- Apache 2.0, ([LICENSE-APACHE](LICENSE-APACHE) / <http://www.apache.org/licenses/LICENSE-2.0>)
|
|
206
|
+
- MIT ([LICENSE-MIT](LICENSE-MIT) / <http://opensource.org/licenses/MIT>)
|
|
207
|
+
|
|
208
|
+
## Contribute
|
|
209
|
+
|
|
210
|
+
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.
|