aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests/shared/views.ts
blob: e6b289715169b0287a9e887d4a96a717c9fae828 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
import { FfmpegCommand } from 'fluent-ffmpeg'
import { wait } from '@shared/core-utils'
import { VideoCreateResult, VideoPrivacy } from '@shared/models'
import {
  createMultipleServers,
  doubleFollow,
  PeerTubeServer,
  setAccessTokensToServers,
  setDefaultVideoChannel,
  waitJobs,
  waitUntilLivePublishedOnAllServers
} from '@shared/server-commands'

async function processViewersStats (servers: PeerTubeServer[]) {
  await wait(6000)

  for (const server of servers) {
    await server.debug.sendCommand({ body: { command: 'process-video-views-buffer' } })
    await server.debug.sendCommand({ body: { command: 'process-video-viewers' } })
  }

  await waitJobs(servers)
}

async function processViewsBuffer (servers: PeerTubeServer[]) {
  for (const server of servers) {
    await server.debug.sendCommand({ body: { command: 'process-video-views-buffer' } })
  }

  await waitJobs(servers)
}

async function prepareViewsServers () {
  const servers = await createMultipleServers(2)
  await setAccessTokensToServers(servers)
  await setDefaultVideoChannel(servers)

  await servers[0].config.updateCustomSubConfig({
    newConfig: {
      live: {
        enabled: true,
        allowReplay: true,
        transcoding: {
          enabled: false
        }
      }
    }
  })

  await doubleFollow(servers[0], servers[1])

  return servers
}

async function prepareViewsVideos (options: {
  servers: PeerTubeServer[]
  live: boolean
  vod: boolean
}) {
  const { servers } = options

  const liveAttributes = {
    name: 'live video',
    channelId: servers[0].store.channel.id,
    privacy: VideoPrivacy.PUBLIC
  }

  let ffmpegCommand: FfmpegCommand
  let live: VideoCreateResult
  let vod: VideoCreateResult

  if (options.live) {
    live = await servers[0].live.create({ fields: liveAttributes })

    ffmpegCommand = await servers[0].live.sendRTMPStreamInVideo({ videoId: live.uuid })
    await waitUntilLivePublishedOnAllServers(servers, live.uuid)
  }

  if (options.vod) {
    vod = await servers[0].videos.quickUpload({ name: 'video' })
  }

  await waitJobs(servers)

  return { liveVideoId: live?.uuid, vodVideoId: vod?.uuid, ffmpegCommand }
}

export {
  processViewersStats,
  prepareViewsServers,
  processViewsBuffer,
  prepareViewsVideos
}