Archived
feat pure rpc example
This commit is contained in:
@@ -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"
|
||||
}
|
||||
|
||||
+17
-10
@@ -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'
|
||||
})
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
import { Rpc } from 'rage-fw-rpc'
|
||||
|
||||
export const rpc = new Rpc({
|
||||
debugLogs: true,
|
||||
})
|
||||
Reference in New Issue
Block a user