📁 Archived - this module has been merged into js-libp2p
JavaScript implementation of the WebSockets module that libp2p uses and that implements the interface-transport spec
$ npm i @libp2p/websockets
Loading this module through a script tag will make it's exports available as Libp2pWebsockets
in the global namespace.
<script src="https://unpkg.com/@libp2p/websockets/dist/index.min.js"></script>
> npm i @libp2p/websockets
import { createLibp2pNode } from 'libp2p'
import { webSockets } from '@libp2p/webrtc-direct'
const node = await createLibp2p({
transports: [
webSockets()
]
//... other config
})
await node.start()
await node.dial('/ip4/127.0.0.1/tcp/9090/ws')
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
import { createLibp2pNode } from 'libp2p'
import { websockets } from '@libp2p/websockets'
import filters from '@libp2p/websockets/filters'
import { mplex } from '@libp2p/mplex'
import { noise } from '@libp2p/noise'
const transportKey = Websockets.prototype[Symbol.toStringTag]
const node = await Libp2p.create({
transport: [
websockets({
// connect to all sockets, even insecure ones
filters: filters.all
})
],
streamMuxers: [
mplex()
],
connectionEncryption: [
noise()
]
})
For more information see libp2p/js-libp2p/doc/CONFIGURATION.md#customizing-transports.
Licensed under either of
- Apache 2.0, (LICENSE-APACHE / http://www.apache.org/licenses/LICENSE-2.0)
- MIT (LICENSE-MIT / http://opensource.org/licenses/MIT)
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.