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 🙏

© 2026 – Pkg Stats / Ryan Hefner

peer_rpc

v1.0.16

Published

```sh npm install peer-rpc --save ```

Readme

Call Remote Procedures on other peer (or even a server)

Installation

npm install peer-rpc --save

Usage

First rpc must be initialized. Therefore import the class:

import remote_procedure_call from 'peer_rpc';

Afterward we need to implement a send function. This is so generic that every protocol may be used for that.

let sendfunction = (msg) => {
	// Here's how to send message to other peer. This may be over
	// WebSocket, WebRTC, XMPP or every other transport protocol.
}

With this sendfunction we are able to instantiate the rpc-class on each peer:

let rpc = remote_procedure_call(sendfunction);

Then we're able to register a function on one peer ...

rpc.register_function('hello_peer', (peer_name) => {
	console.log(`Hello from ${peer_name}!`);
	return 'peer1';
});

... and call it on the other peer under the registered name

rpc.call_function('hello_peer', 'peer2')
	.then((peer_name) => {
		console.log(`Hello from other peer: ${peer_name}`);
	});

this prints out

Hello from peer2

on the first peer and

Hello from other peer: peer1

on the second peer

As we can see, the result of a called function is returned via a Promise on the caller

Callbacks

It's also possible to call callbacks.

Register function on one peer ...

let ob2 = new observer();
rpc.register_function('function_with_callback', (fn) => {
	return fn(42)
		.then((r) => {
			assert(r=='fake');
			return 45;
		})
});

... and call it on the other side

return rpc.call_function('function_with_callback', (v) => {
		assert(v == 42);
		return 'fake';
	})
	.then((res) => {
		assert(res == 45);
	})

Wrap a function

Sometimes it happens that the same function has to be called on both peers. This can be achieved by wrapping the function. The wrapped function returns a Promise that will be resolved with both results as an array.

remote:

rpc.register_function('foo', () => 42);

local:

let wrapped = rpc.wrap_function(() => 43, 'foo');

wrapped('bar')
	.then(([local, remote]) => {
		assert(local == 42);
		assert(remote == 43);
	});

Wrap a class

It's also possible to wrap whole classes. Since classes and function are very similar in javascript we can register the class like a function

remote:

function cls () {
	this.a = 3
	this.hello_remote = () => {
		return 'Hello Remote!';
	}
}
rpc.register_function('cls', cls);

local:

rpc.instantiate_class('cls')
	.then((instance) => {
		instance.a()
			.then((res) => {
				assert(res == 3);
			})
		instance.hello_remote()
			.then(() => {
				assert(res == 'Hello Remote!');
			})
	});