# @viae/pb

Latest version **2.0.3** (published 2024-07-08) · MIT license · 0 weekly downloads

> **Deprecated.** This package is deprecated.

## Install

```sh
npm install @viae/pb
pnpm add @viae/pb
yarn add @viae/pb
bun add @viae/pb
```

## Health

**Score 10/100 (F)** — status: deprecated.

Negative: deprecated.

## Facts

| | |
|---|---|
| Version | 2.0.3 |
| Published | 2024-07-08 |
| First published | 2019-05-01 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 3.5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 5 |
| Author | Meirion Hughes |
| Maintainers | meirionhughes |

## Links

- npm: https://www.npmjs.com/package/@viae/pb
- Repository: https://github.com/viae-io/viae
- Homepage: https://github.com/viae-io/viae#readme
- Issues: https://github.com/viae-io/viae/issues
- npm.io page: https://npm.io/package/@viae/pb

## Recent versions

- 2.0.3 (latest) — 2024-07-08
- 2.0.0-beta.1 (beta) — 2024-07-03
- 1.3.0 — 2019-10-04
- 1.2.0 — 2019-10-01
- 1.1.0 — 2019-09-26
- 1.0.0 — 2019-09-25
- 1.0.0-rc.10 — 2019-09-09
- 1.0.0-rc.9 — 2019-09-06
- 1.0.0-rc.8 — 2019-08-09
- 1.0.0-rc.4 — 2019-06-05
- 1.0.0-rc.3 — 2019-05-10
- 1.0.0-rc.2 — 2019-05-10
- 1.0.0-rc.1 — 2019-05-01

## README

# Viae

A bi-directional communication framework. 

![logopng](https://user-images.githubusercontent.com/3584509/31079620-2603bc88-a77e-11e7-92c8-7ac73c165b0b.png)

[![NPM version][npm-image]][npm-url]
[![NPM downloads][npm-downloads]][npm-url]
[![Travis Status][travis-image]][travis-url]
[![codecov](https://codecov.io/gh/MeirionHughes/viae/branch/master/graph/badge.svg)](https://codecov.io/gh/MeirionHughes/viae)
[![Stability][stability-image]][stability-url]


The goal in developing viae was to allow making asynchronous req/res on a single websocket connection and to allow sending objects containing `TypedArrayView` instances. It evolved to facilitate sending and receiving nested streams. Its opinionated as to the default encoder (msgpack) but json and cbor can be used too. 

## Basic Usage

A server is created by instantiating a `Viae` instance and passing a `WebSocketServer` instance to it: 

```ts
let server = new WebSocketServer({ port: 8080, host: "0.0.0.0" });
let viae = new Viae(server);
```

request middleware can then be added using: 

```ts
viae.use(async (ctx, next) => {
  //do something with ctx
  return next();
});
```

A controller-based router is available by using

```ts
@Controller('chat')
class ChatRoomController {
  private _channel = new Subject<string>();

  @Get()
  join() {
    return this._channel;
  }

  @Post()
  addMsg(@Data() msg: string){
    this._channel.next(msg);
    return Status.OK;        
  }
}

viae.use(new App({
  controllers: [new ChatRoomController()]
}));

```

a client is created by instantiating a `Via` instance and making requests


```ts
let wire = new WebSocket("ws://0.0.0.0:8080");
let via = new Via({ wire: wire as any });

via.on("open", async () => {

  let joinRes = await via.request("GET", "/chat");

  if (isObservable(joinRes.data)) {
    joinRes.data.forEach(x => console.log(x));
  }

  await via.request("POST", "/chat", "hello world...");

  await new Promise((r, _) => setTimeout(r, 100));

  wire.close();
});
```


## Build

```
npm install
npm test
```

## Credits
"Cross" Icon courtesy of [The Noun Project](https://thenounproject.com/), by [Alexander Skowalsky](https://thenounproject.com/sandorsz/), under [CC 3.0](http://creativecommons.org/licenses/by/3.0/us/)

[npm-url]: https://npmjs.org/package/viae
[npm-image]: http://img.shields.io/npm/v/viae.svg
[npm-downloads]: http://img.shields.io/npm/dm/viae.svg
[travis-url]: https://travis-ci.org/MeirionHughes/viae
[travis-image]: https://img.shields.io/travis/MeirionHughes/viae/master.svg
[stability-image]: https://img.shields.io/badge/stability-1%20%3A%20unstable-red.svg
[stability-url]: https://nodejs.org/api/documentation.html#documentation_stability_index

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