8
8
[ ![ ] ( https://img.shields.io/travis/libp2p/js-libp2p-webrtc-direct.svg?style=flat-square )] ( https://travis-ci.com/libp2p/js-libp2p-webrtc-direct )
9
9
[ ![ Dependency Status] ( https://david-dm.org/libp2p/js-libp2p-webrtc-direct.svg?style=flat-square )] ( https://david-dm.org/libp2p/js-libp2p-webrtc-direct ) [ ![ js-standard-style] ( https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square )] ( https://github.com/feross/standard )
10
10
11
- ![ ] ( https://raw.githubusercontent.com/libp2p/interface-connection /master/img/badge.png )
12
- ![ ] ( https://raw.githubusercontent.com/libp2p/interface-transport /master/img/badge.png )
11
+ ![ ] ( https://raw.githubusercontent.com/libp2p/js-libp2p-interfaces /master/packages/libp2p-interfaces/src/connection /img/badge.png )
12
+ ![ ] ( https://raw.githubusercontent.com/libp2p/js-libp2p-interfaces /master/packages/libp2p-interfaces/src/transport /img/badge.png )
13
13
14
14
> A WebRTC transport built for libp2p (not mandatory to use with libp2p) that doesn't require the set up a signalling server. Caveat, you can only establish Browser to Node.js and Node.js to Node.js connections.
15
15
23
23
- [ npm] ( #npm )
24
24
- [ Usage] ( #usage )
25
25
- [ API] ( #api )
26
- - [ Pull-streams] ( #pull-streams )
27
26
28
27
29
28
## Install
@@ -44,30 +43,35 @@ const multiaddr = require('multiaddr')
44
43
const pipe = require (' pull-stream' )
45
44
const { collect } = require (' streaming-iterables' )
46
45
47
- const addr = multiaddr (' /ip4/127.0.0.1/tcp/9090/http/p2p-webrtc-direct' )
48
-
49
- const webRTCDirect = new WebRTCDirect ()
50
-
51
- const listener = webRTCDirect .createListener ((socket ) => {
52
- console .log (' new connection opened' )
53
- pipe (
54
- [' hello' ],
55
- socket
46
+ ;(async () => {
47
+ const addr = new multiaddr.Multiaddr (' /ip4/127.0.0.1/tcp/9090/http/p2p-webrtc-direct' )
48
+ const upgrader = {
49
+ upgradeInbound: async maConn => maConn,
50
+ upgradeOutbound: async maConn => maConn,
51
+ }
52
+ const webRTCDirect = new WebRTCDirect ({upgrader})
53
+
54
+ const listener = webRTCDirect .createListener ((socket ) => {
55
+ console .log (' new connection opened' )
56
+ pipe (
57
+ [' hello' ],
58
+ socket
59
+ )
60
+ })
61
+
62
+ await listener .listen (addr)
63
+ console .log (' listening' )
64
+
65
+ const conn = await webRTCDirect .dial (addr)
66
+ const values = await pipe (
67
+ conn,
68
+ collect
56
69
)
57
- })
58
-
59
- await listener .listen (addr)
60
- console .log (' listening' )
61
-
62
- const conn = await webRTCDirect .dial (addr)
63
- const values = await pipe (
64
- conn,
65
- collect
66
- )
67
- console .log (` Value: ${ values .toString ()} ` )
70
+ console .log (` Value: ${ values .toString ()} ` )
68
71
69
- // Close connection after reading
70
- await listener .close ()
72
+ // Close connection after reading
73
+ await listener .close ()
74
+ })()
71
75
```
72
76
73
77
Outputs:
@@ -83,11 +87,11 @@ Note that it may take some time for the connection to be established.
83
87
84
88
### Transport
85
89
86
- [ ![ ] ( https://raw.githubusercontent.com/libp2p/interface-transport /master/img/badge.png )] ( https://github.com/libp2p/interface- transport )
90
+ [ ![ ] ( https://raw.githubusercontent.com/libp2p/js-libp2p-interfaces /master/packages/libp2p-interfaces/src/transport/ img/badge.png )] ( https://github.com/libp2p/js-libp2p-interfaces/tree/master/packages/libp2p-interfaces/src/ transport )
87
91
88
92
### Connection
89
93
90
- [ ![ ] ( https://raw.githubusercontent.com/libp2p/interface-connection /master/img/badge.png )] ( https://github.com/libp2p/interface- connection )
94
+ [ ![ ] ( https://raw.githubusercontent.com/libp2p/js-libp2p-interfaces /master/packages/libp2p-interfaces/src/connection/ img/badge.png )] ( https://github.com/libp2p/js-libp2p-interfaces/tree/master/packages/libp2p-interfaces/src/ connection )
91
95
92
96
## Contribute
93
97
0 commit comments