rage-framework/rpc
Danya H 2f2b1da99b upd
changed packages to organization
2024-10-28 12:43:15 +00:00
..
src upd rpc 2024-10-27 16:36:50 +00:00
.prettierrc.yaml framework rpc init 2024-08-15 22:47:22 +03:00
index.d.ts feat 2024-10-27 11:47:55 +00:00
LICENSE license 2024-10-27 15:51:22 +00:00
package.json upd 2024-10-28 12:43:15 +00:00
readme.md upd rpc 2024-10-27 16:36:50 +00:00
tsconfig.json feat 2024-10-27 11:47:55 +00:00
tsup.config.ts upd 2024-10-01 18:19:46 +01:00

Rage-FW-RPC

is an all-in package with asynchronous RPC implementation for RageMP servers in JS/TS

Installation

npm i rage-fw-rpc
pnpm i rage-fw-rpc
yarn add rage-fw-rpc

Import installed package and initialize rpc:

    // lib/rpc.js

    import { Rpc } from 'rage-fw-rpc'
    export const rpc = new Rpc(/* options */)

Features

  • Type-safe events via TS generics, avoiding type wrappers
  • Built-in logging options for each environment
  • Error-safe developer mode for browser
  • Calls can receive response from called environments via Promises (browser -> server -> browser, etc.)
  • Actual human-readable errors

Docs

Extended version with details coming soon

register

Registers a callback function for a specified event

rpc.register('playerJoin', (player) => {
  console.log(`Connected: ${player.socialClub}`)
})

unregister

Unregisters callback function for a specified event

rpc.unregister('playerDamage')

callClient

Calls a client-side event from server or browser

From browser:

rpc.callClient('updatePlayerData', ['argument']).then(response => {
    console.log(`Received: ${response}`)
})

From server (requires player):

rpc.callClient(player, 'updatePlayerData', ['argument']).then(response => {
    console.log(`Received: ${response}`)
})

callServer

Calls a server-side event from browser or client

rpc.callServer('updatePlayerData', ['argument']).then(response => {
  console.log(`Received: ${response}`)
})

callBrowser

Calls a server-side event from browser or client

From client:

rpc.callBrowser('updatePlayerData', ['argument']).then(response => {
    console.log(`Received: ${response}`)
})

From client (requires player):

rpc.callBrowser(player, 'updatePlayerData', ['argument']).then(response => {
    console.log(`Received: ${response}`)
})

call

Calls an event in current environment

rpc.call('triggerSomething').then(response => {
    console.log(`Received: ${response}`)
})