X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=client%2Fsrc%2Fassets%2Fplayer%2Fvideojs-components%2Fresolution-menu-item.ts;h=6047f52f7878623cee01a0b69f8794dd925e5fc6;hb=02b2e482e0bdf16432b1ee34e95a71bbad39a4ff;hp=6c42fefd2f1eb60109c9e4ada9ac44ac1ee413e3;hpb=88108880bbdba473cfe36ecbebc1c3c4f972e102;p=github%2FChocobozzz%2FPeerTube.git
diff --git a/client/src/assets/player/videojs-components/resolution-menu-item.ts b/client/src/assets/player/videojs-components/resolution-menu-item.ts
index 6c42fefd2..6047f52f7 100644
--- a/client/src/assets/player/videojs-components/resolution-menu-item.ts
+++ b/client/src/assets/player/videojs-components/resolution-menu-item.ts
@@ -1,83 +1,77 @@
-// FIXME: something weird with our path definition in tsconfig and typings
-// @ts-ignore
-import { Player } from 'video.js'
+import videojs from 'video.js'
-import { AutoResolutionUpdateData, ResolutionUpdateData, VideoJSComponentInterface, videojsUntyped } from '../peertube-videojs-typings'
+const MenuItem = videojs.getComponent('MenuItem')
+
+export interface ResolutionMenuItemOptions extends videojs.MenuItemOptions {
+ id: number
+}
-const MenuItem: VideoJSComponentInterface = videojsUntyped.getComponent('MenuItem')
class ResolutionMenuItem extends MenuItem {
- private readonly id: number
+ private readonly resolutionId: number
private readonly label: string
- // Only used for the automatic item
- private readonly labels: { [id: number]: string }
- private readonly callback: Function
- private autoResolutionPossible: boolean
- private currentResolutionLabel: string
+ private autoResolutionEnabled: boolean
+ private autoResolutionChosen: string
- constructor (player: Player, options: any) {
+ constructor (player: videojs.Player, options?: ResolutionMenuItemOptions) {
options.selectable = true
super(player, options)
- this.autoResolutionPossible = true
- this.currentResolutionLabel = ''
+ this.autoResolutionEnabled = true
+ this.autoResolutionChosen = ''
+ this.resolutionId = options.id
this.label = options.label
- this.labels = options.labels
- this.id = options.id
- this.callback = options.callback
- player.peertube().on('resolutionChange', (_: any, data: ResolutionUpdateData) => this.updateSelection(data))
+ player.peertubeResolutions().on('resolutionChanged', () => this.updateSelection())
// We only want to disable the "Auto" item
- if (this.id === -1) {
- player.peertube().on('autoResolutionChange', (_: any, data: AutoResolutionUpdateData) => this.updateAutoResolution(data))
+ if (this.resolutionId === -1) {
+ player.peertubeResolutions().on('autoResolutionEnabledChanged', () => this.updateAutoResolution())
}
}
handleClick (event: any) {
// Auto button disabled?
- if (this.autoResolutionPossible === false && this.id === -1) return
+ if (this.autoResolutionEnabled === false && this.resolutionId === -1) return
super.handleClick(event)
- this.callback(this.id, 'video')
+ this.player().peertubeResolutions().select({ id: this.resolutionId, byEngine: false })
}
- updateSelection (data: ResolutionUpdateData) {
- if (this.id === -1) {
- this.currentResolutionLabel = this.labels[data.id]
- }
+ updateSelection () {
+ const selectedResolution = this.player().peertubeResolutions().getSelected()
- // Automatic resolution only
- if (data.auto === true) {
- this.selected(this.id === -1)
- return
+ if (this.resolutionId === -1) {
+ this.autoResolutionChosen = this.player().peertubeResolutions().getAutoResolutionChosen()?.label
}
- this.selected(this.id === data.id)
+ this.selected(this.resolutionId === selectedResolution.id)
}
- updateAutoResolution (data: AutoResolutionUpdateData) {
+ updateAutoResolution () {
+ const enabled = this.player().peertubeResolutions().isAutoResolutionEnabeld()
+
// Check if the auto resolution is enabled or not
- if (data.possible === false) {
+ if (enabled === false) {
this.addClass('disabled')
} else {
this.removeClass('disabled')
}
- this.autoResolutionPossible = data.possible
+ this.autoResolutionEnabled = enabled
}
getLabel () {
- if (this.id === -1) {
- return this.label + ' ' + this.currentResolutionLabel + ''
+ if (this.resolutionId === -1) {
+ return this.label + ' ' + this.autoResolutionChosen + ''
}
return this.label
}
}
-MenuItem.registerComponent('ResolutionMenuItem', ResolutionMenuItem)
+videojs.registerComponent('ResolutionMenuItem', ResolutionMenuItem)
export { ResolutionMenuItem }