diff --git a/client/package.json b/client/package.json index 617c7cb49..7b044dbdd 100644 --- a/client/package.json +++ b/client/package.json @@ -13,7 +13,7 @@ "url": "git://github.com/Chocobozzz/PeerTube.git" }, "scripts": { - "lint": "tslint --project ./tsconfig.json -c ./tslint.json 'src/app/**/*.ts'", + "lint": "tslint --project ./tsconfig.json -c ./tslint.json 'src/app/**/*.ts' 'src/standalone/**/*.ts'", "webpack": "webpack", "tslint": "tslint", "ng": "ng", diff --git a/client/src/standalone/player/definitions.ts b/client/src/standalone/player/definitions.ts index 6920672a7..7f9ef9b6f 100644 --- a/client/src/standalone/player/definitions.ts +++ b/client/src/standalone/player/definitions.ts @@ -1,18 +1,16 @@ - export interface EventHandler { - (ev : T) : void + (ev: T): void } -export type PlayerEventType = - 'pause' | 'play' | - 'playbackStatusUpdate' | - 'playbackStatusChange' | - 'resolutionUpdate' -; +export type PlayerEventType = + 'pause' | 'play' | + 'playbackStatusUpdate' | + 'playbackStatusChange' | + 'resolutionUpdate' export interface PeerTubeResolution { - id : any - label : string - src : string - active : boolean -} \ No newline at end of file + id: any + label: string + src: string + active: boolean +} 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 @@ -import { EventHandler } from "./definitions" +import { EventHandler } from './definitions' interface PlayerEventRegistrar { - registrations : Function[] + registrations: Function[] } interface PlayerEventRegistrationMap { - [name : string] : PlayerEventRegistrar + [ name: string ]: PlayerEventRegistrar } export class EventRegistrar { - private eventRegistrations : PlayerEventRegistrationMap = {} + private eventRegistrations: PlayerEventRegistrationMap = {} - public bindToChannel(channel : Channel.MessagingChannel) { - for (let name of Object.keys(this.eventRegistrations)) - channel.bind(name, (txn, params) => this.fire(name, params)) + public bindToChannel (channel: Channel.MessagingChannel) { + for (let 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: [] } + } + } + + public fire (name: string, event: T) { + this.eventRegistrations[ name ].registrations.forEach(x => x(event)) + } + + public addListener (name: string, handler: EventHandler) { + if (!this.eventRegistrations[ name ]) { + console.warn(`PeerTube: addEventListener(): The event '${name}' is not supported`) + return false } - public registerTypes(names : string[]) { - for (let name of names) - this.eventRegistrations[name] = { registrations: [] } - } + this.eventRegistrations[ name ].registrations.push(handler) + return true + } - public fire(name : string, event : T) { - this.eventRegistrations[name].registrations.forEach(x => x(event)) - } + public removeListener (name: string, handler: EventHandler) { + if (!this.eventRegistrations[ name ]) return false - public addListener(name : string, handler : EventHandler) { - if (!this.eventRegistrations[name]) { - console.warn(`PeerTube: addEventListener(): The event '${name}' is not supported`) - return false - } + this.eventRegistrations[ name ].registrations = this.eventRegistrations[ name ].registrations.filter(x => x === handler) - this.eventRegistrations[name].registrations.push(handler) - return true - } - - public removeListener(name : string, handler : EventHandler) { - if (!this.eventRegistrations[name]) - return false - - this.eventRegistrations[name].registrations = - this.eventRegistrations[name].registrations.filter(x => x === handler) - - return true - } + return true + } } diff --git a/client/src/standalone/player/player.ts b/client/src/standalone/player/player.ts index 9fc648d25..91a5e73f3 100644 --- a/client/src/standalone/player/player.ts +++ b/client/src/standalone/player/player.ts @@ -3,29 +3,35 @@ import { EventRegistrar } from './events' import { EventHandler, PlayerEventType, PeerTubeResolution } from './definitions' const PASSTHROUGH_EVENTS = [ - 'pause', 'play', + 'pause', + 'play', 'playbackStatusUpdate', 'playbackStatusChange', 'resolutionUpdate' ] /** - * Allows for programmatic control of a PeerTube embed running in an