Compare commits
6 Commits
react-18
...
rpc-react-
Author | SHA1 | Date | |
---|---|---|---|
2a3e9ab6ad | |||
b53177903e | |||
e7e423adc6 | |||
67be91538b | |||
f8dd4d9fce | |||
092693acb5 |
11
.gitignore
vendored
11
.gitignore
vendored
@ -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/
|
@ -1,10 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "rage-fw-example-cef",
|
"name": "rage-fw-example-browser",
|
||||||
"version": "0.0.0",
|
"description": "Browser side of Rage-FW example",
|
||||||
"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",
|
||||||
@ -12,9 +8,10 @@
|
|||||||
"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",
|
||||||
@ -25,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.2.2",
|
"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"
|
||||||
}
|
}
|
||||||
|
@ -1,14 +1,16 @@
|
|||||||
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('')
|
const [data, setData] = useState<string>('')
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
fw.event.register('customCefEvent', async ([test]) => {
|
rpc.register(events.browser.customBrowserEvent, (args: string) => {
|
||||||
setData(p => p + ' ' + test)
|
setData(prev => prev + ' | ' + args)
|
||||||
return 'from cef'
|
return 'response from cef'
|
||||||
})
|
})
|
||||||
|
rpc.callClient(events.client.cefReady, ['hello from cef'])
|
||||||
}, [])
|
}, [])
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
5
apps/browser/src/lib/index.ts
Normal file
5
apps/browser/src/lib/index.ts
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
import { Rpc } from '@entityseven/rage-fw-rpc'
|
||||||
|
|
||||||
|
export const rpc = new Rpc({
|
||||||
|
debugLogs: true,
|
||||||
|
})
|
@ -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" }]
|
||||||
|
@ -6,6 +6,12 @@ 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/*',
|
||||||
|
},
|
||||||
|
},
|
||||||
})
|
})
|
||||||
|
@ -1,13 +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": "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": {
|
||||||
"rage-fw-client": "latest"
|
"@entityseven/rage-fw-rpc": "0.2.5",
|
||||||
}
|
"@rage-fw/shared": "workspace:^"
|
||||||
|
},
|
||||||
|
"license": "CC BY-ND",
|
||||||
|
"author": "Entity Seven Group",
|
||||||
|
"version": "0.1.0"
|
||||||
}
|
}
|
||||||
|
@ -1,14 +1,22 @@
|
|||||||
import { fw } from '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('cefReady', async () => {
|
rpc.register(events.client.cefReady, async (args: string) => {
|
||||||
fw.system.log.info('cefReady')
|
mp.console.logInfo(args)
|
||||||
|
const res = (await rpc.callServer(events.server.customServerEvent, [
|
||||||
const responseCef = await fw.player.triggerBrowser('customCefEvent', [
|
'hello from client',
|
||||||
'from client',
|
])) as string
|
||||||
])
|
mp.console.logInfo(res)
|
||||||
fw.system.log.info(responseCef)
|
return 'response from client'
|
||||||
|
})
|
||||||
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'
|
||||||
})
|
})
|
||||||
|
5
apps/client/src/lib/index.ts
Normal file
5
apps/client/src/lib/index.ts
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
import { Rpc } from '@entityseven/rage-fw-rpc'
|
||||||
|
|
||||||
|
export const rpc = new Rpc({
|
||||||
|
debugLogs: true,
|
||||||
|
})
|
@ -1,13 +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": "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": {
|
||||||
"rage-fw-server": "latest"
|
"@entityseven/rage-fw-rpc": "0.2.5",
|
||||||
}
|
"@rage-fw/shared": "workspace:^"
|
||||||
|
},
|
||||||
|
"license": "CC BY-ND",
|
||||||
|
"author": "Entity Seven Group",
|
||||||
|
"version": "0.1.0"
|
||||||
}
|
}
|
||||||
|
@ -1,18 +1,20 @@
|
|||||||
import { fw } from '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`)
|
||||||
})
|
})
|
||||||
|
|
||||||
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 resFromCef = await fw.player.triggerBrowser(
|
console.log(args)
|
||||||
|
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'
|
},
|
||||||
})
|
)
|
||||||
|
5
apps/server/src/lib/index.ts
Normal file
5
apps/server/src/lib/index.ts
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
import { Rpc } from '@entityseven/rage-fw-rpc'
|
||||||
|
|
||||||
|
export const rpc = new Rpc({
|
||||||
|
debugLogs: true,
|
||||||
|
})
|
@ -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,11 +0,0 @@
|
|||||||
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
|
|
||||||
}
|
|
||||||
}
|
|
12
apps/shared/index.ts
Normal file
12
apps/shared/index.ts
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
export const events = {
|
||||||
|
server: {
|
||||||
|
customServerEvent: 'customServerEvent',
|
||||||
|
},
|
||||||
|
client: {
|
||||||
|
cefReady: 'cefReady',
|
||||||
|
customClientEvent: 'customClientEvent',
|
||||||
|
},
|
||||||
|
browser: {
|
||||||
|
customBrowserEvent: 'customBrowserEvent',
|
||||||
|
},
|
||||||
|
}
|
6
apps/shared/package.json
Normal file
6
apps/shared/package.json
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
{
|
||||||
|
"name": "@rage-fw/shared",
|
||||||
|
"description": "Shared data for Rage-FW example",
|
||||||
|
"version": "0.1.0",
|
||||||
|
"main": "index.ts"
|
||||||
|
}
|
19
package.json
19
package.json
@ -1,25 +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": ["apps/*"],
|
"workspaces": [
|
||||||
|
"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:cef": "cd apps/cef && pnpm build",
|
"build:browser": "cd apps/cef && pnpm build",
|
||||||
"build:all": "pnpm build:client && pnpm build:server && pnpm build:cef"
|
"build:all": "pnpm build:client && pnpm build:server && pnpm build:browser",
|
||||||
|
"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"
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,2 @@
|
|||||||
packages:
|
packages:
|
||||||
- "apps/browser"
|
- "apps/*"
|
||||||
- "apps/client"
|
|
||||||
- "apps/server"
|
|
||||||
- "apps/shared"
|
|
||||||
|
Loading…
Reference in New Issue
Block a user