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

electron-ipc-tunnel

v3.1.0

Published

Create tunelled conncections over Electron's IPC.

Downloads

16

Readme

electron-ipc-tunnel

Create tunneled connections over Electron's interprocess communication module.

The ipc module is great for interprocess communication, but lacks the ability to have dedicated endpoints. I.e. you might have multiple instances of the same code running in the browser that needs to communicate with the same backend service. Unfortunately there is no way to differentiate these instances other than by introducing message IDs, giving each instance a unique handle, etc.
This module abstracts that away.
In my experience I also want exactly one response from a query I send, that is, I basically want to call a method over IPC asynchronously. This is greatly simplified with this module as it will return a Promise of the return value.

Usage

On the client side

Create a new instance of IpcClient and call the send method to send an asynchronous method. You will get a promise of the return value.

import IpcClient from "electron-ipc-tunnel/client";
// var IpcClient = require("electron-ipc-tunnel/client").default;

var client = new IpcClient();

var result = await client.send("message", "foo");

On the server side

This module exposes a single function to use on the server side to register handlers.

import { registerIpc } from "electron-ipc-tunnel/server";
// var registerIpc = require("electron-ipc-tunnel/server").registerIpc;

registerIpc("message", async function(reply, arg1, arg2) {
    console.log(`Received message with args: ${arg1} ${arg2}`);
    reply("intermediate-update", "I'm still calculating foo!");
    return "foo";
});

A callback function will always receive a callback to send a message to the client. It returns a Promise for the value to send to the client. As such the reply callback should only be used if we need to send multiple/intermediate messages, e.g. to report a percentage of the progress.

Implementation

Upon creation an IpcClient gets a unique handle for itself from the server synchronously. It then wraps any message originating from send inside a paired-message, which includes the channel, the passed arguments, the unique client handle and the internal message id, that is sent over IPC. The method returns a promise and stores resolve and reject handlers internally.
On the server side this message is unwrapped, calling a registered handler for the message type with the given arguments, passing a reply function, that will again, wrap the reply, which will be unwrapped on the client side. The server also waits for the Promise returned from the handler to resolve and sends an appropriate message to the client, which then resolves or rejects the Promise returned by send.