Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
JavaScript
Branch: master

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
node_modules/sockjs
README.md
npm-debug.log
package.json
realtime-client.js
realtime-server.js

README.md

Description

Real time framework that allow client to call functions on server and receive callbacks (and vide versa) based on sockjs

Installation

run

sudo npm install -g realtimejs

Examples

On the server side:

var http_server = require('http').createServer(),
realtime = require("realtime").create(http_server);

realtime.shared.sumAndDifference = function(a,b){
    this.respond(a+b,a-b);
}

http_server.listen(8080);

In the first two lines we create an http server and we initialize the realtime framework. Then we define a client callable function "sumAndDifference" that does the sum and the difference of the two input numbers. The shared functions return an Array that represent the parameters for the callback.

Client:

<script src="http://cdn.sockjs.org/sockjs-0.3.4.min.js"></script>
<script src="link to realtime-client.js"></script>
<script>
    new Realtime(function(){
        this.Call("sumAndDifference",10,5,function(sum,diff){
            console.log(sum+" "+diff);
        });
    });
</script>

In the first we initilize the realtime framework and we define a function that is called when framework is ready. Inside this function this represent the framework. We call the "sumAndDifference" function on the server with 10 and 5 as parameters and we set a callback. The callback outputs the results computed by the server.

Additional

If you want to store connection specific datas on the server side you can use the this.connection object

Something went wrong with that request. Please try again.