]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - server/tests/api/live/live-rtmps.ts
We don't need to import mocha
[github/Chocobozzz/PeerTube.git] / server / tests / api / live / live-rtmps.ts
1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
2
3 import * as chai from 'chai'
4 import { buildAbsoluteFixturePath } from '@shared/core-utils'
5 import { VideoPrivacy } from '@shared/models'
6 import {
7 cleanupTests,
8 createSingleServer,
9 PeerTubeServer,
10 sendRTMPStream,
11 setAccessTokensToServers,
12 setDefaultVideoChannel,
13 stopFfmpeg,
14 testFfmpegStreamError,
15 waitUntilLivePublishedOnAllServers
16 } from '@shared/server-commands'
17
18 const expect = chai.expect
19
20 describe('Test live RTMPS', function () {
21 let server: PeerTubeServer
22 let rtmpUrl: string
23 let rtmpsUrl: string
24
25 async function createLiveWrapper () {
26 const liveAttributes = {
27 name: 'live',
28 channelId: server.store.channel.id,
29 privacy: VideoPrivacy.PUBLIC,
30 saveReplay: false
31 }
32
33 const { uuid } = await server.live.create({ fields: liveAttributes })
34
35 const live = await server.live.get({ videoId: uuid })
36 const video = await server.videos.get({ id: uuid })
37
38 return Object.assign(video, live)
39 }
40
41 before(async function () {
42 this.timeout(120000)
43
44 server = await createSingleServer(1)
45
46 // Get the access tokens
47 await setAccessTokensToServers([ server ])
48 await setDefaultVideoChannel([ server ])
49
50 await server.config.updateCustomSubConfig({
51 newConfig: {
52 live: {
53 enabled: true,
54 allowReplay: true,
55 transcoding: {
56 enabled: false
57 }
58 }
59 }
60 })
61
62 rtmpUrl = 'rtmp://' + server.hostname + ':' + server.rtmpPort + '/live'
63 rtmpsUrl = 'rtmps://' + server.hostname + ':' + server.rtmpsPort + '/live'
64 })
65
66 it('Should enable RTMPS endpoint only', async function () {
67 this.timeout(240000)
68
69 await server.kill()
70 await server.run({
71 live: {
72 rtmp: {
73 enabled: false
74 },
75 rtmps: {
76 enabled: true,
77 port: server.rtmpsPort,
78 key_file: buildAbsoluteFixturePath('rtmps.key'),
79 cert_file: buildAbsoluteFixturePath('rtmps.cert')
80 }
81 }
82 })
83
84 {
85 const liveVideo = await createLiveWrapper()
86
87 expect(liveVideo.rtmpUrl).to.not.exist
88 expect(liveVideo.rtmpsUrl).to.equal(rtmpsUrl)
89
90 const command = sendRTMPStream({ rtmpBaseUrl: rtmpUrl, streamKey: liveVideo.streamKey })
91 await testFfmpegStreamError(command, true)
92 }
93
94 {
95 const liveVideo = await createLiveWrapper()
96
97 const command = sendRTMPStream({ rtmpBaseUrl: rtmpsUrl, streamKey: liveVideo.streamKey })
98 await waitUntilLivePublishedOnAllServers([ server ], liveVideo.uuid)
99 await stopFfmpeg(command)
100 }
101 })
102
103 it('Should enable both RTMP and RTMPS', async function () {
104 this.timeout(240000)
105
106 await server.kill()
107 await server.run({
108 live: {
109 rtmp: {
110 enabled: true,
111 port: server.rtmpPort
112 },
113 rtmps: {
114 enabled: true,
115 port: server.rtmpsPort,
116 key_file: buildAbsoluteFixturePath('rtmps.key'),
117 cert_file: buildAbsoluteFixturePath('rtmps.cert')
118 }
119 }
120 })
121
122 {
123 const liveVideo = await createLiveWrapper()
124
125 expect(liveVideo.rtmpUrl).to.equal(rtmpUrl)
126 expect(liveVideo.rtmpsUrl).to.equal(rtmpsUrl)
127
128 const command = sendRTMPStream({ rtmpBaseUrl: rtmpUrl, streamKey: liveVideo.streamKey })
129 await waitUntilLivePublishedOnAllServers([ server ], liveVideo.uuid)
130 await stopFfmpeg(command)
131 }
132
133 {
134 const liveVideo = await createLiveWrapper()
135
136 const command = sendRTMPStream({ rtmpBaseUrl: rtmpsUrl, streamKey: liveVideo.streamKey })
137 await waitUntilLivePublishedOnAllServers([ server ], liveVideo.uuid)
138 await stopFfmpeg(command)
139 }
140 })
141
142 after(async function () {
143 await cleanupTests([ server ])
144 })
145 })