JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • 0
  • Score
    100M100P100Q25043F
  • License GPL-3.0

A library for local inter process communications on unix based systems.

Package Exports

  • @hoobs/ipc

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@hoobs/ipc) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

IPC

A library for local interprocess communications on unix based systems.

Installation

You can install this module into your project.

yarn add @hoobs/ipc

Options

Options for creating an IPC server or client.

import { IPCOptions } from "@hoobs/ipc";

const options: IPCOptions = {
    id: "test",
    root: "./",
    namespace: "example",
    encoding: "utf8",
    maxConnections: 100,
}

The example above creates a sock file example.test.sock in the application's root.

variable Required description
id Yes a unique name for the socket
root No the path to store the Unix sock file, default is the app root
namespace No adds a domain to the sock files
encoding No text encoding for socket messages, default is utf8
maxConnections No this is the max number of connections allowed to a socket, default is 100 (server only)

Server

Below is an example of a server implantation.

There are two types listeners;

  • Event
  • Route

Events are designed as void functions, where routes return a payload. Routes accept a path, parameters, and a body. Both requests and results are JSON objects.

import { IPCServer } from "@hoobs/ipc";

const server = new IPCServer({
    id: "test",
    maxConnections: 100,
});

// EVENTS
server.on("host", (data) => {
    console.log(data);
});

// ROUTES
server.route("hello", (request, response) => {
    response.send({
        message: `Hello ${request?.params?.name}`,
    });
});

server.start();

Client

The client can access a server's events and routes. Below is an example of a client implantation.

The two methods are;

  • Emit
  • Fetch

Emit sends a request to the server and doesn't expect a result. Fetch works much like HTTP calls. You need to define the route using the path parameter, and excepts parameters and a body object. Fetch is a promise, so it needs to be called with await or using the then method.

import { IPCClient } from "@hoobs/ipc";

const client = new IPCClient({
    id: "test",
});

// EVENTS
client.emit("host", {
    ip: "127.0.0.1",
});

// ROUTES
client.fetch("hello", {
    name: "Luke Skywalker",
}).then((response) => {
    console.log(response);
});

This is a modified project orginally wrote by Brandon Nozaki Miller.

HOOBS and the HOOBS logo are registered trademarks of HOOBS Inc. Copyright (C) 2021 HOOBS Inc. All rights reserved.