aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests/api/live/live-permanent.ts
blob: b9e37c834478e2ce89e16f177d48b27d6220a4dc (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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */

import 'mocha'
import * as chai from 'chai'
import { LiveVideoCreate, VideoDetails, VideoPrivacy, VideoState } from '@shared/models'
import {
  cleanupTests,
  ConfigCommand,
  createLive,
  doubleFollow,
  flushAndRunMultipleServers,
  getLive,
  getPlaylistsCount,
  getVideo,
  sendRTMPStreamInVideo,
  ServerInfo,
  setAccessTokensToServers,
  setDefaultVideoChannel,
  stopFfmpeg,
  updateLive,
  wait,
  waitJobs,
  waitUntilLivePublished,
  waitUntilLiveWaiting
} from '../../../../shared/extra-utils'

const expect = chai.expect

describe('Permanent live', function () {
  let servers: ServerInfo[] = []
  let videoUUID: string

  async function createLiveWrapper (permanentLive: boolean) {
    const attributes: LiveVideoCreate = {
      channelId: servers[0].videoChannel.id,
      privacy: VideoPrivacy.PUBLIC,
      name: 'my super live',
      saveReplay: false,
      permanentLive
    }

    const res = await createLive(servers[0].url, servers[0].accessToken, attributes)
    return res.body.video.uuid
  }

  async function checkVideoState (videoId: string, state: VideoState) {
    for (const server of servers) {
      const res = await getVideo(server.url, videoId)
      expect((res.body as VideoDetails).state.id).to.equal(state)
    }
  }

  before(async function () {
    this.timeout(120000)

    servers = await flushAndRunMultipleServers(2)

    // Get the access tokens
    await setAccessTokensToServers(servers)
    await setDefaultVideoChannel(servers)

    // Server 1 and server 2 follow each other
    await doubleFollow(servers[0], servers[1])

    await servers[0].configCommand.updateCustomSubConfig({
      newConfig: {
        live: {
          enabled: true,
          allowReplay: true,
          maxDuration: -1,
          transcoding: {
            enabled: true,
            resolutions: ConfigCommand.getCustomConfigResolutions(true)
          }
        }
      }
    })
  })

  it('Should create a non permanent live and update it to be a permanent live', async function () {
    this.timeout(20000)

    const videoUUID = await createLiveWrapper(false)

    {
      const res = await getLive(servers[0].url, servers[0].accessToken, videoUUID)
      expect(res.body.permanentLive).to.be.false
    }

    await updateLive(servers[0].url, servers[0].accessToken, videoUUID, { permanentLive: true })

    {
      const res = await getLive(servers[0].url, servers[0].accessToken, videoUUID)
      expect(res.body.permanentLive).to.be.true
    }
  })

  it('Should create a permanent live', async function () {
    this.timeout(20000)

    videoUUID = await createLiveWrapper(true)

    const res = await getLive(servers[0].url, servers[0].accessToken, videoUUID)
    expect(res.body.permanentLive).to.be.true

    await waitJobs(servers)
  })

  it('Should stream into this permanent live', async function () {
    this.timeout(120000)

    const command = await sendRTMPStreamInVideo(servers[0].url, servers[0].accessToken, videoUUID)

    for (const server of servers) {
      await waitUntilLivePublished(server.url, server.accessToken, videoUUID)
    }

    await checkVideoState(videoUUID, VideoState.PUBLISHED)

    await stopFfmpeg(command)
    await waitUntilLiveWaiting(servers[0].url, servers[0].accessToken, videoUUID)

    await waitJobs(servers)
  })

  it('Should not have cleaned up this live', async function () {
    this.timeout(40000)

    await wait(5000)
    await waitJobs(servers)

    for (const server of servers) {
      const res = await getVideo(server.url, videoUUID)

      const videoDetails = res.body as VideoDetails
      expect(videoDetails.streamingPlaylists).to.have.lengthOf(1)
    }
  })

  it('Should have set this live to waiting for live state', async function () {
    this.timeout(20000)

    await checkVideoState(videoUUID, VideoState.WAITING_FOR_LIVE)
  })

  it('Should be able to stream again in the permanent live', async function () {
    this.timeout(20000)

    await servers[0].configCommand.updateCustomSubConfig({
      newConfig: {
        live: {
          enabled: true,
          allowReplay: true,
          maxDuration: -1,
          transcoding: {
            enabled: true,
            resolutions: ConfigCommand.getCustomConfigResolutions(false)
          }
        }
      }
    })

    const command = await sendRTMPStreamInVideo(servers[0].url, servers[0].accessToken, videoUUID)

    for (const server of servers) {
      await waitUntilLivePublished(server.url, server.accessToken, videoUUID)
    }

    await checkVideoState(videoUUID, VideoState.PUBLISHED)

    const count = await getPlaylistsCount(servers[0], videoUUID)
    // master playlist and 720p playlist
    expect(count).to.equal(2)

    await stopFfmpeg(command)
  })

  after(async function () {
    await cleanupTests(servers)
  })
})