Internal middleware functions for handling socket connections, parameter extraction, and authentication within the Feathers ecosystem. These functions are automatically configured when using configureSocketio(). While the functions themselves are internal, their types and interfaces are available for advanced usage scenarios.
Handles socket disconnection events and manages the connection lifecycle between Socket.io sockets and Feathers real-time connections.
/**
* Creates middleware for handling socket disconnection events
* @param app - Feathers application instance
* @param getParams - Function to extract parameters from socket
* @param socketMap - WeakMap for tracking socket-to-connection mapping
* @returns Socket middleware function
*/
function disconnect(
app: Application,
getParams: ParamsGetter,
socketMap: WeakMap<RealTimeConnection, FeathersSocket>
): (socket: FeathersSocket, next: NextFunction) => void;Functionality:
disconnect events and closes corresponding socketsdisconnect eventsUsage Example:
import { disconnect } from "@feathersjs/socketio/middleware";
const getParams = (socket) => socket.feathers;
const socketMap = new WeakMap();
io.use(disconnect(app, getParams, socketMap));Sets up socket connection parameters by extracting information from the Socket.io handshake and creating Feathers-compatible parameter objects.
/**
* Creates middleware for setting up socket connection parameters
* @param _app - Feathers application instance (unused in implementation)
* @param socketMap - WeakMap for tracking socket-to-connection mapping
* @returns Socket middleware function
*/
function params(
_app: Application,
socketMap: WeakMap<RealTimeConnection, FeathersSocket>
): (socket: FeathersSocket, next: NextFunction) => void;Functionality:
'socketio' for Feathers service identificationsocket.feathers object with connection parametersParameters Set:
socket.feathers = {
provider: 'socketio',
headers: socket.handshake.headers
};Integrates Socket.io connections with the Feathers authentication system, parsing authentication data from socket handshakes.
/**
* Creates middleware for handling socket authentication
* @param app - Feathers application instance
* @param getParams - Function to extract parameters from socket
* @param settings - Optional authentication settings
* @returns Socket middleware function
*/
function authentication(
app: Application,
getParams: ParamsGetter,
settings?: any
): (socket: FeathersSocket, next: NextFunction) => void;Functionality:
Authentication Flow:
Usage Example:
import { authentication } from "@feathersjs/socketio/middleware";
const getParams = (socket) => socket.feathers;
const authSettings = { service: 'authentication' };
io.use(authentication(app, getParams, authSettings));Extended Socket.io socket with Feathers-specific properties for parameter storage and connection tracking.
/**
* Extended Socket.io socket with Feathers-specific properties
*/
interface FeathersSocket extends Socket {
/** Feathers connection parameters and metadata */
feathers?: Params & { [key: string]: any };
}Function type for extracting parameters from a socket connection.
/**
* Function type for extracting parameters from socket
* @param socket - Socket.io socket instance
* @returns Parameters object
*/
type ParamsGetter = (socket: Socket) => any;Standard middleware next function for continuing the middleware chain.
/**
* Middleware next function type
* @param err - Optional error to pass to error handling
*/
type NextFunction = (err?: any) => void;The middleware functions are automatically applied in the following order during Socket.io configuration:
This order ensures proper parameter setup before authentication and proper cleanup handling throughout the connection lifecycle.
These middleware functions integrate seamlessly with Socket.io's middleware system:
// Automatic integration during configuration
io.use(disconnect(app, getParams, socketMap));
io.use(params(app, socketMap));
io.use(authentication(app, getParams));All middleware functions support standard Socket.io error handling:
next(error) will prevent connection establishment