mirror of
https://github.com/rilaxik/fivem-rpc.git
synced 2026-09-29 01:30:42 +00:00
fix(rpc): improve handlers
This commit is contained in:
+3
-11
@@ -13,7 +13,6 @@ import {
|
||||
type RPCState,
|
||||
} from '../utils/types'
|
||||
|
||||
/** Shared plumbing of the server, client and webview instances */
|
||||
export class RPCInstanceBase {
|
||||
protected readonly env: RPCEnvironment
|
||||
protected readonly debug: boolean
|
||||
@@ -26,9 +25,7 @@ export class RPCInstanceBase {
|
||||
this._pending = new Pending(cfg.timeout ?? 5000)
|
||||
}
|
||||
|
||||
// ===== LISTENERS =====
|
||||
|
||||
/** Registers `cb` for `event` on `emitter`; `method` is only used for logs */
|
||||
/** Registers `cb` for `event` on `emitter`; `method` is only for logs */
|
||||
protected listen(
|
||||
emitter: Emitter,
|
||||
method: string,
|
||||
@@ -39,15 +36,14 @@ export class RPCInstanceBase {
|
||||
emitter.on(event, cb)
|
||||
return this
|
||||
}
|
||||
|
||||
|
||||
/** Unregisters `cb` for `event` on `emitter`; `method` is only for logs */
|
||||
protected unlisten(emitter: Emitter, method: string, event: string): this {
|
||||
this.log(`${method} ${event}`)
|
||||
emitter.off(event)
|
||||
return this
|
||||
}
|
||||
|
||||
// ===== OUTGOING =====
|
||||
|
||||
/** Builds an event payload sent from this environment to `to` */
|
||||
protected request(
|
||||
event: string,
|
||||
@@ -89,8 +85,6 @@ export class RPCInstanceBase {
|
||||
if (!found) this.logIgnored(response)
|
||||
}
|
||||
|
||||
// ===== INCOMING =====
|
||||
|
||||
/**
|
||||
* Runs the listener for `request` and builds the response to send back.
|
||||
* Never throws: a missing listener or a thrown error ends up in `error`.
|
||||
@@ -147,8 +141,6 @@ export class RPCInstanceBase {
|
||||
})
|
||||
}
|
||||
|
||||
// ===== LOGS =====
|
||||
|
||||
/** Debug-only log, prefixed with the environment */
|
||||
protected log(message: string): void {
|
||||
if (this.debug) console.log(`[RPC]:${this.env}:${message}`)
|
||||
|
||||
Reference in New Issue
Block a user