# libp2p-websockets

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

Latest version **0.16.2** (published 2021-09-28) · MIT license · 0 weekly downloads

## Install

```sh
npm install libp2p-websockets
pnpm add libp2p-websockets
yarn add libp2p-websockets
bun add libp2p-websockets
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.16.2 |
| Published | 2021-09-28 |
| First published | 2016-02-26 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 12 |
| Unpacked size | 148.5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 91 |
| Maintainers | jacobheun, daviddias, achingbrain, vascosantos |
| Keywords | IPFS |

## Links

- npm: https://www.npmjs.com/package/libp2p-websockets
- Repository: https://github.com/libp2p/js-libp2p-websockets
- Homepage: https://github.com/libp2p/js-libp2p-websockets#readme
- Issues: https://github.com/libp2p/js-libp2p-websockets/issues
- npm.io page: https://npm.io/package/libp2p-websockets

## Dependencies (12)

- [debug](https://npm.io/package/debug.md) ^4.3.1
- [it-ws](https://npm.io/package/it-ws.md) ^4.0.0
- [mafmt](https://npm.io/package/mafmt.md) ^10.0.0
- [p-defer](https://npm.io/package/p-defer.md) ^3.0.0
- [class-is](https://npm.io/package/class-is.md) ^1.1.0
- [err-code](https://npm.io/package/err-code.md) ^3.0.1
- [multiaddr](https://npm.io/package/multiaddr.md) ^10.0.0
- [p-timeout](https://npm.io/package/p-timeout.md) ^4.1.0
- [ipfs-utils](https://npm.io/package/ipfs-utils.md) ^9.0.1
- [libp2p-utils](https://npm.io/package/libp2p-utils.md) ^0.4.0
- [multiaddr-to-uri](https://npm.io/package/multiaddr-to-uri.md) ^8.0.0
- [abortable-iterator](https://npm.io/package/abortable-iterator.md) ^3.0.0

## Recent versions

- 0.16.2 (latest) — 2021-09-28
- 0.15.0 (beta) — 2020-11-24
- 0.16.1 — 2021-07-08
- 0.16.0 — 2021-07-07
- 0.15.9 — 2021-06-11
- 0.15.8 — 2021-06-08
- 0.15.7 — 2021-05-04
- 0.15.6 — 2021-04-18
- 0.15.5 — 2021-04-12
- 0.15.4 — 2021-03-31
- 0.15.3 — 2021-02-22
- 0.15.2 — 2021-02-09
- 0.15.1 — 2021-02-05
- 0.14.0 — 2020-08-11
- 0.13.6 — 2020-03-23
- … 41 more at https://npm.io/package/libp2p-websockets/versions

## README

# js-libp2p-websockets

[![](https://img.shields.io/badge/made%20by-Protocol%20Labs-blue.svg?style=flat-square)](http://ipn.io)
[![](https://img.shields.io/badge/project-libp2p-yellow.svg?style=flat-square)](http://libp2p.io/)
[![](https://img.shields.io/badge/freenode-%23ipfs-blue.svg?style=flat-square)](http://webchat.freenode.net/?channels=%23ipfs)
[![Discourse posts](https://img.shields.io/discourse/https/discuss.libp2p.io/posts.svg)](https://discuss.libp2p.io)
[![Coverage Status](https://coveralls.io/repos/github/libp2p/js-libp2p-websockets/badge.svg?branch=master)](https://coveralls.io/github/libp2p/js-libp2p-websockets?branch=master)
[![Travis CI](https://travis-ci.org/libp2p/js-libp2p-websockets.svg?branch=master)](https://travis-ci.org/libp2p/js-libp2p-websockets)
[![Circle CI](https://circleci.com/gh/libp2p/js-libp2p-websockets.svg?style=svg)](https://circleci.com/gh/libp2p/js-libp2p-websockets)
[![Dependency Status](https://david-dm.org/libp2p/js-libp2p-websockets.svg?style=flat-square)](https://david-dm.org/libp2p/js-libp2p-websockets)
[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square)](https://github.com/feross/standard)
![](https://img.shields.io/badge/Node.js-%3E%3D14.0.0-orange.svg?style=flat-square)

[![](https://raw.githubusercontent.com/libp2p/interface-transport/master/img/badge.png)](https://github.com/libp2p/interface-transport)
[![](https://raw.githubusercontent.com/libp2p/interface-connection/master/img/badge.png)](https://github.com/libp2p/interface-connection)

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

## Lead Maintainer

[Jacob Heun](https://github.com/jacobheun)

## Description

`libp2p-websockets` is the WebSockets implementation compatible with libp2p.

## Usage

## Install

### npm

```sh
> npm i libp2p-websockets
```

### Constructor properties

```js
const WS = require('libp2p-websockets')

const properties = {
  upgrader,
  filter
}

const ws = new WS(properties)
```

| Name | Type | Description | Default |
|------|------|-------------|---------|
| upgrader | [`Upgrader`](https://github.com/libp2p/interface-transport#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](./src/filters.js).

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

```js
const Libp2p = require('libp2p')
const Websockets = require('libp2p-websockets')
const filters = require('libp2p-websockets/src/filters')
const MPLEX = require('libp2p-mplex')
const { NOISE } = require('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](https://github.com/libp2p/js-libp2p/blob/master/doc/CONFIGURATION.md#customizing-transports).

## API

### Transport

[![](https://raw.githubusercontent.com/libp2p/interface-transport/master/img/badge.png)](https://github.com/libp2p/interface-transport)

### Connection

[![](https://raw.githubusercontent.com/libp2p/interface-connection/master/img/badge.png)](https://github.com/libp2p/interface-connection)

---
_Source: https://npm.io/package/libp2p-websockets · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
