Core configuration functionality for integrating Socket.io with Feathers applications, providing flexible setup options and server customization.
Main configuration function that integrates Socket.io with Feathers applications. Supports multiple overloaded signatures to accommodate different configuration patterns.
/**
* Configure Socket.io integration with Feathers application
* @param callback - Optional configuration callback for the io instance
* @returns Feathers application configurator function
*/
function configureSocketio(callback?: (io: Server) => void): (app: Application) => void;
/**
* Configure Socket.io with options or port
* @param options - Port number or Socket.io server options
* @param callback - Optional configuration callback for the io instance
* @returns Feathers application configurator function
*/
function configureSocketio(
options: number | Partial<ServerOptions>,
callback?: (io: Server) => void
): (app: Application) => void;
/**
* Configure Socket.io with explicit port and options
* @param port - Port number for the Socket.io server
* @param options - Socket.io server options
* @param callback - Optional configuration callback for the io instance
* @returns Feathers application configurator function
*/
function configureSocketio(
port: number,
options?: Partial<ServerOptions>,
callback?: (io: Server) => void
): (app: Application) => void;Usage Examples:
import { feathers } from "@feathersjs/feathers";
import socketio = require("@feathersjs/socketio");
const app = feathers();
// Basic configuration with no parameters
app.configure(socketio());
// Configuration with callback only
app.configure(socketio((io) => {
io.sockets.setMaxListeners(100);
}));
// Configuration with port number
app.configure(socketio(3030));
// Configuration with options object
app.configure(socketio({
cors: {
origin: "*",
methods: ["GET", "POST"]
},
transports: ["websocket", "polling"]
}));
// Configuration with port and options
app.configure(socketio(3030, {
cors: { origin: "*" }
}));
// Full configuration with port, options, and callback
app.configure(socketio(3030, {
cors: { origin: "*" }
}, (io) => {
io.sockets.setMaxListeners(64);
}));The configuration function extends the Feathers Application with Socket.io-specific methods:
interface Application<Services, Settings> {
/** Socket.io server instance */
io: any;
/**
* Enhanced listen method that works with both Express and standalone servers
* @param options - Listen options (port, host, etc.)
* @returns Promise resolving to HTTP server instance
*/
listen(options: any): Promise<http.Server>;
}When the application is configured with Socket.io, the following setup occurs:
listen method, creates an HTTP serverThe configuration leverages @feathersjs/transport-commons for:
Supports all Socket.io ServerOptions including:
interface ServerOptions {
cors?: {
origin?: string | string[] | boolean;
methods?: string[];
allowedHeaders?: string[];
credentials?: boolean;
};
transports?: string[];
path?: string;
serveClient?: boolean;
adapter?: any;
parser?: any;
connectTimeout?: number;
pingTimeout?: number;
pingInterval?: number;
maxHttpBufferSize?: number;
allowRequest?: Function;
cookie?: any;
// ... other Socket.io options
}