JSPM

  • Created
  • Published
  • Downloads 19691
  • Score
    100M100P100Q133876F
  • License MIT

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

Package Exports

  • libp2p-websockets
  • libp2p-websockets/src/listener.browser.js

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (libp2p-websockets) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

js-libp2p-websockets

Discourse posts Coverage Status Travis CI Circle CI Dependency Status js-standard-style

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

Lead Maintainer

Jacob Heun

Description

libp2p-websockets is the WebSockets implementation compatible with libp2p.

Usage

Install

npm

> npm i libp2p-websockets

Example

const WS = require('libp2p-websockets')
const multiaddr = require('multiaddr')
const pipe = require('it-pipe')
const { collect } = require('streaming-iterables')

const addr = multiaddr('/ip4/0.0.0.0/tcp/9090/ws')

const ws = new WS({ upgrader })

const listener = ws.createListener((socket) => {
  console.log('new connection opened')
  pipe(
    ['hello'],
    socket
  )
})

await listener.listen(addr)
console.log('listening')

const socket = await ws.dial(addr)
const values = await pipe(
  socket,
  collect
)
console.log(`Value: ${values.toString()}`)

// Close connection after reading
await listener.close()

API

Transport

Connection