Skip to content

Commit ef50bc7

Browse files
authored
Update interface definition in readme.md (libp2p#238)
Mplex class is now not exported anymore and so the user is asked to initiate the object using a utility function called "mplex"
1 parent a107785 commit ef50bc7

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

README.md

+8-8
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,10 @@ $ npm i @libp2p/mplex
3939
## Usage
4040

4141
```js
42-
import { Mplex } from '@libp2p/mplex'
42+
import { mplex } from '@libp2p/mplex'
4343
import { pipe } from 'it-pipe'
4444

45-
const factory = new Mplex()
45+
const factory = mplex()
4646

4747
const muxer = factory.createStreamMuxer(components, {
4848
onStream: stream => { // Receive a duplex stream from the remote
@@ -63,7 +63,7 @@ pipe([1, 2, 3], stream)
6363

6464
## API
6565

66-
### `const factory = new Mplex([options])`
66+
### `const factory = mplex([options])`
6767

6868
Creates a factory that can be used to create new muxers.
6969

@@ -84,11 +84,11 @@ Create a new *duplex* stream that can be piped together with a connection in ord
8484
e.g.
8585

8686
```js
87-
import { Mplex } from '@libp2p/mplex'
87+
import { mplex } from '@libp2p/mplex'
8888
import { pipe } from 'it-pipe'
8989

9090
// Create a duplex muxer
91-
const muxer = new Mplex()
91+
const muxer = mplex()
9292

9393
// Use the muxer in a pipeline
9494
pipe(conn, muxer, conn) // conn is duplex connection to another peer
@@ -109,12 +109,12 @@ pipe(conn, muxer, conn) // conn is duplex connection to another peer
109109
stream
110110
)
111111
}
112-
const muxer = new Mplex({ onStream })
112+
const muxer = mplex({ onStream })
113113
// ...
114114
```
115115
**Note:** The `onStream` function can be passed in place of the `options` object. i.e.
116116
```js
117-
new Mplex(stream => { /* ... */ })
117+
mplex(stream => { /* ... */ })
118118
```
119119
- `onStreamEnd` - A function called when a stream ends
120120
```js
@@ -128,7 +128,7 @@ pipe(conn, muxer, conn) // conn is duplex connection to another peer
128128
- `signal` - An [`AbortSignal`](https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal) which can be used to abort the muxer, *including* all of it's multiplexed connections. e.g.
129129
```js
130130
const controller = new AbortController()
131-
const muxer = new Mplex({ signal: controller.signal })
131+
const muxer = mplex({ signal: controller.signal })
132132

133133
pipe(conn, muxer, conn)
134134

0 commit comments

Comments
 (0)