Socket
Socket
Sign inDemoInstall

@scalecube/addressable

Package Overview
Dependencies
83
Maintainers
7
Versions
53
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    @scalecube/addressable

A lightweight standalone micro lib to create addressable post messages. Let say you have some post messages on the main thread a couple of IFrames and a few web workers. Sending message between this element will be a nightmare!


Version published
Weekly downloads
26
decreased by-13.33%
Maintainers
7
Created
Weekly downloads
 

Readme

Source

Addressable

A lightweight standalone micro lib to create addressable post messages.
Let say you have some post messages on the main thread a couple of IFrames and a few web workers.
Sending message between this element will be a nightmare!

The solution, addresses like a plan tcp/ip network, or the WEB

  • This package is independent it maintained under scalecube-js only for convenience.

TODO

Handle address collusion

API

Add thread to network; you must add it to main thread in order iframe/workers will work

import '@scalecube/addressable';

listen for messages on address

import {listen} from '@scalecube/addressable';
listen("address", (msg, port: MessagePort)=>{port.postMessage("pong")});

connect to address

import {connect} from '@scalecube/addressable';
const port = connect("address");
port.addEventListener("message", console.log);
port.postMessage("ping");

Cleaning connections

import {connect, listen} from '@scalecube/addressable';
listen("address", (msg, port: MessagePort) => {
    if( msg === "ping" ) {
        port.postMessage("pong");
    } else if (msg === "close") {
        port.close();
    }
});

const port = connect("address");
port.addEventListener("message", console.log);
port.postMessage("ping");
port.postMessage("close");
port.close();

How it's works

  • Each time you import addressable it will create global event listener in each thread
  • Threads will register them self by sending a message to main thread
  • Each time new listener added it will spread to main thread and to all thread from there
  • When connect is called it will create a message channel and give a port to listen callback and open side

FAQs

Last updated on 11 Aug 2021

Did you know?

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc