6 Commits
Author SHA1 Message Date
rilaxik 2a3e9ab6ad upd deps 2024-10-30 20:03:31 +00:00
rilaxik b53177903e upd path fix 2024-10-28 10:54:40 +00:00
rilaxik e7e423adc6 feat pure rpc example 2024-10-28 10:28:56 +00:00
rilaxik 67be91538b upd
- rpc generics
- some internal types to expose from rpc
2024-10-03 23:11:39 +01:00
rilaxik f8dd4d9fce upd
- added all non-jumping calls (cef <=> client, client <=> server)
- added @ragempcommunity types (todo)
2024-10-03 18:59:41 +01:00
rilaxik 092693acb5 rpc test 2024-10-03 12:56:21 +01:00
19 changed files with 138 additions and 120 deletions
+8 -3
View File
@@ -1,8 +1,8 @@
# Editor # Editor
.vscode .vscode/
.idea .idea/
.git .git/
# Server Files # Server Files
server/bin server/bin
@@ -18,3 +18,8 @@ server/ragemp-server.exe
# Development # Development
node_modules node_modules
pnpm-lock.yaml pnpm-lock.yaml
# Build
build/
dist/
out/
+10 -10
View File
@@ -1,10 +1,6 @@
{ {
"name": "rage-fw-example-browser", "name": "rage-fw-example-browser",
"version": "0.0.0", "description": "Browser side of Rage-FW example",
"type": "module",
"author": "Entity Seven Group",
"license": "MIT",
"description": "Browser side of rage-fw-example",
"scripts": { "scripts": {
"dev": "vite", "dev": "vite",
"build": "tsc && vite build", "build": "tsc && vite build",
@@ -12,8 +8,8 @@
"preview": "vite preview" "preview": "vite preview"
}, },
"dependencies": { "dependencies": {
"@entityseven/rage-fw-rpc": "workspace:*", "@entityseven/rage-fw-rpc": "0.2.5",
"@entityseven/rage-fw-browser": "workspace:*", "@rage-fw/shared": "workspace:^",
"react": "^18.2.0", "react": "^18.2.0",
"react-dom": "^18.2.0" "react-dom": "^18.2.0"
}, },
@@ -26,7 +22,11 @@
"eslint": "^8.57.0", "eslint": "^8.57.0",
"eslint-plugin-react-hooks": "^4.6.0", "eslint-plugin-react-hooks": "^4.6.0",
"eslint-plugin-react-refresh": "^0.4.6", "eslint-plugin-react-refresh": "^0.4.6",
"typescript": "^5.7.3", "typescript": "^5.6.3",
"vite": "^5.2.0" "vite": "^5.4.10"
} },
"type": "module",
"license": "CC BY-ND",
"author": "Entity Seven Group",
"version": "0.1.0"
} }
+7 -11
View File
@@ -1,20 +1,16 @@
import { fw } from '@entityseven/rage-fw-browser'
import { useEffect, useState } from 'react' import { useEffect, useState } from 'react'
import { events } from '@rage-fw/shared'
import { rpc } from '@/lib'
function App() { function App() {
const [data, setData] = useState('initial') const [data, setData] = useState<string>('')
useEffect(() => { useEffect(() => {
fw.event.register('customBrowserEvent', async message => { rpc.register(events.browser.customBrowserEvent, (args: string) => {
setData(p => p + ' | ' + message) setData(prev => prev + ' | ' + args)
return 'response from cef'
const response = await fw.event.triggerServer('customServerEvent', [
'hello from browser',
])
setData(p => p + ' | ' + response)
return 'response from browser'
}) })
rpc.callClient(events.client.cefReady, ['hello from cef'])
}, []) }, [])
return ( return (
+5
View File
@@ -0,0 +1,5 @@
import { Rpc } from '@entityseven/rage-fw-rpc'
export const rpc = new Rpc({
debugLogs: true,
})
+5 -1
View File
@@ -22,7 +22,11 @@
"types": [ "types": [
"../../node_modules/@ragempcommunity/types-cef", "../../node_modules/@ragempcommunity/types-cef",
"../shared/declarations/rage-fw-shared-types/" "../shared/declarations/rage-fw-shared-types/"
] ],
"paths": {
"@": ["./src"],
"@/*": ["./src/*"],
}
}, },
"include": ["src"], "include": ["src"],
"references": [{ "path": "./tsconfig.node.json" }] "references": [{ "path": "./tsconfig.node.json" }]
+11 -5
View File
@@ -3,9 +3,15 @@ import react from '@vitejs/plugin-react'
// https://vitejs.dev/config/ // https://vitejs.dev/config/
export default defineConfig({ export default defineConfig({
plugins: [react()], plugins: [react()],
build: { build: {
outDir: '../../server/client_packages/cef', outDir: '../../server/client_packages/cef',
emptyOutDir: true emptyOutDir: true,
} },
resolve: {
alias: {
'@': './src',
'@/*': './src/*',
},
},
}) })
+7 -7
View File
@@ -1,14 +1,14 @@
{ {
"name": "rage-fw-example-client", "name": "rage-fw-example-client",
"version": "0.1.0", "description": "Client side of Rage-FW example",
"author": "Entity Seven Group",
"license": "MIT",
"description": "Client side of rage-fw-example",
"scripts": { "scripts": {
"build": "esbuild src/index.ts --bundle --platform=node --outfile=../../server/client_packages/index.js --format=esm" "build": "esbuild src/index.ts --bundle --platform=node --outfile=../../server/client_packages/index.js --format=esm"
}, },
"dependencies": { "dependencies": {
"@entityseven/rage-fw-rpc": "workspace:*", "@entityseven/rage-fw-rpc": "0.2.5",
"@entityseven/rage-fw-client": "workspace:*" "@rage-fw/shared": "workspace:^"
} },
"license": "CC BY-ND",
"author": "Entity Seven Group",
"version": "0.1.0"
} }
+16 -8
View File
@@ -1,14 +1,22 @@
import { fw } from '@entityseven/rage-fw-client' import { events } from '@rage-fw/shared'
import { rpc } from './lib'
fw.player.browser = mp.browsers.new('package://cef/index.html') rpc.browser = mp.browsers.new('package://cef/index.html')
fw.event.register('customClientEvent', async msg => { rpc.register(events.client.cefReady, async (args: string) => {
fw.system.log.info(msg) mp.console.logInfo(args)
const res = (await rpc.callServer(events.server.customServerEvent, [
const response = await fw.player.triggerBrowser('customBrowserEvent', [
'hello from client', 'hello from client',
]) ])) as string
fw.system.log.info(response) mp.console.logInfo(res)
return 'response from client'
})
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' return 'response from client'
}) })
+5
View File
@@ -0,0 +1,5 @@
import { Rpc } from '@entityseven/rage-fw-rpc'
export const rpc = new Rpc({
debugLogs: true,
})
+7 -7
View File
@@ -1,14 +1,14 @@
{ {
"name": "rage-fw-example-server", "name": "rage-fw-example-server",
"version": "0.1.0", "description": "Server side of Rage-FW example",
"author": "Entity Seven Group",
"license": "MIT",
"description": "Server side of rage-fw-example",
"scripts": { "scripts": {
"build": "esbuild src/index.ts --bundle --platform=node --target=node10.4 --outfile=../../server/packages/server/index.js" "build": "esbuild src/index.ts --bundle --platform=node --target=node10.4 --outfile=../../server/packages/server/index.js"
}, },
"dependencies": { "dependencies": {
"@entityseven/rage-fw-rpc": "workspace:*", "@entityseven/rage-fw-rpc": "0.2.5",
"@entityseven/rage-fw-server": "workspace:*" "@rage-fw/shared": "workspace:^"
} },
"license": "CC BY-ND",
"author": "Entity Seven Group",
"version": "0.1.0"
} }
+17 -22
View File
@@ -1,25 +1,20 @@
import { fw } from '@entityseven/rage-fw-server' import { events } from '@rage-fw/shared'
import { rpc } from './lib'
fw.event.register('playerJoin', async player => { rpc.register('playerJoin', async (player: PlayerMp) => {
fw.system.log.info('Connected:', player.socialClub) console.log(`[Server] ${player.socialClub} connected`)
const response = await fw.player.triggerClient(
player,
'customClientEvent',
['hello from server'],
)
fw.system.log.info(response)
}) })
fw.event.register('customServerEvent', async (player, msg) => { rpc.register(
fw.system.log.info(player.socialClub, msg) events.server.customServerEvent,
async (player: PlayerMp, args: string) => {
const response = await fw.player.triggerBrowser( console.log(args)
player, const res = await rpc.callClient(
'customBrowserEvent', player,
['hello from server'], events.client.customClientEvent,
) ['hello from server'],
fw.system.log.info(player.socialClub, response) )
console.log(res)
return 'response from server' return 'response from server'
}) },
)
+5
View File
@@ -0,0 +1,5 @@
import { Rpc } from '@entityseven/rage-fw-rpc'
export const rpc = new Rpc({
debugLogs: true,
})
+1
View File
@@ -1,6 +1,7 @@
{ {
"extends": "../../tsconfig.json", "extends": "../../tsconfig.json",
"compilerOptions": { "compilerOptions": {
"lib": ["DOM", "ESNext"],
"resolveJsonModule": true, "resolveJsonModule": true,
"baseUrl": "./src", "baseUrl": "./src",
"types": [ "types": [
@@ -1,13 +0,0 @@
declare module '@entityseven/rage-fw-shared-types' {
export interface RageFW_ICustomClientEvent {
customClientEvent(greetings: string): string
}
export interface RageFW_ICustomServerEvent {
customServerEvent(greetings: string): string
}
export interface RageFW_ICustomBrowserEvent {
customBrowserEvent(greetings: string): string
}
}
+12
View File
@@ -0,0 +1,12 @@
export const events = {
server: {
customServerEvent: 'customServerEvent',
},
client: {
cefReady: 'cefReady',
customClientEvent: 'customClientEvent',
},
browser: {
customBrowserEvent: 'customBrowserEvent',
},
}
+6
View File
@@ -0,0 +1,6 @@
{
"name": "@rage-fw/shared",
"description": "Shared data for Rage-FW example",
"version": "0.1.0",
"main": "index.ts"
}
+13 -27
View File
@@ -1,44 +1,30 @@
{ {
"name": "framework-example", "name": "framework-example",
"description": "This project is example of RAGE FW usage.", "description": "This project is an example of RAGE FW usage",
"workspaces": [ "workspaces": [
"apps/*" "apps/*"
], ],
"scripts": { "scripts": {
"server:update": "cd server && rage-win64.exe", "server:update": "cd server && rage-win64.exe",
"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:client": "cd apps/client && pnpm build",
"build:server": "cd apps/server && pnpm build", "build:server": "cd apps/server && pnpm build",
"build:browser": "cd apps/browser && pnpm build", "build:browser": "cd apps/cef && pnpm build",
"build:all": "pnpm build:client && pnpm build:server && pnpm build:browser" "build:all": "pnpm build:client && pnpm build:server && pnpm build:browser",
"build": "pnpm build:all"
}, },
"devDependencies": { "devDependencies": {
"@ragempcommunity/types-cef": "^2.1.8",
"@ragempcommunity/types-client": "^2.1.8", "@ragempcommunity/types-client": "^2.1.8",
"@ragempcommunity/types-server": "^2.1.8", "@ragempcommunity/types-server": "^2.1.8",
"@ragempcommunity/types-cef": "^2.1.8",
"esbuild": "^0.21.5", "esbuild": "^0.21.5",
"prettier": "^3.3.2", "typescript": "^5.4.5",
"typescript": "^5.7.3" "prettier": "^3.3.2"
}, },
"author": "Entity Seven Group",
"license": "MIT", "license": "MIT",
"version": "0.1.0", "author": "Entity Seven Group",
"pnpm": { "version": "0.1.0"
"onlyBuiltDependencies": [
"esbuild"
],
"overrides": {
"@entityseven/rage-fw-rpc": "link:..\\rage-framework\\rpc",
"@entityseven/rage-fw-browser": "link:..\\rage-framework\\browser",
"@entityseven/rage-fw-client": "link:..\\rage-framework\\client",
"@entityseven/rage-fw-server": "link:..\\rage-framework\\server",
"@entityseven/rage-fw-shared-types": "link:..\\rage-framework\\shared-types"
}
},
"dependencies": {
"@entityseven/rage-fw-browser": "link:..\\rage-framework\\browser",
"@entityseven/rage-fw-client": "link:..\\rage-framework\\client",
"@entityseven/rage-fw-rpc": "link:..\\rage-framework\\rpc",
"@entityseven/rage-fw-server": "link:..\\rage-framework\\server",
"@entityseven/rage-fw-shared-types": "link:..\\rage-framework\\shared-types"
}
} }
+1 -4
View File
@@ -1,5 +1,2 @@
packages: packages:
- "apps/browser" - "apps/*"
- "apps/client"
- "apps/server"
- "apps/shared"
+1 -1
View File
@@ -2,7 +2,7 @@
"compilerOptions": { "compilerOptions": {
"target": "ESNext", "target": "ESNext",
"lib": ["ESNext", "ES2019"], "lib": ["ESNext", "ES2019"],
"moduleResolution": "bundler", "moduleResolution": "node",
"module": "ESNext", "module": "ESNext",
"resolveJsonModule": true, "resolveJsonModule": true,
"esModuleInterop": true, "esModuleInterop": true,