aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests/api/live/live-rtmps.ts
blob: 31e8f906ebc73e6f85907dc634dab4dc5710d4ac (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
/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */

import 'mocha'
import * as chai from 'chai'
import { VideoPrivacy } from '@shared/models'
import {
  buildAbsoluteFixturePath,
  cleanupTests,
  createSingleServer,
  PeerTubeServer,
  sendRTMPStream,
  setAccessTokensToServers,
  setDefaultVideoChannel,
  stopFfmpeg,
  testFfmpegStreamError,
  waitUntilLivePublishedOnAllServers
} from '../../../../shared/server-commands'

const expect = chai.expect

describe('Test live RTMPS', function () {
  let server: PeerTubeServer
  let rtmpUrl: string
  let rtmpsUrl: string

  async function createLiveWrapper () {
    const liveAttributes = {
      name: 'live',
      channelId: server.store.channel.id,
      privacy: VideoPrivacy.PUBLIC,
      saveReplay: false
    }

    const { uuid } = await server.live.create({ fields: liveAttributes })

    const live = await server.live.get({ videoId: uuid })
    const video = await server.videos.get({ id: uuid })

    return Object.assign(video, live)
  }

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

    server = await createSingleServer(1)

    // Get the access tokens
    await setAccessTokensToServers([ server ])
    await setDefaultVideoChannel([ server ])

    await server.config.updateCustomSubConfig({
      newConfig: {
        live: {
          enabled: true,
          allowReplay: true,
          transcoding: {
            enabled: false
          }
        }
      }
    })

    rtmpUrl = 'rtmp://' + server.hostname + ':' + server.rtmpPort + '/live'
    rtmpsUrl = 'rtmps://' + server.hostname + ':' + server.rtmpsPort + '/live'
  })

  it('Should enable RTMPS endpoint only', async function () {
    this.timeout(240000)

    await server.kill()
    await server.run({
      live: {
        rtmp: {
          enabled: false
        },
        rtmps: {
          enabled: true,
          port: server.rtmpsPort,
          key_file: buildAbsoluteFixturePath('rtmps.key'),
          cert_file: buildAbsoluteFixturePath('rtmps.cert')
        }
      }
    })

    {
      const liveVideo = await createLiveWrapper()

      expect(liveVideo.rtmpUrl).to.not.exist
      expect(liveVideo.rtmpsUrl).to.equal(rtmpsUrl)

      const command = sendRTMPStream({ rtmpBaseUrl: rtmpUrl, streamKey: liveVideo.streamKey })
      await testFfmpegStreamError(command, true)
    }

    {
      const liveVideo = await createLiveWrapper()

      const command = sendRTMPStream({ rtmpBaseUrl: rtmpsUrl, streamKey: liveVideo.streamKey })
      await waitUntilLivePublishedOnAllServers([ server ], liveVideo.uuid)
      await stopFfmpeg(command)
    }
  })

  it('Should enable both RTMP and RTMPS', async function () {
    this.timeout(240000)

    await server.kill()
    await server.run({
      live: {
        rtmp: {
          enabled: true,
          port: server.rtmpPort
        },
        rtmps: {
          enabled: true,
          port: server.rtmpsPort,
          key_file: buildAbsoluteFixturePath('rtmps.key'),
          cert_file: buildAbsoluteFixturePath('rtmps.cert')
        }
      }
    })

    {
      const liveVideo = await createLiveWrapper()

      expect(liveVideo.rtmpUrl).to.equal(rtmpUrl)
      expect(liveVideo.rtmpsUrl).to.equal(rtmpsUrl)

      const command = sendRTMPStream({ rtmpBaseUrl: rtmpUrl, streamKey: liveVideo.streamKey })
      await waitUntilLivePublishedOnAllServers([ server ], liveVideo.uuid)
      await stopFfmpeg(command)
    }

    {
      const liveVideo = await createLiveWrapper()

      const command = sendRTMPStream({ rtmpBaseUrl: rtmpsUrl, streamKey: liveVideo.streamKey })
      await waitUntilLivePublishedOnAllServers([ server ], liveVideo.uuid)
      await stopFfmpeg(command)
    }
  })

  after(async function () {
    await cleanupTests([ server ])
  })
})