npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

socket.io-rmi-client

v1.2.0

Published

RMI client using socket.io

Downloads

5

Readme

RMI Client (RPC Client)

npm version

The client side library for the RMI Server for making Remote Procedure Calls.

The RPC Client uses 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 or browserify. 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:

<script src="https://cdn.socket.io/socket.io-1.4.5.js"></script>
<script src="https://npmcdn.com/[email protected]/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.

'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.

// 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());
}
// 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.