Archived
feat pure rpc example
This commit is contained in:
@@ -1,13 +1,14 @@
|
||||
{
|
||||
"name": "rage-fw-example-server",
|
||||
"version": "0.1.0",
|
||||
"author": "Entity Seven Group",
|
||||
"license": "CC BY-ND",
|
||||
"description": "Server side of rage-fw example",
|
||||
"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": {
|
||||
"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"
|
||||
}
|
||||
|
||||
@@ -1,11 +1,20 @@
|
||||
import { rpc } from 'rpc'
|
||||
import { events } from '@rage-fw/shared'
|
||||
import { rpc } from './lib'
|
||||
|
||||
rpc.register('playerJoin', async (player: PlayerMp) => {
|
||||
console.log(`Connected: ${player.socialClub}`)
|
||||
console.log(`[Server] ${player.socialClub} connected`)
|
||||
})
|
||||
|
||||
rpc.register('customServerEvent', (player: PlayerMp, data) => {
|
||||
console.log(player, data)
|
||||
|
||||
rpc.callClient(player, 'customClientEvent', ['server to client'])
|
||||
})
|
||||
rpc.register(
|
||||
events.server.customServerEvent,
|
||||
async (player: PlayerMp, args: string) => {
|
||||
console.log(args)
|
||||
const res = await rpc.callClient(
|
||||
player,
|
||||
events.client.customClientEvent,
|
||||
['hello from server'],
|
||||
)
|
||||
console.log(res)
|
||||
return 'response from server'
|
||||
},
|
||||
)
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
import { Rpc } from 'rage-fw-rpc'
|
||||
|
||||
export const rpc = new Rpc({
|
||||
debugLogs: true,
|
||||
})
|
||||
Reference in New Issue
Block a user