Skip to content

Commit

Permalink
fix(client, server): fix and improve RPC docs
Browse files Browse the repository at this point in the history
  • Loading branch information
xxshady committed May 18, 2024
1 parent beba645 commit 24b630e
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 8 deletions.
20 changes: 15 additions & 5 deletions client/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2602,20 +2602,30 @@ declare module "alt-client" {
export function emitRpc<K extends string>(rpcName: Exclude<K, keyof shared.ICustomClientServerRpc>, ...args: any[]): Promise<any>;

/**
* Subscribes to a client event with the specified listener.
* Subscribes to a server -> client RPC with the specified listener.
* @param rpcName Name of the RPC
* @param listener Listener that should be added.
* @param listener Listener to be assigned to this RPC name (there can only be one listener for each RPC name).
*
* * @example
* ```js
* alt.onRpc("testRpc", (...args) => {
* alt.log(`server called testRpc`, args);
*
* @remarks The return value of the listener function determines the response clients will receive. When returning multiple values, use an array. Returning an Error object will cause the promise on the server to throw an exception which has to be caught.
* // throw new Error("I am an error! Notice me!");
* return [1, 2, [10, 13, 19], false, "hey there"];
* });
* ```
*
* @remarks The return value of the listener function determines the response server will receive. When returning multiple values, use an array. Returning an Error object will cause the promise on the server to throw an exception which has to be caught.
*
*/
export function onRpc<K extends keyof shared.ICustomServerClientRpc>(rpcName: K, listener: (...args: Parameters<shared.ICustomServerClientRpc[K]>) => Promise<ReturnType<shared.ICustomClientServerRpc[K]>> | ReturnType<shared.ICustomClientServerRpc[K]>): void;
export function onRpc<K extends keyof shared.ICustomServerClientRpc>(rpcName: K, listener: (...args: Parameters<shared.ICustomServerClientRpc[K]>) => Promise<ReturnType<shared.ICustomServerClientRpc[K]>> | ReturnType<shared.ICustomServerClientRpc[K]>): void;
export function onRpc<K extends string>(rpcName: Exclude<K, keyof shared.ICustomServerClientRpc>, listener: (...args: any[]) => Promise<any> | any): void;

/**
*
* @param rpcName Name of the RPC
* @param listener Listener that should be added.
* @param listener Listener that should be removed (if not passed current listener will be removed).
*
*/
export function offRpc<K extends keyof shared.ICustomServerClientRpc>(rpcName: K, listener?: (...args: Parameters<shared.ICustomServerClientRpc[K]>) => Promise<ReturnType<shared.ICustomServerClientRpc[K]>> | ReturnType<shared.ICustomServerClientRpc[K]>): void;
Expand Down
7 changes: 4 additions & 3 deletions server/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3004,9 +3004,9 @@ declare module "alt-server" {
export function emitAllClientsUnreliable<K extends string>(eventName: Exclude<K, keyof shared.ICustomServerClientEvent>, ...args: any[]): void;

/**
* Subscribes to a client event with the specified listener.
* Subscribes to a client -> server RPC with the specified listener.
* @param rpcName Name of the RPC
* @param listener Listener that should be added.
* @param listener Listener to be assigned to this RPC name (there can only be one listener for each RPC name).
*
* @example
* ```js
Expand All @@ -3017,6 +3017,7 @@ declare module "alt-server" {
* return [1, 2, [10, 13, 19], false, "hey there"];
* });
* ```
*
* @remarks The return value of the listener function determines the response clients will receive. When returning multiple values, use an array. Returning an Error object will cause the promise on the client to throw an exception which has to be caught.
*
*/
Expand All @@ -3026,7 +3027,7 @@ declare module "alt-server" {
/**
*
* @param rpcName Name of the RPC
* @param listener Listener that should be added.
* @param listener Listener that should be removed (if not passed current listener will be removed).
*
*/
export function offRpc<K extends keyof shared.ICustomClientServerRpc>(rpcName: string, listener: (player: Player, ...args: Parameters<shared.ICustomClientServerRpc[K]>) => Promise<ReturnType<shared.ICustomClientServerRpc[K]>> | ReturnType<shared.ICustomClientServerRpc[K]>): void;
Expand Down

0 comments on commit 24b630e

Please sign in to comment.