# brokr

> Websocket RPC+PUB/SUB library

Latest version **0.6.1** (published 2013-07-19) · MIT license · 0 weekly downloads

## Install

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

## Health

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

Positive: no vulnerabilities.

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

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.6.1 |
| Published | 2013-07-19 |
| First published | 2013-06-13 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 7 |
| Known vulnerabilities | 0 (+6 in 3 direct dependencies) |
| Install scripts | no |
| Author | Henrik Tudborg |
| Maintainers | tudborg |
| Keywords | pubsub, rpc, rmi, websocket |

## Links

- npm: https://www.npmjs.com/package/brokr
- Repository: https://github.com/henriktudborg/brokr
- Issues: https://github.com/henriktudborg/brokr/issues
- npm.io page: https://npm.io/package/brokr

## Dependencies (7)

- [q](https://npm.io/package/q.md) ~0.9.5
- [ws](https://npm.io/package/ws.md) ~0.4.25
- [sift](https://npm.io/package/sift.md) 0.0.12
- [debug](https://npm.io/package/debug.md) ~0.7.2
- [node-uuid](https://npm.io/package/node-uuid.md) ~1.4.0
- [uglify-js](https://npm.io/package/uglify-js.md) ~2.3.6
- [browserify](https://npm.io/package/browserify.md) ~2.18.1

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

- 0.6.1 (latest) — 2013-07-19
- 0.6.0 — 2013-07-19
- 0.5.0 — 2013-06-25
- 0.4.0 — 2013-06-16
- 0.3.4 — 2013-06-16
- 0.3.3 — 2013-06-16
- 0.3.2 — 2013-06-16
- 0.3.1 — 2013-06-16
- 0.3.0 — 2013-06-15
- 0.2.0 — 2013-06-13
- 0.1.0 — 2013-06-13

## README

[![Build Status](https://travis-ci.org/henriktudborg/brokr-js.png?branch=master)](https://travis-ci.org/henriktudborg/brokr-js)

Brokr
===================
brokr is a javascript RPC+PUB/SUB via Websocket library that you shouldn't use yet.

If you want to anyway, go get it with `npm install brokr`

I am quite serious with my versioning of this, so please install a specific version to
avoid breaking your application.

I follow [Semantic Versioning 2.0.*](http://semver.org/)

Usage
------------------

### In the browser

If you need to use Brokr in the browser, you can
* Use the included connect middleware `Brokr.middleware(url)` to serve a browser friendly Brokr version.
* Use the `Brokr.browserify(callback)` function to get the source as a string.
* Use the included build tool. Simply run `make build` in the Brokr module root to build the `brokr.web.js` file. 

**Note** that i am writing a better more optimised version exclusively for the browser, 
and that the current browser implementation works, but have a gigantic footprint.

The browser version will have it's own repository, will properly not be avaiable through
npm.

#### Example with connect

Your node application (lets call it app.js):

```javascript
var Brokr   = require('brokr')
  , connect = require('connect');

//let us choose a reasonable port number
var port = 4000;

 //Start a http.Server as you usually would
 //Here we are using connect() to take advantage of
 //brokr's built in middleware for serving the static client
var server =//our http.Server instance as returned by connect's .listen() method
    connect()
    //serve the brokr source on requests to /brokr.js
    .use(Brokr.static('/brokr.js'))
    //serve the "public" directory as is (put your index.html here)
    .use(connect.static(__dirname+'/public'))
    //and start the webserver
    .listen(port);
console.log("listening on port "+port);

//create a new Brokr object, exposing a single method called ping
var brokr = new Brokr({
    ping: function (response) {
        //when client requests ping, send with no error and the string "pong"
        response(null, "pong");
    }
});

//attach our brokr to our server instance using the .listen() method
//The listen method could also take a port number which would start
//a new server on that port
brokr.listen(server).then(function(){
    console.log("brokr listening on port "+port);
}).done();
```

Your ./public/index.html file:

```html
<!DOCTYPE html>
<html>
    <head>
        <title>Brokr web demo</title>
    </head>
    <body>
        <!-- request the brokr script -->
        <script src="/brokr.js"></script>
        <script>
            var brokr = new Brokr();
            //connect to the server
            brokr.connect('ws://'+window.location.host)
            .then(function(connection){ //then, on connect
                                        //return a promise for a ping response
                console.log("connected");
                return connection.request('ping');
            })
            .then(function(response){   //then on response
                console.log("got ping response,", response);
            })
            .then(function(){           //then return a promise to disconnect
                console.log("disconnecting..");
                return brokr.disconnect();
            })
            .done(); //and we are done
        </script>
    </body>
</html>
```

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