RPCs (Remote Procedure Calls, sometimes also referred to as Remote Method Invocation) is deepstream's implementation of request-response workflows.

Methods

client.rpc.provide( name, callback )

argument type optional description
name String false The name of the RPC. Each client can only register as a provider for an RPC name once.
callback Function false A function that handles incoming RPCs. Will be called with data and an RPC response object.

Registers the client as a provider for incoming RPCs of a specific name. The callback will be invoked when another client calls client.rpc.make().

client.rpc.provide( 'add-two-numbers', function( data, response ){
    response.send( data.numA + data.numB );
});


Info

  • Only one callback per client can be registered for the same RPC
  • Data can be any serializable object
  • Documentation for the response object can be found here

client.rpc.unprovide( name )

argument type optional description
name String false The name of the RPC.

Removes the client as a provider previously registered using provide().

client.rpc.unprovide( 'add-two-numbers' );

client.rpc.make( name, data, callback )

argument type optional description
name String false The name of the RPC.
data Mixed true Any serialisable data ( Objects, Strings, Numbers... ) that will be send with the RPC.

Executes a remote procedure call. callback will be invoked with the returned result or with an error if the RPC failed.

client.rpc.make( 'add-two-numbers', { numA:4, numB: 7 }, ( error, result ) => {
    // error = null, result = 11
});
Need support, architectural consulting or training? Buy Support