*Add onSelf and emitSelf methods to use local event emitter
*Emit local init before processing queued actions
This commit is contained in:
parent
8427cbdff6
commit
42f0c1b60d
16
src/index.ts
16
src/index.ts
|
@ -12,7 +12,7 @@ import { load } from "@lumeweb/libkernel-universal";
|
|||
// @ts-ignore
|
||||
import Hyperswarm from "hyperswarm";
|
||||
import randomNumber from "random-number-csprng";
|
||||
import EventEmitter from "eventemitter2";
|
||||
import EventEmitter, { OnOptions } from "eventemitter2";
|
||||
import { Mutex } from "async-mutex";
|
||||
|
||||
export default class HyperswarmWeb extends EventEmitter {
|
||||
|
@ -83,6 +83,14 @@ export default class HyperswarmWeb extends EventEmitter {
|
|||
return this._processOrQueueAction("on", ...arguments);
|
||||
}
|
||||
|
||||
onSelf(
|
||||
eventName: string | symbol,
|
||||
listener: (...args: any[]) => void,
|
||||
options?: boolean | OnOptions
|
||||
): Hyperswarm {
|
||||
return super.on(eventName, listener, options);
|
||||
}
|
||||
|
||||
addListener(
|
||||
eventName: string | symbol,
|
||||
listener: (...args: any[]) => void
|
||||
|
@ -108,6 +116,10 @@ export default class HyperswarmWeb extends EventEmitter {
|
|||
return this._processOrQueueAction("emit", ...arguments);
|
||||
}
|
||||
|
||||
emitSelf(eventName: string | symbol, ...args: any[]): boolean {
|
||||
return super.emit(eventName, ...args);
|
||||
}
|
||||
|
||||
once(eventName: string | symbol, listener: (...args: any[]) => void): this {
|
||||
return this._processOrQueueAction("once", ...arguments);
|
||||
}
|
||||
|
@ -205,6 +217,8 @@ export default class HyperswarmWeb extends EventEmitter {
|
|||
throw new Error("Failed to find an available relay");
|
||||
}
|
||||
|
||||
this.emitSelf("init");
|
||||
|
||||
this._processQueuedActions();
|
||||
await this._activeRelay.dht.ready();
|
||||
this._connectionMutex.release();
|
||||
|
|
Loading…
Reference in New Issue