Compare commits

..

1 Commits

Author SHA1 Message Date
81639386e5 upd cef -> browser 2024-10-28 11:58:57 +00:00
18 changed files with 86 additions and 141 deletions

11
.gitignore vendored
View File

@ -1,8 +1,8 @@
# Editor # Editor
.vscode/ .vscode
.idea/ .idea
.git/ .git
# Server Files # Server Files
server/bin server/bin
@ -18,8 +18,3 @@ server/ragemp-server.exe
# Development # Development
node_modules node_modules
pnpm-lock.yaml pnpm-lock.yaml
# Build
build/
dist/
out/

View File

@ -1,6 +1,10 @@
{ {
"name": "rage-fw-example-browser", "name": "rage-fw-example-cef",
"description": "Browser side of Rage-FW example", "version": "0.0.0",
"type": "module",
"author": "Entity Seven Group",
"license": "CC BY-ND",
"description": "CEF side of rage-fw example",
"scripts": { "scripts": {
"dev": "vite", "dev": "vite",
"build": "tsc && vite build", "build": "tsc && vite build",
@ -8,10 +12,9 @@
"preview": "vite preview" "preview": "vite preview"
}, },
"dependencies": { "dependencies": {
"@entityseven/rage-fw-rpc": "0.2.5",
"@rage-fw/shared": "workspace:^",
"react": "^18.2.0", "react": "^18.2.0",
"react-dom": "^18.2.0" "react-dom": "^18.2.0",
"rage-fw-cef": "latest"
}, },
"devDependencies": { "devDependencies": {
"@types/react": "^18.2.66", "@types/react": "^18.2.66",
@ -22,11 +25,7 @@
"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.6.3", "typescript": "^5.2.2",
"vite": "^5.4.10" "vite": "^5.2.0"
}, }
"type": "module",
"license": "CC BY-ND",
"author": "Entity Seven Group",
"version": "0.1.0"
} }

View File

@ -1,16 +1,14 @@
import { fw } from 'rage-fw-cef'
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<string>('') const [data, setData] = useState('')
useEffect(() => { useEffect(() => {
rpc.register(events.browser.customBrowserEvent, (args: string) => { fw.event.register('customCefEvent', async ([test]) => {
setData(prev => prev + ' | ' + args) setData(p => p + ' ' + test)
return 'response from cef' return 'from cef'
}) })
rpc.callClient(events.client.cefReady, ['hello from cef'])
}, []) }, [])
return ( return (

View File

@ -1,5 +0,0 @@
import { Rpc } from '@entityseven/rage-fw-rpc'
export const rpc = new Rpc({
debugLogs: true,
})

View File

@ -22,11 +22,7 @@
"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" }]

View File

