Types & Interfaces
Types & Interfaces
All types are re-exported from the top-level ioserver package:
import type {
IOServerOptions,
ServiceOptions,
ControllerOptions,
ManagerOptions,
WatcherOptions,
SendToOptions,
AppHandle,
LogLevel,
TransportMode,
} from "ioserver";
IOServerOptions
Configuration object for the IOServer constructor. All fields are optional.
interface IOServerOptions {
host?: string;
port?: number;
verbose?: LogLevel;
routes?: string;
cors?: any;
mode?: TransportMode | TransportMode[];
cookie?: boolean;
rootDir?: string;
spaFallback?: boolean;
}
See Configuration guide for field descriptions and defaults.
ServiceOptions
interface ServiceOptions {
name?: string; // Namespace name (default: "/")
service: new (appHandle: AppHandle) => any;
middlewares?: (new () => any)[];
}
ControllerOptions
interface ControllerOptions {
name: string; // Must match route file name
controller: new (appHandle: AppHandle) => any;
prefix?: string; // URL prefix (default: /{name})
middlewares?: (new () => any)[];
}
ManagerOptions
interface ManagerOptions {
name: string; // Property name on appHandle
manager: new (appHandle: AppHandle) => any;
}
WatcherOptions
interface WatcherOptions {
name: string;
watcher: new (appHandle: AppHandle) => any;
}
SendToOptions
Options for server.sendTo() and appHandle.send().
interface SendToOptions {
event: string; // Socket.IO event name
data: any; // Payload
namespace?: string; // Target namespace (default: "/")
room?: string; // Target a specific room
sid?: string; // Target a specific socket ID
}
room and sid are mutually exclusive in practice — if both are provided, sid takes precedence (the framework looks up the individual socket).
AppHandle
The shared object passed to every component constructor.
interface AppHandle {
send: (options: SendToOptions) => boolean;
log: (level: number, text: string) => void;
verbose: LogLevel;
[key: string]: any; // Registered managers, keyed by name
}
The [key: string]: any index signature is how managers become available: addManager({ name: "db", manager: DbManager }) sets appHandle.db = new DbManager(appHandle).
LogLevel
type LogLevel =
| "EMERGENCY" // 0 — System unusable
| "ALERT" // 1 — Immediate action required
| "CRITICAL" // 2 — Critical conditions
| "ERROR" // 3 — Error conditions
| "WARNING" // 4 — Warning conditions
| "NOTIFICATION" // 5 — Significant normal events
| "INFORMATION" // 6 — Informational
| "DEBUG"; // 7 — Verbose debug
Used as the verbose option and returned by appHandle.verbose.
TransportMode
type TransportMode = "websocket" | "polling";
Controls Socket.IO transport negotiation. Can be passed as a single value or an array to the mode option.