diff options
Diffstat (limited to 'client/src/assets/player/peertube-plugin.ts')
-rw-r--r-- | client/src/assets/player/peertube-plugin.ts | 41 |
1 files changed, 40 insertions, 1 deletions
diff --git a/client/src/assets/player/peertube-plugin.ts b/client/src/assets/player/peertube-plugin.ts index 0bd607697..f83d9094a 100644 --- a/client/src/assets/player/peertube-plugin.ts +++ b/client/src/assets/player/peertube-plugin.ts | |||
@@ -2,7 +2,14 @@ | |||
2 | // @ts-ignore | 2 | // @ts-ignore |
3 | import * as videojs from 'video.js' | 3 | import * as videojs from 'video.js' |
4 | import './videojs-components/settings-menu-button' | 4 | import './videojs-components/settings-menu-button' |
5 | import { PeerTubePluginOptions, UserWatching, VideoJSCaption, VideoJSComponentInterface, videojsUntyped } from './peertube-videojs-typings' | 5 | import { |
6 | PeerTubePluginOptions, | ||
7 | ResolutionUpdateData, | ||
8 | UserWatching, | ||
9 | VideoJSCaption, | ||
10 | VideoJSComponentInterface, | ||
11 | videojsUntyped | ||
12 | } from './peertube-videojs-typings' | ||
6 | import { isMobile, timeToInt } from './utils' | 13 | import { isMobile, timeToInt } from './utils' |
7 | import { | 14 | import { |
8 | getStoredLastSubtitle, | 15 | getStoredLastSubtitle, |
@@ -30,6 +37,7 @@ class PeerTubePlugin extends Plugin { | |||
30 | private videoViewInterval: any | 37 | private videoViewInterval: any |
31 | private userWatchingVideoInterval: any | 38 | private userWatchingVideoInterval: any |
32 | private qualityObservationTimer: any | 39 | private qualityObservationTimer: any |
40 | private lastResolutionChange: ResolutionUpdateData | ||
33 | 41 | ||
34 | constructor (player: videojs.Player, options: PeerTubePluginOptions) { | 42 | constructor (player: videojs.Player, options: PeerTubePluginOptions) { |
35 | super(player, options) | 43 | super(player, options) |
@@ -44,6 +52,22 @@ class PeerTubePlugin extends Plugin { | |||
44 | this.player.ready(() => { | 52 | this.player.ready(() => { |
45 | const playerOptions = this.player.options_ | 53 | const playerOptions = this.player.options_ |
46 | 54 | ||
55 | if (this.player.webtorrent) { | ||
56 | this.player.webtorrent().on('resolutionChange', (_: any, d: any) => this.handleResolutionChange(d)) | ||
57 | this.player.webtorrent().on('autoResolutionChange', (_: any, d: any) => this.trigger('autoResolutionChange', d)) | ||
58 | } | ||
59 | |||
60 | if (this.player.p2pMediaLoader) { | ||
61 | this.player.p2pMediaLoader().on('resolutionChange', (_: any, d: any) => this.handleResolutionChange(d)) | ||
62 | } | ||
63 | |||
64 | this.player.tech_.on('loadedqualitydata', () => { | ||
65 | setTimeout(() => { | ||
66 | // Replay a resolution change, now we loaded all quality data | ||
67 | if (this.lastResolutionChange) this.handleResolutionChange(this.lastResolutionChange) | ||
68 | }, 0) | ||
69 | }) | ||
70 | |||
47 | const volume = getStoredVolume() | 71 | const volume = getStoredVolume() |
48 | if (volume !== undefined) this.player.volume(volume) | 72 | if (volume !== undefined) this.player.volume(volume) |
49 | 73 | ||
@@ -158,6 +182,21 @@ class PeerTubePlugin extends Plugin { | |||
158 | return fetch(url, { method: 'PUT', body, headers }) | 182 | return fetch(url, { method: 'PUT', body, headers }) |
159 | } | 183 | } |
160 | 184 | ||
185 | private handleResolutionChange (data: ResolutionUpdateData) { | ||
186 | this.lastResolutionChange = data | ||
187 | |||
188 | const qualityLevels = this.player.qualityLevels() | ||
189 | |||
190 | for (let i = 0; i < qualityLevels.length; i++) { | ||
191 | if (qualityLevels[i].height === data.resolutionId) { | ||
192 | data.id = qualityLevels[i].id | ||
193 | break | ||
194 | } | ||
195 | } | ||
196 | |||
197 | this.trigger('resolutionChange', data) | ||
198 | } | ||
199 | |||
161 | private alterInactivity () { | 200 | private alterInactivity () { |
162 | let saveInactivityTimeout: number | 201 | let saveInactivityTimeout: number |
163 | 202 | ||