1.0.7 • Published 8 years ago

oshare v1.0.7

Weekly downloads
3
License
MIT
Repository
github
Last release
8 years ago

npm.io

Node Object Sharing (Socket) | Remote Method Invocation | Support for callbacks

npm

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.

1.0.7

8 years ago

1.0.6

8 years ago

1.0.5

8 years ago

1.0.4

8 years ago

1.0.3

8 years ago

1.0.2

8 years ago

1.0.1

8 years ago

1.0.0

8 years ago