diff --git a/.gitignore b/.gitignore index ff08c6c..383662a 100644 --- a/.gitignore +++ b/.gitignore @@ -1,8 +1,8 @@ # Editor -.vscode -.idea +.vscode/ +.idea/ -.git +.git/ # Server Files server/bin @@ -18,4 +18,8 @@ server/ragemp-server.exe # Development node_modules pnpm-lock.yaml -dist \ No newline at end of file + +# Build +build/ +dist/ +out/ \ No newline at end of file diff --git a/apps/cef/.eslintrc.cjs b/apps/browser/.eslintrc.cjs similarity index 100% rename from apps/cef/.eslintrc.cjs rename to apps/browser/.eslintrc.cjs diff --git a/apps/cef/index.html b/apps/browser/index.html similarity index 100% rename from apps/cef/index.html rename to apps/browser/index.html diff --git a/apps/cef/package.json b/apps/browser/package.json similarity index 72% rename from apps/cef/package.json rename to apps/browser/package.json index 8af2839..fd0dcbb 100644 --- a/apps/cef/package.json +++ b/apps/browser/package.json @@ -1,10 +1,6 @@ { - "name": "rage-fw-example-cef", - "version": "0.0.0", - "type": "module", - "author": "Entity Seven Group", - "license": "CC BY-ND", - "description": "CEF side of rage-fw example", + "name": "rage-fw-example-browser", + "description": "Browser side of Rage-FW example", "scripts": { "dev": "vite", "build": "tsc && vite build", @@ -12,9 +8,10 @@ "preview": "vite preview" }, "dependencies": { + "@rage-fw/shared": "workspace:^", "react": "^18.2.0", "react-dom": "^18.2.0", - "rpc": "workspace:^" + "rage-fw-rpc": "file:../../../rage-framework/rpc" }, "devDependencies": { "@types/react": "^18.2.66", @@ -25,7 +22,11 @@ "eslint": "^8.57.0", "eslint-plugin-react-hooks": "^4.6.0", "eslint-plugin-react-refresh": "^0.4.6", - "typescript": "^5.2.2", - "vite": "^5.2.0" - } + "typescript": "^5.6.3", + "vite": "^5.4.10" + }, + "type": "module", + "license": "CC BY-ND", + "author": "Entity Seven Group", + "version": "0.1.0" } diff --git a/apps/cef/public/vite.svg b/apps/browser/public/vite.svg similarity index 100% rename from apps/cef/public/vite.svg rename to apps/browser/public/vite.svg diff --git a/apps/browser/src/App.tsx b/apps/browser/src/App.tsx new file mode 100644 index 0000000..6e5ff21 --- /dev/null +++ b/apps/browser/src/App.tsx @@ -0,0 +1,24 @@ +import { useEffect, useState } from 'react' +import { events } from '@rage-fw/shared' +import { rpc } from '@/lib' + +function App() { + const [data, setData] = useState('') + + useEffect(() => { + rpc.register(events.browser.customBrowserEvent, (args: string) => { + setData(prev => prev + ' | ' + args) + return 'response from cef' + }) + rpc.callClient(events.client.cefReady, ['hello from cef']) + }, []) + + return ( +
+

Hello World!

+

{data}

