🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
DemoInstallSign in
Socket

@libp2p/websockets

Package Overview
Dependencies
Maintainers
6
Versions
738
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@libp2p/websockets

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

3.0.4
Source
npm
Version published
Weekly downloads
18K
8.52%
Maintainers
6
Weekly downloads
 
Created
Source

@libp2p/websockets

libp2p.io IRC 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

Description

libp2p-websockets is the WebSockets implementation compatible with libp2p.

Usage

> npm i @libp2p/websockets

Constructor properties

import { WebSockets } from '@libp2p/websockets'

const properties = {
  upgrader,
  filter
}

const ws = new WebSockets(properties)
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:

  • 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 Libp2p 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({
  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.

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.

Keywords

IPFS

FAQs

Package last updated on 21 Sep 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts