@randlabs/communication-bridge

v1.0.1
* [Overview](#Overview) * [Installation](#Installation) * [API Usage](#API-Usage) * [Copyright and License](#Copyright-and-License)

Communication-bridge

Overview

A cross-domain communication library develop by Rand Labs that enables send and receive messages between browser windows/tabs.

Instalation

The library can be installed via npm:

npm i @randlabs/communication-bridge

API Usage

Import and define the communication channel

const Messenger = require("@randlabs/communication-bridge");
const channelName = "channel name";

Tab #1

const client = new Messenger(channelName); // If listener is undefined, it will ignore all incoming request

const window = window.open("https://another.website.com");

const response = await client.sendMessage(window, { customMethod: "doSomething" }, { waitForReply: true, origin: "*" }); // If you are sending sensitive data, put a specific origin, for example: https://another.website.com

console.log(response); // { response: "OK" }

Tab #2

const hub = new Messenger(channelName, function(data, origin, source, sendResponse) {
    console.log(data); // { customMethod: "doSomething" }
    sendResponse({ response: "OK" });
});

Copyright and License

See LICENSE file.

npm i @randlabs/communication-bridge

Metadata

Downloads