@aurora-mp/server
Version:
Server package of the aurora-mp TypeScript framework.
125 lines (115 loc) • 5.24 kB
TypeScript
import { IConfigService, IConfigLoader, IPlatformDriver, ILogger } from '@aurora-mp/core';
/**
* Binds a server controller method to a client-originating event.
*
* When applied, the decorated method will be invoked whenever the specified
* event is emitted from the client side.
*
* @typeParam E - Literal type of the event name.
* @param eventName - Optional custom event name; if omitted, the method name is used.
* @returns A method decorator that registers the handler under EventType.ON_CLIENT.
*/
declare function OnClient<E extends string>(eventName?: E): MethodDecorator;
/**
* Binds a server controller method to an event emitted from a specific WebView instance.
*
* When applied, the decorated method will be invoked whenever the WebView identified
* by `webviewId` emits the given event name.
*
* @param webviewId - Identifier of the target WebView (e.g. the numeric or string ID you passed to createWebview).
* @param eventName - Optional custom event name emitted by the WebView; if omitted, the method name is used.
* @returns - A method decorator that registers the handler under EventType.ON_CLIENT
* (multiplexed via the WebView dispatch channel).
*/
declare function OnWebView(webviewId: string | number, eventName?: string): MethodDecorator;
declare function OnClientRpc<E extends string>(rpcName?: E): MethodDecorator;
declare function OnWebViewRpc<E extends string>(webviewId: string | number, rpcName?: E): MethodDecorator;
/**
* Service responsible for loading and providing access to application configuration.
* The configuration is loaded once at construction time via the injected loader.
*/
declare class ConfigService implements IConfigService {
private readonly loader;
/**
* Internal storage for configuration key/value pairs.
*/
private readonly config;
/**
* Creates an instance of ConfigService.
* @param loader - The platform-specific configuration loader.
* It should implement IConfigLoader.load() to return a map of config values.
*/
constructor(loader: IConfigLoader);
/**
* Retrieves a configuration value by key, optionally casting it to the type of a default value.
*
* @typeParam T - The expected return type.
* @param key - The configuration key to look up.
* @param defaultValue - An optional default value to return if the key is not found.
* @returns The configuration value cast to T, or the provided defaultValue.
* @throws If the key is missing and no defaultValue is provided.
*/
get<T = any>(key: string, defaultValue?: T): T;
}
/**
* Service for emitting events through the underlying platform driver.
*
* Supports:
* - Global events (`emit`)
* - Targeted client events (`emitClient`)
* - WebView events multiplexed via a dispatch channel (`emitWebview`)
*
* @typeParam TPlayer - The platform’s player type (e.g. alt.Player, PlayerMp, etc.)
*/
declare class EventService<TPlayer = any> {
private readonly platformDriver;
/**
* @param platformDriver - The platform-specific driver implementation,
* injected via the PLATFORM_DRIVER token.
*/
constructor(platformDriver: IPlatformDriver<TPlayer>);
/**
* Emit a global event on the server or client (depending on driver).
*
* @param eventName - The name of the event to emit.
* @param args - Additional arguments to pass to event listeners.
*/
emit(eventName: string, ...args: any[]): void;
/**
* Emit an event to a specific client/player.
*
* @param player - The target player instance.
* @param eventName - The name of the event to emit to that player.
* @param args - Additional arguments to pass to the player's event listener.
*/
emitClient(player: TPlayer, eventName: string, ...args: any[]): void;
/**
* Emit an event into a WebView owned by a player.
*
* This method uses a single multiplex channel (`WebViewEvents.DISPATCH`)
* to route calls from the game server through the client into the CEF context.
*
* @param player - The player who owns the WebView.
* @param webviewId - The identifier of the target WebView.
* @param eventName - The name of the WebView event.
* @param args - Arguments to pass into the WebView handler.
*/
emitWebview(player: TPlayer, webviewId: string | number, eventName: string, ...args: any[]): void;
}
declare class RpcService<TPlayer = any> {
private readonly platformDriver;
private readonly logger;
/**
* @param platformDriver - The platform-specific driver implementation,
* injected via the PLATFORM_DRIVER token.
*/
constructor(platformDriver: IPlatformDriver<TPlayer>, logger: ILogger);
invokeClient<T = any>(player: TPlayer, method: string, ...args: unknown[]): Promise<T>;
}
/**
* Provides shared server-side services.
* Users should import this module into their application's root module.
*/
declare class ServerModule {
}
export { ConfigService, EventService, OnClient, OnClientRpc, OnWebView, OnWebViewRpc, RpcService, ServerModule };