# rpep-websockets

> Websocket transport for rpep.js

Latest version **1.1.4** (published 2022-12-15) · 0 weekly downloads

## Install

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

## Health

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

Positive: no vulnerabilities.

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

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.1.4 |
| Published | 2022-12-15 |
| First published | 2017-11-27 |
| Weekly downloads | 0 |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 1.7 MB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Maintainers | fresheneesz |
| Keywords | rpc, event, protocol, communication, messaging, zeromq, zmq, 0mq, socket, stream, BSON, serialization, encode, decode |

## Links

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

## Dependencies (1)

- [websocket](https://npm.io/package/websocket.md) *

## Alternatives

- [@opentelemetry/exporter-zipkin](https://npm.io/package/@opentelemetry/exporter-zipkin.md) — 14.8M weekly downloads
- [pusher-js](https://npm.io/package/pusher-js.md) — 2.0M weekly downloads
- [browserify](https://npm.io/package/browserify.md) — 1.7M weekly downloads
- [sqs-consumer](https://npm.io/package/sqs-consumer.md) — 1.7M weekly downloads
- [@sanity/eventsource](https://npm.io/package/@sanity/eventsource.md) — 930.8K weekly downloads

## Recent versions

- 1.1.4 (latest) — 2022-12-15
- 1.1.3 — 2022-12-14
- 1.1.1 — 2020-06-17
- 1.1.0 — 2020-06-15
- 1.0.0 — 2017-11-27

## README

`rpep-websockets`
=====

This is a [Websocket](https://tools.ietf.org/html/rfc6455) transport for [rpep.js](https://github.com/Tixit/rpep.js) using [theturtle32/WebSocket-Node](https://github.com/theturtle32/WebSocket-Node). RPEP is a simple, light-weight protocol for request-response and stream-event style communication between peers.

Install
=======

```
yarn install rpep-websockets
```

Usage
=====

Accessing rpep websockets:
```javascript
// node.js
var rpepWebsockets = require('rpep-websockets')

// node.js style for the browser (eg webpack)
var rpepWebsockets = require('rpep-websockets/ws.browser')

// amd
require.config({paths: {rpepWebsockets: '../dist/rpep-websockets.umd.js'}})
require(['rpepWebsockets'], function(rpepWebsockets) { /* your code */ })

// global variable
<script src="rpep-websockets.umd.js"></script>
rpepWebsockets; // rpep-websockets.umd.js can define rpepWebsockets globally if you really
             //   want to shun module-based design
```

API:

* **`var transport = rpepWebsockets()`** - Creates a new instance of the transport (to be passed into `rpep`'s constructor).
  
* **`transport.connect(host, port, [connectionOptions,] rpepOptions)`** - Connects to a websocket host. These arguments will be passed through to this method from a call to `rpep.connect`.
  * `connectionOptions` for node.js - These are [theturtle32/WebSocket-Node WebSocketClient](https://github.com/theturtle32/WebSocket-Node/blob/master/docs/WebSocketClient.md) options. Important ones being:
    * `protocol` - (Default: 'ws') Either 'wss' or 'ws'
    * `wsProtocols` - A string or array of strings representing the websocket-protocols to request.
    * `origin`
    * `headers`
    * `requestOptions`
  * `connectionOptions` for the browser:
    * `binaryType` - The [binaryType property](https://developer.mozilla.org/en-US/docs/Web/API/WebSocket/binaryType) of a websocket connection. Defaults to "arraybuffer", which is what the `theturtle32/WebSocket-Node` library used for node.js requires.
    * `protocol` - (Default: 'ws') Either 'wss' or 'ws'.
  * `rpepOptions` are pass through arguments that don't affect the operation of this transport.

* **`transport.listen(port, [listenerOptions,] rpepOptions, requestHandler)`** - Listens for websocket connections. These arguments will be passed through to this method from a call to `rpep.listen`. This method only exists for the node.js version. You can't listen for websocket connections from a browser.
  * `port` - Optional if `listenerOptions.httpServer` is passed.
  * `listenerOptions`- These are [theturtle32/WebSocket-Node WebSocketServer](https://github.com/theturtle32/WebSocket-Node/blob/master/docs/WebSocketServer.md) options. Important ones being:
    * `secure` - (Default:`false`) If `true` and `transportOptions.httpServer` is undefined, will create an https server. If `transportOptions.httpServer` is defined, this is ignored.
    * `secureOptions` - The options to pass into `https.createServer` if `secure` is true.
    * `httpServer` - If this is defined, uses this server instead of creating a new one. The passed `port` won't be used. If no http/https server is passed, one will be created internally (http or https is determined by arguments passed to `listen`). For the browser, there are no transportOptions so none need be passed.
    * `httpHandler(request, response)` - If this is defined, it is a callback that's called when a normal http/https request comes through.
  * `rpepOptions` are pass through arguments that don't affect the operation of this transport.

How to Test
===========

* Test for node: `node test/test.node`
* Test for browsers: `node test/testServer`

License
=======
Released under the MIT license: http://opensource.org/licenses/MIT

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