Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

jpc-core

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

jpc-core

Allows remote procedure calls between JS objects over event-like channels or the network

  • 0.3.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
2
Maintainers
1
Weekly downloads
 
Created
Source

jpc - Remote procedure calls between JS objects in different processes

jpc allows you to call JS objects in other processes. From your JS objects, it automatically creates an API that resembles your object API, just with an await in front of every call. It then transmits the call over the channel and call the objects in the remote process, and returns the result back to you.

It can work over various communication channels to communicate with the remote process:

  • WebSockets
  • Electron IPC
  • DOM events
  • TCP

API

Start object

This is what your client calls initially and gets the first object references from.

Objects

The remote API is the same as the local API, just with an await prepended to all calls, aside from new and setters.

Local objectRemote objectDifference
functioncar.startEngine()await car.startEngine()same, just with await
gettercar.ownerawait car.ownersame, just with await
settercar.owner = valawait car.setOwner(val)because setters always return the assigned value
newnew Car()await Car.newRemote()because new always returns the object
Example

Given an object of class

class Movable {
  constructor() {}
}
class Car extends Movable {
  constructor() {
    this.super();
    this._owner = "Fred Flintstone";
  }
  startEngine() {
    console.log("Engine started");
  }
  get owner {
    return this._owner;
  }
  set owner(val) {
    this._owner = val;
  }
}

The local API in the server process is standard JS:

let car = new Car();
car.owner = "Wilma";
console.log(car.owner);
car.startEngine();

The client API in the other process is almost the same, just with an await added in front of all calls:

let car = await Car.newRemote(); // creates a new object in the server process
await car.setOwner("Wilma");
console.log(await car.owner); // shows "Wilma" on the client
await car.startEngine(); // shows "Engine started" on the server

Keywords

FAQs

Package last updated on 16 Feb 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc