1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
4 import * as chai from 'chai'
5 import { buildAbsoluteFixturePath } from '@shared/core-utils'
6 import { VideoPrivacy } from '@shared/models'
12 setAccessTokensToServers,
13 setDefaultVideoChannel,
15 testFfmpegStreamError,
16 waitUntilLivePublishedOnAllServers
17 } from '@shared/server-commands'
19 const expect = chai.expect
21 describe('Test live RTMPS', function () {
22 let server: PeerTubeServer
26 async function createLiveWrapper () {
27 const liveAttributes = {
29 channelId: server.store.channel.id,
30 privacy: VideoPrivacy.PUBLIC,
34 const { uuid } = await server.live.create({ fields: liveAttributes })
36 const live = await server.live.get({ videoId: uuid })
37 const video = await server.videos.get({ id: uuid })
39 return Object.assign(video, live)
42 before(async function () {
45 server = await createSingleServer(1)
47 // Get the access tokens
48 await setAccessTokensToServers([ server ])
49 await setDefaultVideoChannel([ server ])
51 await server.config.updateCustomSubConfig({
63 rtmpUrl = 'rtmp://' + server.hostname + ':' + server.rtmpPort + '/live'
64 rtmpsUrl = 'rtmps://' + server.hostname + ':' + server.rtmpsPort + '/live'
67 it('Should enable RTMPS endpoint only', async function () {
78 port: server.rtmpsPort,
79 key_file: buildAbsoluteFixturePath('rtmps.key'),
80 cert_file: buildAbsoluteFixturePath('rtmps.cert')
86 const liveVideo = await createLiveWrapper()
88 expect(liveVideo.rtmpUrl).to.not.exist
89 expect(liveVideo.rtmpsUrl).to.equal(rtmpsUrl)
91 const command = sendRTMPStream({ rtmpBaseUrl: rtmpUrl, streamKey: liveVideo.streamKey })
92 await testFfmpegStreamError(command, true)
96 const liveVideo = await createLiveWrapper()
98 const command = sendRTMPStream({ rtmpBaseUrl: rtmpsUrl, streamKey: liveVideo.streamKey })
99 await waitUntilLivePublishedOnAllServers([ server ], liveVideo.uuid)
100 await stopFfmpeg(command)
104 it('Should enable both RTMP and RTMPS', async function () {
112 port: server.rtmpPort
116 port: server.rtmpsPort,
117 key_file: buildAbsoluteFixturePath('rtmps.key'),
118 cert_file: buildAbsoluteFixturePath('rtmps.cert')
124 const liveVideo = await createLiveWrapper()
126 expect(liveVideo.rtmpUrl).to.equal(rtmpUrl)
127 expect(liveVideo.rtmpsUrl).to.equal(rtmpsUrl)
129 const command = sendRTMPStream({ rtmpBaseUrl: rtmpUrl, streamKey: liveVideo.streamKey })
130 await waitUntilLivePublishedOnAllServers([ server ], liveVideo.uuid)
131 await stopFfmpeg(command)
135 const liveVideo = await createLiveWrapper()
137 const command = sendRTMPStream({ rtmpBaseUrl: rtmpsUrl, streamKey: liveVideo.streamKey })
138 await waitUntilLivePublishedOnAllServers([ server ], liveVideo.uuid)
139 await stopFfmpeg(command)
143 after(async function () {
144 await cleanupTests([ server ])