+
+ ) +} + +export default App diff --git a/apps/cef/src/assets/react.svg b/apps/browser/src/assets/react.svg similarity index 100% rename from apps/cef/src/assets/react.svg rename to apps/browser/src/assets/react.svg diff --git a/apps/cef/src/index.css b/apps/browser/src/index.css similarity index 100% rename from apps/cef/src/index.css rename to apps/browser/src/index.css diff --git a/apps/browser/src/lib/index.ts b/apps/browser/src/lib/index.ts new file mode 100644 index 0000000..c936193 --- /dev/null +++ b/apps/browser/src/lib/index.ts @@ -0,0 +1,5 @@ +import { Rpc } from 'rage-fw-rpc' + +export const rpc = new Rpc({ + debugLogs: true, +}) diff --git a/apps/cef/src/main.tsx b/apps/browser/src/main.tsx similarity index 100% rename from apps/cef/src/main.tsx rename to apps/browser/src/main.tsx diff --git a/apps/cef/src/vite-env.d.ts b/apps/browser/src/vite-env.d.ts similarity index 100% rename from apps/cef/src/vite-env.d.ts rename to apps/browser/src/vite-env.d.ts diff --git a/apps/cef/tsconfig.json b/apps/browser/tsconfig.json similarity index 90% rename from apps/cef/tsconfig.json rename to apps/browser/tsconfig.json index 3c73139..57cca6b 100644 --- a/apps/cef/tsconfig.json +++ b/apps/browser/tsconfig.json @@ -22,7 +22,11 @@ "types": [ "../../node_modules/@ragempcommunity/types-cef", "../shared/declarations/rage-fw-shared-types/" - ] + ], + "paths": { + "@": ["./src"], + "@/*": ["./src/*"], + } }, "include": ["src"], "references": [{ "path": "./tsconfig.node.json" }] diff --git a/apps/cef/tsconfig.node.json b/apps/browser/tsconfig.node.json similarity index 100% rename from apps/cef/tsconfig.node.json rename to apps/browser/tsconfig.node.json diff --git a/apps/browser/vite.config.ts b/apps/browser/vite.config.ts new file mode 100644 index 0000000..c3c3f0a --- /dev/null +++ b/apps/browser/vite.config.ts @@ -0,0 +1,17 @@ +import { defineConfig } from 'vite' +import react from '@vitejs/plugin-react' + +// https://vitejs.dev/config/ +export default defineConfig({ + plugins: [react()], + build: { + outDir: '../../server/client_packages/cef', + emptyOutDir: true, + }, + resolve: { + alias: { + '@': './src', + '@/*': './src/*', + }, + }, +}) diff --git a/apps/cef/src/App.tsx b/apps/cef/src/App.tsx deleted file mode 100644 index 16c6cef..0000000 --- a/apps/cef/src/App.tsx +++ /dev/null @@ -1,20 +0,0 @@ -import { useEffect, useState } from 'react' -import { rpc } from 'rpc' - -function App() { - const [data, setData] = useState('') - - useEffect(() => { - rpc.callClient('cefReady') - rpc.register('customCefEvent', args => setData(args)) - }, []) - - return ( -
-

Hello World!

-

{data!.toString()}

