aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--client/src/assets/player/webtorrent/webtorrent-plugin.ts40
-rw-r--r--client/src/standalone/videos/embed-api.ts41
-rw-r--r--client/src/standalone/videos/test-embed.ts2
-rw-r--r--server/tools/peertube.ts2
4 files changed, 26 insertions, 59 deletions
diff --git a/client/src/assets/player/webtorrent/webtorrent-plugin.ts b/client/src/assets/player/webtorrent/webtorrent-plugin.ts
index a464f02d5..1a1cd7f1a 100644
--- a/client/src/assets/player/webtorrent/webtorrent-plugin.ts
+++ b/client/src/assets/player/webtorrent/webtorrent-plugin.ts
@@ -178,7 +178,7 @@ class WebTorrentPlugin extends Plugin {
178 this.selectAppropriateResolution(true) 178 this.selectAppropriateResolution(true)
179 } 179 }
180 180
181 updateResolution (resolutionId: number, delay = 0) { 181 updateEngineResolution (resolutionId: number, delay = 0) {
182 // Remember player state 182 // Remember player state
183 const currentTime = this.player.currentTime() 183 const currentTime = this.player.currentTime()
184 const isPaused = this.player.paused() 184 const isPaused = this.player.paused()
@@ -236,6 +236,22 @@ class WebTorrentPlugin extends Plugin {
236 return this.currentVideoFile 236 return this.currentVideoFile
237 } 237 }
238 238
239 changeQuality (id: number) {
240 if (id === -1) {
241 if (this.autoResolutionPossible === true) {
242 this.autoResolution = true
243
244 this.selectAppropriateResolution(false)
245 }
246
247 return
248 }
249
250 this.autoResolution = false
251 this.updateEngineResolution(id)
252 this.selectAppropriateResolution(false)
253 }
254
239 private addTorrent ( 255 private addTorrent (
240 magnetOrTorrentUrl: string, 256 magnetOrTorrentUrl: string,
241 previousVideoFile: VideoFile, 257 previousVideoFile: VideoFile,
@@ -458,7 +474,7 @@ class WebTorrentPlugin extends Plugin {
458 } 474 }
459 475
460 if (changeResolution === true) { 476 if (changeResolution === true) {
461 this.updateResolution(file.resolution.id, changeResolutionDelay) 477 this.updateEngineResolution(file.resolution.id, changeResolutionDelay)
462 478
463 // Wait some seconds in observation of our new resolution 479 // Wait some seconds in observation of our new resolution
464 this.isAutoResolutionObservation = true 480 this.isAutoResolutionObservation = true
@@ -598,14 +614,14 @@ class WebTorrentPlugin extends Plugin {
598 label: this.buildQualityLabel(file), 614 label: this.buildQualityLabel(file),
599 height: file.resolution.id, 615 height: file.resolution.id,
600 selected: false, 616 selected: false,
601 selectCallback: () => this.qualitySwitchCallback(file.resolution.id) 617 selectCallback: () => this.changeQuality(file.resolution.id)
602 })) 618 }))
603 619
604 resolutions.push({ 620 resolutions.push({
605 id: -1, 621 id: -1,
606 label: this.player.localize('Auto'), 622 label: this.player.localize('Auto'),
607 selected: true, 623 selected: true,
608 selectCallback: () => this.qualitySwitchCallback(-1) 624 selectCallback: () => this.changeQuality(-1)
609 }) 625 })
610 626
611 this.player.peertubeResolutions().add(resolutions) 627 this.player.peertubeResolutions().add(resolutions)
@@ -621,22 +637,6 @@ class WebTorrentPlugin extends Plugin {
621 return label 637 return label
622 } 638 }
623 639
624 private qualitySwitchCallback (id: number) {
625 if (id === -1) {
626 if (this.autoResolutionPossible === true) {
627 this.autoResolution = true
628
629 this.selectAppropriateResolution(false)
630 }
631
632 return
633 }
634
635 this.autoResolution = false
636 this.updateResolution(id)
637 this.selectAppropriateResolution(false)
638 }
639
640 private selectAppropriateResolution (byEngine: boolean) { 640 private selectAppropriateResolution (byEngine: boolean) {
641 const resolution = this.autoResolution 641 const resolution = this.autoResolution
642 ? -1 642 ? -1
diff --git a/client/src/standalone/videos/embed-api.ts b/client/src/standalone/videos/embed-api.ts
index 8443cb7e9..a28aeeaef 100644
--- a/client/src/standalone/videos/embed-api.ts
+++ b/client/src/standalone/videos/embed-api.ts
@@ -64,19 +64,12 @@ export class PeerTubeEmbedApi {
64 if (this.isWebtorrent()) { 64 if (this.isWebtorrent()) {
65 if (resolutionId === -1 && this.embed.player.webtorrent().isAutoResolutionPossible() === false) return 65 if (resolutionId === -1 && this.embed.player.webtorrent().isAutoResolutionPossible() === false) return
66 66
67 // Auto resolution 67 this.embed.player.webtorrent().changeQuality(resolutionId)
68 if (resolutionId === -1) {
69 this.embed.player.webtorrent().enableAutoResolution()
70 return
71 }
72
73 this.embed.player.webtorrent().disableAutoResolution()
74 this.embed.player.webtorrent().updateResolution(resolutionId)
75 68
76 return 69 return
77 } 70 }
78 71
79 this.embed.player.p2pMediaLoader().getHLSJS().nextLevel = resolutionId 72 this.embed.player.p2pMediaLoader().getHLSJS().currentLevel = resolutionId
80 } 73 }
81 74
82 private getCaptions (): PeerTubeTextTrack[] { 75 private getCaptions (): PeerTubeTextTrack[] {
@@ -142,6 +135,8 @@ export class PeerTubeEmbedApi {
142 this.embed.player.peertubeResolutions().on('resolutionsAdded', () => this.loadResolutions()) 135 this.embed.player.peertubeResolutions().on('resolutionsAdded', () => this.loadResolutions())
143 this.embed.player.peertubeResolutions().on('resolutionChanged', () => this.loadResolutions()) 136 this.embed.player.peertubeResolutions().on('resolutionChanged', () => this.loadResolutions())
144 137
138 this.loadResolutions()
139
145 this.embed.player.on('volumechange', () => { 140 this.embed.player.on('volumechange', () => {
146 this.channel.notify({ 141 this.channel.notify({
147 method: 'volumeChange', 142 method: 'volumeChange',
@@ -150,37 +145,11 @@ export class PeerTubeEmbedApi {
150 }) 145 })
151 } 146 }
152 147
153 private loadWebTorrentResolutions () {
154 this.resolutions = []
155
156 const currentResolutionId = this.embed.player.webtorrent().getCurrentResolutionId()
157
158 for (const videoFile of this.embed.player.webtorrent().videoFiles) {
159 let label = videoFile.resolution.label
160 if (videoFile.fps && videoFile.fps >= 50) {
161 label += videoFile.fps
162 }
163
164 this.resolutions.push({
165 id: videoFile.resolution.id,
166 label,
167 src: videoFile.magnetUri,
168 active: videoFile.resolution.id === currentResolutionId,
169 height: videoFile.resolution.id
170 })
171 }
172
173 this.channel.notify({
174 method: 'resolutionUpdate',
175 params: this.resolutions
176 })
177 }
178
179 private loadResolutions () { 148 private loadResolutions () {
180 this.resolutions = this.embed.player.peertubeResolutions().getResolutions() 149 this.resolutions = this.embed.player.peertubeResolutions().getResolutions()
181 .map(r => ({ 150 .map(r => ({
182 id: r.id, 151 id: r.id,
183 label: r.height + 'p', 152 label: r.label,
184 active: r.selected, 153 active: r.selected,
185 width: r.width, 154 width: r.width,
186 height: r.height 155 height: r.height
diff --git a/client/src/standalone/videos/test-embed.ts b/client/src/standalone/videos/test-embed.ts
index 301c95d7b..7213cbf8b 100644
--- a/client/src/standalone/videos/test-embed.ts
+++ b/client/src/standalone/videos/test-embed.ts
@@ -84,8 +84,6 @@ window.addEventListener('load', async () => {
84 captionEl.innerHTML = '' 84 captionEl.innerHTML = ''
85 85
86 captions.forEach(c => { 86 captions.forEach(c => {
87 console.log(c)
88
89 if (c.mode === 'showing') { 87 if (c.mode === 'showing') {
90 const itemEl = document.createElement('strong') 88 const itemEl = document.createElement('strong')
91 itemEl.innerText = `${c.label} (active)` 89 itemEl.innerText = `${c.label} (active)`
diff --git a/server/tools/peertube.ts b/server/tools/peertube.ts
index 34152bd13..9e07640f0 100644
--- a/server/tools/peertube.ts
+++ b/server/tools/peertube.ts
@@ -43,7 +43,7 @@ if (!process.argv.slice(2).length) {
43 / / -" _/"/ 43 / / -" _/"/
44 / | ._\\\\ |\\ |_.".-" / 44 / | ._\\\\ |\\ |_.".-" /
45 / | __\\)|)|),/|_." _,." 45 / | __\\)|)|),/|_." _,."
46 / \_." " ") | ).-""---''-- 46 / \\_." " ") | ).-""---''--
47 ( "/.""7__-""'' 47 ( "/.""7__-""''
48 | " ."._--._ 48 | " ."._--._
49 \\ \\ (_ __ "" ".,_ 49 \\ \\ (_ __ "" ".,_