# @randlabs/communication-bridge

> * [Overview](#Overview) * [Installation](#Installation) * [API Usage](#API-Usage) * [Copyright and License](#Copyright-and-License)

Latest version **1.0.1** (published 2022-09-05) · Apache-2.0 license · 0 weekly downloads

## Install

```sh
npm install @randlabs/communication-bridge
pnpm add @randlabs/communication-bridge
yarn add @randlabs/communication-bridge
bun add @randlabs/communication-bridge
```

## Health

**Score 20/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.1 |
| Published | 2022-09-05 |
| First published | 2020-12-07 |
| Weekly downloads | 0 |
| License | Apache-2.0 |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 19.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | RandLabs.IO |
| Maintainers | mpicco-randlabs, mxmauro, alex99y |

## Links

- npm: https://www.npmjs.com/package/@randlabs/communication-bridge
- npm.io page: https://npm.io/package/@randlabs/communication-bridge

## Recent versions

- 1.0.1 (latest) — 2022-09-05
- 1.0.0 — 2020-12-07

## README

# Communication-bridge

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

### 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:

```sh
npm i @randlabs/communication-bridge
```

### API Usage

Import and define the communication channel

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

#### Tab #1

```js
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

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

```

### Copyright and License  

See [LICENSE](LICENSE.md) file.

---
_Source: https://npm.io/package/@randlabs/communication-bridge · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
