# pubsub

> PubSub for Node and the Browser.

Latest version **3.2.1** (published 2016-06-24) · MIT license · 0 weekly downloads

## Install

```sh
npm install pubsub
pnpm add pubsub
yarn add pubsub
bun add pubsub
```

## Health

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

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 3.2.1 |
| Published | 2016-06-24 |
| First published | 2013-04-30 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | wski |
| Maintainers | mdwisniewski |
| Keywords | pubsub, publish, subscribe, browser, global |

## Links

- npm: https://www.npmjs.com/package/pubsub
- Repository: git@gitlab.me:wski/pubsub
- Homepage: https://gitlab.me/wski/pubsub
- Issues: https://gitlab.me/wski/pubsub/issues
- npm.io page: https://npm.io/package/pubsub

## Alternatives

- [@opentelemetry/exporter-zipkin](https://npm.io/package/@opentelemetry/exporter-zipkin.md) — 14.8M weekly downloads
- [pusher-js](https://npm.io/package/pusher-js.md) — 2.0M weekly downloads
- [browserify](https://npm.io/package/browserify.md) — 1.7M weekly downloads
- [sqs-consumer](https://npm.io/package/sqs-consumer.md) — 1.7M weekly downloads
- [@sanity/eventsource](https://npm.io/package/@sanity/eventsource.md) — 930.8K weekly downloads

## Recent versions

- 3.2.1 (latest) — 2016-06-24
- 3.2.0 — 2016-06-23
- 3.1.8 — 2016-06-23
- 3.1.2 — 2016-06-23
- 3.1.1 — 2016-06-23
- 3.1.0 — 2016-06-23
- 3.0.6 — 2016-06-23
- 3.0.5 — 2016-06-23
- 3.0.4 — 2016-06-23
- 3.0.3 — 2016-06-23
- 3.0.2 — 2016-06-23
- 3.0.1 — 2016-06-22
- 3.0.0 — 2016-06-22
- 2.1.7 — 2016-04-15
- 2.1.6 — 2016-04-14
- … 15 more at https://npm.io/package/pubsub/versions

## README

## Installation

Install and save the pubsub module.
`npm i --save pubsub`

Or use with script tag
`<script type="text/javascript" src="https://gitlab.me/wski/pubsub/raw/master/dist.js"></script>`

Then simply require it at the root level of your project.
```javascript
require('pubsub');
```

## Usage

Join a channel
```javascript
PubSub.join('general', (message, uuid) => {
  // Upon joining you will receive a uuid without a message.
  // Other times, you will be sent a message, and a uuid.
  if (message)
    console.log(`${uuid} recived message`, message);
});
```

Leave a channel
```javascript
// You can leave the channel by passing the uuid provided in join.
PubSub
  .leave('general', uuid)
  .then(() => {
    // successfully left channel
  });
```

Publish to a channel
```javascript
PubSub
  .publish('general', {test: 'passed'})
  .then(() => {
    // message sent to all subscribers
  });
```

Enable cross tab communication (for web applications)
```javascript
PubSub.setFlag('crossTabEnabled', true);
```

Enable history
```javascript
PubSub.setFlag('historyEnabled', true);
```

Increase history limit (default 15)
```javascript
PubSub.setFlag('historyLength', 30);
```

Get history
```javascript
PubSub.history('general', 15); // Returns 15 messages from history
```

## Example

[JSFiddle.net example](https://jsfiddle.net/whqbec73/11/)

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