JSPM

@libp2p/websockets

5.0.1
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 23406
  • Score
    100M100P100Q149910F
  • License Apache-2.0 OR MIT

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

Package Exports

  • @libp2p/websockets
  • @libp2p/websockets/filters

Readme

@libp2p/websockets

libp2p.io Discuss codecov CI

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

Table of contents

Install

$ npm i @libp2p/websockets

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')
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 or wss.
  • filters.dnsWss
    • Returns all DNS based addresses with wss.
  • filters.dnsWsOrWss
    • Returns all DNS based addresses, both with ws or wss.

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

License

Licensed under either of

Contribute

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.