Official WebSocket plugin for the Egg.js framework (current version 3.0.0-beta.0). It integrates WebSocket endpoints into Egg's routing and controller system, supporting route parameters, app-level and route-level middleware, Redis pub/sub for broadcasting, and room-based messaging. Unlike socket.io, it does not require sticky sessions and directly wraps the ws library. It is compatible with Egg 3.x and ships TypeScript definitions. Release cadence is tied to Egg major versions; v3 corresponds to Egg 3.
npm install egg-websocket-pluginNo compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
Demonstrates enabling the plugin, defining a WebSocket route, and handling messages in a controller.
Always call app.ws.use() before any app.ws.route() calls.
Use egg-websocket-plugin@1.0.1 for Egg 2.x projects.
Pin to exact version and upgrade with caution.
Set `config.websocket = { useAppMiddlewares: false }` in config.default.js.Install ioredis as a project dependency; configure redis in config.websocket.redis.
Ensure the route is defined with app.ws.route(), not app.router.
Check that the plugin is enabled in config/plugin.js and that routes are defined after the plugin is loaded (usually in app/router.js).
Do not use ctx.body or similar HTTP methods inside WebSocket controller actions; use ctx.websocket.send instead.