Rpc integration + type fixes #3

Merged
rilaxik merged 26 commits from dev into master 2024-10-28 12:13:19 +00:00
Showing only changes of commit cd142e4414 - Show all commits

View File

@ -17,10 +17,20 @@ import {
} from './types' } from './types'
class Cef { class Cef {
private _debugMode: boolean = false
set debug(debug: boolean) {
this._debugMode = debug
}
public register<EventName extends keyof RageFW_ICustomCefEvent>( public register<EventName extends keyof RageFW_ICustomCefEvent>(
eventName: EventName, eventName: EventName,
callback: RageFW_CefCallback<EventName>, callback: RageFW_CefCallback<EventName>,
): void { ): void {
if (this._debugMode) {
console.log('[RPC](register):', eventName, callback)
}
if ('mp' in window) { if ('mp' in window) {
rpc.register(eventName, callback) rpc.register(eventName, callback)
} }
@ -32,6 +42,10 @@ class Cef {
? [RageFW_CefArgs<EventName>] ? [RageFW_CefArgs<EventName>]
: [] : []
): Promise<RageFW_CefReturn<EventName>> { ): Promise<RageFW_CefReturn<EventName>> {
if (this._debugMode) {
console.log('[RPC](trigger):', eventName, ...args)
}
if ('mp' in window) { if ('mp' in window) {
return rpc.call(eventName, args) return rpc.call(eventName, args)
} }
@ -47,6 +61,10 @@ class Cef {
? [RageFW_ServerArgs<EventName>] ? [RageFW_ServerArgs<EventName>]
: [] : []
): Promise<RageFW_ServerReturn<EventName>> { ): Promise<RageFW_ServerReturn<EventName>> {
if (this._debugMode) {
console.log('[RPC](triggerServer):', eventName, ...args)
}
if ('mp' in window) { if ('mp' in window) {
return rpc.callServer(eventName, args) return rpc.callServer(eventName, args)
} }
@ -62,6 +80,10 @@ class Cef {
? [RageFW_ClientArgs<EventName>] ? [RageFW_ClientArgs<EventName>]
: [] : []
): Promise<RageFW_ClientReturn<EventName>> { ): Promise<RageFW_ClientReturn<EventName>> {
if (this._debugMode) {
console.log('[RPC](triggerClient):', eventName, ...args)
}
if ('mp' in window) { if ('mp' in window) {
return rpc.callClient(eventName, args) return rpc.callClient(eventName, args)
} }