Rpc integration + type fixes #3
@ -11,7 +11,7 @@
|
|||||||
"build": "tsup"
|
"build": "tsup"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"ragefw-rpc": "workspace:^"
|
"rage-fw-rpc": "workspace:^"
|
||||||
},
|
},
|
||||||
"peerDependencies": {
|
"peerDependencies": {
|
||||||
"@ragempcommunity/types-cef": "^2.1.8",
|
"@ragempcommunity/types-cef": "^2.1.8",
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import rpc from 'rage-rpc'
|
import { Rpc } from 'rage-fw-rpc'
|
||||||
|
|
||||||
import {
|
import type {
|
||||||
_CefEventHasArgs,
|
_CefEventHasArgs,
|
||||||
_ClientEventHasArgs,
|
_ClientEventHasArgs,
|
||||||
_ServerEventHasArgs,
|
_ServerEventHasArgs,
|
||||||
@ -18,11 +18,18 @@ import {
|
|||||||
|
|
||||||
class Cef {
|
class Cef {
|
||||||
private _debugMode: boolean = false
|
private _debugMode: boolean = false
|
||||||
|
private _rpc: Rpc = new Rpc()
|
||||||
|
|
||||||
|
constructor() {}
|
||||||
|
|
||||||
set debug(debug: boolean) {
|
set debug(debug: boolean) {
|
||||||
this._debugMode = debug
|
this._debugMode = debug
|
||||||
}
|
}
|
||||||
|
|
||||||
|
get rpc(): Rpc {
|
||||||
|
return this._rpc
|
||||||
|
}
|
||||||
|
|
||||||
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>,
|
||||||
@ -32,11 +39,11 @@ class Cef {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if ('mp' in window) {
|
if ('mp' in window) {
|
||||||
rpc.register(eventName, callback)
|
this._rpc.register(eventName, callback)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public trigger<EventName extends keyof RageFW_ICustomCefEvent>(
|
public async trigger<EventName extends keyof RageFW_ICustomCefEvent>(
|
||||||
eventName: EventName,
|
eventName: EventName,
|
||||||
...args: _CefEventHasArgs<EventName> extends true
|
...args: _CefEventHasArgs<EventName> extends true
|
||||||
? [RageFW_CefArgs<EventName>]
|
? [RageFW_CefArgs<EventName>]
|
||||||
@ -47,7 +54,7 @@ class Cef {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if ('mp' in window) {
|
if ('mp' in window) {
|
||||||
return rpc.call(eventName, args)
|
return await this._rpc.call(eventName, args)
|
||||||
}
|
}
|
||||||
|
|
||||||
return Promise.reject(
|
return Promise.reject(
|
||||||
@ -55,7 +62,9 @@ class Cef {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
public triggerServer<EventName extends keyof RageFW_ICustomServerEvent>(
|
public async triggerServer<
|
||||||
|
EventName extends keyof RageFW_ICustomServerEvent,
|
||||||
|
>(
|
||||||
eventName: EventName,
|
eventName: EventName,
|
||||||
...args: _ServerEventHasArgs<EventName> extends true
|
...args: _ServerEventHasArgs<EventName> extends true
|
||||||
? [RageFW_ServerArgs<EventName>]
|
? [RageFW_ServerArgs<EventName>]
|
||||||
@ -66,7 +75,7 @@ class Cef {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if ('mp' in window) {
|
if ('mp' in window) {
|
||||||
return rpc.callServer(eventName, args)
|
return await this._rpc.callServer(eventName, args)
|
||||||
}
|
}
|
||||||
|
|
||||||
return Promise.reject(
|
return Promise.reject(
|
||||||
@ -74,7 +83,9 @@ class Cef {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
public triggerClient<EventName extends keyof RageFW_ICustomClientEvent>(
|
public async triggerClient<
|
||||||
|
EventName extends keyof RageFW_ICustomClientEvent,
|
||||||
|
>(
|
||||||
eventName: EventName,
|
eventName: EventName,
|
||||||
...args: _ClientEventHasArgs<EventName> extends true
|
...args: _ClientEventHasArgs<EventName> extends true
|
||||||
? [RageFW_ClientArgs<EventName>]
|
? [RageFW_ClientArgs<EventName>]
|
||||||
@ -85,7 +96,7 @@ class Cef {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if ('mp' in window) {
|
if ('mp' in window) {
|
||||||
return rpc.callClient(eventName, args)
|
return await this._rpc.callClient(eventName, args)
|
||||||
}
|
}
|
||||||
|
|
||||||
return Promise.reject(
|
return Promise.reject(
|
||||||
|
@ -16,13 +16,11 @@
|
|||||||
],
|
],
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@inquirer/prompts": "^5.0.5",
|
"@inquirer/prompts": "^5.0.5",
|
||||||
"axios": "^1.7.2",
|
"ky": "^1.7.2",
|
||||||
"chalk": "4.1.2",
|
"chalk": "4.1.2",
|
||||||
"git-clone": "^0.2.0",
|
|
||||||
"yargs": "^17.7.2"
|
"yargs": "^17.7.2"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@types/git-clone": "^0.2.4",
|
|
||||||
"@types/node": "^20.14.2",
|
"@types/node": "^20.14.2",
|
||||||
"@types/yargs": "^17.0.32",
|
"@types/yargs": "^17.0.32",
|
||||||
"prettier": "^3.3.2",
|
"prettier": "^3.3.2",
|
||||||
|
@ -11,7 +11,7 @@
|
|||||||
"build": "tsup"
|
"build": "tsup"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"ragefw-rpc": "workspace:^"
|
"rage-fw-rpc": "workspace:^"
|
||||||
},
|
},
|
||||||
"peerDependencies": {
|
"peerDependencies": {
|
||||||
"@ragempcommunity/types-client": "^2.1.8",
|
"@ragempcommunity/types-client": "^2.1.8",
|
||||||
|
@ -1,20 +1,33 @@
|
|||||||
import rpc from 'rage-rpc'
|
import { Rpc } from 'rage-fw-rpc'
|
||||||
|
|
||||||
import { RageFW_ClientCallback, RageFW_ClientEvent } from '../types'
|
import type {
|
||||||
|
RageFW_ClientArgs,
|
||||||
|
RageFW_ClientCallback,
|
||||||
|
RageFW_ClientEvent,
|
||||||
|
} from '../types'
|
||||||
|
|
||||||
export class Client {
|
export class Client {
|
||||||
|
private _rpc: Rpc = new Rpc()
|
||||||
|
|
||||||
|
get rpc(): Rpc {
|
||||||
|
return this._rpc
|
||||||
|
}
|
||||||
|
|
||||||
public register<EventName extends RageFW_ClientEvent>(
|
public register<EventName extends RageFW_ClientEvent>(
|
||||||
eventName: EventName,
|
eventName: EventName,
|
||||||
callback: RageFW_ClientCallback<EventName>,
|
callback: RageFW_ClientCallback<EventName>,
|
||||||
): void {
|
): void {
|
||||||
rpc.register(eventName, async data => {
|
this._rpc.register(
|
||||||
return await callback(data)
|
eventName,
|
||||||
})
|
async (data: RageFW_ClientArgs<EventName>) => {
|
||||||
|
return await callback(data)
|
||||||
|
},
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
public unregister<EventName extends RageFW_ClientEvent>(
|
public unregister<EventName extends RageFW_ClientEvent>(
|
||||||
eventName: EventName,
|
eventName: EventName,
|
||||||
): void {
|
): void {
|
||||||
rpc.unregister(eventName)
|
this._rpc.unregister(eventName)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import rpc from 'rage-rpc'
|
import { Rpc } from 'rage-fw-rpc'
|
||||||
import type { RageFW_ICustomClientEvent } from 'rage-fw-shared-types'
|
import type { RageFW_ICustomClientEvent } from 'rage-fw-shared-types'
|
||||||
|
|
||||||
import {
|
import {
|
||||||
@ -16,15 +16,19 @@ import {
|
|||||||
} from '../types'
|
} from '../types'
|
||||||
|
|
||||||
export class Player {
|
export class Player {
|
||||||
|
private _rpc: Rpc = new Rpc()
|
||||||
public browser: BrowserMp | undefined
|
public browser: BrowserMp | undefined
|
||||||
|
|
||||||
|
get rpc(): Rpc {
|
||||||
|
return this._rpc
|
||||||
|
}
|
||||||
public trigger<EventName extends keyof RageFW_ICustomClientEvent>(
|
public trigger<EventName extends keyof RageFW_ICustomClientEvent>(
|
||||||
eventName: EventName,
|
eventName: EventName,
|
||||||
...args: _ClientEventHasArgs<EventName> extends true
|
...args: _ClientEventHasArgs<EventName> extends true
|
||||||
? [RageFW_ClientArgs<EventName>]
|
? [RageFW_ClientArgs<EventName>]
|
||||||
: []
|
: []
|
||||||
): Promise<RageFW_ClientReturn<EventName>> {
|
): Promise<RageFW_ClientReturn<EventName>> {
|
||||||
return rpc.call<RageFW_ClientReturn<EventName>>(eventName, args)
|
return this._rpc.call(eventName, args)
|
||||||
}
|
}
|
||||||
|
|
||||||
public triggerServer<EventName extends RageFW_ClientServerEvent>(
|
public triggerServer<EventName extends RageFW_ClientServerEvent>(
|
||||||
@ -33,7 +37,7 @@ export class Player {
|
|||||||
? [RageFW_ClientServerArgs<EventName>]
|
? [RageFW_ClientServerArgs<EventName>]
|
||||||
: []
|
: []
|
||||||
): Promise<RageFW_ClientServerReturn<EventName>> {
|
): Promise<RageFW_ClientServerReturn<EventName>> {
|
||||||
return rpc.callServer(eventName, args)
|
return this._rpc.callServer(eventName, args)
|
||||||
}
|
}
|
||||||
|
|
||||||
public triggerBrowser<EventName extends RageFW_CefEvent>(
|
public triggerBrowser<EventName extends RageFW_CefEvent>(
|
||||||
@ -44,6 +48,6 @@ export class Player {
|
|||||||
): Promise<RageFW_CefReturn<EventName>> {
|
): Promise<RageFW_CefReturn<EventName>> {
|
||||||
if (!this.browser)
|
if (!this.browser)
|
||||||
throw new Error('You need to initialize browser first')
|
throw new Error('You need to initialize browser first')
|
||||||
return rpc.callBrowser(this.browser, eventName, args)
|
return this._rpc.callBrowser(this.browser, eventName, args)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
{
|
{
|
||||||
"name": "ragefw-rpc",
|
"name": "rage-fw-rpc",
|
||||||
"description": "RageFW RPC",
|
"description": "RageFW RPC",
|
||||||
"version": "0.2.1",
|
"version": "0.2.1",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
@ -11,7 +11,7 @@
|
|||||||
"build": "tsup"
|
"build": "tsup"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"ragefw-rpc": "workspace:^"
|
"rage-fw-rpc": "workspace:^"
|
||||||
},
|
},
|
||||||
"peerDependencies": {
|
"peerDependencies": {
|
||||||
"@ragempcommunity/types-server": "^2.1.8",
|
"@ragempcommunity/types-server": "^2.1.8",
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import rpc from 'rage-rpc'
|
import { Rpc } from 'rage-fw-rpc'
|
||||||
|
|
||||||
import {
|
import type {
|
||||||
_CefEventHasArgs,
|
_CefEventHasArgs,
|
||||||
_ClientEventHasArgs,
|
_ClientEventHasArgs,
|
||||||
RageFW_CefArgs,
|
RageFW_CefArgs,
|
||||||
@ -12,6 +12,12 @@ import {
|
|||||||
} from '../types'
|
} from '../types'
|
||||||
|
|
||||||
export class Player {
|
export class Player {
|
||||||
|
private _rpc: Rpc = new Rpc()
|
||||||
|
|
||||||
|
get rpc(): Rpc {
|
||||||
|
return this._rpc
|
||||||
|
}
|
||||||
|
|
||||||
public triggerClient<EventName extends RageFW_ClientEvent>(
|
public triggerClient<EventName extends RageFW_ClientEvent>(
|
||||||
player: PlayerMp,
|
player: PlayerMp,
|
||||||
eventName: EventName,
|
eventName: EventName,
|
||||||
@ -19,7 +25,7 @@ export class Player {
|
|||||||
? [RageFW_ServerClientArgs<EventName>]
|
? [RageFW_ServerClientArgs<EventName>]
|
||||||
: []
|
: []
|
||||||
): Promise<RageFW_ServerClientReturn<EventName>> {
|
): Promise<RageFW_ServerClientReturn<EventName>> {
|
||||||
return rpc.callClient(player, eventName, args)
|
return this._rpc.callClient(player, eventName, args)
|
||||||
}
|
}
|
||||||
|
|
||||||
public triggerBrowser<EventName extends RageFW_CefEvent>(
|
public triggerBrowser<EventName extends RageFW_CefEvent>(
|
||||||
@ -29,6 +35,6 @@ export class Player {
|
|||||||
? [RageFW_CefArgs<EventName>]
|
? [RageFW_CefArgs<EventName>]
|
||||||
: []
|
: []
|
||||||
): Promise<RageFW_CefReturn<EventName>> {
|
): Promise<RageFW_CefReturn<EventName>> {
|
||||||
return rpc.callBrowsers(player, eventName, args)
|
return this._rpc.callBrowser(player, eventName, args)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
import rpc from 'rage-rpc'
|
import { Rpc } from 'rage-fw-rpc'
|
||||||
import { RageFW_ICustomServerEvent } from 'rage-fw-shared-types'
|
import { RageFW_ICustomServerEvent } from 'rage-fw-shared-types'
|
||||||
|
|
||||||
import { nativeEvents } from '../native.events'
|
import { nativeEvents } from '../native.events'
|
||||||
import {
|
import type {
|
||||||
_ServerEventHasArgs,
|
_ServerEventHasArgs,
|
||||||
RageFW_ServerArgs,
|
RageFW_ServerArgs,
|
||||||
RageFW_ServerCallback,
|
RageFW_ServerCallback,
|
||||||
@ -13,6 +13,12 @@ import {
|
|||||||
} from '../types'
|
} from '../types'
|
||||||
|
|
||||||
export class Server {
|
export class Server {
|
||||||
|
private _rpc: Rpc = new Rpc()
|
||||||
|
|
||||||
|
get rpc(): Rpc {
|
||||||
|
return this._rpc
|
||||||
|
}
|
||||||
|
|
||||||
private isNativeEvent(eventName: string): eventName is keyof IServerEvents {
|
private isNativeEvent(eventName: string): eventName is keyof IServerEvents {
|
||||||
return nativeEvents.includes(eventName)
|
return nativeEvents.includes(eventName)
|
||||||
}
|
}
|
||||||
@ -21,8 +27,9 @@ export class Server {
|
|||||||
eventName: EventName,
|
eventName: EventName,
|
||||||
callback: RageFW_ServerCallbackCustom<EventName>,
|
callback: RageFW_ServerCallbackCustom<EventName>,
|
||||||
): void {
|
): void {
|
||||||
rpc.register(
|
this._rpc.register(
|
||||||
eventName,
|
eventName,
|
||||||
|
// fixme
|
||||||
async (args: RageFW_ServerArgs<EventName>, info) => {
|
async (args: RageFW_ServerArgs<EventName>, info) => {
|
||||||
await callback([info.player as PlayerMp, ...args])
|
await callback([info.player as PlayerMp, ...args])
|
||||||
},
|
},
|
||||||
@ -80,7 +87,7 @@ export class Server {
|
|||||||
private unregisterCustom<EventName extends keyof RageFW_ICustomServerEvent>(
|
private unregisterCustom<EventName extends keyof RageFW_ICustomServerEvent>(
|
||||||
eventName: EventName,
|
eventName: EventName,
|
||||||
): void {
|
): void {
|
||||||
rpc.unregister(eventName)
|
this._rpc.unregister(eventName)
|
||||||
}
|
}
|
||||||
|
|
||||||
private unregisterNative<EventName extends keyof IServerEvents>(
|
private unregisterNative<EventName extends keyof IServerEvents>(
|
||||||
@ -105,6 +112,6 @@ export class Server {
|
|||||||
? [RageFW_ServerArgs<EventName>]
|
? [RageFW_ServerArgs<EventName>]
|
||||||
: []
|
: []
|
||||||
): Promise<RageFW_ServerReturn<EventName>> {
|
): Promise<RageFW_ServerReturn<EventName>> {
|
||||||
return rpc.call<RageFW_ServerReturn<EventName>>(eventName, args)
|
return this._rpc.call(eventName, args)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user