aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/app
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2020-12-09 15:00:02 +0100
committerChocobozzz <me@florianbigard.com>2020-12-09 16:31:42 +0100
commita800dbf345e856ab790e7b3ab9a97e8c5dfa0a32 (patch)
treeb7f814ee0dae543a6f2937b9ab5154cfeff3e986 /client/src/app
parent5cac83a78d6ba5212755fafce2ed25f7c74b04e5 (diff)
downloadPeerTube-a800dbf345e856ab790e7b3ab9a97e8c5dfa0a32.tar.gz
PeerTube-a800dbf345e856ab790e7b3ab9a97e8c5dfa0a32.tar.zst
PeerTube-a800dbf345e856ab790e7b3ab9a97e8c5dfa0a32.zip
Live views update
Diffstat (limited to 'client/src/app')
-rw-r--r--client/src/app/+videos/+video-watch/video-watch.component.ts50
-rw-r--r--client/src/app/core/notification/peertube-socket.service.ts7
2 files changed, 39 insertions, 18 deletions
diff --git a/client/src/app/+videos/+video-watch/video-watch.component.ts b/client/src/app/+videos/+video-watch/video-watch.component.ts
index 33de901c0..7eb56eb48 100644
--- a/client/src/app/+videos/+video-watch/video-watch.component.ts
+++ b/client/src/app/+videos/+video-watch/video-watch.component.ts
@@ -25,6 +25,7 @@ import { VideoActionsDisplayType, VideoDownloadComponent } from '@app/shared/sha
25import { VideoPlaylist, VideoPlaylistService } from '@app/shared/shared-video-playlist' 25import { VideoPlaylist, VideoPlaylistService } from '@app/shared/shared-video-playlist'
26import { MetaService } from '@ngx-meta/core' 26import { MetaService } from '@ngx-meta/core'
27import { peertubeLocalStorage } from '@root-helpers/peertube-web-storage' 27import { peertubeLocalStorage } from '@root-helpers/peertube-web-storage'
28import { HttpStatusCode } from '@shared/core-utils/miscs/http-error-codes'
28import { ServerConfig, ServerErrorCode, UserVideoRateType, VideoCaption, VideoPrivacy, VideoState } from '@shared/models' 29import { ServerConfig, ServerErrorCode, UserVideoRateType, VideoCaption, VideoPrivacy, VideoState } from '@shared/models'
29import { getStoredP2PEnabled, getStoredTheater } from '../../../assets/player/peertube-player-local-storage' 30import { getStoredP2PEnabled, getStoredTheater } from '../../../assets/player/peertube-player-local-storage'
30import { 31import {
@@ -39,7 +40,6 @@ import { isWebRTCDisabled, timeToInt } from '../../../assets/player/utils'
39import { environment } from '../../../environments/environment' 40import { environment } from '../../../environments/environment'
40import { VideoSupportComponent } from './modal/video-support.component' 41import { VideoSupportComponent } from './modal/video-support.component'
41import { VideoWatchPlaylistComponent } from './video-watch-playlist.component' 42import { VideoWatchPlaylistComponent } from './video-watch-playlist.component'
42import { HttpStatusCode } from '@shared/core-utils/miscs/http-error-codes'
43 43
44type URLOptions = CustomizationOptions & { playerMode: PlayerMode } 44type URLOptions = CustomizationOptions & { playerMode: PlayerMode }
45 45
@@ -866,21 +866,7 @@ export class VideoWatchComponent implements OnInit, OnDestroy {
866 866
867 private async subscribeToLiveEventsIfNeeded (oldVideo: VideoDetails, newVideo: VideoDetails) { 867 private async subscribeToLiveEventsIfNeeded (oldVideo: VideoDetails, newVideo: VideoDetails) {
868 if (!this.liveVideosSub) { 868 if (!this.liveVideosSub) {
869 this.liveVideosSub = this.peertubeSocket.getLiveVideosObservable() 869 this.liveVideosSub = this.buildLiveEventsSubscription()
870 .subscribe(({ payload }) => {
871 if (payload.state !== VideoState.PUBLISHED) return
872
873 const videoState = this.video.state.id
874 if (videoState !== VideoState.WAITING_FOR_LIVE && videoState !== VideoState.LIVE_ENDED) return
875
876 console.log('Loading video after live update.')
877
878 const videoUUID = this.video.uuid
879
880 // Reset to refetch the video
881 this.video = undefined
882 this.loadVideo(videoUUID)
883 })
884 } 870 }
885 871
886 if (oldVideo && oldVideo.id !== newVideo.id) { 872 if (oldVideo && oldVideo.id !== newVideo.id) {
@@ -892,6 +878,38 @@ export class VideoWatchComponent implements OnInit, OnDestroy {
892 await this.peertubeSocket.subscribeToLiveVideosSocket(newVideo.id) 878 await this.peertubeSocket.subscribeToLiveVideosSocket(newVideo.id)
893 } 879 }
894 880
881 private buildLiveEventsSubscription () {
882 return this.peertubeSocket.getLiveVideosObservable()
883 .subscribe(({ type, payload }) => {
884 if (type === 'state-change') return this.handleLiveStateChange(payload.state)
885 if (type === 'views-change') return this.handleLiveViewsChange(payload.views)
886 })
887 }
888
889 private handleLiveStateChange (newState: VideoState) {
890 if (newState !== VideoState.PUBLISHED) return
891
892 const videoState = this.video.state.id
893 if (videoState !== VideoState.WAITING_FOR_LIVE && videoState !== VideoState.LIVE_ENDED) return
894
895 console.log('Loading video after live update.')
896
897 const videoUUID = this.video.uuid
898
899 // Reset to refetch the video
900 this.video = undefined
901 this.loadVideo(videoUUID)
902 }
903
904 private handleLiveViewsChange (newViews: number) {
905 if (!this.video) {
906 console.error('Cannot update video live views because video is no defined.')
907 return
908 }
909
910 this.video.views = newViews
911 }
912
895 private initHotkeys () { 913 private initHotkeys () {
896 this.hotkeys = [ 914 this.hotkeys = [
897 // These hotkeys are managed by the player 915 // These hotkeys are managed by the player
diff --git a/client/src/app/core/notification/peertube-socket.service.ts b/client/src/app/core/notification/peertube-socket.service.ts
index 7e1c43364..089276cfc 100644
--- a/client/src/app/core/notification/peertube-socket.service.ts
+++ b/client/src/app/core/notification/peertube-socket.service.ts
@@ -73,8 +73,11 @@ export class PeerTubeSocket {
73 this.liveVideosSocket = this.io(environment.apiUrl + '/live-videos') 73 this.liveVideosSocket = this.io(environment.apiUrl + '/live-videos')
74 }) 74 })
75 75
76 const type: LiveVideoEventType = 'state-change' 76 const types: LiveVideoEventType[] = [ 'views-change', 'state-change' ]
77 this.liveVideosSocket.on(type, (payload: LiveVideoEventPayload) => this.dispatchLiveVideoEvent(type, payload)) 77
78 for (const type of types) {
79 this.liveVideosSocket.on(type, (payload: LiveVideoEventPayload) => this.dispatchLiveVideoEvent(type, payload))
80 }
78 } 81 }
79 82
80 private async importIOIfNeeded () { 83 private async importIOIfNeeded () {