From 269269771d0abde0f107b21944eb9434827cbdcd Mon Sep 17 00:00:00 2001 From: Danya H Date: Mon, 28 Sep 2026 01:26:03 +0100 Subject: [PATCH] docs: bump readme.md --- readme.md | 63 ++++++++++++++++++++++++++++++------------ rpc/readme.md | 50 ++++----------------------------- shared-types/readme.md | 14 ++-------- 3 files changed, 52 insertions(+), 75 deletions(-) diff --git a/readme.md b/readme.md index ae6997d..6af4fe4 100644 --- a/readme.md +++ b/readme.md @@ -2,37 +2,64 @@ is an all-in-one package with asynchronous RPC implementation for FiveM servers in JS/TS +## Motivation + +The idea was to create an extensible package, with various features to simplify the development process and provide as much comfort as possible. Inspired by usage of [altv-xrpc](https://github.com/xxshady/altv-xrpc) + +## Packages + +| Package | Docs | +| ----------------------------------------------------- | -------------------------------------- | +| [`@entityseven/fivem-rpc`](rpc) | [API reference](rpc/readme.md) | +| [`@entityseven/fivem-rpc-shared-types`](shared-types) | [Typing setup](shared-types/readme.md) | + ## Installation ```bash - pnpm i @entityseven/fivem-rpc +npm i @entityseven/fivem-rpc +pnpm add @entityseven/fivem-rpc +yarn add @entityseven/fivem-rpc +bun add @entityseven/fivem-rpc ``` +Optional, for typed event names, arguments and results ([typing setup](shared-types/readme.md)): + ```bash - yarn add @entityseven/fivem-rpc +npm i -D @entityseven/fivem-rpc-shared-types +pnpm add -D @entityseven/fivem-rpc-shared-types +yarn add -D @entityseven/fivem-rpc-shared-types +bun add -d @entityseven/fivem-rpc-shared-types ``` -```bash - bun add @entityseven/fivem-rpc +## Quick start + +Create exactly one instance per environment and import it from your own module, not from the library. The client needs one even if it only relays between server and webview. + +```ts +// server/rpc.ts +import { createRPC } from '@entityseven/fivem-rpc' +export const rpc = createRPC({ env: 'server' }) + +// client/rpc.ts +import { createRPC } from '@entityseven/fivem-rpc' +export const rpc = createRPC({ env: 'client' }) + +// webview/rpc.ts +import { createRPC } from '@entityseven/fivem-rpc' +export const rpc = createRPC({ env: 'webview' }) ``` -It is highly recommended to also install additional package for enhanced typing +Listen on one side, emit from the other and await the listener's return value: -```bash - pnpm i @entityseven/fivem-rpc-shared-types -D +```ts +// server +rpc.onClient('ping', (player, message) => `pong: ${message} (from ${player})`) + +// client +const reply = await rpc.emitServer('ping', 'hello') ``` -```bash - yarn add @entityseven/fivem-rpc-shared-types --dev -``` - -```bash - bun add @entityseven/fivem-rpc-shared-types -d -``` - -## Docs - -Can be found in [/rpc/readme.md](https://github.com/rilaxik/fivem-rpc/blob/master/rpc/readme.md) +All methods: [API reference](rpc/readme.md). ## Features diff --git a/rpc/readme.md b/rpc/readme.md index bdc7f99..5cd48fb 100644 --- a/rpc/readme.md +++ b/rpc/readme.md @@ -1,48 +1,8 @@ # FiveM RPC -is an all-in package with asynchronous RPC implementation for RageMP servers in JS/TS. [Extra info](https://github.com/rilaxik/fivem-rpc/blob/master/readme.md) +is an all-in package with asynchronous RPC implementation for RageMP servers in JS/TS -# Motivation - -The idea was to create an extensible package, with various features to simplify the development process and provide as much comfort as possible. Inspired by usage of [altv-xrpc](https://github.com/xxshady/altv-xrpc) - -# Installation - -```bash - pnpm i @entityseven/fivem-rpc -``` - -```bash - yarn add @entityseven/fivem-rpc -``` - -```bash - bun add @entityseven/fivem-rpc -``` - -It is highly recommended to also install additional package for enhanced typing - -```bash - pnpm i @entityseven/fivem-rpc-shared-types -D -``` - -```bash - yarn add @entityseven/fivem-rpc-shared-types --dev -``` - -```bash - bun add @entityseven/fivem-rpc-shared-types -d -``` - -## Usage - -FiveM RPC is meant to be a singletone per environment. This means you _must create only one_ `RPCFactory` per your server/client/web. This also enables modifying `const rpc` to your needs, adding new methods or variables by forcing you to import it from file instead of library reference - -```ts -// lib/rpc.ts -import { RPCFactory } from '@entityseven/fivem-rpc' -export const rpc = new RPCFactory(/* options */).get() -``` +Installation, quick start and package overview: [main readme](../readme.md). Typed events: [shared-types](../shared-types/readme.md). # Docs @@ -91,7 +51,7 @@ Type: 'event' Data: [] ``` -## Server ([source](https://github.com/rilaxik/fivem-rpc/blob/master/rpc/src/core/server.ts)) +## Server ([source](src/core/server.ts)) ### onClient @@ -205,7 +165,7 @@ rpc.onNativeEvent('playerJoining', (source, oldId) => { }) ``` -## Client ([source](https://github.com/rilaxik/fivem-rpc/blob/master/rpc/src/core/client.ts)) +## Client ([source](src/core/client.ts)) ### onServer @@ -329,7 +289,7 @@ Sets or removes focus and cursor from own webview rpc.setWebviewFocus(true /* focus */, true /* show cursor */) ``` -## Webview ([source](https://github.com/rilaxik/fivem-rpc/blob/master/rpc/src/core/webview.ts)) +## Webview ([source](src/core/webview.ts)) ### onClient diff --git a/shared-types/readme.md b/shared-types/readme.md index 31f08bf..8287670 100644 --- a/shared-types/readme.md +++ b/shared-types/readme.md @@ -1,20 +1,10 @@ # FiveM RPC Shared Types -### [Docs & Info](https://github.com/rilaxik/fivem-rpc/blob/master/readme.md) +### [Docs & Info](../readme.md) ## Installation -```bash - pnpm i @entityseven/fivem-rpc-shared-types -D -``` - -```bash - yarn add @entityseven/fivem-rpc-shared-types --dev -``` - -```bash - bun add @entityseven/fivem-rpc-shared-types -d -``` +See the [main readme](../readme.md#installation). ## Usage