+ private async subscribeToLiveEventsIfNeeded (oldVideo: VideoDetails, newVideo: VideoDetails) {
+ if (!this.liveVideosSub) {
+ this.liveVideosSub = this.peertubeSocket.getLiveVideosObservable()
+ .subscribe(({ payload }) => {
+ if (payload.state !== VideoState.PUBLISHED || this.video.state.id !== VideoState.WAITING_FOR_LIVE) return
+
+ const videoUUID = this.video.uuid
+
+ // Reset to refetch the video
+ this.video = undefined
+ this.loadVideo(videoUUID)
+ })
+ }
+
+ if (oldVideo && oldVideo.id !== newVideo.id) {
+ await this.peertubeSocket.unsubscribeLiveVideos(oldVideo.id)
+ }
+
+ if (!newVideo.isLive) return
+
+ await this.peertubeSocket.subscribeToLiveVideosSocket(newVideo.id)
+ }
+