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

@optio-labs/comms-bridge

Package Overview
Dependencies
Maintainers
2
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@optio-labs/comms-bridge

The library implements a "communications bridge" between endpoints in a multi-node messaging network.

  • 0.0.3
  • latest
  • npm
  • Socket score

Version published
Weekly downloads
0
decreased by-100%
Maintainers
2
Weekly downloads
 
Created
Source

comms-bridge

The library implements a "communications bridge" between endpoints in a multi-node messaging network.

For instance, it can be used for messaging between the multiple processes required in a Chrome extension.

Usage

Install the library:

npm install --save @optio-labs/comms-bridge

Import the library:

import { CommsBridge } from "@optio-labs/comms-bridge";

Create an instance of the comms bridge:

const commsBridge = new CommsBridge("<identifier-for-this-endpoint>");

Add handlers to respond to incoming messages:

commsBridge.respond("<your-message-name>", payload => {

    //
    // Do something...
    //
    console.log("Message received!");
    console.log(payload);

    // Data that is returned from the handler 
    // is the reply payload received at other end of the message.
    return {
        // ... your data goes here ...
    };
});

Send a message to another endpoint:

await commsBridge.send({
    targetId: "<identifier-for-other-endpoint>",
    name: "<your-message-name>",
    payload: {
        // ... your data goes here ...
    },
});

Send a message and await a reply:

const replyPayload = await commsBridge.send(
    {
        targetId: "<identifier-for-other-endpoint>",
        name: "<your-message-name>",
        payload: {
            // ... your data goes here ...
        },
    },
    {
        awaitReply: true,
    }
);
console.log("Other endpoint replied with:");
console.log(replyPayload);

Add incoming and outgoing network transports:

commsBridge.addIncoming("", new IncomingMessageTransport());
commsBridge.addOutgoing("", new OutgoingMessageTransport()); 

IncomingMessageTransport and OutgoingMessageTransport are classes that should be implemented by you.

IncomingMessageTransport feeds incoming messages from some messaging system or network protocol into the communications bridge.

OutgoingMessageTransport sends outgoing messages from the communications bridge into some messaging system or network protocol.

Development setup

Clone the repo and install dependencies:

npm install

Build the library:

npm run build

FAQs

Package last updated on 18 Jan 2022

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