From 6aa541481390980f9c85d2e66514ba0e6ce77a35 Mon Sep 17 00:00:00 2001 From: LoveIsGrief Date: Tue, 24 Sep 2019 08:48:01 +0200 Subject: Autoplay next recommended video (#2137) * Start working on autoplay of next video * Ignore changes made by gitpod * Apply changes from PR#1370 * Correct the spelling of recommendations * Fix linting errors * Move boolean check to existing onEnded handler * Pick a random video until the recommendations are improved * Add simple tests for autoPlayNextVideo * Fix lint ...again --- .../app/videos/+video-watch/video-watch.component.html | 6 +++++- .../app/videos/+video-watch/video-watch.component.ts | 17 +++++++++++++++++ .../recommendations/recommended-videos.component.ts | 4 +++- 3 files changed, 25 insertions(+), 2 deletions(-) (limited to 'client/src/app/videos') diff --git a/client/src/app/videos/+video-watch/video-watch.component.html b/client/src/app/videos/+video-watch/video-watch.component.html index 6a02f630a..cd60c407f 100644 --- a/client/src/app/videos/+video-watch/video-watch.component.html +++ b/client/src/app/videos/+video-watch/video-watch.component.html @@ -199,7 +199,11 @@ - +
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 21a24113f..1e7991738 100644 --- a/client/src/app/videos/+video-watch/video-watch.component.ts +++ b/client/src/app/videos/+video-watch/video-watch.component.ts @@ -35,6 +35,7 @@ import { getStoredTheater } from '../../../assets/player/peertube-player-local-s import { PluginService } from '@app/core/plugins/plugin.service' import { HooksService } from '@app/core/plugins/hooks.service' import { PlatformLocation } from '@angular/common' +import { randomInt } from '@shared/core-utils/miscs/miscs' @Component({ selector: 'my-video-watch', @@ -69,6 +70,7 @@ export class VideoWatchComponent implements OnInit, OnDestroy { remoteServerDown = false hotkeys: Hotkey[] + private nextVideoUuid = '' private currentTime: number private paramsSub: Subscription private queryParamsSub: Subscription @@ -217,6 +219,13 @@ export class VideoWatchComponent implements OnInit, OnDestroy { return this.video.tags } + onRecommendations (videos: Video[]) { + if (videos.length > 0) { + // Pick a random video until the recommendations are improved + this.nextVideoUuid = videos[randomInt(0,videos.length - 1)].uuid + } + } + onVideoRemoved () { this.redirectService.redirectToHomepage() } @@ -477,6 +486,8 @@ export class VideoWatchComponent implements OnInit, OnDestroy { this.player.one('ended', () => { if (this.playlist) { this.zone.run(() => this.videoWatchPlaylist.navigateToNextPlaylistVideo()) + } else if (this.user && this.user.autoPlayNextVideo) { + this.zone.run(() => this.autoplayNext()) } }) @@ -500,6 +511,12 @@ export class VideoWatchComponent implements OnInit, OnDestroy { this.hooks.runAction('action:video-watch.video.loaded', 'video-watch') } + private autoplayNext () { + if (this.nextVideoUuid) { + this.router.navigate([ '/videos/watch', this.nextVideoUuid ]) + } + } + private setRating (nextRating: UserVideoRateType) { const ratingMethods: { [id in UserVideoRateType]: (id: number) => Observable } = { like: this.videoService.setVideoLike, diff --git a/client/src/app/videos/recommendations/recommended-videos.component.ts b/client/src/app/videos/recommendations/recommended-videos.component.ts index 68fd750cc..7e0fb8856 100644 --- a/client/src/app/videos/recommendations/recommended-videos.component.ts +++ b/client/src/app/videos/recommendations/recommended-videos.component.ts @@ -1,4 +1,4 @@ -import { Component, Input, OnChanges } from '@angular/core' +import { Component, Input, Output, OnChanges, EventEmitter } from '@angular/core' import { Observable } from 'rxjs' import { Video } from '@app/shared/video/video.model' import { RecommendationInfo } from '@app/shared/video/recommendation-info.model' @@ -12,6 +12,7 @@ import { User } from '@app/shared' export class RecommendedVideosComponent implements OnChanges { @Input() inputRecommendation: RecommendationInfo @Input() user: User + @Output() gotRecommendations = new EventEmitter() readonly hasVideos$: Observable readonly videos$: Observable @@ -21,6 +22,7 @@ export class RecommendedVideosComponent implements OnChanges { ) { this.videos$ = this.store.recommendations$ this.hasVideos$ = this.store.hasRecommendations$ + this.videos$.subscribe(videos => this.gotRecommendations.emit(videos)) } public ngOnChanges (): void { -- cgit v1.2.3