# pull-ws-server

> wrap pull streams around ws server and client

Latest version **1.9.7** (published 2016-12-09) · MIT license · 0 weekly downloads

## Install

```sh
npm install pull-ws-server
pnpm add pull-ws-server
yarn add pull-ws-server
bun add pull-ws-server
```

## 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.9.7 |
| Published | 2016-12-09 |
| First published | 2014-11-21 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 3 |
| Known vulnerabilities | 0 (+1 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 12 |
| Author | Dominic Tarr |
| Maintainers | dominictarr, pfraze |

## Links

- npm: https://www.npmjs.com/package/pull-ws-server
- Repository: https://github.com/ssbc/pull-ws-server
- Issues: https://github.com/ssbc/pull-ws-server/issues
- npm.io page: https://npm.io/package/pull-ws-server

## Dependencies (3)

- [ws](https://npm.io/package/ws.md) ^1.1.0
- [pull-ws](https://npm.io/package/pull-ws.md) ^2.3.0
- [relative-url](https://npm.io/package/relative-url.md) ^1.0.0

## Recent versions

- 1.9.7 (latest) — 2016-12-09
- 1.9.6 — 2016-11-20
- 1.9.5 — 2016-11-19
- 1.9.4 — 2016-11-19
- 1.9.3 — 2016-06-25
- 1.9.2 — 2016-06-01
- 1.9.1 — 2016-06-01
- 1.9.0 — 2016-06-01
- 1.8.0 — 2016-04-25
- 1.7.0 — 2016-03-28
- 1.6.2 — 2016-03-27
- 1.6.1 — 2016-03-27
- 1.6.0 — 2016-03-27
- 1.5.0 — 2016-03-02
- 1.4.0 — 2016-01-07
- … 12 more at https://npm.io/package/pull-ws-server/versions

## README

# pull-ws-server

use [pull-ws](https://github.com/pull-stream/pull-ws) instead.

create pull stream websockets, servers, and clients.

## example

one duplex service you may want to use this with is [muxrpc](https://github.com/dominictarr/muxrpc)

``` js
var ws = require('pull-ws-server')
var pull = require('pull-stream')

ws.createServer(function (stream) {
  //pipe duplex style to your service.
  pull(stream, service.createStream(), stream)
})
.listen(9999)

var stream = ws.connect('ws://localhost:9999')

pull(stream, client.createStream(), stream)
```

if the connection fails, the first read from the stream will be an error,
otherwise, to get a handle of stream end/error pass a callback to connect.

``` js
ws.connect('ws://localhost:9999', function (err, stream) {
  if(err) return handleError(err)
  //stream is now ready
})

```

To run the server over TLS:

```js
var tlsOpts = {
  key: fs.readFileSync('test/fixtures/keys/agent2-key.pem'),
  cert: fs.readFileSync('test/fixtures/keys/agent2-cert.pem')
};
ws.createServer(tlsOpts, function (stream) {
  //pipe duplex style to your service.
  pull(stream, service.createStream(), stream)
})
.listen(9999)
```

To add client-authentication to the server, you can set `verifyClient`.
[Documentation here](https://github.com/websockets/ws/blob/master/doc/ws.md#optionsverifyclient).

```js
function verifyClient (info) {
  return info.secure == true
}
ws.createServer({ verifyClient: verifyClient }, onStream)
```

## use with an http server

if you have an http server that you also need to serve stuff
over, and want to use a single port, use the `server` option.

``` js
var http = require('http')
var server = http.createServer(function(req, res){...}).listen(....)
ws.createServer({server: server}, function (stream) { ... })

```

## License

MIT

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