Skip to content
This repository was archived by the owner on Apr 24, 2023. It is now read-only.

Commit ba9facb

Browse files
authored
chore: update Readme (#148)
1 parent ab4cc82 commit ba9facb

File tree

2 files changed

+32
-30
lines changed

2 files changed

+32
-30
lines changed

README.md

Lines changed: 31 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
[![](https://img.shields.io/travis/libp2p/js-libp2p-webrtc-direct.svg?style=flat-square)](https://travis-ci.com/libp2p/js-libp2p-webrtc-direct)
99
[![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)
1010

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)
1313

1414
> 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.
1515
@@ -23,7 +23,6 @@
2323
- [npm](#npm)
2424
- [Usage](#usage)
2525
- [API](#api)
26-
- [Pull-streams](#pull-streams)
2726

2827

2928
## Install
@@ -44,30 +43,35 @@ const multiaddr = require('multiaddr')
4443
const pipe = require('pull-stream')
4544
const { collect } = require('streaming-iterables')
4645

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
5669
)
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()}`)
6871

69-
// Close connection after reading
70-
await listener.close()
72+
// Close connection after reading
73+
await listener.close()
74+
})()
7175
```
7276

7377
Outputs:
@@ -83,11 +87,11 @@ Note that it may take some time for the connection to be established.
8387

8488
### Transport
8589

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)
8791

8892
### Connection
8993

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)
9195

9296
## Contribute
9397

package.json

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,7 @@
3030
"webrtc",
3131
"dial",
3232
"stream",
33-
"connection",
34-
"woot",
35-
"woot"
33+
"connection"
3634
],
3735
"license": "MIT",
3836
"bugs": {

0 commit comments

Comments
 (0)