aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/assets/player/peertube-plugin.ts
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2019-01-24 10:16:30 +0100
committerChocobozzz <chocobozzz@cpy.re>2019-02-11 09:13:02 +0100
commit3b6f205c34bb931de0323581edf991ca33256e6b (patch)
treef6ba40b7c666e38ff9c321906f04cb2c2630163e /client/src/assets/player/peertube-plugin.ts
parent2adfc7ea9a1f858db874df9fe322e7ae833db77c (diff)
downloadPeerTube-3b6f205c34bb931de0323581edf991ca33256e6b.tar.gz
PeerTube-3b6f205c34bb931de0323581edf991ca33256e6b.tar.zst
PeerTube-3b6f205c34bb931de0323581edf991ca33256e6b.zip
Correctly implement p2p-media-loader
Diffstat (limited to 'client/src/assets/player/peertube-plugin.ts')
-rw-r--r--client/src/assets/player/peertube-plugin.ts41
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
3import * as videojs from 'video.js' 3import * as videojs from 'video.js'
4import './videojs-components/settings-menu-button' 4import './videojs-components/settings-menu-button'
5import { PeerTubePluginOptions, UserWatching, VideoJSCaption, VideoJSComponentInterface, videojsUntyped } from './peertube-videojs-typings' 5import {
6 PeerTubePluginOptions,
7 ResolutionUpdateData,
8 UserWatching,
9 VideoJSCaption,
10 VideoJSComponentInterface,
11 videojsUntyped
12} from './peertube-videojs-typings'
6import { isMobile, timeToInt } from './utils' 13import { isMobile, timeToInt } from './utils'
7import { 14import {
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