1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
3 import * as chai from 'chai'
4 import { buildAbsoluteFixturePath } from '@shared/core-utils'
5 import { VideoPrivacy } from '@shared/models'
11 setAccessTokensToServers,
12 setDefaultVideoChannel,
14 testFfmpegStreamError,
15 waitUntilLivePublishedOnAllServers
16 } from '@shared/server-commands'
18 const expect = chai.expect
20 describe('Test live RTMPS', function () {
21 let server: PeerTubeServer
25 async function createLiveWrapper () {
26 const liveAttributes = {
28 channelId: server.store.channel.id,
29 privacy: VideoPrivacy.PUBLIC,
33 const { uuid } = await server.live.create({ fields: liveAttributes })
35 const live = await server.live.get({ videoId: uuid })
36 const video = await server.videos.get({ id: uuid })
38 return Object.assign(video, live)
41 before(async function () {
44 server = await createSingleServer(1)
46 // Get the access tokens
47 await setAccessTokensToServers([ server ])
48 await setDefaultVideoChannel([ server ])
50 await server.config.updateCustomSubConfig({
62 rtmpUrl = 'rtmp://' + server.hostname + ':' + server.rtmpPort + '/live'
63 rtmpsUrl = 'rtmps://' + server.hostname + ':' + server.rtmpsPort + '/live'
66 it('Should enable RTMPS endpoint only', async function () {
77 port: server.rtmpsPort,
78 key_file: buildAbsoluteFixturePath('rtmps.key'),
79 cert_file: buildAbsoluteFixturePath('rtmps.cert')
85 const liveVideo = await createLiveWrapper()
87 expect(liveVideo.rtmpUrl).to.not.exist
88 expect(liveVideo.rtmpsUrl).to.equal(rtmpsUrl)
90 const command = sendRTMPStream({ rtmpBaseUrl: rtmpUrl, streamKey: liveVideo.streamKey })
91 await testFfmpegStreamError(command, true)
95 const liveVideo = await createLiveWrapper()
97 const command = sendRTMPStream({ rtmpBaseUrl: rtmpsUrl, streamKey: liveVideo.streamKey })
98 await waitUntilLivePublishedOnAllServers([ server ], liveVideo.uuid)
99 await stopFfmpeg(command)
103 it('Should enable both RTMP and RTMPS', async function () {
111 port: server.rtmpPort
115 port: server.rtmpsPort,
116 key_file: buildAbsoluteFixturePath('rtmps.key'),
117 cert_file: buildAbsoluteFixturePath('rtmps.cert')
123 const liveVideo = await createLiveWrapper()
125 expect(liveVideo.rtmpUrl).to.equal(rtmpUrl)
126 expect(liveVideo.rtmpsUrl).to.equal(rtmpsUrl)
128 const command = sendRTMPStream({ rtmpBaseUrl: rtmpUrl, streamKey: liveVideo.streamKey })
129 await waitUntilLivePublishedOnAllServers([ server ], liveVideo.uuid)
130 await stopFfmpeg(command)
134 const liveVideo = await createLiveWrapper()
136 const command = sendRTMPStream({ rtmpBaseUrl: rtmpsUrl, streamKey: liveVideo.streamKey })
137 await waitUntilLivePublishedOnAllServers([ server ], liveVideo.uuid)
138 await stopFfmpeg(command)
142 after(async function () {
143 await cleanupTests([ server ])