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

Commit 083f462

Browse files
authored
docs: publish api docs (#241)
Update project config to publish api docs
1 parent bd03365 commit 083f462

File tree

3 files changed

+21
-164
lines changed

3 files changed

+21
-164
lines changed

.gitignore

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
node_modules
2-
coverage
3-
.nyc_output
4-
package-lock.json
5-
yarn.lock
6-
docs
2+
build
73
dist
4+
.docs
85
.coverage
6+
node_modules
7+
package-lock.json
8+
yarn.lock

README.md

Lines changed: 13 additions & 157 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,18 @@
11
# @libp2p/mplex <!-- omit in toc -->
22

33
[![libp2p.io](https://img.shields.io/badge/project-libp2p-yellow.svg?style=flat-square)](http://libp2p.io/)
4-
[![IRC](https://img.shields.io/badge/freenode-%23libp2p-yellow.svg?style=flat-square)](http://webchat.freenode.net/?channels=%23libp2p)
54
[![Discuss](https://img.shields.io/discourse/https/discuss.libp2p.io/posts.svg?style=flat-square)](https://discuss.libp2p.io)
65
[![codecov](https://img.shields.io/codecov/c/github/libp2p/js-libp2p-mplex.svg?style=flat-square)](https://codecov.io/gh/libp2p/js-libp2p-mplex)
7-
[![CI](https://img.shields.io/github/workflow/status/libp2p/js-libp2p-interfaces/test%20&%20maybe%20release/master?style=flat-square)](https://github.com/libp2p/js-libp2p-mplex/actions/workflows/js-test-and-release.yml)
6+
[![CI](https://img.shields.io/github/actions/workflow/status/libp2p/js-libp2p-mplex/js-test-and-release.yml?branch=master\&style=flat-square)](https://github.com/libp2p/js-libp2p-mplex/actions/workflows/js-test-and-release.yml?query=branch%3Amaster)
87

98
> JavaScript implementation of <https://github.com/libp2p/mplex>
109
1110
## Table of contents <!-- omit in toc -->
1211

1312
- [Install](#install)
13+
- [Browser `<script>` tag](#browser-script-tag)
1414
- [Usage](#usage)
15-
- [API](#api)
16-
- [`const factory = new Mplex([options])`](#const-factory--new-mplexoptions)
17-
- [`const muxer = factory.createStreamMuxer(components, [options])`](#const-muxer--factorycreatestreammuxercomponents-options)
18-
- [`muxer.onStream`](#muxeronstream)
19-
- [`muxer.onStreamEnd`](#muxeronstreamend)
20-
- [`muxer.streams`](#muxerstreams)
21-
- [`const stream = muxer.newStream([options])`](#const-stream--muxernewstreamoptions)
22-
- [`stream.close()`](#streamclose)
23-
- [`stream.abort([err])`](#streamaborterr)
24-
- [`stream.reset()`](#streamreset)
25-
- [`stream.timeline`](#streamtimeline)
26-
- [`stream.id`](#streamid)
27-
- [Contribute](#contribute)
15+
- [API Docs](#api-docs)
2816
- [License](#license)
2917
- [Contribution](#contribution)
3018

@@ -34,6 +22,14 @@
3422
$ npm i @libp2p/mplex
3523
```
3624

25+
### Browser `<script>` tag
26+
27+
Loading this module through a script tag will make it's exports available as `Libp2pMplex` in the global namespace.
28+
29+
```html
30+
<script src="https://unpkg.com/@libp2p/mplex/dist/index.min.js"></script>
31+
```
32+
3733
[![](https://github.com/libp2p/interface-stream-muxer/raw/master/img/badge.png)](https://github.com/libp2p/interface-stream-muxer)
3834

3935
## Usage
@@ -61,149 +57,9 @@ const stream = muxer.newStream() // Create a new duplex stream to the remote
6157
pipe([1, 2, 3], stream)
6258
```
6359

64-
## API
65-
66-
### `const factory = mplex([options])`
67-
68-
Creates a factory that can be used to create new muxers.
69-
70-
`options` is an optional `Object` that may have the following properties:
71-
72-
- `maxMsgSize` - a number that defines how large mplex data messages can be in bytes, if messages are larger than this they will be sent as multiple messages (default: 1048576 - e.g. 1MB)
73-
- `maxUnprocessedMessageQueueSize` - a number that limits the size of the unprocessed input buffer (default: 4194304 - e.g. 4MB)
74-
- `minSendBytes` - if set, message bytes from the current tick will be batched up to this amount before being yielded by the muxer source, unless the next tick begins in which case all available bytes will be yielded
75-
- `maxInboundStreams` - a number that defines how many incoming streams are allowed per connection (default: 1024)
76-
- `maxOutboundStreams` - a number that defines how many outgoing streams are allowed per connection (default: 1024)
77-
- `maxStreamBufferSize` - a number that defines how large the message buffer is allowed to grow (default: 1024 \* 1024 \* 4 - e.g. 4MB)
78-
- `disconnectThreshold` - if `maxInboundStreams` is reached, close the connection if the remote continues trying to open more than this many streams per second (default: 5)
79-
80-
### `const muxer = factory.createStreamMuxer(components, [options])`
81-
82-
Create a new *duplex* stream that can be piped together with a connection in order to allow multiplexed communications.
83-
84-
e.g.
85-
86-
```js
87-
import { mplex } from '@libp2p/mplex'
88-
import { pipe } from 'it-pipe'
89-
90-
// Create a duplex muxer
91-
const muxer = mplex()
92-
93-
// Use the muxer in a pipeline
94-
pipe(conn, muxer, conn) // conn is duplex connection to another peer
95-
```
96-
97-
`options` is an optional `Object` that may have the following properties:
98-
99-
- `onStream` - A function called when receiving a new stream from the remote. e.g.
100-
```js
101-
// Receive a new stream on the muxed connection
102-
const onStream = stream => {
103-
// Read from this stream and write back to it (echo server)
104-
pipe(
105-
stream,
106-
source => (async function * () {
107-
for await (const data of source) yield data
108-
})(),
109-
stream
110-
)
111-
}
112-
const muxer = mplex({ onStream })
113-
// ...
114-
```
115-
**Note:** The `onStream` function can be passed in place of the `options` object. i.e.
116-
```js
117-
mplex(stream => { /* ... */ })
118-
```
119-
- `onStreamEnd` - A function called when a stream ends
120-
```js
121-
// Receive a notification when a stream ends
122-
const onStreamEnd = stream => {
123-
// Manage any tracking changes, etc
124-
}
125-
const muxer = new Mplex({ onStreamEnd })
126-
// ...
127-
```
128-
- `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.
129-
```js
130-
const controller = new AbortController()
131-
const muxer = mplex({ signal: controller.signal })
132-
133-
pipe(conn, muxer, conn)
134-
135-
controller.abort()
136-
```
137-
- `maxMsgSize` - The maximum size in bytes the data field of multiplexed messages may contain (default 1MB)
138-
139-
### `muxer.onStream`
140-
141-
Use this property as an alternative to passing `onStream` as an option to the `Mplex` constructor.
142-
143-
### `muxer.onStreamEnd`
144-
145-
Use this property as an alternative to passing `onStreamEnd` as an option to the `Mplex` constructor.
146-
147-
### `muxer.streams`
148-
149-
Returns an `Array` of streams that are currently open. Closed streams will not be returned.
150-
151-
### `const stream = muxer.newStream([options])`
152-
153-
Initiate a new stream with the remote. Returns a [duplex stream](https://gist.github.com/alanshaw/591dc7dd54e4f99338a347ef568d6ee9#duplex-it).
154-
155-
e.g.
156-
157-
```js
158-
// Create a new stream on the muxed connection
159-
const stream = muxer.newStream()
160-
161-
// Use this new stream like any other duplex stream:
162-
pipe([1, 2, 3], stream, consume)
163-
```
164-
165-
In addition to `sink` and `source` properties, this stream also has the following API, that will **normally *not* be used by stream consumers**.
166-
167-
#### `stream.close()`
168-
169-
Closes the stream for **reading**. If iterating over the source of this stream in a `for await of` loop, it will return (exit the loop) after any buffered data has been consumed.
170-
171-
This function is called automatically by the muxer when it receives a `CLOSE` message from the remote.
172-
173-
The source will return normally, the sink will continue to consume.
174-
175-
#### `stream.abort([err])`
176-
177-
Closes the stream for **reading** *and* **writing**. This should be called when a *local error* has occurred.
178-
179-
Note, if called without an error any buffered data in the source can still be consumed and the stream will end normally.
180-
181-
This will cause a `RESET` message to be sent to the remote, *unless* the sink has already ended.
182-
183-
The sink will return and the source will throw if an error is passed or return normally if not.
184-
185-
#### `stream.reset()`
186-
187-
Closes the stream *immediately* for **reading** *and* **writing**. This should be called when a *remote error* has occurred.
188-
189-
This function is called automatically by the muxer when it receives a `RESET` message from the remote.
190-
191-
The sink will return and the source will throw.
192-
193-
#### `stream.timeline`
194-
195-
Returns an `object` with `close` and `open` times of the stream.
196-
197-
#### `stream.id`
198-
199-
Returns a `string` with an identifier unique to **this** muxer. Identifiers are not unique across muxers.
200-
201-
## Contribute
202-
203-
The libp2p implementation in JavaScript is a work in progress. As such, there are a few things you can do right now to help out:
60+
## API Docs
20461

205-
- 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.
206-
- **Perform code reviews**. More eyes will help a) speed the project along b) ensure quality and c) reduce possible future bugs.
62+
- <https://libp2p.github.io/js-libp2p-mplex>
20763

20864
## License
20965

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
"types": "./dist/src/index.d.ts",
3030
"files": [
3131
"src",
32-
"dist/src",
32+
"dist",
3333
"!dist/test",
3434
"!**/*.tsbuildinfo"
3535
],
@@ -143,7 +143,8 @@
143143
"test:firefox-webworker": "aegir test -t webworker -- --browser firefox",
144144
"test:node": "aegir test -t node --cov",
145145
"test:electron-main": "aegir test -t electron-main",
146-
"release": "aegir release"
146+
"release": "aegir release",
147+
"docs": "aegir docs"
147148
},
148149
"dependencies": {
149150
"@libp2p/interface-connection": "^3.0.1",

0 commit comments

Comments
 (0)