mirror of
https://github.com/rilaxik/fivem-rpc.git
synced 2026-09-28 01:29:13 +00:00
2.3 KiB
2.3 KiB
Migrating from 0.1 to 1.0
Upgrade server, client and webview together. The payload format changed, so 0.1 and 1.0 cannot talk to each other
Creating the instance
RPCFactory is gone, use createRPC:
// 0.1
import { RPCFactory } from '@entityseven/fivem-rpc'
export const rpc = new RPCFactory({ env: 'server' }).get()
// 1.0
import { createRPC } from '@entityseven/fivem-rpc'
export const rpc = createRPC({ env: 'server' })
Errors and timeouts
- a failed call now rejects on the caller with
RPCError(code,message,details). In 0.1 the error was thrown on the receiving side and the call never settled - every call times out after 5000 ms by default. Change it with
RPCConfig.timeout,0restores the 0.1 behaviour (wait forever) RPCErrors.INVALID_DATAandRPCErrors.NO_PLAYERare removed (invalid payloads are dropped),RPCErrors.TIMEOUTandRPCErrors.HANDLER_ERRORare new- the texts of
RPCErrors.UNKNOWN_NATIVEandRPCErrors.UNKNOWN_ENVIRONMENTchanged. Compareerror.codewithRPCErrors, not message strings
See Errors and How it works
Typing
Declarations are now module augmentation of interfaces, the types / typeRoots tsconfig setup is no longer needed. Follow the shared-types readme, then:
-
commands are interface keys instead of string unions:
// 0.1 export type RPCCommands_Server = 'ban' | 'kick' // 1.0 interface RPCCommands_Server { ban: true kick: true } -
remove placeholder members such as
_(): void. An interface with any member is strict, an empty one accepts everything
Other API changes
onCommandcallbacks getargsasstring[](the generic argument type is gone)RPCNativeClientNetworksEventsis renamed toRPCNativeClientNetworkEvents- internal types are no longer exported:
RPCEnvironmentResolved,RPCEventType,RPCEvents,RPCState,RPCStateRaw,RPCStateWeb,RPCStateWebRaw. UseRPCInstanceServer,RPCInstanceClientorRPCInstanceWebviewfor the instance type - server listeners get the player id from FiveM's
source. Ids a client puts into the payload are ignored emitClientEveryoneis one-way: clients run their listener but no longer send a response