Compare commits
2 Commits
95352908f8
...
642545595b
Author | SHA1 | Date | |
---|---|---|---|
|
642545595b | ||
|
1766f047a4 |
@ -1,16 +1,19 @@
|
||||
import rpc from 'rage-rpc'
|
||||
|
||||
import {
|
||||
_CefEventHasArgs,
|
||||
_ClientEventHasArgs,
|
||||
_ServerEventHasArgs,
|
||||
RageFW_CefArguments,
|
||||
RageFW_CefCallback,
|
||||
RageFW_CefReturn,
|
||||
RageFW_ClientArguments,
|
||||
RageFW_ClientReturn,
|
||||
RageFW_ServerArguments,
|
||||
RageFW_ServerReturn,
|
||||
RageFW_ICustomCefEvent,
|
||||
RageFW_ICustomClientEvent,
|
||||
RageFW_ICustomServerEvent,
|
||||
RageFW_ServerArguments,
|
||||
RageFW_ServerReturn,
|
||||
} from './types'
|
||||
|
||||
class Cef {
|
||||
@ -23,21 +26,27 @@ class Cef {
|
||||
|
||||
public trigger<EventName extends keyof RageFW_ICustomCefEvent>(
|
||||
eventName: EventName,
|
||||
args: RageFW_CefArguments<EventName>,
|
||||
...args: _CefEventHasArgs<EventName> extends true
|
||||
? [RageFW_CefArguments<EventName>]
|
||||
: []
|
||||
): Promise<RageFW_CefReturn<EventName>> {
|
||||
return rpc.call(eventName, args)
|
||||
}
|
||||
|
||||
public triggerServer<EventName extends keyof RageFW_ICustomServerEvent>(
|
||||
eventName: EventName,
|
||||
args: RageFW_ServerArguments<EventName>,
|
||||
...args: _ServerEventHasArgs<EventName> extends true
|
||||
? [RageFW_ServerArguments<EventName>]
|
||||
: []
|
||||
): Promise<RageFW_ServerReturn<EventName>> {
|
||||
return rpc.callServer(eventName, args)
|
||||
}
|
||||
|
||||
public triggerClient<EventName extends keyof RageFW_ICustomClientEvent>(
|
||||
eventName: EventName,
|
||||
args: RageFW_ClientArguments<EventName>,
|
||||
...args: _ClientEventHasArgs<EventName> extends true
|
||||
? [RageFW_ClientArguments<EventName>]
|
||||
: []
|
||||
): Promise<RageFW_ClientReturn<EventName>> {
|
||||
return rpc.callClient(eventName, args)
|
||||
}
|
||||
|
@ -30,3 +30,10 @@ export type RageFW_CefReturn<K extends RageFW_CefEvent> = ReturnType<
|
||||
export type RageFW_CefCallback<K extends keyof RageFW_ICustomCefEvent> = (
|
||||
args: RageFW_CefArguments<K>,
|
||||
) => RageFW_CefReturn<K>
|
||||
|
||||
export type _CefEventHasArgs<EventName extends keyof RageFW_ICustomCefEvent> =
|
||||
keyof RageFW_ICustomCefEvent extends never
|
||||
? false
|
||||
: Parameters<RageFW_ICustomCefEvent[EventName]>[0] extends undefined
|
||||
? false
|
||||
: true
|
||||
|
@ -22,3 +22,11 @@ export type RageFW_ClientArguments<K extends RageFW_ClientEvent> = Parameters<
|
||||
export type RageFW_ClientReturn<K extends RageFW_ClientEvent> = ReturnType<
|
||||
RageFW_ICustomClientEvent[K]
|
||||
>
|
||||
|
||||
export type _ClientEventHasArgs<
|
||||
EventName extends keyof RageFW_ICustomClientEvent,
|
||||
> = keyof RageFW_ICustomClientEvent extends never
|
||||
? false
|
||||
: Parameters<RageFW_ICustomClientEvent[EventName]>[0] extends undefined
|
||||
? false
|
||||
: true
|
||||
|
@ -22,3 +22,11 @@ export type RageFW_ServerArguments<K extends RageFW_ServerEvent> = Parameters<
|
||||
export type RageFW_ServerReturn<K extends RageFW_ServerEvent> = ReturnType<
|
||||
RageFW_ICustomServerEvent[K]
|
||||
>
|
||||
|
||||
export type _ServerEventHasArgs<
|
||||
EventName extends keyof RageFW_ICustomServerEvent,
|
||||
> = keyof RageFW_ICustomServerEvent extends never
|
||||
? false
|
||||
: Parameters<RageFW_ICustomServerEvent[EventName]>[0] extends undefined
|
||||
? false
|
||||
: true
|
||||
|
@ -3,19 +3,19 @@ import rpc from 'rage-rpc'
|
||||
import Logger from './logger'
|
||||
|
||||
import {
|
||||
RageFW_ClientEventCallback,
|
||||
_CefEventHasArgs,
|
||||
_ClientEventHasArgs,
|
||||
_ServerEventHasArgs,
|
||||
RageFW_CefArgs,
|
||||
RageFW_CefEvent,
|
||||
RageFW_CefReturn,
|
||||
RageFW_ClientEvent,
|
||||
RageFW_ClientEventArguments,
|
||||
RageFW_ClientEventCallback,
|
||||
RageFW_ClientEventReturn,
|
||||
RageFW_ClientServerEvent,
|
||||
RageFW_ClientServerEventArguments,
|
||||
RageFW_ClientServerEventReturn,
|
||||
RageFW_ClientEventArguments,
|
||||
RageFW_ClientEventReturn,
|
||||
_ClientEventHasArgs,
|
||||
_ServerEventHasArgs,
|
||||
RageFW_CefEvent,
|
||||
RageFW_CefArgs,
|
||||
RageFW_CefReturn,
|
||||
_CefEventHasArgs,
|
||||
} from './types'
|
||||
|
||||
import type { RageFW_ICustomClientEvent } from 'rage-fw-shared-types'
|
||||
|
@ -3,16 +3,16 @@ import rpc from 'rage-rpc'
|
||||
import Logger from './logger'
|
||||
|
||||
import {
|
||||
RageFW_CefArgs,
|
||||
RageFW_CefEvent,
|
||||
RageFW_CefReturn,
|
||||
_CefEventHasArgs,
|
||||
_ClientEventHasArgs,
|
||||
_ServerEventHasArgs,
|
||||
RageFW_CefArgs,
|
||||
RageFW_CefEvent,
|
||||
RageFW_CefReturn,
|
||||
RageFW_ClientEvent,
|
||||
RageFW_ICustomServerEvent,
|
||||
RageFW_ServerClientEventArguments,
|
||||
RageFW_ServerClientEventReturn,
|
||||
RageFW_ICustomServerEvent,
|
||||
RageFW_ServerEvent,
|
||||
RageFW_ServerEventArguments,
|
||||
RageFW_ServerEventCallback,
|
||||
|
4
shared-types/types/types/index.d.ts
vendored
4
shared-types/types/types/index.d.ts
vendored
@ -3,5 +3,7 @@ declare module 'rage-fw-shared-types' {
|
||||
|
||||
export interface RageFW_ICustomClientEvent {}
|
||||
|
||||
export interface RageFW_ICustomCefEvent {}
|
||||
export interface RageFW_ICustomCefEvent {
|
||||
test(test: string): void
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user