A TypeScript library that provides class-based controllers for handling WebSocket events using decorators. Current stable version is 0.3.1. Developed by the TypeStack team, it allows organizing WebSocket handling in a structured, object-oriented manner similar to Express or routing-controllers. It relies on reflect-metadata and optionally a DI container like TypeDI. It supports socket.io and integrates well with TypeScript projects. Differentiators include declarative decorators (@OnConnect, @OnMessage) and automatic dependency injection.
npm install socket-controllersNo compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
Sets up a basic socket server using socket-controllers with a single controller handling connect, disconnect, and a 'chat' message event.
Add 'import "reflect-metadata"' at the entry point of your application.
Always include parentheses: @ConnectedSocket() and @MessageBody(), even if no parameters.
Apply @SocketController() decorator to each controller class.
Install typedi and pass container in SocketControllers options.
Write code in TypeScript and ensure emitDecoratorMetadata and experimentalDecorators are enabled in tsconfig.json.
Add 'import "reflect-metadata"' at the top of your main file.
Set 'experimentalDecorators': true and 'emitDecoratorMetadata': true in tsconfig.json.
Ensure controller is listed in controllers array and, if using DI, pass container: Container in SocketControllers options.
Use @ConnectedSocket() as a parameter decorator inside a method, not on a property.