Socket.io Transport
The@feathersjs/socketio module provides real-time communication for Feathers services using Socket.io.
Installation
socketio()
Configures Socket.io as a real-time transport provider for Feathers services.Signature
number
Port number for standalone Socket.io server (when not using Express/Koa)
Partial<ServerOptions>
Socket.io server configuration options
(io: Server) => void
Configuration callback that receives the Socket.io server instance
ServerOptions
Socket.io server options include:object
CORS configuration for Socket.io connections
string
default:"/socket.io"
Path where Socket.io server listens
string[]
Allowed transports (e.g.,
['websocket', 'polling'])number
default:"20000"
Ping timeout in milliseconds
number
default:"25000"
Ping interval in milliseconds
Example
Application Extensions
When Socket.io is configured, the application is extended with:Server
The Socket.io server instance for direct access
Example
Connection Parameters
Socket connections automatically receive Feathers params:Params
Feathers params object with connection metadata
string
Set to
'socketio' for Socket.io connectionsobject
Connection handshake headers
object
Parsed authentication data (when authentication is configured)
Authentication
Socket.io automatically integrates with Feathers authentication:- Connection handshake headers
- JWT tokens in the
Authorizationheader - Custom authentication strategies
Events
Socket.io connections emit standard Feathers events:Connection Events
Service Events
Services automatically emit events to connected clients:Event Filtering
Control which clients receive service events:Channels
Manage Socket.io connections using channels:Direct Socket Access
Access the underlying Socket.io socket in service hooks:Middleware
Socket.io middleware is automatically configured:- disconnect: Handles client disconnections
- params: Sets up Feathers params on the socket
- authentication: Parses authentication credentials