@aurora-mp/webview
Version:
Webview package of the aurora-mp TypeScript framework.
48 lines (44 loc) • 2.03 kB
TypeScript
declare class WebviewService {
private platform;
constructor();
on(eventName: string, listener: (...args: any[]) => void): void;
off(eventName: string, listener: (...args: any[]) => void): void;
onServer(eventName: string, listener: (...args: any[]) => void): void;
emit(eventName: string, ...args: any[]): void;
emitServer(eventName: string, ...args: any[]): void;
/**
* Invoke a client-side RPC and await its result.
*/
invokeClientRpc<T = any>(rpcName: string, ...args: any[]): Promise<T>;
onClientRpc(rpcName: string, listener: (...args: any[]) => void): void;
/**
* Invoke a server-side RPC and await its result.
*/
invokeServerRpc<T = any>(rpcName: string, ...args: any[]): Promise<T>;
private getPlatform;
}
interface IWebViewPlatform {
on(eventName: string, listener: (...args: any[]) => void): void;
off(eventName: string, listener: (...args: any[]) => void): void;
onServer(eventName: string, listener: (...args: any[]) => void): void;
emit(eventName: string, ...args: any[]): void;
emitServer(eventName: string, ...args: any[]): void;
/**
* Invoke a client-side RPC; returns a Promise of the result.
*
* @param rpcName - the RPC identifier
* @param args - arguments to pass to the RPC handler on the client
* @returns a Promise resolving to the handler’s return value
*/
invokeClientRpc<TResult = unknown>(rpcName: string, ...args: any[]): Promise<TResult>;
/**
* Register a handler for RPC calls coming from the client.
*
* @param rpcName - the RPC identifier
* @param handler - async function to handle the call
*/
onClientRpc<TArgs extends unknown[] = any[], TResult = unknown>(rpcName: string, handler: (...args: TArgs) => Promise<TResult> | TResult): void;
invokeServerRpc<TResult = unknown>(rpcName: string, ...args: any[]): Promise<TResult>;
}
declare const aurora: WebviewService;
export { type IWebViewPlatform, WebviewService, aurora };