socket.io-rpc-client

1.1.3 • Public • Published

socket.io-rpc-client Build Status js-standard-style

client library for a socket.io-rpc

All libraries are written in commonJS module style, so you need to use SystemJS loader to be able to use them in the browser. Browserify/webpack might work, if you set it up correctly, but might be a pain and you're probably will have to delve deep into the code. Angular.js lib contains special rpc-controller directive, which when compiled asynchronously loads server channel and instantiates classic angular controller when this channel is ready.

Usage

npm install socket.io-rpc-client for serverside usage

jspm install socket.io-rpc-client for clientside usage

then in Node.js:

var rpcClient = require('socket.io-rpc-client');
 
var rpc = rpcClient('http://localhost:8032');
//call to the server
rpc('plain')().then(function(ret) {
    console.log('plain returned ', ret); //for test-utils/sample-server.js server prints out: plain returned 41
});
//expose some for the server to call
rpc.expose({
    fnOnClient: function() {
        console.log('called client method');
        return 42;
    },
    asyncOnClient: function() {
        return new Promise(function(resolve, reject) {
            setTimeout(function(){
                resolve('resolved after 40ms');
            }, 40);
        });
    },
    erroringMethod: function() {
        notdefined.error.will.propagate;
    }
});
 

in the browser:

var myChannel = require('rpc/test');   //CJS style require
//or
import {default as myChannel} from 'rpc/myChannel'; //ES6 style require
 
myChannel.getTime().then(t => { //calls getTime function on the server
    console.log("t", t);    //t is the serverside return value or serverside promise resolve value
});    

For complete examples including server side refer to socket.io-rpc project

Versions

Current Tags

VersionDownloads (Last 7 Days)Tag
1.1.35latest

Version History

VersionDownloads (Last 7 Days)Published
1.1.35
1.1.21
1.1.01
1.0.61
1.0.51
1.0.34
1.0.21
1.0.01
0.9.111
0.9.101
0.9.91
0.9.81
0.9.74
0.9.61
0.9.54
0.9.40
0.9.30
0.9.21
0.9.10
0.9.00
0.8.150
0.8.130
0.8.120
0.8.110
0.8.100
0.8.90

Package Sidebar

Install

npm i socket.io-rpc-client

Weekly Downloads

27

Version

1.1.3

License

MIT

Last publish

Collaborators

  • capaj