# socket.io-rmi-client

> RMI client using socket.io

Latest version **1.2.0** (published 2016-07-19) · MIT license · 0 weekly downloads

## Install

```sh
npm install socket.io-rmi-client
pnpm add socket.io-rmi-client
yarn add socket.io-rmi-client
bun add socket.io-rmi-client
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.2.0 |
| Published | 2016-07-19 |
| First published | 2016-05-24 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 2 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Author | Ranjan Shrestha |
| Maintainers | syaau |

## Links

- npm: https://www.npmjs.com/package/socket.io-rmi-client
- Repository: https://github.com/sharingapples/socket.io-rpc-client
- Homepage: https://github.com/sharingapples/socket.io-rpc-client#readme
- Issues: https://github.com/sharingapples/socket.io-rpc-client/issues
- npm.io page: https://npm.io/package/socket.io-rmi-client

## Dependencies (2)

- [socket.io-rmi](https://npm.io/package/socket.io-rmi.md) ^1.1.1
- [socket.io-client](https://npm.io/package/socket.io-client.md) ^1.4.8

## Recent versions

- 1.2.0 (latest) — 2016-07-19
- 1.1.3 — 2016-07-19
- 1.1.2 — 2016-06-29
- 1.1.1 — 2016-06-21
- 1.0.6 — 2016-06-09
- 1.0.5 — 2016-05-27
- 1.0.0 — 2016-05-24

## README

# RMI Client (RPC Client)
[![npm version](https://badge.fury.io/js/socket.io-rmi-client.svg)](https://badge.fury.io/js/socket.io-rmi-client)

The client side library for the [RMI Server](https://github.com/sharingapples/socket.io-rmi-server)
for making Remote Procedure Calls.

The RPC Client uses [socket.io](https://github.com/socketio/socket.io) for
communication over network.

### Installation
#### As a common js module
The library could be used as a common js module as a node client or in a
browser application through bundlers like [webpack](https://webpack.github.io)
or [browserify](http://browserify.org/). The socket.io-client library is not
bundled together so you will have to install the socket.io-client library
as well.

    $ npm install --save socket.io-client
    $ npm install --save socket.io-rmi-client

#### UMD build through npmcdn
The UMD build of the library is available at
[npmcdn](https://npmcdn.com/socket.io-rmi-client@1.0/umd/socket.io-rmi-client.min.js):

```html
<script src="https://cdn.socket.io/socket.io-1.4.5.js"></script>
<script src="https://npmcdn.com/socket.io-rmi-client@1.0/umd/socket.io-rmi-client.min.js"></script>
```

### Usage
#### CommonJS module
The RMI Client could be used as a CommonJS modules when used in a node as a
client or in browsers through webpack/browserify or in a ReactNative project.
```javascript
'use strict';
import RMIClient from 'socket.io-rmi-client';
import io from 'socket.io-client';

// Connect to the RPC Server at the given address and port
// In case of browsers, the second argument could be empty
const client = RMIClient.connect(io, 'ws://server:port');
client.onConnected = function (remoteInstance) {
  // This callback is invoked as soon as a remote connection is established.
  // The RPC calls could now be carried on the remoteInstance
  remoteInstance.invoke().then((res) => {
    // The res is available after the remote invocation is completed.
  });

  // make rpc call with callbacks
  remoteInstance.invokeWithCallback(function() {
    // this callback will be called from the server later.
  });

  // get instances than can further make RPC calls
  remoteInstance.getAnotherInstance().then((anotherInstance) => {
    // anotherInstance can now be used to make RPC calls (if the method
    // actually returned a callable instance on the server)
    anotherInstance.invoke().then((res) => {

    });
  });
});

client.onDisconnected = function () {
  // If the client gets disconnected from the server, this method is invoked,
  // this could be taken as an opportunity to update the UI with the
  // disconnected state.
}
```

### Using EventHandler
The RPC calls can also be used to pass EventHandler instances to the server.
The server could raise events on this server as and when needed.

```javascript
// Using Class for creating event handlers
'use strict';
const  RMIClient = require('socket.io-rmi-client');
const io = require('socket.io-client');

// The EventHandler class must be extended from RMIClient.EventHandler
class EventHandler extends RMIClient.EventHandler {
  // The event methods should be prefixed with 'on'
  onEvent() {

  }
}

RMIClient.connect(io, 'ws://localhost').onConnected = function (instance) {
  instance.setEventHandler(new EventHandler());
}
```

```javascript
// Using without declaring classes, most likely using UMD modules
RMIClient.connect(io, 'ws://localhost').onConnected = function (instance) {
  const eventHandler = RMIClient.createEventHandler();
  eventHandler.onEvent = function () {
    // This event will be raised from the server
  }

  instance.setEventHandler(eventHandler);
}
```

### More Documentation
For further more documentation and use cases, check out the
[RMI Server](https://github.com/sharingapples/socket.io-rmi-server).

---
_Source: https://npm.io/package/socket.io-rmi-client · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
