A progressive Node.js tools for building efficient and scalable applications.
Typeix websocket package for resty framework, each connection has dedicated controller instance and it's destroyed once connection is closed or staled.
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();