internal-event-emitter.ts 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. import { MChannel, MVideo, MVideoImmutable } from '@server/types/models/index.js'
  2. import { EventEmitter } from 'events'
  3. export interface PeerTubeInternalEvents {
  4. 'video-created': (options: { video: MVideo }) => void
  5. 'video-updated': (options: { video: MVideo }) => void
  6. 'video-deleted': (options: { video: MVideo }) => void
  7. 'channel-created': (options: { channel: MChannel }) => void
  8. 'channel-updated': (options: { channel: MChannel }) => void
  9. 'channel-deleted': (options: { channel: MChannel }) => void
  10. 'chapters-updated': (options: { video: MVideoImmutable }) => void
  11. }
  12. declare interface InternalEventEmitter {
  13. on<U extends keyof PeerTubeInternalEvents>(
  14. event: U, listener: PeerTubeInternalEvents[U]
  15. ): this
  16. emit<U extends keyof PeerTubeInternalEvents>(
  17. event: U, ...args: Parameters<PeerTubeInternalEvents[U]>
  18. ): boolean
  19. }
  20. class InternalEventEmitter extends EventEmitter {
  21. private static instance: InternalEventEmitter
  22. static get Instance () {
  23. return this.instance || (this.instance = new this())
  24. }
  25. }
  26. export {
  27. InternalEventEmitter
  28. }