replay-emitter
v1.1.1
Published
Replay-emitter is a simple tool to record/replay events from a file to nodejs EventEmitter.
Downloads
4
Readme
Replay-emitter
Replay-emitter is a simple tool to record/replay events from a file to nodejs EventEmitter.
Installation
npm install replay-emitter
yarn add replay-emitter
Options
| Option | Type | Default | Description |
|----------|------------------|---------|---------------------------------------------|
| offset
| number
| 0 | time offset |
| mode
| auto \| manual
| auto
| Specify the mode |
| events
| string[]
| [] | If manual mode, the events you wanna record |
Usage
Record events
import handler, { replayEnd } from 'replay-emitter';
import { EventEmitter } from 'events';
// After registering all the `.on` and `.once` listeners
const emitter = new EventEmitter();
handler(emitter)
// When you did finish recording enough sample
setTimeout(async () => {
await replayEnd()
console.log('REPLAY END')
// This function is gonna save the events to the replay.txt file at the root of the project
}, 10000)
Replay events
import handler, { replayEnd } from 'replay-emitter';
import { EventEmitter } from 'events';
// After registering all the `.on` and `.once` listeners
const emitter = new EventEmitter();
const startFunction = await execute(emitter, 'pathtothefile/replay.txt');
// start the replay
await startFunction();