import { EventHandler } from './definitions'
interface PlayerEventRegistrar {
- registrations: Function[]
+ registrations: EventHandler<any>[]
}
interface PlayerEventRegistrationMap {
private eventRegistrations: PlayerEventRegistrationMap = {}
public bindToChannel (channel: Channel.MessagingChannel) {
- for (let name of Object.keys(this.eventRegistrations)) {
+ for (const name of Object.keys(this.eventRegistrations)) {
channel.bind(name, (txn, params) => this.fire(name, params))
}
}
public registerTypes (names: string[]) {
- for (let name of names) {
- this.eventRegistrations[ name ] = { registrations: [] }
+ for (const name of names) {
+ this.eventRegistrations[name] = { registrations: [] }
}
}
public fire<T> (name: string, event: T) {
- this.eventRegistrations[ name ].registrations.forEach(x => x(event))
+ this.eventRegistrations[name].registrations.forEach(x => x(event))
}
public addListener<T> (name: string, handler: EventHandler<T>) {
- if (!this.eventRegistrations[ name ]) {
+ if (!this.eventRegistrations[name]) {
console.warn(`PeerTube: addEventListener(): The event '${name}' is not supported`)
return false
}
- this.eventRegistrations[ name ].registrations.push(handler)
+ this.eventRegistrations[name].registrations.push(handler)
return true
}
public removeListener<T> (name: string, handler: EventHandler<T>) {
- if (!this.eventRegistrations[ name ]) return false
+ if (!this.eventRegistrations[name]) return false
- this.eventRegistrations[ name ].registrations = this.eventRegistrations[ name ].registrations.filter(x => x === handler)
+ this.eventRegistrations[name].registrations = this.eventRegistrations[name].registrations.filter(x => x === handler)
return true
}