8.6.0 • Published 6 months ago

@typeix/resty-socket-io v8.6.0

Weekly downloads
-
License
MIT
Repository
github
Last release
6 months ago

@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();
8.6.0

6 months ago

8.5.2-rc.1

6 months ago

8.5.2-rc.2

6 months ago

8.5.1

11 months ago

8.5.0

11 months ago