Home

Awesome

📁 Archived - this module has been merged into js-libp2p

@libp2p/websockets <!-- omit in toc -->

libp2p.io Discuss codecov CI

JavaScript implementation of the WebSockets module that libp2p uses and that implements the interface-transport spec

Table of contents <!-- omit in toc -->

Install

$ npm i @libp2p/websockets

Browser <script> tag

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>

Usage

> npm i @libp2p/websockets

Constructor properties

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')
NameTypeDescriptionDefault
upgraderUpgraderconnection upgrader object with upgradeOutbound and upgradeInboundREQUIRED
filter(multiaddrs: Array<Multiaddr>) => Array<Multiaddr>override transport addresses filterBrowser: 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:

Libp2p Usage Example

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.

API

Transport

Connection

API Docs

License

Licensed under either of

Contribution

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.