]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - shared/extra-utils/videos/live-command.ts
Shorter server command names
[github/Chocobozzz/PeerTube.git] / shared / extra-utils / videos / live-command.ts
index 55811b8baf009abaa373db406be69ffe69efbac3..fd66c99243b8b8be6d005a2bc5ba4a6f934ab52a 100644 (file)
@@ -5,16 +5,14 @@ import { omit } from 'lodash'
 import { join } from 'path'
 import { LiveVideo, LiveVideoCreate, LiveVideoUpdate, VideoCreateResult, VideoDetails, VideoState } from '@shared/models'
 import { HttpStatusCode } from '../../core-utils/miscs/http-error-codes'
-import { buildServerDirectory, wait } from '../miscs/miscs'
+import { wait } from '../miscs'
 import { unwrapBody } from '../requests'
-import { waitUntilLog } from '../server/servers'
 import { AbstractCommand, OverrideCommandOptions } from '../shared'
 import { sendRTMPStream, testFfmpegStreamError } from './live'
-import { getVideoWithToken } from './videos'
 
 export class LiveCommand extends AbstractCommand {
 
-  getLive (options: OverrideCommandOptions & {
+  get (options: OverrideCommandOptions & {
     videoId: number | string
   }) {
     const path = '/api/v1/videos/live'
@@ -23,11 +21,12 @@ export class LiveCommand extends AbstractCommand {
       ...options,
 
       path: path + '/' + options.videoId,
+      implicitToken: true,
       defaultExpectedStatus: HttpStatusCode.OK_200
     })
   }
 
-  updateLive (options: OverrideCommandOptions & {
+  update (options: OverrideCommandOptions & {
     videoId: number | string
     fields: LiveVideoUpdate
   }) {
@@ -39,11 +38,12 @@ export class LiveCommand extends AbstractCommand {
 
       path: path + '/' + videoId,
       fields,
+      implicitToken: true,
       defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204
     })
   }
 
-  async createLive (options: OverrideCommandOptions & {
+  async create (options: OverrideCommandOptions & {
     fields: LiveVideoCreate
   }) {
     const { fields } = options
@@ -59,6 +59,7 @@ export class LiveCommand extends AbstractCommand {
       path,
       attaches,
       fields: omit(fields, 'thumbnailfile', 'previewfile'),
+      implicitToken: true,
       defaultExpectedStatus: HttpStatusCode.OK_200
     }))
 
@@ -70,12 +71,12 @@ export class LiveCommand extends AbstractCommand {
     fixtureName?: string
   }) {
     const { videoId, fixtureName } = options
-    const videoLive = await this.getLive({ videoId })
+    const videoLive = await this.get({ videoId })
 
     return sendRTMPStream(videoLive.rtmpUrl, videoLive.streamKey, fixtureName)
   }
 
-  async runAndTestFfmpegStreamError (options: OverrideCommandOptions & {
+  async runAndTestStreamError (options: OverrideCommandOptions & {
     videoId: number | string
     shouldHaveError: boolean
   }) {
@@ -84,28 +85,28 @@ export class LiveCommand extends AbstractCommand {
     return testFfmpegStreamError(command, options.shouldHaveError)
   }
 
-  waitUntilLivePublished (options: OverrideCommandOptions & {
+  waitUntilPublished (options: OverrideCommandOptions & {
     videoId: number | string
   }) {
     const { videoId } = options
-    return this.waitUntilLiveState({ videoId, state: VideoState.PUBLISHED })
+    return this.waitUntilState({ videoId, state: VideoState.PUBLISHED })
   }
 
-  waitUntilLiveWaiting (options: OverrideCommandOptions & {
+  waitUntilWaiting (options: OverrideCommandOptions & {
     videoId: number | string
   }) {
     const { videoId } = options
-    return this.waitUntilLiveState({ videoId, state: VideoState.WAITING_FOR_LIVE })
+    return this.waitUntilState({ videoId, state: VideoState.WAITING_FOR_LIVE })
   }
 
-  waitUntilLiveEnded (options: OverrideCommandOptions & {
+  waitUntilEnded (options: OverrideCommandOptions & {
     videoId: number | string
   }) {
     const { videoId } = options
-    return this.waitUntilLiveState({ videoId, state: VideoState.LIVE_ENDED })
+    return this.waitUntilState({ videoId, state: VideoState.LIVE_ENDED })
   }
 
-  waitUntilLiveSegmentGeneration (options: OverrideCommandOptions & {
+  waitUntilSegmentGeneration (options: OverrideCommandOptions & {
     videoUUID: string
     resolution: number
     segment: number
@@ -113,26 +114,25 @@ export class LiveCommand extends AbstractCommand {
     const { resolution, segment, videoUUID } = options
     const segmentName = `${resolution}-00000${segment}.ts`
 
-    return waitUntilLog(this.server, `${videoUUID}/${segmentName}`, 2, false)
+    return this.server.servers.waitUntilLog(`${videoUUID}/${segmentName}`, 2, false)
   }
 
-  async waitUntilLiveSaved (options: OverrideCommandOptions & {
+  async waitUntilSaved (options: OverrideCommandOptions & {
     videoId: number | string
   }) {
     let video: VideoDetails
 
     do {
-      const res = await getVideoWithToken(this.server.url, options.token ?? this.server.accessToken, options.videoId)
-      video = res.body
+      video = await this.server.videos.getWithToken({ token: options.token, id: options.videoId })
 
       await wait(500)
     } while (video.isLive === true && video.state.id !== VideoState.PUBLISHED)
   }
 
-  async getPlaylistsCount (options: OverrideCommandOptions & {
+  async countPlaylists (options: OverrideCommandOptions & {
     videoUUID: string
   }) {
-    const basePath = buildServerDirectory(this.server, 'streaming-playlists')
+    const basePath = this.server.servers.buildDirectory('streaming-playlists')
     const hlsPath = join(basePath, 'hls', options.videoUUID)
 
     const files = await readdir(hlsPath)
@@ -140,15 +140,14 @@ export class LiveCommand extends AbstractCommand {
     return files.filter(f => f.endsWith('.m3u8')).length
   }
 
-  private async waitUntilLiveState (options: OverrideCommandOptions & {
+  private async waitUntilState (options: OverrideCommandOptions & {
     videoId: number | string
     state: VideoState
   }) {
     let video: VideoDetails
 
     do {
-      const res = await getVideoWithToken(this.server.url, options.token ?? this.server.accessToken, options.videoId)
-      video = res.body
+      video = await this.server.videos.getWithToken({ token: options.token, id: options.videoId })
 
       await wait(500)
     } while (video.state.id !== options.state)