Remoting.IO Client
Simple and transparent remote procedure calls (RPC) using Engine.IO
.
The server repository is located here.
About
Remoting.IO
allows services to export methods remotely. Services are simply plain prototypical Javascript classes which define a number of methods that can be called remotely.
Because Engine.IO
is connection oriented, services are stateful. This means session data can be persisted across services and method invocations. Remoting.IO
provides a session
hash map that is injected into instances of services for exactly this purpose.
Remoting.IO
is able to handle both synchronous and asynchronous methods. The only constraint is that asynchronous methods must return an ES6 promise.
Because Remoting.IO
is based on Engine.IO
, it inherits the strengths of Engine.IO
, such as multiple transports and resilience in the presence of proxies, load balancers, and firewalls.
Installation
Install the Engine.IO
and Remoting.IO
clients as follows:
npm install engine.io-client
npm install remoting.io-client
Server Example
Define a service as follows:
{ thisarg1 = arg1; thissession'arg2' = arg2;} TestServiceprototype { return str1 + str2;}; TestServiceprototype { var self = this; return { ; };}; TestServiceexports = 'test1' 'test2' ;
Setup the RPC server as follows:
var engine = ;var remoting = ; var socketServer = engine;var rpcServer = ; rpcServer;rpcServerstart;
When a client connects and requests an instance of TestService
, 'Hello'
and 'World!'
will be passed into arg1
and arg2
of the service constructor respectively.
Client Example
Using the server example above, we can remotely request an instance of the service and call it's method as follows:
var socket = ;var client = ; client;
This example assumes that engine.io.js
and remoting.io.js
have been loaded into the DOM.
Using Browserify:
var socket = 'ws://localhost';var client = socket; client;
API
Client
-
constructor
- Initializes the client
- Parameters:
socket
: anEngine.IO
(or equivalent) socket
-
services
- Returns a
Promise
containing the list of services exposed by the server
- Returns a
-
exports
- Returns a
Promise
containing the list of methods exported by a service - Parameters:
serviceName
: the service
- Returns a
-
proxy
- Returns a
Promise
containing a proxy of the service - Parameters:
serviceName
: the service
- Returns a
Proxy
- release
- Releases the proxy. Should be called when the proxy is no longer in use. Note: the instance associated with a proxy is automatically released when the connection is closed.
Head over to the Remoting.IO
server repository for instructions on how to use the server.
License
Copyright (c) 2015 James McLean
Licensed under the MIT license.