-
- ) -} - -export default App diff --git a/apps/cef/vite.config.ts b/apps/cef/vite.config.ts deleted file mode 100644 index e84ee6e..0000000 --- a/apps/cef/vite.config.ts +++ /dev/null @@ -1,11 +0,0 @@ -import { defineConfig } from 'vite' -import react from '@vitejs/plugin-react' - -// https://vitejs.dev/config/ -export default defineConfig({ - plugins: [react()], - build: { - outDir: '../../server/client_packages/cef', - emptyOutDir: true - } -}) diff --git a/apps/client/package.json b/apps/client/package.json index b3d2f88..3df349f 100644 --- a/apps/client/package.json +++ b/apps/client/package.json @@ -1,13 +1,14 @@ { "name": "rage-fw-example-client", - "version": "0.1.0", - "author": "Entity Seven Group", - "license": "CC BY-ND", - "description": "Client side of rage-fw example", + "description": "Client side of Rage-FW example", "scripts": { "build": "esbuild src/index.ts --bundle --platform=node --outfile=../../server/client_packages/index.js --format=esm" }, "dependencies": { - "rpc": "workspace:^" - } + "@rage-fw/shared": "workspace:^", + "rage-fw-rpc": "file:../../../rage-framework/rpc" + }, + "license": "CC BY-ND", + "author": "Entity Seven Group", + "version": "0.1.0" } diff --git a/apps/client/src/index.ts b/apps/client/src/index.ts index 24dbb34..70188fe 100644 --- a/apps/client/src/index.ts +++ b/apps/client/src/index.ts @@ -1,15 +1,22 @@ -import { rpc, client } from 'rpc' +import { events } from '@rage-fw/shared' +import { rpc } from './lib' -client.browser = mp.browsers.new('package://cef/index.html') +rpc.browser = mp.browsers.new('package://cef/index.html') -rpc.register('cefReady', async () => { - mp.console.logInfo('cef to client') - - rpc.callServer('customServerEvent', ['client to server']) +rpc.register(events.client.cefReady, async (args: string) => { + mp.console.logInfo(args) + const res = (await rpc.callServer(events.server.customServerEvent, [ + 'hello from client', + ])) as string + mp.console.logInfo(res) + return 'response from client' }) -rpc.register('customClientEvent', async data => { - mp.console.logInfo(JSON.stringify(data)) - - rpc.callBrowser('customCefEvent', ['client to cef']) +rpc.register(events.client.cefReady, async (args: string) => { + mp.console.logInfo(args) + const res = (await rpc.callBrowser(events.browser.customBrowserEvent, [ + 'hello from client', + ])) as string + mp.console.logInfo(res) + return 'response from client' }) diff --git a/apps/client/src/lib/index.ts b/apps/client/src/lib/index.ts new file mode 100644 index 0000000..c936193 --- /dev/null +++ b/apps/client/src/lib/index.ts @@ -0,0 +1,5 @@ +import { Rpc } from 'rage-fw-rpc' + +export const rpc = new Rpc({ + debugLogs: true, +}) diff --git a/apps/rpc/.prettierrc.yaml b/apps/rpc/.prettierrc.yaml deleted file mode 100644 index aa7ff98..0000000 --- a/apps/rpc/.prettierrc.yaml +++ /dev/null @@ -1,6 +0,0 @@ -tabWidth: 4 -printWidth: 80 -singleQuote: true -semi: false -arrowParens: avoid -endOfLine: auto diff --git a/apps/rpc/index.d.ts b/apps/rpc/index.d.ts deleted file mode 100644 index e5d2117..0000000 --- a/apps/rpc/index.d.ts +++ /dev/null @@ -1,22 +0,0 @@ -export {} - -interface Mp { - trigger(event: string, data?: any): void - events: { - add(event: string, data: any): void - call(event: string, data: any): void - callRemote(event: string, data: any): void - } - joaat?: unknown - game: { - joaat?: unknown - } -} - -declare global { - const mp: Mp - const global: Record unknown> - interface Window { - [p: string]: any - } -} diff --git a/apps/rpc/package.json b/apps/rpc/package.json deleted file mode 100644 index 10913d3..0000000 --- a/apps/rpc/package.json +++ /dev/null @@ -1,32 +0,0 @@ -{ - "name": "rpc", - "version": "0.1.0", - "main": "src/index.ts", - "types": "dist/src/index.d.ts", - "scripts": { - "build": "tsup", - "start": "npx ./dist create" - }, - "files": [ - "dist/**/*" - ], - "devDependencies": { - "@microsoft/api-extractor": "^7.47.9", - "prettier": "^3.3.2", - "tsup": "^8.3.0" - }, - "peerDependencies": { - "typescript": "^5.0.0" - }, - "description": "RageFW RPC", - "keywords": [], - "author": "SashaGoncharov19", - "contributors": [ - { - "name": "rilaxik", - "email": "dev.rilaxik@gmail.com", - "url": "https://github.com/rilaxik" - } - ], - "license": "MIT" -} diff --git a/apps/rpc/src/browser.ts b/apps/rpc/src/browser.ts deleted file mode 100644 index 7404729..0000000 --- a/apps/rpc/src/browser.ts +++ /dev/null @@ -1,44 +0,0 @@ -import { Wrapper } from './wrapper' -import { Environment, Errors, Events, RPCState, Utils } from './utils' - -class Browser extends Wrapper { - constructor() { - super() - } - - public resolveEmitDestination(dataRaw: string) { - if (!dataRaw) throw new Error(Errors.NO_DATA) - - let state = Utils.prepareExecution(dataRaw) - - switch (state.calledTo) { - case Environment.BROWSER: - this.emit(dataRaw) - break - - default: - this.emitClient(dataRaw) - break - } - } - - private emitClient(dataRaw: string) { - mp.trigger(Events.LOCAL_EVENT_LISTENER, dataRaw) - } - - private emit(dataRaw: string) { - let state = Utils.prepareExecution(dataRaw) - - state = this.verifyEvent_(state) - if (state.knownError) { - this.triggerError_(state, state.knownError) - return - } - - const { eventName, data } = Utils.prepareExecution(dataRaw) - this.state_[eventName](...data) - } -} - -const browser = new Browser() -export { browser } diff --git a/apps/rpc/src/client.ts b/apps/rpc/src/client.ts deleted file mode 100644 index 7299f0a..0000000 --- a/apps/rpc/src/client.ts +++ /dev/null @@ -1,67 +0,0 @@ -import { Wrapper } from './wrapper' -import { Environment, Errors, Events, Utils } from './utils' -import type { RPCState } from './utils' - -class Client extends Wrapper { - private _browser: any = null - - constructor() { - super() - } - - set browser(browser: any) { - this._browser = browser - } - - public resolveEmitDestination(dataRaw: string) { - if (!dataRaw) throw new Error(Errors.NO_DATA) - - const state = Utils.prepareExecution(dataRaw) - - switch (state.calledTo) { - case Environment.SERVER: - this.emitServer(dataRaw) - break - - case Environment.BROWSER: - this.emitBrowser(dataRaw, state) - break - - case Environment.CLIENT: - this.emit(state) - break - - default: - this.triggerError_(state, Errors.UNKNOWN_ENVIRONMENT) - break - } - } - - private emit(state: RPCState) { - state = this.verifyEvent_(state) - if (state.knownError) { - this.triggerError_(state, state.knownError) - return - } - - this.state_[state.eventName]( - ...(Array.isArray(state.data) ? state.data : []), - ) - } - - private emitServer(dataRaw: string) { - mp.events.callRemote(Events.SERVER_EVENT_LISTENER, dataRaw) - } - - private emitBrowser(dataRaw: string, state: RPCState) { - if (!this._browser) { - this.triggerError_(state, Errors.NO_BROWSER) - return - } - - this._browser.call(Events.LOCAL_EVENT_LISTENER, dataRaw) - } -} - -const client = new Client() -export { client } diff --git a/apps/rpc/src/index.ts b/apps/rpc/src/index.ts deleted file mode 100644 index e5b7982..0000000 --- a/apps/rpc/src/index.ts +++ /dev/null @@ -1,225 +0,0 @@ -import { Wrapper } from './wrapper' -import { - Environment, - Errors, - Events, - RPCState, - Utils, - type PlayerMp, -} from './utils' - -import { server } from './server' -import { client } from './client' -import { browser } from './browser' - -export { server } from './server' -export { client } from './client' -export { browser } from './browser' - -class Rpc extends Wrapper { - constructor() { - super() - - if (this.environment_ === Environment.UNKNOWN) - throw new Error(Errors.UNKNOWN_ENVIRONMENT) - - mp.events.add( - Events.LOCAL_EVENT_LISTENER, - async (player: PlayerMp | string, dataRaw: string) => { - switch (this.environment_) { - case Environment.SERVER: - server.resolveEmitDestination( - player as PlayerMp, - dataRaw, - ) - break - - case Environment.CLIENT: - dataRaw = player as string - client.resolveEmitDestination(dataRaw) - break - - case Environment.BROWSER: - dataRaw = player as string - browser.resolveEmitDestination(dataRaw) - break - - default: - void { player, dataRaw } - break - } - }, - ) - } - - public register< - CallbackArguments extends unknown[] = unknown[], - CallbackReturn extends unknown = unknown, - EventName extends string = string, - >( - eventName: EventName, - cb: (...args: CallbackArguments) => CallbackReturn, - ): void { - Utils.errorUnknownEnvironment(this.environment_) - - this.state_[eventName] = cb - } - - public unregister( - eventName: EventName, - ): void { - Utils.errorUnknownEnvironment(this.environment_) - - delete this.state_[eventName] - } - - public callClient< - Arguments extends unknown[] = unknown[], - EventName extends string = string, - >(eventName: EventName, args?: Arguments): void - public callClient< - Arguments extends unknown[] = unknown[], - EventName extends string = string, - >(player: PlayerMp, eventName: EventName, args?: Arguments): void - public callClient( - playerOrEventName: PlayerMp | string, - eventNameOrArgs?: string | unknown[], - args?: unknown[], - ): void { - Utils.errorUnknownEnvironment(this.environment_) - - function _is1StParamPlayer(x: unknown): x is PlayerMp { - return typeof x === 'object' - } - function _is2NdParamEventName(x: unknown): x is string { - return !Array.isArray(x) && typeof x === 'string' - } - - // client - if (this.environment_ === Environment.CLIENT) { - this.call(playerOrEventName as string, args as unknown[]) - return - } - - // server - if ( - this.environment_ === Environment.SERVER && - _is1StParamPlayer(playerOrEventName) && - _is2NdParamEventName(eventNameOrArgs) - ) { - const state: RPCState = { - uuid: Utils.generateUUID(), - eventName: eventNameOrArgs, - calledTo: Environment.CLIENT, - calledFrom: this.environment_, - knownError: undefined, - data: args as unknown[], - } - - const dataRaw = Utils.prepareTransfer(state) - - playerOrEventName.call(Events.LOCAL_EVENT_LISTENER, [dataRaw]) - return - } - - // browser - if ( - this.environment_ === Environment.BROWSER && - !_is1StParamPlayer(playerOrEventName) && - !_is2NdParamEventName(eventNameOrArgs) - ) { - const state: RPCState = { - uuid: Utils.generateUUID(), - eventName: playerOrEventName, - calledTo: Environment.CLIENT, - calledFrom: this.environment_, - knownError: undefined, - data: eventNameOrArgs, - } - - const dataRaw = Utils.prepareTransfer(state) - - mp.trigger(Events.LOCAL_EVENT_LISTENER, dataRaw) - return - } - } - - public callServer< - Arguments extends unknown[] = unknown[], - EventName extends string = string, - >(eventName: EventName, args?: Arguments) { - Utils.errorUnknownEnvironment(this.environment_) - - const state: RPCState = { - uuid: Utils.generateUUID(), - eventName, - calledTo: Environment.SERVER, - calledFrom: this.environment_, - knownError: undefined, - data: args, - } - - if (state.calledFrom === Environment.SERVER) { - this.callSelf(state) - } else { - const dataRaw = Utils.prepareTransfer(state) - - mp.events.call(Events.LOCAL_EVENT_LISTENER, dataRaw) - } - } - - public callBrowser< - Arguments extends unknown[] = unknown[], - EventName extends string = string, - >(eventName: EventName, args?: Arguments) { - Utils.errorUnknownEnvironment(this.environment_) - - const state: RPCState = { - uuid: Utils.generateUUID(), - eventName, - calledTo: Environment.BROWSER, - calledFrom: this.environment_, - knownError: undefined, - data: args, - } - - if (state.calledFrom === Environment.BROWSER) { - this.callSelf(state) - } else { - const dataRaw = Utils.prepareTransfer(state) - - mp.events.call(Events.LOCAL_EVENT_LISTENER, dataRaw) - } - } - - public call< - Arguments extends unknown[] = unknown[], - EventName extends string = string, - >(eventName: EventName, args?: Arguments) { - Utils.errorUnknownEnvironment(this.environment_) - - let state: RPCState = { - uuid: Utils.generateUUID(), - eventName, - calledTo: this.environment_, - calledFrom: this.environment_, - knownError: undefined, - data: args, - } - - this.callSelf(state) - } - - private callSelf(state: RPCState) { - state = this.verifyEvent_(state) - if (state.knownError) { - this.triggerError_(state, state.knownError) - return - } - - this.state_[state.eventName](...state.data) - } -} - -const rpc = new Rpc() -export { rpc } diff --git a/apps/rpc/src/server.ts b/apps/rpc/src/server.ts deleted file mode 100644 index c453d3a..0000000 --- a/apps/rpc/src/server.ts +++ /dev/null @@ -1,49 +0,0 @@ -import { Wrapper } from './wrapper' -import { Environment, Events, Utils, type PlayerMp } from './utils' - -class Server extends Wrapper { - constructor() { - super() - - mp.events.add( - Events.SERVER_EVENT_LISTENER, - async (player: PlayerMp, dataRaw: string) => { - this.emit(player, dataRaw) - }, - ) - } - - public resolveEmitDestination(player: PlayerMp, dataRaw: string) { - let state = Utils.prepareExecution(dataRaw) - - switch (state.calledTo) { - case Environment.SERVER: - this.emit(player, dataRaw) - break - - default: - this.emitClient(player as PlayerMp, dataRaw) - break - } - } - - private emitClient(player: PlayerMp, dataRaw: string) { - player.call(Events.LOCAL_EVENT_LISTENER, [dataRaw]) - } - - private emit(player: PlayerMp, dataRaw: string) { - let state = Utils.prepareExecution(dataRaw) - - state = this.verifyEvent_(state) - if (state.knownError) { - this.triggerError_(state, state.knownError) - return - } - - const { eventName, data } = Utils.prepareExecution(dataRaw) - this.state_[eventName](player, ...data) - } -} - -const server = new Server() -export { server } diff --git a/apps/rpc/src/utils.ts b/apps/rpc/src/utils.ts deleted file mode 100644 index 958a703..0000000 --- a/apps/rpc/src/utils.ts +++ /dev/null @@ -1,82 +0,0 @@ -export enum Environment { - BROWSER = 'BROWSER', - CLIENT = 'CLIENT', - SERVER = 'SERVER', - UNKNOWN = 'UNKNOWN', -} - -export enum Events { - LOCAL_EVENT_LISTENER = '__rpc:listener', - CLIENT_EVENT_LISTENER = '__rpc:clientListener', - SERVER_EVENT_LISTENER = '__rpc:serverListener', - EVENT_RESPONSE = '__rpc:response', -} - -export enum Errors { - EVENT_NOT_REGISTERED = 'Event not registered', - UNKNOWN_ENVIRONMENT = 'Unknown environment', - NO_DATA = 'No data', - NO_BROWSER = 'You need to initialize browser first', -} - -export class Utils { - public static getEnvironment(): Environment { - if ('joaat' in mp) return Environment.SERVER - if ( - 'game' in mp && - 'joaat' in (mp as { game: { joaat?: unknown } }).game - ) - return Environment.CLIENT - if (window && 'mp' in window) return Environment.BROWSER - return Environment.UNKNOWN - } - - public static prepareExecution(data: string): RPCState { - return JSON.parse(data) - } - - public static prepareTransfer(data: RPCState): string { - return JSON.stringify(data) - } - - public static generateUUID(): string { - let uuid = '', - random - - for (let i = 0; i < 32; i++) { - random = (Math.random() * 16) | 0 - - if (i === 8 || i === 12 || i === 16 || i === 20) { - uuid += '-' - } - - uuid += ( - i === 12 ? 4 : i === 16 ? (random & 3) | 8 : random - ).toString(16) - } - - return uuid - } - - public static generateResponseEventName(uuid: string): string { - return `${Events.EVENT_RESPONSE}_${uuid}` - } - - public static errorUnknownEnvironment(environment: Environment) { - if (environment === Environment.UNKNOWN) - throw new Error(Errors.UNKNOWN_ENVIRONMENT) - } -} - -export type RPCState = { - eventName: string - uuid: string - knownError?: string - data?: any - calledFrom: Environment - calledTo: Environment -} - -export type PlayerMp = { - call(event: string, args?: unknown[]): void -} diff --git a/apps/rpc/src/wrapper.ts b/apps/rpc/src/wrapper.ts deleted file mode 100644 index b5d75cf..0000000 --- a/apps/rpc/src/wrapper.ts +++ /dev/null @@ -1,33 +0,0 @@ -import { Environment, Errors, RPCState, Utils } from './utils' - -export class Wrapper { - protected environment_ = Utils.getEnvironment() - protected state_ = - this.environment_ === Environment.BROWSER ? window : global - - protected verifyEvent_(data: string | RPCState): RPCState { - let rpcData = - typeof data === 'string' ? Utils.prepareExecution(data) : data - - if (!this.state_[rpcData.eventName]) { - rpcData.knownError = Errors.EVENT_NOT_REGISTERED - } - - return rpcData - } - - protected triggerError_(rpcData: RPCState, error?: any) { - const errorMessage = [ - `${rpcData.knownError}`, - `Caller: ${rpcData.calledFrom}`, - `Receiver: ${this.environment_}`, - `Event: ${rpcData.eventName}`, - ] - - if (error) { - errorMessage.push(`Additional Info: ${error}`) - } - - throw new Error(errorMessage.join('\n | ')) - } -} diff --git a/apps/rpc/tsconfig.json b/apps/rpc/tsconfig.json deleted file mode 100644 index 7f0dfdc..0000000 --- a/apps/rpc/tsconfig.json +++ /dev/null @@ -1,29 +0,0 @@ -{ - "compilerOptions": { - "target": "es6", - "module": "commonjs", - "moduleResolution": "node", - "lib": [ - "ES6", - "dom" - ], - "declaration": true, - "declarationMap": true, - "sourceMap": true, - - "outDir": "bin", - "esModuleInterop": true, - - "strict": true, - "forceConsistentCasingInFileNames": true, - "noImplicitAny": true, - }, - "include": [ - "src/**/*", - "./index.d.ts" - ], - "exclude": [ - "node_modules", - "dist" - ] -} \ No newline at end of file diff --git a/apps/rpc/tsup.config.ts b/apps/rpc/tsup.config.ts deleted file mode 100644 index b1987c1..0000000 --- a/apps/rpc/tsup.config.ts +++ /dev/null @@ -1,11 +0,0 @@ -import { defineConfig } from 'tsup' - -export default defineConfig({ - entry: ['src/index.ts'], - outDir: './dist', - format: ['cjs'], - experimentalDts: true, - splitting: false, - sourcemap: false, - clean: true, -}) diff --git a/apps/server/package.json b/apps/server/package.json index 5bc860e..89cd32b 100644 --- a/apps/server/package.json +++ b/apps/server/package.json @@ -1,13 +1,14 @@ { "name": "rage-fw-example-server", - "version": "0.1.0", - "author": "Entity Seven Group", - "license": "CC BY-ND", - "description": "Server side of rage-fw example", + "description": "Server side of Rage-FW example", "scripts": { "build": "esbuild src/index.ts --bundle --platform=node --target=node10.4 --outfile=../../server/packages/server/index.js" }, "dependencies": { - "rpc": "workspace:^" - } + "@rage-fw/shared": "workspace:^", + "rage-fw-rpc": "file:../../../rage-framework/rpc" + }, + "license": "CC BY-ND", + "author": "Entity Seven Group", + "version": "0.1.0" } diff --git a/apps/server/src/index.ts b/apps/server/src/index.ts index 6cf6673..8013154 100644 --- a/apps/server/src/index.ts +++ b/apps/server/src/index.ts @@ -1,11 +1,20 @@ -import { rpc } from 'rpc' +import { events } from '@rage-fw/shared' +import { rpc } from './lib' rpc.register('playerJoin', async (player: PlayerMp) => { - console.log(`Connected: ${player.socialClub}`) + console.log(`[Server] ${player.socialClub} connected`) }) -rpc.register('customServerEvent', (player: PlayerMp, data) => { - console.log(player, data) - - rpc.callClient(player, 'customClientEvent', ['server to client']) -}) +rpc.register( + events.server.customServerEvent, + async (player: PlayerMp, args: string) => { + console.log(args) + const res = await rpc.callClient( + player, + events.client.customClientEvent, + ['hello from server'], + ) + console.log(res) + return 'response from server' + }, +) diff --git a/apps/server/src/lib/index.ts b/apps/server/src/lib/index.ts new file mode 100644 index 0000000..c936193 --- /dev/null +++ b/apps/server/src/lib/index.ts @@ -0,0 +1,5 @@ +import { Rpc } from 'rage-fw-rpc' + +export const rpc = new Rpc({ + debugLogs: true, +}) diff --git a/apps/shared/declarations/rage-fw-shared-types/index.d.ts b/apps/shared/declarations/rage-fw-shared-types/index.d.ts deleted file mode 100644 index a5e414e..0000000 --- a/apps/shared/declarations/rage-fw-shared-types/index.d.ts +++ /dev/null @@ -1,13 +0,0 @@ -declare module 'rage-fw-shared-types' { - export interface RageFW_ICustomClientEvent { - customClientEvent(greetings: string): void - } - - export interface RageFW_ICustomServerEvent { - customServerEvent(greetings: string): void - } - - export interface RageFW_ICustomCefEvent { - customCefEvent(greetings: string): void - } -} diff --git a/apps/shared/index.ts b/apps/shared/index.ts new file mode 100644 index 0000000..47abdc9 --- /dev/null +++ b/apps/shared/index.ts @@ -0,0 +1,12 @@ +export const events = { + server: { + customServerEvent: 'customServerEvent', + }, + client: { + cefReady: 'cefReady', + customClientEvent: 'customClientEvent', + }, + browser: { + customBrowserEvent: 'customBrowserEvent', + }, +} diff --git a/apps/shared/package.json b/apps/shared/package.json new file mode 100644 index 0000000..d2d616b --- /dev/null +++ b/apps/shared/package.json @@ -0,0 +1,6 @@ +{ + "name": "@rage-fw/shared", + "description": "Shared data for Rage-FW example", + "version": "0.1.0", + "main": "index.ts" +} diff --git a/package.json b/package.json index 82f938d..77ad83d 100644 --- a/package.json +++ b/package.json @@ -1,29 +1,30 @@ { "name": "framework-example", - "version": "0.1.0", - "author": "Entity Seven Group", - "license": "CC BY-ND", - "description": "This project is example of RAGE FW usage.", + "description": "This project is an example of RAGE-FW usage", + "workspaces": [ + "apps/*" + ], "scripts": { "server:update": "cd server && rage-win64.exe", - - "i:client": "cd apps/client && pnpm i rpc", - "i:server": "cd apps/server && pnpm i rpc", - "i:cef": "cd apps/cef && pnpm i rpc", - "i:all": "pnpm i:client && pnpm i:server && pnpm i:cef", - + "server:run": "cd server && ragemp-server.exe", + "i:client": "cd apps/client && pnpm i", + "i:server": "cd apps/server && pnpm i", + "i:browser": "cd apps/browser && pnpm i", "build:client": "cd apps/client && pnpm build", "build:server": "cd apps/server && pnpm build", - "build:cef": "cd apps/cef && pnpm build", - "build:all": "pnpm build:client && pnpm build:server && pnpm build:cef" + "build:browser": "cd apps/cef && pnpm build", + "build:all": "pnpm build:client && pnpm build:server && pnpm build:browser", + "build": "pnpm build:all" }, "devDependencies": { "@ragempcommunity/types-client": "^2.1.8", "@ragempcommunity/types-server": "^2.1.8", "@ragempcommunity/types-cef": "^2.1.8", - "rage-fw-shared-types": "latest", "esbuild": "^0.21.5", "typescript": "^5.4.5", "prettier": "^3.3.2" - } + }, + "license": "CC BY-ND", + "author": "Entity Seven Group", + "version": "0.1.0" } diff --git a/pnpm-workspace.yaml b/pnpm-workspace.yaml index 85b7e6f..06b6051 100644 --- a/pnpm-workspace.yaml +++ b/pnpm-workspace.yaml @@ -1,6 +1,2 @@ packages: - - "apps/cef" - - "apps/client" - - "apps/server" - - "apps/shared" - - "apps/rpc" \ No newline at end of file + - "apps/*"