# primus-emitter

> Simple emitter wrapper for Primus

Latest version **3.1.1** (published 2015-06-22) · MIT license · 0 weekly downloads

## Install

```sh
npm install primus-emitter
pnpm add primus-emitter
yarn add primus-emitter
bun add primus-emitter
```

## 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.1.1 |
| Published | 2015-06-22 |
| First published | 2013-07-19 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 51 |
| Author | Jonathan Brumley |
| Maintainers | cayasso |
| Keywords | emitter, realtime, websocket, engine.io, socket.io, primus, sockjs, browserchannel, publish, subscribe |

## Links

- npm: https://www.npmjs.com/package/primus-emitter
- Repository: https://github.com/cayasso/primus-emitter
- Issues: https://github.com/cayasso/primus-emitter/issues
- npm.io page: https://npm.io/package/primus-emitter

## 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.1.1 (latest) — 2015-06-22
- 3.1.0 — 2015-04-07
- 3.0.3 — 2014-07-15
- 3.0.2 — 2014-04-28
- 3.0.1 — 2014-04-24
- 3.0.0 — 2014-02-19
- 2.1.0 — 2014-02-11
- 2.0.5 — 2013-12-04
- 2.0.4 — 2013-11-19
- 2.0.3 — 2013-11-18
- 2.0.2 — 2013-11-14
- 2.0.1 — 2013-11-05
- 2.0.0 — 2013-11-01
- 1.1.0 — 2013-11-01
- 1.0.2 — 2013-09-25
- … 10 more at https://npm.io/package/primus-emitter/versions

## README

# Primus Emitter

[![Build Status](https://img.shields.io/travis/cayasso/primus-emitter/master.svg)](https://travis-ci.org/cayasso/primus-emitter)
[![NPM version](https://img.shields.io/npm/v/primus-emitter.svg)](https://www.npmjs.com/package/primus-emitter)
[![Coverage Status](https://img.shields.io/coveralls/cayasso/primus-emitter/master.svg)](https://coveralls.io/r/cayasso/primus-emitter)

Node.JS module that adds emitter capabilities to [Primus](https://github.com/primus/primus).

## Installation

```
$ npm install primus-emitter
```

## Usage

### On the Server

```javascript
var Primus = require('primus');
var Emitter = require('primus-emitter');
var server = require('http').createServer();

// primus instance
var primus = new Primus(server, { transformer: 'websockets', parser: 'JSON' });

// add emitter to Primus
primus.use('emitter', Emitter);

primus.on('connection', function (spark) {

  // emit hi event
  spark.send('hi', 'good morning');

  // emit to news with ack
  spark.send('news', 'good morning', function (data) {
    console.log(data); // => 'by client'
  });

  // receive incoming sport messages
  spark.on('sport', function (data) {
    console.log('sport', data); // => ping-pong
  });

});

server.listen(8080);
```

### On the Client

```javascript
var primus = Primus.connect('ws://localhost:8080');

primus.on('open', function () {

  // receive incoming hi msgs
  primus.on('hi', function (data) {
    console.log(data); // => good morning
  });

  // respond ack to server
  primus.on('news', function (data, fn) {
    fn('by client');
  });

  // send message to server
  primus.send('sport', 'ping-pong');

});

```

## API

### spark#send(event, ..., [fn])

Send an event to server to client or client to server.

```javascript
spark.send('news', 'hi', fn);
```

### spark#on(event, fn)

Listen to incoming events.

```javascript
spark.on('news', fn);
```

## Run tests

``` bash
$ make test
```

## Other plugins

 * [primus-rooms](https://github.com/cayasso/primus-rooms)
 * [primus-multiplex](https://github.com/cayasso/primus-multiplex)
 * [primus-resource](https://github.com/cayasso/primus-resource)

## License

(The MIT License)

Copyright (c) 2013 Jonathan Brumley &lt;cayasso@gmail.com&gt;

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
'Software'), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

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