Skip to content

Commit

Permalink
Fix embed when waiting for a live
Browse files Browse the repository at this point in the history
  • Loading branch information
Chocobozzz committed Dec 8, 2023
1 parent b39214c commit ff338f7
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export class WebVideoOptionsBuilder {

videoFiles: this.options.webVideo.videoFiles.length !== 0
? this.options.webVideo.videoFiles
: this.options?.hls.videoFiles || []
: this.options.hls?.videoFiles || []
}
}
}
22 changes: 12 additions & 10 deletions client/src/assets/player/shared/web-video/web-video-plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ class WebVideoPlugin extends Plugin {
this.videoFiles = options.videoFiles
this.videoFileToken = options.videoFileToken

this.updateVideoFile({ videoFile: this.pickAverageVideoFile(), isUserResolutionChange: false })
const videoFile = this.pickAverageVideoFile()
if (videoFile) this.updateVideoFile({ videoFile, isUserResolutionChange: false })

this.onLoadedMetadata = () => {
player.trigger('video-ratio-changed', { ratio: this.player.videoWidth() / this.player.videoHeight() })
Expand All @@ -36,19 +37,19 @@ class WebVideoPlugin extends Plugin {
player.on('loadedmetadata', this.onLoadedMetadata)

player.ready(() => {
this.buildQualities()

this.setupNetworkInfoInterval()

if (this.videoFiles.length === 0) {
this.player.addClass('disabled')
return
}

this.buildQualities()

this.setupNetworkInfoInterval()
})
}

dispose () {
clearInterval(this.networkInfoInterval)
if (this.networkInfoInterval) clearInterval(this.networkInfoInterval)

if (this.onLoadedMetadata) this.player.off('loadedmetadata', this.onLoadedMetadata)
if (this.onErrorHandler) this.player.off('error', this.onErrorHandler)
Expand All @@ -58,7 +59,7 @@ class WebVideoPlugin extends Plugin {
}

getCurrentResolutionId () {
return this.currentVideoFile.resolution.id
return this.currentVideoFile?.resolution.id
}

updateVideoFile (options: {
Expand Down Expand Up @@ -123,7 +124,7 @@ class WebVideoPlugin extends Plugin {

private adaptPosterForAudioOnly () {
// Audio-only (resolutionId === 0) gets special treatment
if (this.currentVideoFile.resolution.id === 0) {
if (this.currentVideoFile?.resolution.id === 0) {
this.player.audioPosterMode(true)
} else {
this.player.audioPosterMode(false)
Expand Down Expand Up @@ -154,6 +155,7 @@ class WebVideoPlugin extends Plugin {
}

private pickAverageVideoFile () {
if (!this.videoFiles || this.videoFiles.length === 0) return undefined
if (this.videoFiles.length === 1) return this.videoFiles[0]

const files = this.videoFiles.filter(f => f.resolution.id !== 0)
Expand All @@ -165,7 +167,7 @@ class WebVideoPlugin extends Plugin {
id: videoFile.resolution.id,
label: this.buildQualityLabel(videoFile),
height: videoFile.resolution.id,
selected: videoFile.id === this.currentVideoFile.id,
selected: videoFile.id === this.currentVideoFile?.id,
selectCallback: () => this.updateVideoFile({ videoFile, isUserResolutionChange: true })
}))

Expand All @@ -187,7 +189,7 @@ class WebVideoPlugin extends Plugin {
return this.player.trigger('network-info', {
source: 'web-video',
http: {
downloaded: this.player.bufferedPercent() * this.currentVideoFile.size
downloaded: this.player.bufferedPercent() * this.currentVideoFile?.size
}
} as PlayerNetworkInfo)
}, 1000)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,9 @@ export class FFmpegTranscodingWrapper extends AbstractTranscodingWrapper {

logger.debug('Killing ffmpeg after live abort of ' + this.videoUUID, this.lTags())

this.ffmpegCommand.kill('SIGINT')
if (this.ffmpegCommand) {
this.ffmpegCommand.kill('SIGINT')
}

this.aborted = true
this.emit('end')
Expand Down

0 comments on commit ff338f7

Please sign in to comment.