This commit is contained in:
Danya H 2024-10-30 20:17:26 +00:00
parent 81639386e5
commit fcb83f6636
8 changed files with 57 additions and 42 deletions

View File

@ -1,10 +1,10 @@
{
"name": "rage-fw-example-cef",
"name": "rage-fw-example-browser",
"version": "0.0.0",
"type": "module",
"author": "Entity Seven Group",
"license": "CC BY-ND",
"description": "CEF side of rage-fw example",
"license": "MIT",
"description": "Browser side of rage-fw-example",
"scripts": {
"dev": "vite",
"build": "tsc && vite build",
@ -12,9 +12,9 @@
"preview": "vite preview"
},
"dependencies": {
"@entityseven/rage-fw-browser": "0.2.0",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"rage-fw-cef": "latest"
"react-dom": "^18.2.0"
},
"devDependencies": {
"@types/react": "^18.2.66",

View File

@ -1,13 +1,19 @@
import { fw } from 'rage-fw-cef'
import { fw } from '@entityseven/rage-fw-browser'
import { useEffect, useState } from 'react'
function App() {
const [data, setData] = useState('')
const [data, setData] = useState('initial')
useEffect(() => {
fw.event.register('customCefEvent', async ([test]) => {
setData(p => p + ' ' + test)
return 'from cef'
fw.event.register('customBrowserEvent', async message => {
setData(p => p + ' | ' + message)
const response = await fw.event.triggerServer('customServerEvent', [
'hello from browser',
])
setData(p => p + ' | ' + response)
return 'response from browser'
})
}, [])

View File

@ -2,12 +2,12 @@
"name": "rage-fw-example-client",
"version": "0.1.0",
"author": "Entity Seven Group",
"license": "CC BY-ND",
"description": "Client side of rage-fw example",
"license": "MIT",
"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": {
"rage-fw-client": "latest"
"@entityseven/rage-fw-client": "0.2.0"
}
}

View File

@ -1,14 +1,14 @@
import { fw } from 'rage-fw-client'
import { fw } from '@entityseven/rage-fw-client'
fw.player.browser = mp.browsers.new('package://cef/index.html')
fw.event.register('cefReady', async () => {
fw.system.log.info('cefReady')
fw.event.register('customClientEvent', async msg => {
fw.system.log.info(msg)
const responseCef = await fw.player.triggerBrowser('customCefEvent', [
'from client',
const response = await fw.player.triggerBrowser('customBrowserEvent', [
'hello from client',
])
fw.system.log.info(responseCef)
fw.system.log.info(response)
await fw.player.triggerServer('customServerEvent', ['from client'])
return 'response from client'
})

View File

@ -2,12 +2,12 @@
"name": "rage-fw-example-server",
"version": "0.1.0",
"author": "Entity Seven Group",
"license": "CC BY-ND",
"description": "Server side of rage-fw example",
"license": "MIT",
"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": {
"rage-fw-server": "latest"
"@entityseven/rage-fw-server": "0.2.0"
}
}

View File

@ -1,18 +1,25 @@
import { fw } from 'rage-fw-server'
import { fw } from '@entityseven/rage-fw-server'
fw.event.register('playerJoin', async ([player]) => {
fw.system.log.info(`Connected: ${player.socialClub}`)
})
fw.event.register('playerJoin', async player => {
fw.system.log.info('Connected:', player.socialClub)
fw.event.register('customServerEvent', async ([player, msg]) => {
fw.system.log.info(player.socialClub + ' ' + msg)
const resFromCef = await fw.player.triggerBrowser(
const response = await fw.player.triggerClient(
player,
'customCefEvent',
['from server'],
'customClientEvent',
['hello from server'],
)
fw.system.log.info(player.socialClub + ' ' + resFromCef)
return 'from server'
fw.system.log.info(response)
})
fw.event.register('customServerEvent', async (player, msg) => {
fw.system.log.info(player.socialClub, msg)
const response = await fw.player.triggerBrowser(
player,
'customBrowserEvent',
['hello from server'],
)
fw.system.log.info(player.socialClub, response)
return 'response from server'
})

View File

@ -1,11 +1,13 @@
declare module 'rage-fw-shared-types' {
export interface RageFW_ICustomClientEvent {}
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_ICustomCefEvent {
customCefEvent(greetings: string): string
export interface RageFW_ICustomBrowserEvent {
customBrowserEvent(greetings: string): string
}
}

View File

@ -11,15 +11,15 @@
"build:all": "pnpm build:client && pnpm build:server && pnpm build:cef"
},
"devDependencies": {
"@entityseven/rage-fw-shared-types": "0.2.0",
"@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"
},
"author": "Entity Seven Group",
"license": "CC BY-ND",
"license": "MIT",
"version": "0.1.0"
}