Events
The EventsManager and HttpServerEventArgs form the server-side event infrastructure that wires HTTP request processing in non-browser (back-end only) mode.
EventsManager
Extends the GUI-layer EventsManager with server-specific subscriptions.
import { EventsManager } from "@io-oidis-localhost/Io/Oidis/Localhost/Events/EventsManager.js";
Accessed via Loader:
import { Loader } from "@io-oidis-localhost/Io/Oidis/Localhost/Loader.js";
const events : EventsManager = Loader.getInstance().getEventsManager();
events.Subscribe();
Subscribe
Wires the HTTP request pipeline. Behaviour depends on the render mode:
| Mode | Behaviour |
|---|---|
| Non-browser (server-only) | Subscribes ON_HTTP_REQUEST and ON_ASYNC_REQUEST on WINDOW to route requests through HttpResolver.ResolveRequest() |
| Browser | Delegates to the parent GUI EventsManager.Subscribe() |
public Subscribe() : void
Subscribe() is called automatically during application startup by Loader. It typically does not need to be called manually.
HttpServerEventArgs
Event arguments for HTTP server lifecycle events (connect / disconnect).
import { HttpServerEventArgs } from "@io-oidis-localhost/Io/Oidis/Localhost/Events/Args/HttpServerEventArgs.js";
Constructor
constructor($port : number, $clientId? : number)
Port
Gets or sets the server port associated with this event.
public Port($value? : number) : number
ClientId
Gets or sets the client connection ID associated with this event.
public ClientId($value? : number) : number
HttpServerEventType
Enum of server lifecycle event types.
import { HttpServerEventType } from "@io-oidis-localhost/Io/Oidis/Localhost/Enums/HttpServerEventType.js";
| Constant | Value | Description |
|---|---|---|
HttpServerEventType.ON_CONNECT | "onConnect" | Fired when a client connects to the HTTP server |
HttpServerEventType.ON_DISCONNECT | "onDisconnect" | Fired when a client disconnects from the HTTP server |
Subscribing to Server Events
import { IHttpServerEvents } from "@io-oidis-localhost/Io/Oidis/Localhost/Interfaces/Events/IHttpServerEvents.js";
const serverEvents : IHttpServerEvents = Loader.getInstance().getHttpServer().getEvents();
serverEvents.setOnConnect(($args : HttpServerEventArgs) => {
console.log("Client connected on port:", $args.Port());
});
serverEvents.setOnDisconnect(($args : HttpServerEventArgs) => {
console.log("Client disconnected, id:", $args.ClientId());
});
See also: Utilities Overview | Events System (GUI) | Localhost Overview