1.3.0 • Published 5 years ago

@viae/core v1.3.0

Weekly downloads
29
License
MIT
Repository
github
Last release
5 years ago

Viae

A bi-directional communication framework.

logopng

NPM version NPM downloads Travis Status codecov Stability

:warning: Currently still under development. :warning:

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 rxjs Observables (stream request, stream response);

Basic Usage

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

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

request middleware can then be added using:

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

A controller-based router is available by using

@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

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, by Alexander Skowalsky, under CC 3.0

1.3.0

5 years ago

1.2.0

5 years ago

1.1.0

5 years ago

1.0.0

5 years ago

1.0.0-rc.10

5 years ago

1.0.0-rc.9

5 years ago

1.0.0-rc.8

5 years ago

1.0.0-rc.4

5 years ago

1.0.0-rc.3

5 years ago

1.0.0-rc.2

5 years ago

1.0.0-rc.1

5 years ago