]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - client/src/app/shared/shared-main/video/video.model.ts
Add live info in watch page
[github/Chocobozzz/PeerTube.git] / client / src / app / shared / shared-main / video / video.model.ts
index 3e6d6a38d6422e1cfe0eb208adc81b818cb7cb85..92f5bc0c07c3b2696a95ad8d544f5ab5fd6227b5 100644 (file)
@@ -1,9 +1,9 @@
 import { AuthUser } from '@app/core'
 import { User } from '@app/core/users/user.model'
-import { durationToString, getAbsoluteAPIUrl } from '@app/helpers'
+import { durationToString, getAbsoluteAPIUrl, getAbsoluteEmbedUrl } from '@app/helpers'
+import { peertubeTranslate } from '@shared/core-utils/i18n'
 import {
   Avatar,
-  peertubeTranslate,
   ServerConfig,
   UserRight,
   Video as VideoServerModel,
@@ -12,7 +12,6 @@ import {
   VideoScheduleUpdate,
   VideoState
 } from '@shared/models'
-import { environment } from '../../../../environments/environment'
 import { Actor } from '../account/actor.model'
 
 export class Video implements VideoServerModel {
@@ -41,6 +40,8 @@ export class Video implements VideoServerModel {
   thumbnailPath: string
   thumbnailUrl: string
 
+  isLive: boolean
+
   previewPath: string
   previewUrl: string
 
@@ -85,6 +86,8 @@ export class Video implements VideoServerModel {
     currentTime: number
   }
 
+  pluginData?: any
+
   static buildClientUrl (videoUUID: string) {
     return '/videos/watch/' + videoUUID
   }
@@ -102,6 +105,8 @@ export class Video implements VideoServerModel {
     this.state = hash.state
     this.description = hash.description
 
+    this.isLive = hash.isLive
+
     this.duration = hash.duration
     this.durationLabel = durationToString(hash.duration)
 
@@ -112,13 +117,17 @@ export class Video implements VideoServerModel {
     this.name = hash.name
 
     this.thumbnailPath = hash.thumbnailPath
-    this.thumbnailUrl = hash.thumbnailUrl || (absoluteAPIUrl + hash.thumbnailPath)
+    this.thumbnailUrl = this.thumbnailPath
+      ? hash.thumbnailUrl || (absoluteAPIUrl + hash.thumbnailPath)
+      : null
 
     this.previewPath = hash.previewPath
-    this.previewUrl = hash.previewUrl || (absoluteAPIUrl + hash.previewPath)
+    this.previewUrl = this.previewPath
+      ? hash.previewUrl || (absoluteAPIUrl + hash.previewPath)
+      : null
 
     this.embedPath = hash.embedPath
-    this.embedUrl = hash.embedUrl || (environment.embedUrl + hash.embedPath)
+    this.embedUrl = hash.embedUrl || (getAbsoluteEmbedUrl() + hash.embedPath)
 
     this.url = hash.url
 
@@ -153,6 +162,8 @@ export class Video implements VideoServerModel {
 
     this.originInstanceHost = this.account.host
     this.originInstanceUrl = 'https://' + this.originInstanceHost
+
+    this.pluginData = hash.pluginData
   }
 
   isVideoNSFWForUser (user: User, serverConfig: ServerConfig) {
@@ -182,6 +193,11 @@ export class Video implements VideoServerModel {
     return user && this.isLocal === true && (this.account.name === user.username || user.hasRight(UserRight.UPDATE_ANY_VIDEO))
   }
 
+  isLiveInfoAvailableBy (user: AuthUser) {
+    return this.isLive &&
+      user && this.isLocal === true && (this.account.name === user.username || user.hasRight(UserRight.GET_ANY_LIVE))
+  }
+
   canBeDuplicatedBy (user: AuthUser) {
     return user && this.isLocal === false && user.hasRight(UserRight.MANAGE_VIDEOS_REDUNDANCIES)
   }