diff --git a/rpc/readme.md b/rpc/readme.md index ebd86f9..8176e12 100644 --- a/rpc/readme.md +++ b/rpc/readme.md @@ -57,6 +57,25 @@ try { ## How it works +### Directions + +Every call goes from an `emit*` method in one environment to the matching `on*` listener in another. The last column is the [shared-types](../shared-types/readme.md) interface that types it + +| From | Call | To | Listener | Typed by | +| ------- | ------------------------------------- | ----------- | ------------------------------------- | ------------------------- | +| server | `emitClient(player, event, ...args)` | client | `onServer` | `RPCEvents_ServerClient` | +| server | `emitClientEveryone(event, ...args)` | all clients | `onServer`, no response | `RPCEvents_ServerClient` | +| server | `emitWebview(player, event, ...args)` | webview | `onServer`, via client | `RPCEvents_ServerWebview` | +| server | `emitSelf(event, ...args)` | server | `onSelf` | `RPCEvents_Server` | +| client | `emitServer(event, ...args)` | server | `onClient`, player first | `RPCEvents_ClientServer` | +| client | `emitWebview(event, ...args)` | webview | `onClient` | `RPCEvents_ClientWebview` | +| client | `emitSelf(event, ...args)` | client | `onSelf` | `RPCEvents_Client` | +| webview | `emitServer(event, ...args)` | server | `onWebview`, player first, via client | `RPCEvents_WebviewServer` | +| webview | `emitClient(event, ...args)` | client | `onWebview` | `RPCEvents_WebviewClient` | +| webview | `emitSelf(event, ...args)` | webview | `onSelf` | `RPCEvents_Webview` | + +Commands registered with `onCommand` are typed by `RPCCommands_Server` and `RPCCommands_Client` + ### Routing Server and client talk over FiveM network events, client and webview over NUI messages and NUI callbacks. Webview and server never talk directly: every call between them is relayed by the client of that player. So every client must run `createRPC({ env: 'client' })`, even with no listeners of its own, or those calls time out diff --git a/shared-types/readme.md b/shared-types/readme.md index 8913a69..c0abcd9 100644 --- a/shared-types/readme.md +++ b/shared-types/readme.md @@ -51,21 +51,7 @@ See the [main readme](../readme.md#installation). The declaration file below imp ## Interfaces -Each interface is one direction. An interface you leave empty stays loose (any name, arguments and result), so you can declare them one at a time - -| Interface | Direction | Caller | Listener | -| ------------------------- | ------------------ | ------------------------------------------- | -------------------- | -| `RPCEvents_Client` | client -> client | `emitSelf` (client) | `onSelf` (client) | -| `RPCEvents_ClientServer` | client -> server | `emitServer` (client) | `onClient` (server) | -| `RPCEvents_ClientWebview` | client -> webview | `emitWebview` (client) | `onClient` (webview) | -| `RPCEvents_Server` | server -> server | `emitSelf` (server) | `onSelf` (server) | -| `RPCEvents_ServerClient` | server -> client | `emitClient`, `emitClientEveryone` (server) | `onServer` (client) | -| `RPCEvents_ServerWebview` | server -> webview | `emitWebview` (server) | `onServer` (webview) | -| `RPCEvents_Webview` | webview -> webview | `emitSelf` (webview) | `onSelf` (webview) | -| `RPCEvents_WebviewClient` | webview -> client | `emitClient` (webview) | `onWebview` (client) | -| `RPCEvents_WebviewServer` | webview -> server | `emitServer` (webview) | `onWebview` (server) | -| `RPCCommands_Client` | - | - | `onCommand` (client) | -| `RPCCommands_Server` | - | - | `onCommand` (server) | +Each interface types one direction, see the [direction table](../rpc/readme.md#directions) for which `emit*` and `on*` methods use it. `RPCCommands_Server` and `RPCCommands_Client` type `onCommand`. An interface you leave empty stays loose (any name, arguments and result), so you can declare them one at a time - events: the member name is the event name, its parameters are the arguments, its return type is what `emit*` resolves with. Server `onClient` and `onWebview` listeners get the player id before the declared arguments. Names that are not identifiers work too: `'buy-item'(item: string): boolean` - commands: the key is the command name, the value is not used (`true`)