]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - client/src/app/videos/+video-watch/video-watch.component.ts
Design video player
[github/Chocobozzz/PeerTube.git] / client / src / app / videos / +video-watch / video-watch.component.ts
index 2e1adb0434a757caa18a0d35da77ca8813f58909..48842602efcfd1e48cca5d0350d1f114ba4f7c05 100644 (file)
@@ -1,21 +1,20 @@
 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 { VideoService } from 'app/shared/video/video.service'
 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 } 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 { VideoShareComponent } from './video-share.component'
+import { VideoDetails } from '../../shared/video/video-details.model'
 
 @Component({
   selector: 'my-video-watch',
@@ -27,17 +26,19 @@ export class VideoWatchComponent implements OnInit, OnDestroy {
   @ViewChild('videoShareModal') videoShareModal: VideoShareComponent
   @ViewChild('videoReportModal') videoReportModal: VideoReportComponent
 
-  downloadSpeed: number
   error = false
   loading = false
-  numPeers: number
   player: videojs.Player
   playerElement: HTMLMediaElement
-  uploadSpeed: number
   userRating: UserVideoRateType = null
   video: VideoDetails = null
   videoPlayerLoaded = false
   videoNotFound = false
+  descriptionLoading = false
+
+  completeDescriptionShown = false
+  completeVideoDescription: string
+  shortVideoDescription: string
   videoHTMLDescription = ''
 
   private paramsSub: Subscription
@@ -154,6 +155,43 @@ export class VideoWatchComponent implements OnInit, OnDestroy {
     )
   }
 
+  showMoreDescription () {
+    if (this.completeVideoDescription === undefined) {
+      return this.loadCompleteDescription()
+    }
+
+    this.updateVideoDescription(this.completeVideoDescription)
+    this.completeDescriptionShown = true
+  }
+
+  showLessDescription () {
+
+    this.updateVideoDescription(this.shortVideoDescription)
+    this.completeDescriptionShown = false
+  }
+
+  loadCompleteDescription () {
+    this.descriptionLoading = true
+
+    this.videoService.loadCompleteDescription(this.video.descriptionPath)
+      .subscribe(
+        description => {
+          this.completeDescriptionShown = true
+          this.descriptionLoading = false
+
+          this.shortVideoDescription = this.video.description
+          this.completeVideoDescription = description
+
+          this.updateVideoDescription(this.completeVideoDescription)
+        },
+
+        error => {
+          this.descriptionLoading = false
+          this.notificationsService.error('Error', error.text)
+        }
+      )
+  }
+
   showReportModal (event: Event) {
     event.preventDefault()
     this.videoReportModal.show()
@@ -184,6 +222,15 @@ export class VideoWatchComponent implements OnInit, OnDestroy {
     return this.video.isBlackistableBy(this.authService.getUser())
   }
 
+  private updateVideoDescription (description: string) {
+    this.video.description = description
+    this.setVideoDescriptionHTML()
+  }
+
+  private setVideoDescriptionHTML () {
+    this.videoHTMLDescription = this.markdownService.markdownToHTML(this.video.description)
+  }
+
   private handleError (err: any) {
     const errorMessage: string = typeof err === 'string' ? err : err.message
     let message = ''
@@ -218,7 +265,10 @@ export class VideoWatchComponent implements OnInit, OnDestroy {
 
     let observable
     if (this.video.isVideoNSFWForUser(this.authService.getUser())) {
-      observable = this.confirmService.confirm('This video is not safe for work. Are you sure you want to watch it?', 'NSFW')
+      observable = this.confirmService.confirm(
+        'This video contains mature or explicit content. Are you sure you want to watch it?',
+        'Mature or explicit content'
+      )
     } else {
       observable = Observable.of(true)
     }
@@ -230,7 +280,7 @@ export class VideoWatchComponent implements OnInit, OnDestroy {
           return this.router.navigate([ '/videos/list' ])
         }
 
-        this.playerElement = this.elementRef.nativeElement.querySelector('#video-container')
+        this.playerElement = this.elementRef.nativeElement.querySelector('#video-element')
 
         const videojsOptions = {
           controls: true,
@@ -253,18 +303,14 @@ export class VideoWatchComponent implements OnInit, OnDestroy {
           this.on('customError', (event, data) => {
             self.handleError(data.err)
           })
-
-          this.on('torrentInfo', (event, data) => {
-            self.downloadSpeed = data.downloadSpeed
-            self.numPeers = data.numPeers
-            self.uploadSpeed = data.uploadSpeed
-          })
         })
 
-        this.videoHTMLDescription = this.markdownService.markdownToHTML(this.video.description)
+        this.setVideoDescriptionHTML()
 
         this.setOpenGraphTags()
         this.checkUserRating()
+
+        this.prepareViewAdd()
       }
     )
   }
@@ -305,4 +351,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)
+  }
 }