https://github.com/capaj/socket.io-rpc-client
client library for a socket.io-rpc
https://github.com/capaj/socket.io-rpc-client
Last synced: about 1 year ago
JSON representation
client library for a socket.io-rpc
- Host: GitHub
- URL: https://github.com/capaj/socket.io-rpc-client
- Owner: capaj
- License: mit
- Created: 2015-01-18T16:17:01.000Z (over 11 years ago)
- Default Branch: master
- Last Pushed: 2016-02-16T11:08:23.000Z (over 10 years ago)
- Last Synced: 2025-03-28T17:01:46.746Z (over 1 year ago)
- Language: JavaScript
- Size: 48.8 KB
- Stars: 4
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# socket.io-rpc-client [](https://travis-ci.org/capaj/socket.io-rpc-client) [](https://github.com/feross/standard)
client library for a [socket.io-rpc](https://github.com/capaj/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:
```javascript
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:
```javascript
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](https://github.com/capaj/socket.io-rpc)