diff options
author | Chocobozzz <me@florianbigard.com> | 2018-07-10 18:02:30 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2018-07-10 18:02:40 +0200 |
commit | 902aa3a099638b2198c24c076c61577a8435277b (patch) | |
tree | aa53daa4f071b7f8f2985e61a16c0ded2fcce7cd /client/src/standalone/player/events.ts | |
parent | 999417328bde0e60cd59318fc1c18672356254ce (diff) | |
download | PeerTube-902aa3a099638b2198c24c076c61577a8435277b.tar.gz PeerTube-902aa3a099638b2198c24c076c61577a8435277b.tar.zst PeerTube-902aa3a099638b2198c24c076c61577a8435277b.zip |
Fix player lint
Diffstat (limited to 'client/src/standalone/player/events.ts')
-rw-r--r-- | client/src/standalone/player/events.ts | 56 |
1 files changed, 28 insertions, 28 deletions
diff --git a/client/src/standalone/player/events.ts b/client/src/standalone/player/events.ts index c01328352..f1639ef19 100644 --- a/client/src/standalone/player/events.ts +++ b/client/src/standalone/player/events.ts | |||
@@ -1,48 +1,48 @@ | |||
1 | import { EventHandler } from "./definitions" | 1 | import { EventHandler } from './definitions' |
2 | 2 | ||
3 | interface PlayerEventRegistrar { | 3 | interface PlayerEventRegistrar { |
4 | registrations : Function[] | 4 | registrations: Function[] |
5 | } | 5 | } |
6 | 6 | ||
7 | interface PlayerEventRegistrationMap { | 7 | interface PlayerEventRegistrationMap { |
8 | [name : string] : PlayerEventRegistrar | 8 | [ name: string ]: PlayerEventRegistrar |
9 | } | 9 | } |
10 | 10 | ||
11 | export class EventRegistrar { | 11 | export class EventRegistrar { |
12 | 12 | ||
13 | private eventRegistrations : PlayerEventRegistrationMap = {} | 13 | private eventRegistrations: PlayerEventRegistrationMap = {} |
14 | 14 | ||
15 | public bindToChannel(channel : Channel.MessagingChannel) { | 15 | public bindToChannel (channel: Channel.MessagingChannel) { |
16 | for (let name of Object.keys(this.eventRegistrations)) | 16 | for (let name of Object.keys(this.eventRegistrations)) { |
17 | channel.bind(name, (txn, params) => this.fire(name, params)) | 17 | channel.bind(name, (txn, params) => this.fire(name, params)) |
18 | } | 18 | } |
19 | } | ||
19 | 20 | ||
20 | public registerTypes(names : string[]) { | 21 | public registerTypes (names: string[]) { |
21 | for (let name of names) | 22 | for (let name of names) { |
22 | this.eventRegistrations[name] = { registrations: [] } | 23 | this.eventRegistrations[ name ] = { registrations: [] } |
23 | } | 24 | } |
25 | } | ||
24 | 26 | ||
25 | public fire<T>(name : string, event : T) { | 27 | public fire<T> (name: string, event: T) { |
26 | this.eventRegistrations[name].registrations.forEach(x => x(event)) | 28 | this.eventRegistrations[ name ].registrations.forEach(x => x(event)) |
29 | } | ||
30 | |||
31 | public addListener<T> (name: string, handler: EventHandler<T>) { | ||
32 | if (!this.eventRegistrations[ name ]) { | ||
33 | console.warn(`PeerTube: addEventListener(): The event '${name}' is not supported`) | ||
34 | return false | ||
27 | } | 35 | } |
28 | 36 | ||
29 | public addListener<T>(name : string, handler : EventHandler<T>) { | 37 | this.eventRegistrations[ name ].registrations.push(handler) |
30 | if (!this.eventRegistrations[name]) { | 38 | return true |
31 | console.warn(`PeerTube: addEventListener(): The event '${name}' is not supported`) | 39 | } |
32 | return false | ||
33 | } | ||
34 | 40 | ||
35 | this.eventRegistrations[name].registrations.push(handler) | 41 | public removeListener<T> (name: string, handler: EventHandler<T>) { |
36 | return true | 42 | if (!this.eventRegistrations[ name ]) return false |
37 | } | ||
38 | 43 | ||
39 | public removeListener<T>(name : string, handler : EventHandler<T>) { | 44 | this.eventRegistrations[ name ].registrations = this.eventRegistrations[ name ].registrations.filter(x => x === handler) |
40 | if (!this.eventRegistrations[name]) | ||
41 | return false | ||
42 | 45 | ||
43 | this.eventRegistrations[name].registrations = | 46 | return true |
44 | this.eventRegistrations[name].registrations.filter(x => x === handler) | 47 | } |
45 | |||
46 | return true | ||
47 | } | ||
48 | } | 48 | } |