diff options
author | Chocobozzz <florian.bigard@gmail.com> | 2017-11-30 09:21:11 +0100 |
---|---|---|
committer | Chocobozzz <florian.bigard@gmail.com> | 2017-11-30 09:21:11 +0100 |
commit | 1f3e9feca2caf68024168b0ea9ed39d8438fa235 (patch) | |
tree | b77b02d11796cf435496fd22b85c430a7ed2479f /client | |
parent | 86d13ec2aa94ec10810ddf9c8b33314bd4968791 (diff) | |
download | PeerTube-1f3e9feca2caf68024168b0ea9ed39d8438fa235.tar.gz PeerTube-1f3e9feca2caf68024168b0ea9ed39d8438fa235.tar.zst PeerTube-1f3e9feca2caf68024168b0ea9ed39d8438fa235.zip |
Better view counter
Diffstat (limited to 'client')
-rw-r--r-- | client/src/app/videos/+video-watch/video-watch.component.ts | 31 | ||||
-rw-r--r-- | client/src/app/videos/shared/video.service.ts | 6 |
2 files changed, 27 insertions, 10 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 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 @@ | |||
1 | import { Component, ElementRef, OnDestroy, OnInit, ViewChild } from '@angular/core' | 1 | import { Component, ElementRef, OnDestroy, OnInit, ViewChild } from '@angular/core' |
2 | import { ActivatedRoute, Router } from '@angular/router' | 2 | import { ActivatedRoute, Router } from '@angular/router' |
3 | import { MetaService } from '@ngx-meta/core' | ||
4 | import { NotificationsService } from 'angular2-notifications' | ||
3 | import { Observable } from 'rxjs/Observable' | 5 | import { Observable } from 'rxjs/Observable' |
4 | import { Subscription } from 'rxjs/Subscription' | 6 | import { Subscription } from 'rxjs/Subscription' |
5 | |||
6 | import videojs from 'video.js' | 7 | import videojs from 'video.js' |
8 | import { UserVideoRateType, VideoRateType } from '../../../../../shared' | ||
7 | import '../../../assets/player/peertube-videojs-plugin' | 9 | import '../../../assets/player/peertube-videojs-plugin' |
8 | |||
9 | import { MetaService } from '@ngx-meta/core' | ||
10 | import { NotificationsService } from 'angular2-notifications' | ||
11 | |||
12 | import { AuthService, ConfirmService } from '../../core' | 10 | import { AuthService, ConfirmService } from '../../core' |
11 | import { VideoBlacklistService } from '../../shared' | ||
12 | import { MarkdownService, VideoDetails, VideoService } from '../shared' | ||
13 | import { VideoDownloadComponent } from './video-download.component' | 13 | import { VideoDownloadComponent } from './video-download.component' |
14 | import { VideoShareComponent } from './video-share.component' | ||
15 | import { VideoReportComponent } from './video-report.component' | 14 | import { VideoReportComponent } from './video-report.component' |
16 | import { VideoDetails, VideoService, MarkdownService } from '../shared' | 15 | import { VideoShareComponent } from './video-share.component' |
17 | import { VideoBlacklistService } from '../../shared' | ||
18 | import { UserVideoRateType, VideoRateType } from '../../../../../shared' | ||
19 | import { BehaviorSubject } from 'rxjs/BehaviorSubject' | ||
20 | 16 | ||
21 | @Component({ | 17 | @Component({ |
22 | selector: 'my-video-watch', | 18 | selector: 'my-video-watch', |
@@ -320,6 +316,8 @@ export class VideoWatchComponent implements OnInit, OnDestroy { | |||
320 | 316 | ||
321 | this.setOpenGraphTags() | 317 | this.setOpenGraphTags() |
322 | this.checkUserRating() | 318 | this.checkUserRating() |
319 | |||
320 | this.prepareViewAdd() | ||
323 | } | 321 | } |
324 | ) | 322 | ) |
325 | } | 323 | } |
@@ -360,4 +358,17 @@ export class VideoWatchComponent implements OnInit, OnDestroy { | |||
360 | this.metaService.setTag('og:url', window.location.href) | 358 | this.metaService.setTag('og:url', window.location.href) |
361 | this.metaService.setTag('url', window.location.href) | 359 | this.metaService.setTag('url', window.location.href) |
362 | } | 360 | } |
361 | |||
362 | private prepareViewAdd () { | ||
363 | // After 30 seconds (or 3/4 of the video), increment add a view | ||
364 | let viewTimeoutSeconds = 30 | ||
365 | if (this.video.duration < viewTimeoutSeconds) viewTimeoutSeconds = (this.video.duration * 3) / 4 | ||
366 | |||
367 | setTimeout(() => { | ||
368 | this.videoService | ||
369 | .viewVideo(this.video.uuid) | ||
370 | .subscribe() | ||
371 | |||
372 | }, viewTimeoutSeconds * 1000) | ||
373 | } | ||
363 | } | 374 | } |
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 { | |||
41 | .catch((res) => this.restExtractor.handleError(res)) | 41 | .catch((res) => this.restExtractor.handleError(res)) |
42 | } | 42 | } |
43 | 43 | ||
44 | viewVideo (uuid: string): Observable<VideoDetails> { | ||
45 | return this.authHttp.post(VideoService.BASE_VIDEO_URL + uuid + '/views', {}) | ||
46 | .map(this.restExtractor.extractDataBool) | ||
47 | .catch(this.restExtractor.handleError) | ||
48 | } | ||
49 | |||
44 | updateVideo (video: VideoEdit) { | 50 | updateVideo (video: VideoEdit) { |
45 | const language = video.language ? video.language : null | 51 | const language = video.language ? video.language : null |
46 | 52 | ||