@typeix/resty-ws
TypeScript icon, indicating that this package has built-in type declarations

8.6.0 • Public • Published

Typeix Logo

A progressive Node.js tools for building efficient and scalable applications.

@typeix/resty-ws

Build Status Coverage Status npm

Typeix websocket package for resty framework, each connection has dedicated controller instance and it's destroyed once connection is closed or staled.

Usage

In example below you can find basic application server starter:

@WebSocketController({
  socketOptions: {
    path: "/ws"
  }
})
class ChatController implements IAfterConstruct {

  @Inject() logger: Logger;
  @Inject() socket: WebSocket;
  @Inject() request: IncomingMessage;

  @Subscribe("message")
  onMessage(@Arg() buffer: Buffer, @Arg() isBinary: boolean, @Args() args: [RawData, boolean]) {
    this.logger.info(data.toString(), isBinary);
    this.socket.send(data.toString());
  }

  afterConstruct(): void {
    this.logger.info({
      headers: this.request.headers
    });
  }
}

@RootModule({
  shared_providers: [],
  controllers: [ChatController]
})
class Application {

}

// START SERVER
async function bootstrap() {
  const server = createServer();
  await pipeServer(server, Application);
  await pipeWebSocket(server, Application);
  server.on("error", e => console.error(e));
  server.listen(8080);
}

export default bootstrap();

Package Sidebar

Install

npm i @typeix/resty-ws

Homepage

typeix.com

Weekly Downloads

1

Version

8.6.0

License

MIT

Unpacked Size

65.4 kB

Total Files

35

Last publish

Collaborators

  • igorzg