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.ts | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'client/src/app/videos/+video-watch/video-watch.component.ts') 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, -- cgit v1.2.3