1.0.7 • Published 8 years ago
oshare v1.0.7
Node Object Sharing (Socket) | Remote Method Invocation | Support for callbacks
Install
npm i --save oshare
Usage
Server
server( port: int, options: object [, callback, language] )
const share = require('oshare');
const shared = {
api: require('./api'),
api2: require('./api')
}
share.server(3000, { shared /* , authorization */ }, (alert) => {
alert('hello')
});
api.js
exports.run = (cb) => {
console.log("wait 3000 ms and run callback");
setTimeout(cb, 3000);
};
Client
client( url: string, options: object [, callback] )
const share = require('oshare');
const shared = {
alert: console.log
};
share.client('http://localhost:3000', { shared /* , authorization */ }, (api, api2) => {
api.run(() => {
console.log('Called after 3000 ms!');
});
});
Browser
<script src="oshare-browser.js"></script>
<script>
const shared = {
alert: console.log
};
oshare('http://localhost:3000', { shared /* , authorization */ }, (api, api2) => {
api.run(() => {
console.log('Called after 3000 ms!');
});
});
</script>
Options
- shared: object to share
- authorization: optional auth key to prevent unauthorized rmi access. Server and Client should have the same key.
Callback
- Arguments should be key of shared data of server/client.
- Order is not relevant.
// if shared object is
var shared = {
module1 : require('../something'),
max: 5,
fn : () => console.log('hi!')
}
// callback will be
var callback = (module1, fn, max) => {
fn();
console.log(max);
}
Supported Languages
Use "language" argument to generate "Remote" class for a client.
- javascript
- java oshare-java, oshare-android
- python