@ -3,15 +3,9 @@ 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/*',
},
},
}) })

View File

@ -1,14 +1,13 @@
{ {
"name": "rage-fw-example-client", "name": "rage-fw-example-client",
"description": "Client side of Rage-FW example", "version": "0.1.0",
"author": "Entity Seven Group",
"license": "CC BY-ND",
"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": "0.2.5", "rage-fw-client": "latest"
"@rage-fw/shared": "workspace:^" }
},
"license": "CC BY-ND",
"author": "Entity Seven Group",
"version": "0.1.0"
} }

View File

@ -1,22 +1,14 @@
import { events } from '@rage-fw/shared' import { fw } from 'rage-fw-client'
import { rpc } from './lib'
rpc.browser = mp.browsers.new('package://cef/index.html') fw.player.browser = mp.browsers.new('package://cef/index.html')
rpc.register(events.client.cefReady, async (args: string) => { fw.event.register('cefReady', async () => {
mp.console.logInfo(args) fw.system.log.info('cefReady')
const res = (await rpc.callServer(events.server.customServerEvent, [
'hello from client', const responseCef = await fw.player.triggerBrowser('customCefEvent', [
])) as string 'from client',
mp.console.logInfo(res) ])
return 'response from client' fw.system.log.info(responseCef)
})
await fw.player.triggerServer('customServerEvent', ['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'
}) })

View File

@ -1,5 +0,0 @@
import { Rpc } from '@entityseven/rage-fw-rpc'
export const rpc = new Rpc({
debugLogs: true,
})

View File

@ -1,14 +1,13 @@
{ {
"name": "rage-fw-example-server", "name": "rage-fw-example-server",
"description": "Server side of Rage-FW example", "version": "0.1.0",
"author": "Entity Seven Group",
"license": "CC BY-ND",
"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": "0.2.5", "rage-fw-server": "latest"
"@rage-fw/shared": "workspace:^" }
},
"license": "CC BY-ND",
"author": "Entity Seven Group",
"version": "0.1.0"
} }

View File

@ -1,20 +1,18 @@
import { events } from '@rage-fw/shared' import { fw } from 'rage-fw-server'
import { rpc } from './lib'
rpc.register('playerJoin', async (player: PlayerMp) => { fw.event.register('playerJoin', async ([player]) => {
console.log(`[Server] ${player.socialClub} connected`) fw.system.log.info(`Connected: ${player.socialClub}`)
}) })
rpc.register( fw.event.register('customServerEvent', async ([player, msg]) => {
events.server.customServerEvent, fw.system.log.info(player.socialClub + ' ' + msg)
async (player: PlayerMp, args: string) => {
console.log(args) const resFromCef = await fw.player.triggerBrowser(
const res = await rpc.callClient( player,
player, 'customCefEvent',
events.client.customClientEvent, ['from server'],
['hello from server'], )
) fw.system.log.info(player.socialClub + ' ' + resFromCef)
console.log(res)
return 'response from server' return 'from server'
}, })
)

View File

@ -1,5 +0,0 @@
import { Rpc } from '@entityseven/rage-fw-rpc'
export const rpc = new Rpc({
debugLogs: true,
})

View File

@ -1,7 +1,6 @@
{ {
"extends": "../../tsconfig.json", "extends": "../../tsconfig.json",
"compilerOptions": { "compilerOptions": {
"lib": ["DOM", "ESNext"],
"resolveJsonModule": true, "resolveJsonModule": true,
"baseUrl": "./src", "baseUrl": "./src",
"types": [ "types": [

View File

@ -0,0 +1,11 @@
declare module 'rage-fw-shared-types' {
export interface RageFW_ICustomClientEvent {}
export interface RageFW_ICustomServerEvent {
customServerEvent(greetings: string): string
}
export interface RageFW_ICustomCefEvent {
customCefEvent(greetings: string): string
}
}

View File

@ -1,12 +0,0 @@
export const events = {
server: {
customServerEvent: 'customServerEvent',
},
client: {
cefReady: 'cefReady',
customClientEvent: 'customClientEvent',
},
browser: {
customBrowserEvent: 'customBrowserEvent',
},
}

View File

@ -1,6 +0,0 @@
{
"name": "@rage-fw/shared",
"description": "Shared data for Rage-FW example",
"version": "0.1.0",
"main": "index.ts"
}

View File

@ -1,30 +1,25 @@
{ {
"name": "framework-example", "name": "framework-example",
"description": "This project is an example of RAGE FW usage", "description": "This project is 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/cef && pnpm build", "build:cef": "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:cef"
"build": "pnpm build:all"
}, },
"devDependencies": { "devDependencies": {
"@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", "@ragempcommunity/types-cef": "^2.1.8",
"rage-fw-shared-types": "latest",
"esbuild": "^0.21.5", "esbuild": "^0.21.5",
"typescript": "^5.4.5", "typescript": "^5.4.5",
"prettier": "^3.3.2" "prettier": "^3.3.2"
}, },
"license": "MIT",
"author": "Entity Seven Group", "author": "Entity Seven Group",
"license": "CC BY-ND",
"version": "0.1.0" "version": "0.1.0"
} }

View File

@ -1,2 +1,5 @@
packages: packages:
- "apps/*" - "apps/browser"
- "apps/client"
- "apps/server"
- "apps/shared"