is an all-in package with asynchronous RPC implementation for RageMP servers in JS/TS
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 */)
The idea was to create an extensible package, with various features to simplify the development process and provide as much comfort as possible. It should also be using similar architecture as the framework it was specially built for
Inspired by usage of rage-rpc
- 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
Registers a callback function for a specified event
rpc.register('playerJoin', (player) => {
console.log(`Connected: ${player.socialClub}`)
})
Unregisters callback function for a specified event
rpc.unregister('playerDamage')
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}`)
})
Calls a server-side event from browser or client
rpc.callServer('updatePlayerData', ['argument']).then(response => {
console.log(`Received: ${response}`)
})
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}`)
})
Calls an event in current environment
rpc.call('triggerSomething').then(response => {
console.log(`Received: ${response}`)
})