mirror of
https://github.com/Chocobozzz/PeerTube.git
synced 2026-09-03 20:53:09 -05:00
Cleanup live listeners
This commit is contained in:
@@ -55,6 +55,9 @@ export class PeerTubeEmbed {
|
|||||||
private alreadyInitialized = false
|
private alreadyInitialized = false
|
||||||
private alreadyPlayed = false
|
private alreadyPlayed = false
|
||||||
|
|
||||||
|
private currentLiveVideo: VideoDetails
|
||||||
|
private currentLiveEndedHandler: () => void
|
||||||
|
|
||||||
private videoPassword: string
|
private videoPassword: string
|
||||||
private videoPasswordFromAPI: string
|
private videoPasswordFromAPI: string
|
||||||
private onVideoPasswordFromAPIResolver: (value: string) => void
|
private onVideoPasswordFromAPIResolver: (value: string) => void
|
||||||
@@ -353,12 +356,15 @@ export class PeerTubeEmbed {
|
|||||||
|
|
||||||
if (this.videoPassword) this.playerHTML.removeVideoPasswordBlock()
|
if (this.videoPassword) this.playerHTML.removeVideoPasswordBlock()
|
||||||
|
|
||||||
|
this.stopCurrentLiveListeners()
|
||||||
|
|
||||||
if (video.isLive) {
|
if (video.isLive) {
|
||||||
|
this.currentLiveVideo = video
|
||||||
|
|
||||||
this.liveManager.listenForChanges({
|
this.liveManager.listenForChanges({
|
||||||
video,
|
video,
|
||||||
|
|
||||||
onPublishedVideo: () => {
|
onPublishedVideo: () => {
|
||||||
this.liveManager.stopListeningForChanges(video)
|
|
||||||
this.loadVideoAndBuildPlayer({ uuid: video.uuid, forceAutoplay: true })
|
this.loadVideoAndBuildPlayer({ uuid: video.uuid, forceAutoplay: true })
|
||||||
},
|
},
|
||||||
|
|
||||||
@@ -369,7 +375,8 @@ export class PeerTubeEmbed {
|
|||||||
this.liveManager.displayInfo({ state: video.state.id, translations })
|
this.liveManager.displayInfo({ state: video.state.id, translations })
|
||||||
this.peertubePlayer.disable()
|
this.peertubePlayer.disable()
|
||||||
} else {
|
} else {
|
||||||
this.player.one('ended', () => this.endLive(video, translations))
|
this.currentLiveEndedHandler = () => this.endLive(video, translations)
|
||||||
|
this.player.one('ended', this.currentLiveEndedHandler)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -425,6 +432,19 @@ export class PeerTubeEmbed {
|
|||||||
this.peertubePlayer.setPoster(video.thumbnails)
|
this.peertubePlayer.setPoster(video.thumbnails)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private stopCurrentLiveListeners () {
|
||||||
|
if (!this.currentLiveVideo) return
|
||||||
|
|
||||||
|
this.liveManager.stopListeningForChanges(this.currentLiveVideo)
|
||||||
|
|
||||||
|
if (this.currentLiveEndedHandler) {
|
||||||
|
this.player.off('ended', this.currentLiveEndedHandler)
|
||||||
|
this.currentLiveEndedHandler = undefined
|
||||||
|
}
|
||||||
|
|
||||||
|
this.currentLiveVideo = undefined
|
||||||
|
}
|
||||||
|
|
||||||
private async handlePasswordError (err: PeerTubeServerError) {
|
private async handlePasswordError (err: PeerTubeServerError) {
|
||||||
let incorrectPassword: boolean = null
|
let incorrectPassword: boolean = null
|
||||||
if (err.serverCode === ServerErrorCode.VIDEO_REQUIRES_PASSWORD) incorrectPassword = false
|
if (err.serverCode === ServerErrorCode.VIDEO_REQUIRES_PASSWORD) incorrectPassword = false
|
||||||
|
|||||||
Reference in New Issue
Block a user