The Feathers Socket.io real-time API provider for bidirectional communication between clients and servers
npx @tessl/cli install tessl/npm-feathersjs--socketio@5.0.0The Feathers Socket.io real-time API provider enables bidirectional communication between clients and servers through WebSocket connections. It integrates Socket.io with Feathers' service architecture, allowing real-time method calls, event subscriptions, and automatic connection management.
npm install @feathersjs/socketio// Main configuration function (CommonJS style export)
import socketio = require("@feathersjs/socketio");
// Types and interfaces (when needed for advanced usage)
import type { FeathersSocket, ParamsGetter, NextFunction } from "@feathersjs/socketio/middleware";For CommonJS:
const socketio = require("@feathersjs/socketio");import { feathers } from "@feathersjs/feathers";
import socketio = require("@feathersjs/socketio");
const app = feathers();
// Basic configuration
app.configure(socketio());
// With custom port and options
app.configure(socketio(3030, {
cors: { origin: "*" }
}));
// With configuration callback
app.configure(socketio((io) => {
io.sockets.setMaxListeners(64);
}));
await app.listen(3030);The package is built around key components:
configureSocketio function that integrates Socket.io with FeathersMain configuration function for integrating Socket.io with Feathers applications, supporting various configuration patterns.
function configureSocketio(callback?: (io: Server) => void): (app: Application) => void;
function configureSocketio(
options: number | Partial<ServerOptions>,
callback?: (io: Server) => void
): (app: Application) => void;
function configureSocketio(
port: number,
options?: Partial<ServerOptions>,
callback?: (io: Server) => void
): (app: Application) => void;The package exposes types and interfaces for advanced usage scenarios, particularly when working with custom Socket.io middleware.
interface FeathersSocket extends Socket {
feathers?: Params & { [key: string]: any };
}
type ParamsGetter = (socket: Socket) => any;
type NextFunction = (err?: any) => void;Internal Middleware Functions: The package automatically configures internal middleware for connection handling, authentication, and parameter extraction. While these functions are not directly accessible, their types are available for advanced customization scenarios.
// Socket.io types from the socket.io package
interface Server { /* Socket.io Server interface */ }
interface ServerOptions { /* Socket.io ServerOptions interface */ }
interface Socket { /* Socket.io Socket interface */ }
// Feathers types
interface Application { /* Feathers Application interface */ }
interface Params { /* Feathers Params interface */ }
interface RealTimeConnection { /* Feathers RealTimeConnection interface */ }The package extends the Feathers Application interface:
interface Application<Services, Settings> {
io: any;
listen(options: any): Promise<http.Server>;
}