Connect to a Prism Server from the browser or a remote Node app.
var prismClient = require('prism-client');
var rtt = require('rtt-engine.io')();
var transport = rtt.client({port: 3001, host: 'localhost'});
var app = prismClient({transport: transport});
app.connect(function(err, info){
console.log("Connected to Prism Server %s with Session ID %s", info.version, info.sessionId);
app.discover(function(){
console.log('Available services are', app.api);
});
});
Please see the REPL client example in examples/repl.js
.
Note: Not all transports support Node.js clients. rtt-engineio
and rtt-ws
do.
I've not tried this yet, but in theory it should be possible. You may need to use PersistJS. Please get in touch to let me know how you get on.
A Prism Server will be running one or more Realtime Services. Each Service will probably (but not necessarily) contain code to be run on the client (accessible via the app.api
object).
Client's can either be told what services are available in advance (using app.provide()
), or discover them upon connection (using app.discover()
).
We recommending providing service info in advance where possible as this minimizes the traffic over the WebSocket. It also allows for the client-side code to be minimized and served by CDNs.
Prism Server can make this easy for you by building a custom client module containing all the code you need for the transport and services. Just call server.buildClient();
.
However it's not always possible to know what Services are provided by a server until you connect. For example, you may want to run a query over the REPL against a remote server. In this case, you'll need to call app.discover()
upon initial connection.
MIT