Package Exports
- libp2p-websockets
- libp2p-websockets/src/filters
- libp2p-websockets/src/listener.browser.js
- libp2p-websockets/src/listener.js
- libp2p-websockets/src/socket-to-conn
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (libp2p-websockets) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
js-libp2p-websockets
JavaScript implementation of the WebSockets module that libp2p uses and that implements the interface-transport interface
Lead Maintainer
Description
libp2p-websockets
is the WebSockets implementation compatible with libp2p.
Usage
Install
npm
> npm i libp2p-websockets
Constructor properties
const WS = require('libp2p-websockets')
const properties = {
upgrader,
filter
}
const ws = new WS(properties)
Name | Type | Description | Default |
---|---|---|---|
upgrader | Upgrader |
connection upgrader object with upgradeOutbound and upgradeInbound |
REQUIRED |
filter | (multiaddrs: Array<Multiaddr>) => Array<Multiaddr> |
override transport addresses filter | Browser: DNS+WSS multiaddrs / Node.js: DNS+{WS, WSS} multiaddrs |
You can create your own address filters for this transports, or rely in the filters provided.
The available filters are:
filters.all
- Returns all TCP and DNS based addresses, both with
ws
orwss
.
- Returns all TCP and DNS based addresses, both with
filters.dnsWss
- Returns all DNS based addresses with
wss
.
- Returns all DNS based addresses with
filters.dnsWsOrWss
- Returns all DNS based addresses, both with
ws
orwss
.
- Returns all DNS based addresses, both with
Libp2p Usage Example
const Libp2p = require('libp2p')
const Websockets = require('libp2p-websockets')
const filters = require('libp2p-websockets/src/filters')
const MPLEX = require('libp2p-mplex')
const { NOISE } = require('libp2p-noise')
const transportKey = Websockets.prototype[Symbol.toStringTag]
const node = await Libp2p.create({
modules: {
transport: [Websockets],
streamMuxer: [MPLEX],
connEncryption: [NOISE]
},
config: {
transport: {
[transportKey]: { // Transport properties -- Libp2p upgrader is automatically added
filter: filters.dnsWsOrWss
}
}
}
})
For more information see libp2p/js-libp2p/doc/CONFIGURATION.md#customizing-transports.