@libp2p/webrtc 4.0.19 → 4.0.20-f71bc49bd

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 CHANGED
@@ -1,3 +1,5 @@
1
+ # @libp2p/webrtc
2
+
1
3
  [![libp2p.io](https://img.shields.io/badge/project-libp2p-yellow.svg?style=flat-square)](http://libp2p.io/)
2
4
  [![Discuss](https://img.shields.io/discourse/https/discuss.libp2p.io/posts.svg?style=flat-square)](https://discuss.libp2p.io)
3
5
  [![codecov](https://img.shields.io/codecov/c/github/libp2p/js-libp2p.svg?style=flat-square)](https://codecov.io/gh/libp2p/js-libp2p)
@@ -7,11 +9,26 @@
7
9
 
8
10
  # About
9
11
 
12
+ <!--
13
+
14
+ !IMPORTANT!
15
+
16
+ Everything in this README between "# About" and "# Install" is automatically
17
+ generated and will be overwritten the next time the doc generator is run.
18
+
19
+ To make changes to this section, please update the @packageDocumentation section
20
+ of src/index.js or src/index.ts
21
+
22
+ To experiment with formatting, please run "npm run docs" from the root of this
23
+ repo and examine the changes made.
24
+
25
+ -->
26
+
10
27
  A [libp2p transport](https://docs.libp2p.io/concepts/transports/overview/) based on [WebRTC datachannels](https://webrtc.org/).
11
28
 
12
29
  ## Example
13
30
 
14
- ```js
31
+ ```TypeScript
15
32
  import { createLibp2p } from 'libp2p'
16
33
  import { noise } from '@chainsafe/libp2p-noise'
17
34
  import { multiaddr } from '@multiformats/multiaddr'
@@ -21,17 +38,30 @@ import { fromString, toString } from 'uint8arrays'
21
38
  import { webRTC } from '@libp2p/webrtc'
22
39
 
23
40
  const node = await createLibp2p({
24
- transports: [webRTC()],
25
- connectionEncryption: [noise()],
41
+ transports: [
42
+ webRTC()
43
+ ],
44
+ connectionEncryption: [
45
+ noise()
46
+ ]
26
47
  })
27
48
 
28
49
  await node.start()
29
50
 
30
- const ma = multiaddr('/ip4/0.0.0.0/udp/56093/webrtc/certhash/uEiByaEfNSLBexWBNFZy_QB1vAKEj7JAXDizRs4_SnTflsQ')
31
- const stream = await node.dialProtocol(ma, ['/my-protocol/1.0.0'])
32
- const message = `Hello js-libp2p-webrtc\n`
33
- const response = await pipe([fromString(message)], stream, async (source) => await first(source))
34
- const responseDecoded = toString(response.slice(0, response.length))
51
+ const ma = multiaddr('/ip4/0.0.0.0/udp/56093/webrtc/certhash/uEiByaEfNSLBexWBNFZy_QB1vAKEj7JAXDizRs4_SnTflsQ')
52
+ const stream = await node.dialProtocol(ma, '/my-protocol/1.0.0', {
53
+ signal: AbortSignal.timeout(10_000)
54
+ })
55
+
56
+ await pipe(
57
+ [fromString(`Hello js-libp2p-webrtc\n`)],
58
+ stream,
59
+ async function (source) {
60
+ for await (const buf of source) {
61
+ console.info(toString(buf.subarray()))
62
+ }
63
+ }
64
+ )
35
65
  ```
36
66
 
37
67
  # Install