Skip to content

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

License

Notifications You must be signed in to change notification settings

robertkiel/js-libp2p-websockets

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

js-libp2p-websockets

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 pull = require('pull-stream')

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

const ws = new WS()

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

listener.listen(mh, () => {
  console.log('listening')

  pull(
    ws.dial(mh),
    pull.collect((err, values) => {
      if (!err) {
        console.log(`Value: ${values.toString()}`)
      } else {
        console.log(`Error: ${err}`)
      }

      // Close connection after reading
      listener.close()
    }),
  )
})

API

Transport

Connection

About

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

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • JavaScript 99.1%
  • Groovy 0.9%