diff options
Diffstat (limited to 'server/lib/internal-event-emitter.ts')
-rw-r--r-- | server/lib/internal-event-emitter.ts | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/server/lib/internal-event-emitter.ts b/server/lib/internal-event-emitter.ts new file mode 100644 index 000000000..08b46a5c3 --- /dev/null +++ b/server/lib/internal-event-emitter.ts | |||
@@ -0,0 +1,35 @@ | |||
1 | import { MChannel, MVideo } from '@server/types/models' | ||
2 | import { EventEmitter } from 'events' | ||
3 | |||
4 | export interface PeerTubeInternalEvents { | ||
5 | 'video-created': (options: { video: MVideo }) => void | ||
6 | 'video-updated': (options: { video: MVideo }) => void | ||
7 | 'video-deleted': (options: { video: MVideo }) => void | ||
8 | |||
9 | 'channel-created': (options: { channel: MChannel }) => void | ||
10 | 'channel-updated': (options: { channel: MChannel }) => void | ||
11 | 'channel-deleted': (options: { channel: MChannel }) => void | ||
12 | } | ||
13 | |||
14 | declare interface InternalEventEmitter { | ||
15 | on<U extends keyof PeerTubeInternalEvents>( | ||
16 | event: U, listener: PeerTubeInternalEvents[U] | ||
17 | ): this | ||
18 | |||
19 | emit<U extends keyof PeerTubeInternalEvents>( | ||
20 | event: U, ...args: Parameters<PeerTubeInternalEvents[U]> | ||
21 | ): boolean | ||
22 | } | ||
23 | |||
24 | class InternalEventEmitter extends EventEmitter { | ||
25 | |||
26 | private static instance: InternalEventEmitter | ||
27 | |||
28 | static get Instance () { | ||
29 | return this.instance || (this.instance = new this()) | ||
30 | } | ||
31 | } | ||
32 | |||
33 | export { | ||
34 | InternalEventEmitter | ||
35 | } | ||