# jschan-ws

> WebSocket transport for jschan

Latest version **0.0.2** (published 2015-08-06) · MIT license · 0 weekly downloads

## Install

```sh
npm install jschan-ws
pnpm add jschan-ws
yarn add jschan-ws
bun add jschan-ws
```

## 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.0.2 |
| Published | 2015-08-06 |
| First published | 2015-08-06 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Node | v0.10.x |
| Dependencies | 4 |
| Known vulnerabilities | 0 (+2 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 2 |
| Maintainers | adrianrossouw |
| Keywords | docker, libchan, streams, stream, channel, channels |

## Links

- npm: https://www.npmjs.com/package/jschan-ws
- Repository: https://github.com/GraftJS/jschan-ws
- Homepage: https://github.com/GraftJS/jschan-ws#readme
- Issues: https://github.com/GraftJS/jschan-ws/issues
- npm.io page: https://npm.io/package/jschan-ws

## Dependencies (4)

- [ws](https://npm.io/package/ws.md) ^0.4.32
- [jschan](https://npm.io/package/jschan.md) ^0.3.0
- [inherits](https://npm.io/package/inherits.md) ^2.0.1
- [websocket-stream](https://npm.io/package/websocket-stream.md) ^1.1.0

## Alternatives

- [byte-size](https://npm.io/package/byte-size.md) — 2.1M weekly downloads
- [speed-limiter](https://npm.io/package/speed-limiter.md) — 16.0K weekly downloads
- [@powersync/node](https://npm.io/package/@powersync/node.md) — 10.9K weekly downloads
- [@ledgerhq/coin-cardano](https://npm.io/package/@ledgerhq/coin-cardano.md) — 1.0K weekly downloads
- [@jayesol/jayeson.lib.streamfinder](https://npm.io/package/@jayesol/jayeson.lib.streamfinder.md) — 1.0K weekly downloads

## Recent versions

- 0.0.2 (latest) — 2015-08-06

## README

# jschan websocket transport &nbsp;&nbsp;[![Build Status](https://travis-ci.org/GraftJS/jschan.png)](https://travis-ci.org/GraftJS/jschan)

__jschan__ is a JavaScript port of [libchan](https://github.com/docker/libchan) based around node streams

[Find out more about jschan](https://github.com/GraftJS/jschan)

## Install

```bash
npm install jschan-ws --save
```
-------------------------------------------------------
<a name="websocketClientSession"></a>
### ws.clientSession(url)

Creates a new websocket session. The url can be in the form
'ws://localhost' or passes as an object.
It is based on [`streamSession`](#streamSession).

_`ws.clientSession` is not compatible with libchan._

This method can also work in the browser thanks to
[Browserify](http://npm.im/browserify).

Example:

```js
var websocket = require('jschan-ws');
var session = websocket.clientSession('ws://localhost:3000');
var chan    = session.WriteChannel();
var ret     = chan.ReadChannel();

ret.on('data', function(res) {
  console.log(res);
  session.close();
});

chan.end({
  hello:'world',
  returnChannel: ret
});
```

-------------------------------------------------------
<a name="websocketServer"></a>
### websocket.server(options)

Creates a new websocketServer, or attach the websocket handler to the
passed-through `httpServer` object.
It is based on [`streamSession`](#streamSession).

_`websocket.server` is not compatible with libchan._

If a new http server is created, remeber to call listen, like so:

```js

'use strict';

var websocket = require('jschan-ws');
var server = websocket.server();

function handleMsg(msg) {
  var stream = msg.returnChannel;
  delete msg.returnChannel;
  stream.end(msg);
}

function handleChannel(chan) {
  chan.on('data', handleMsg);
}

function handleSession(session) {
  session.on('channel', handleChannel);
}

server.on('session', handleSession);

server.listen(3000);
```

## About LibChan

It's most unique characteristic is that it replicates the semantics of go channels across network connections, while allowing for nested channels to be transferred in messages. This would let you to do things like attach a reference to a remote file on an HTTP response, that could be opened on the client side for reading or writing.

The protocol uses SPDY as it's default transport with MSGPACK as it's default serialization format. Both are able to be switched out, with http1+websockets and protobuf fallbacks planned.
SPDY is encrypted over TLS by default.

While the RequestResponse pattern is the primary focus, Asynchronous Message Passing is still possible, due to the low level nature of the protocol.

![Graft](https://rawgit.com/GraftJS/graft.io/master/static/images/graft_logo.svg)

The Graft project is formed to explore the possibilities of a web where servers and clients are able to communicate freely through a microservices architecture.

> "instead of pretending everything is a local function even over the network (which turned out to be a bad idea), what if we did it the other way around? Pretend your components are communicating over a network even when they aren't."
> [Solomon Hykes](http://github.com/shykes) (of Docker fame) on LibChan - [[link]](https://news.ycombinator.com/item?id=7874317)

[Find out more about Graft](https://github.com/GraftJS/graft)

## Contributors

* [Adrian Rossouw](http://github.com/Vertice)
* [Peter Elger](https://github.com/pelger)
* [Matteo Collina](https://github.com/mcollina)

## License

MIT

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