@mcbe-mods/rpc
v1.0.0-beta.3
Published
RPC layer for MCBE Script API — invoke/handle on bedrock:// protocol
Maintainers
Readme
@mcbe-mods/rpc
Remote Procedure Call for Minecraft Bedrock Edition Script API.
Request-response communication between addons over the bedrock:// protocol.
Install
npm install @mcbe-mods/rpcUsage
import { RPC } from '@mcbe-mods/rpc'
// Side A: handle
const server = new RPC({ namespace: 'myAddon' })
server.handle('add', (data: { a: number, b: number }) => data.a + data.b)
// Side B: invoke
const client = new RPC({ namespace: 'myAddon' })
const sum = await client.invoke<number>('add', { a: 1, b: 2 })
// sum === 3Timeout
// Per-call timeout (ms)
const result = await client.invoke('ping', data, 5000)
// Global default
const rpc = new RPC({ namespace: 'myAddon', timeout: 10_000 })
// Disable timeout
const result = await client.invoke('ping', data, 0)Error handling
// Handler throws → error sent back to caller
server.handle('fail', () => {
throw new Error('something broke')
})
try {
await client.invoke('fail')
}
catch (e) {
console.error(e.message) // 'something broke'
}Lifecycle
rpc.dispose()Options
interface RPCOptions {
namespace?: string // default: 'global'
timeout?: number // default: 5000 (ms), 0 to disable
}