call

The mode parameter can be used to specify the mode of the RPC call. The default mode is RPC.Mode.ALL.

RPCs can be triggered in three different modes:

  • RPC.Mode.HOST: The RPC is triggered on the host only.

  • RPC.Mode.ALL: The RPC is triggered on all clients (including the host and the caller).

  • RPC.Mode.OTHERS: The RPC is triggered on all clients except the caller.

Signature

function call(name: string, data: any, mode?: Mode, callbackOnResponse?: (data: any) => void): Promise<any>

Parameters

NameTypeDescription
namestringThe RPC name to call.
dataanyData to send to other players.
mode?ModeMode of the RPC. Defaults to RPC.Mode.ALL.
callbackOnResponse?(data: any) => voidOptional callback for the response.

Returns

Promise<any>

Usage

// Trigger an RPC on the host only
RPC.call('playTurn', { thing: 'rock' }, RPC.Mode.HOST);
 
// Trigger an RPC on all clients (including the host and the caller)
RPC.call('playTurn', { thing: 'rock' }, RPC.Mode.ALL);
 
// Trigger an RPC on all clients except the caller
RPC.call('playTurn', { thing: 'rock' }, RPC.Mode.OTHERS);