# Event Hub

A module for local and remote Inter Process Event

![image](./docs/event-hub.svg)

## Usage

Install

```shell
bun install @arcblock/event-hub
```

Server

```javascript
process.env.ABT_NODE_EVENT_PORT=8888;

require('@arcblock/event-hub/lib/server.js);
```

Client

```javascript
// process 1

const Client = require('@arcblock/event-hub/lib/client');

const port = ''; // event-hub server port
const did = ''; // your did
const sk = ''; // your sk

const client = new Client({ port, did, sk, autoConnect: true });

const data = { foo: bar };

client.broadcast('my-event', data);
```

```javascript
// process 2

const Client = require('@arcblock/event-hub/lib/client');

const port = ''; // event-hub server port
const did = ''; // your did
const sk = ''; // your sk

const client = new Client({ port, did, sk, autoConnect: true });

client.on('my-event', (data) => {
  // handle data
});
```
