From 1f3e9feca2caf68024168b0ea9ed39d8438fa235 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Thu, 30 Nov 2017 09:21:11 +0100 Subject: Better view counter --- .../videos/+video-watch/video-watch.component.ts | 31 +++++++++++++++------- client/src/app/videos/shared/video.service.ts | 6 +++++ 2 files changed, 27 insertions(+), 10 deletions(-) (limited to 'client/src/app') 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 2a7290cbd..b26f3092f 100644 --- a/client/src/app/videos/+video-watch/video-watch.component.ts +++ b/client/src/app/videos/+video-watch/video-watch.component.ts @@ -1,22 +1,18 @@ import { Component, ElementRef, OnDestroy, OnInit, ViewChild } from '@angular/core' import { ActivatedRoute, Router } from '@angular/router' +import { MetaService } from '@ngx-meta/core' +import { NotificationsService } from 'angular2-notifications' import { Observable } from 'rxjs/Observable' import { Subscription } from 'rxjs/Subscription' - import videojs from 'video.js' +import { UserVideoRateType, VideoRateType } from '../../../../../shared' import '../../../assets/player/peertube-videojs-plugin' - -import { MetaService } from '@ngx-meta/core' -import { NotificationsService } from 'angular2-notifications' - import { AuthService, ConfirmService } from '../../core' +import { VideoBlacklistService } from '../../shared' +import { MarkdownService, VideoDetails, VideoService } from '../shared' import { VideoDownloadComponent } from './video-download.component' -import { VideoShareComponent } from './video-share.component' import { VideoReportComponent } from './video-report.component' -import { VideoDetails, VideoService, MarkdownService } from '../shared' -import { VideoBlacklistService } from '../../shared' -import { UserVideoRateType, VideoRateType } from '../../../../../shared' -import { BehaviorSubject } from 'rxjs/BehaviorSubject' +import { VideoShareComponent } from './video-share.component' @Component({ selector: 'my-video-watch', @@ -320,6 +316,8 @@ export class VideoWatchComponent implements OnInit, OnDestroy { this.setOpenGraphTags() this.checkUserRating() + + this.prepareViewAdd() } ) } @@ -360,4 +358,17 @@ export class VideoWatchComponent implements OnInit, OnDestroy { this.metaService.setTag('og:url', window.location.href) this.metaService.setTag('url', window.location.href) } + + private prepareViewAdd () { + // After 30 seconds (or 3/4 of the video), increment add a view + let viewTimeoutSeconds = 30 + if (this.video.duration < viewTimeoutSeconds) viewTimeoutSeconds = (this.video.duration * 3) / 4 + + setTimeout(() => { + this.videoService + .viewVideo(this.video.uuid) + .subscribe() + + }, viewTimeoutSeconds * 1000) + } } diff --git a/client/src/app/videos/shared/video.service.ts b/client/src/app/videos/shared/video.service.ts index b1ab5f8b9..5d25a26d4 100644 --- a/client/src/app/videos/shared/video.service.ts +++ b/client/src/app/videos/shared/video.service.ts @@ -41,6 +41,12 @@ export class VideoService { .catch((res) => this.restExtractor.handleError(res)) } + viewVideo (uuid: string): Observable { + return this.authHttp.post(VideoService.BASE_VIDEO_URL + uuid + '/views', {}) + .map(this.restExtractor.extractDataBool) + .catch(this.restExtractor.handleError) + } + updateVideo (video: VideoEdit) { const language = video.language ? video.language : null -- cgit v1.2.3