mirror of https://github.com/Chocobozzz/PeerTube
Fix broken player on live reload
parent
41c26d154a
commit
b1934b7e9c
|
@ -259,6 +259,7 @@ export class PeerTubeEmbed {
|
||||||
|
|
||||||
if (this.player) {
|
if (this.player) {
|
||||||
this.player.dispose()
|
this.player.dispose()
|
||||||
|
this.player = undefined
|
||||||
alreadyHadPlayer = true
|
alreadyHadPlayer = true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -6,6 +6,8 @@ import { Translations } from './translations'
|
||||||
export class LiveManager {
|
export class LiveManager {
|
||||||
private liveSocket: Socket
|
private liveSocket: Socket
|
||||||
|
|
||||||
|
private listeners = new Map<string, (payload: LiveVideoEventPayload) => void>()
|
||||||
|
|
||||||
constructor (
|
constructor (
|
||||||
private readonly playerHTML: PlayerHTML
|
private readonly playerHTML: PlayerHTML
|
||||||
) {
|
) {
|
||||||
|
@ -26,18 +28,26 @@ export class LiveManager {
|
||||||
this.liveSocket = io(window.location.origin + '/live-videos')
|
this.liveSocket = io(window.location.origin + '/live-videos')
|
||||||
}
|
}
|
||||||
|
|
||||||
this.liveSocket.on('state-change', (payload: LiveVideoEventPayload) => {
|
const listener = (payload: LiveVideoEventPayload) => {
|
||||||
if (payload.state === VideoState.PUBLISHED) {
|
if (payload.state === VideoState.PUBLISHED) {
|
||||||
this.playerHTML.removeInformation()
|
this.playerHTML.removeInformation()
|
||||||
onPublishedVideo()
|
onPublishedVideo()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
})
|
}
|
||||||
|
|
||||||
|
this.liveSocket.on('state-change', listener)
|
||||||
|
this.listeners.set(video.uuid, listener)
|
||||||
|
|
||||||
this.liveSocket.emit('subscribe', { videoId: video.id })
|
this.liveSocket.emit('subscribe', { videoId: video.id })
|
||||||
}
|
}
|
||||||
|
|
||||||
stopListeningForChanges (video: VideoDetails) {
|
stopListeningForChanges (video: VideoDetails) {
|
||||||
|
const listener = this.listeners.get(video.uuid)
|
||||||
|
if (listener) {
|
||||||
|
this.liveSocket.off('state-change', listener)
|
||||||
|
}
|
||||||
|
|
||||||
this.liveSocket.emit('unsubscribe', { videoId: video.id })
|
this.liveSocket.emit('unsubscribe', { videoId: video.id })
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue