@typeix/resty-socket-io
v8.7.0
Published
typeix websockets support for resty framework
Downloads
23
Maintainers
Readme
@typeix/resty-ws
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();