Fix embed api
This commit is contained in:
parent
624e42fdf9
commit
89ac282e04
|
@ -178,7 +178,7 @@ class WebTorrentPlugin extends Plugin {
|
||||||
this.selectAppropriateResolution(true)
|
this.selectAppropriateResolution(true)
|
||||||
}
|
}
|
||||||
|
|
||||||
updateResolution (resolutionId: number, delay = 0) {
|
updateEngineResolution (resolutionId: number, delay = 0) {
|
||||||
// Remember player state
|
// Remember player state
|
||||||
const currentTime = this.player.currentTime()
|
const currentTime = this.player.currentTime()
|
||||||
const isPaused = this.player.paused()
|
const isPaused = this.player.paused()
|
||||||
|
@ -236,6 +236,22 @@ class WebTorrentPlugin extends Plugin {
|
||||||
return this.currentVideoFile
|
return this.currentVideoFile
|
||||||
}
|
}
|
||||||
|
|
||||||
|
changeQuality (id: number) {
|
||||||
|
if (id === -1) {
|
||||||
|
if (this.autoResolutionPossible === true) {
|
||||||
|
this.autoResolution = true
|
||||||
|
|
||||||
|
this.selectAppropriateResolution(false)
|
||||||
|
}
|
||||||
|
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
this.autoResolution = false
|
||||||
|
this.updateEngineResolution(id)
|
||||||
|
this.selectAppropriateResolution(false)
|
||||||
|
}
|
||||||
|
|
||||||
private addTorrent (
|
private addTorrent (
|
||||||
magnetOrTorrentUrl: string,
|
magnetOrTorrentUrl: string,
|
||||||
previousVideoFile: VideoFile,
|
previousVideoFile: VideoFile,
|
||||||
|
@ -458,7 +474,7 @@ class WebTorrentPlugin extends Plugin {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (changeResolution === true) {
|
if (changeResolution === true) {
|
||||||
this.updateResolution(file.resolution.id, changeResolutionDelay)
|
this.updateEngineResolution(file.resolution.id, changeResolutionDelay)
|
||||||
|
|
||||||
// Wait some seconds in observation of our new resolution
|
// Wait some seconds in observation of our new resolution
|
||||||
this.isAutoResolutionObservation = true
|
this.isAutoResolutionObservation = true
|
||||||
|
@ -598,14 +614,14 @@ class WebTorrentPlugin extends Plugin {
|
||||||
label: this.buildQualityLabel(file),
|
label: this.buildQualityLabel(file),
|
||||||
height: file.resolution.id,
|
height: file.resolution.id,
|
||||||
selected: false,
|
selected: false,
|
||||||
selectCallback: () => this.qualitySwitchCallback(file.resolution.id)
|
selectCallback: () => this.changeQuality(file.resolution.id)
|
||||||
}))
|
}))
|
||||||
|
|
||||||
resolutions.push({
|
resolutions.push({
|
||||||
id: -1,
|
id: -1,
|
||||||
label: this.player.localize('Auto'),
|
label: this.player.localize('Auto'),
|
||||||
selected: true,
|
selected: true,
|
||||||
selectCallback: () => this.qualitySwitchCallback(-1)
|
selectCallback: () => this.changeQuality(-1)
|
||||||
})
|
})
|
||||||
|
|
||||||
this.player.peertubeResolutions().add(resolutions)
|
this.player.peertubeResolutions().add(resolutions)
|
||||||
|
@ -621,22 +637,6 @@ class WebTorrentPlugin extends Plugin {
|
||||||
return label
|
return label
|
||||||
}
|
}
|
||||||
|
|
||||||
private qualitySwitchCallback (id: number) {
|
|
||||||
if (id === -1) {
|
|
||||||
if (this.autoResolutionPossible === true) {
|
|
||||||
this.autoResolution = true
|
|
||||||
|
|
||||||
this.selectAppropriateResolution(false)
|
|
||||||
}
|
|
||||||
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
this.autoResolution = false
|
|
||||||
this.updateResolution(id)
|
|
||||||
this.selectAppropriateResolution(false)
|
|
||||||
}
|
|
||||||
|
|
||||||
private selectAppropriateResolution (byEngine: boolean) {
|
private selectAppropriateResolution (byEngine: boolean) {
|
||||||
const resolution = this.autoResolution
|
const resolution = this.autoResolution
|
||||||
? -1
|
? -1
|
||||||
|
|
|
@ -64,19 +64,12 @@ export class PeerTubeEmbedApi {
|
||||||
if (this.isWebtorrent()) {
|
if (this.isWebtorrent()) {
|
||||||
if (resolutionId === -1 && this.embed.player.webtorrent().isAutoResolutionPossible() === false) return
|
if (resolutionId === -1 && this.embed.player.webtorrent().isAutoResolutionPossible() === false) return
|
||||||
|
|
||||||
// Auto resolution
|
this.embed.player.webtorrent().changeQuality(resolutionId)
|
||||||
if (resolutionId === -1) {
|
|
||||||
this.embed.player.webtorrent().enableAutoResolution()
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
this.embed.player.webtorrent().disableAutoResolution()
|
|
||||||
this.embed.player.webtorrent().updateResolution(resolutionId)
|
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
this.embed.player.p2pMediaLoader().getHLSJS().nextLevel = resolutionId
|
this.embed.player.p2pMediaLoader().getHLSJS().currentLevel = resolutionId
|
||||||
}
|
}
|
||||||
|
|
||||||
private getCaptions (): PeerTubeTextTrack[] {
|
private getCaptions (): PeerTubeTextTrack[] {
|
||||||
|
@ -142,6 +135,8 @@ export class PeerTubeEmbedApi {
|
||||||
this.embed.player.peertubeResolutions().on('resolutionsAdded', () => this.loadResolutions())
|
this.embed.player.peertubeResolutions().on('resolutionsAdded', () => this.loadResolutions())
|
||||||
this.embed.player.peertubeResolutions().on('resolutionChanged', () => this.loadResolutions())
|
this.embed.player.peertubeResolutions().on('resolutionChanged', () => this.loadResolutions())
|
||||||
|
|
||||||
|
this.loadResolutions()
|
||||||
|
|
||||||
this.embed.player.on('volumechange', () => {
|
this.embed.player.on('volumechange', () => {
|
||||||
this.channel.notify({
|
this.channel.notify({
|
||||||
method: 'volumeChange',
|
method: 'volumeChange',
|
||||||
|
@ -150,37 +145,11 @@ export class PeerTubeEmbedApi {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
private loadWebTorrentResolutions () {
|
|
||||||
this.resolutions = []
|
|
||||||
|
|
||||||
const currentResolutionId = this.embed.player.webtorrent().getCurrentResolutionId()
|
|
||||||
|
|
||||||
for (const videoFile of this.embed.player.webtorrent().videoFiles) {
|
|
||||||
let label = videoFile.resolution.label
|
|
||||||
if (videoFile.fps && videoFile.fps >= 50) {
|
|
||||||
label += videoFile.fps
|
|
||||||
}
|
|
||||||
|
|
||||||
this.resolutions.push({
|
|
||||||
id: videoFile.resolution.id,
|
|
||||||
label,
|
|
||||||
src: videoFile.magnetUri,
|
|
||||||
active: videoFile.resolution.id === currentResolutionId,
|
|
||||||
height: videoFile.resolution.id
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
this.channel.notify({
|
|
||||||
method: 'resolutionUpdate',
|
|
||||||
params: this.resolutions
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
private loadResolutions () {
|
private loadResolutions () {
|
||||||
this.resolutions = this.embed.player.peertubeResolutions().getResolutions()
|
this.resolutions = this.embed.player.peertubeResolutions().getResolutions()
|
||||||
.map(r => ({
|
.map(r => ({
|
||||||
id: r.id,
|
id: r.id,
|
||||||
label: r.height + 'p',
|
label: r.label,
|
||||||
active: r.selected,
|
active: r.selected,
|
||||||
width: r.width,
|
width: r.width,
|
||||||
height: r.height
|
height: r.height
|
||||||
|
|
|
@ -84,8 +84,6 @@ window.addEventListener('load', async () => {
|
||||||
captionEl.innerHTML = ''
|
captionEl.innerHTML = ''
|
||||||
|
|
||||||
captions.forEach(c => {
|
captions.forEach(c => {
|
||||||
console.log(c)
|
|
||||||
|
|
||||||
if (c.mode === 'showing') {
|
if (c.mode === 'showing') {
|
||||||
const itemEl = document.createElement('strong')
|
const itemEl = document.createElement('strong')
|
||||||
itemEl.innerText = `${c.label} (active)`
|
itemEl.innerText = `${c.label} (active)`
|
||||||
|
|
|
@ -43,7 +43,7 @@ if (!process.argv.slice(2).length) {
|
||||||
/ / -" _/"/
|
/ / -" _/"/
|
||||||
/ | ._\\\\ |\\ |_.".-" /
|
/ | ._\\\\ |\\ |_.".-" /
|
||||||
/ | __\\)|)|),/|_." _,."
|
/ | __\\)|)|),/|_." _,."
|
||||||
/ \_." " ") | ).-""---''--
|
/ \\_." " ") | ).-""---''--
|
||||||
( "/.""7__-""''
|
( "/.""7__-""''
|
||||||
| " ."._--._
|
| " ."._--._
|
||||||
\\ \\ (_ __ "" ".,_
|
\\ \\ (_ __ "" ".,_
|
||||||
|
|
Loading…
Reference in New Issue