Skip to content
This repository has been archived by the owner on Jul 21, 2023. It is now read-only.

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

License

Unknown and 2 other licenses found

Licenses found

Unknown
LICENSE
Unknown
LICENSE-APACHE
MIT
LICENSE-MIT
Notifications You must be signed in to change notification settings

libp2p/js-libp2p-websockets

Repository files navigation

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

@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

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')
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

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.