活动枢纽
本地和远程进程间活动模块
使用量
安装
bun install @arcblock/event-hub
服务器
process.env.ABT_NODE_EVENT_PORT=8888;
require('@arcblock/event-hub/lib/server.js);
客户端
// 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);
// 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
});