aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/app
diff options
context:
space:
mode:
authorChocobozzz <florian.bigard@gmail.com>2017-11-30 09:21:11 +0100
committerChocobozzz <florian.bigard@gmail.com>2017-11-30 09:21:11 +0100
commit1f3e9feca2caf68024168b0ea9ed39d8438fa235 (patch)
treeb77b02d11796cf435496fd22b85c430a7ed2479f /client/src/app
parent86d13ec2aa94ec10810ddf9c8b33314bd4968791 (diff)
downloadPeerTube-1f3e9feca2caf68024168b0ea9ed39d8438fa235.tar.gz
PeerTube-1f3e9feca2caf68024168b0ea9ed39d8438fa235.tar.zst
PeerTube-1f3e9feca2caf68024168b0ea9ed39d8438fa235.zip
Better view counter
Diffstat (limited to 'client/src/app')
-rw-r--r--client/src/app/videos/+video-watch/video-watch.component.ts31
-rw-r--r--client/src/app/videos/shared/video.service.ts6
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 @@
1import { Component, ElementRef, OnDestroy, OnInit, ViewChild } from '@angular/core' 1import { Component, ElementRef, OnDestroy, OnInit, ViewChild } from '@angular/core'
2import { ActivatedRoute, Router } from '@angular/router' 2import { ActivatedRoute, Router } from '@angular/router'
3import { MetaService } from '@ngx-meta/core'
4import { NotificationsService } from 'angular2-notifications'
3import { Observable } from 'rxjs/Observable' 5import { Observable } from 'rxjs/Observable'
4import { Subscription } from 'rxjs/Subscription' 6import { Subscription } from 'rxjs/Subscription'
5
6import videojs from 'video.js' 7import videojs from 'video.js'
8import { UserVideoRateType, VideoRateType } from '../../../../../shared'
7import '../../../assets/player/peertube-videojs-plugin' 9import '../../../assets/player/peertube-videojs-plugin'
8
9import { MetaService } from '@ngx-meta/core'
10import { NotificationsService } from 'angular2-notifications'
11
12import { AuthService, ConfirmService } from '../../core' 10import { AuthService, ConfirmService } from '../../core'
11import { VideoBlacklistService } from '../../shared'
12import { MarkdownService, VideoDetails, VideoService } from '../shared'
13import { VideoDownloadComponent } from './video-download.component' 13import { VideoDownloadComponent } from './video-download.component'
14import { VideoShareComponent } from './video-share.component'
15import { VideoReportComponent } from './video-report.component' 14import { VideoReportComponent } from './video-report.component'
16import { VideoDetails, VideoService, MarkdownService } from '../shared' 15import { VideoShareComponent } from './video-share.component'
17import { VideoBlacklistService } from '../../shared'
18import { UserVideoRateType, VideoRateType } from '../../../../../shared'
19import { 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