+ private buildLiveEventsSubscription () {
+ return this.peertubeSocket.getLiveVideosObservable()
+ .subscribe(({ type, payload }) => {
+ if (type === 'state-change') return this.handleLiveStateChange(payload.state)
+ if (type === 'views-change') return this.handleLiveViewsChange(payload.views)
+ })
+ }
+
+ private handleLiveStateChange (newState: VideoState) {
+ if (newState !== VideoState.PUBLISHED) return
+
+ const videoState = this.video.state.id
+ if (videoState !== VideoState.WAITING_FOR_LIVE && videoState !== VideoState.LIVE_ENDED) return