Extends
Methods
-
Creates a RPC proxy object of the given object, which can then be passed to the RPC client.
The proxy object is destroyed when the connection to the client closes. In order to destroy it earlier, it exposes the special method
destroy()
to the client.Example
class MyClass { constructor(initial) { this.value = initial; } add(n) { this.value += n; } value() { return this.value; } } registerMethod("getMyClass", (initial) => { return proxyObject(new MyClass(initial)); });
Name Type Description obj
object The object for which to create the proxy.
exposedMethods
Array.<string> An optional list of the methods to expose. If this parameter is not used, all methods will be exposed.
Returns:
Type Description object The RPC proxy object. -
Registers a function as RPC method.
Example
registerMethod("sum", (a, b) => a + b); registerMethod("countDown", cb => { for (let i = 10; i > 0; --i) { cb(i); } });
Name Type Description name
string The name of the method.
f
function The method's implementation.