aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tools/test-live.ts
diff options
context:
space:
mode:
Diffstat (limited to 'server/tools/test-live.ts')
-rw-r--r--server/tools/test-live.ts102
1 files changed, 102 insertions, 0 deletions
diff --git a/server/tools/test-live.ts b/server/tools/test-live.ts
new file mode 100644
index 000000000..0cb0c3668
--- /dev/null
+++ b/server/tools/test-live.ts
@@ -0,0 +1,102 @@
1import { program } from 'commander'
2import { LiveVideoCreate, VideoPrivacy } from '@shared/models'
3import {
4 createSingleServer,
5 killallServers,
6 sendRTMPStream,
7 PeerTubeServer,
8 setAccessTokensToServers,
9 setDefaultVideoChannel
10} from '../../shared/extra-utils'
11import { registerTSPaths } from '../helpers/register-ts-paths'
12
13registerTSPaths()
14
15type CommandType = 'live-mux' | 'live-transcoding'
16
17registerTSPaths()
18
19const command = program
20 .name('test-live')
21 .option('-t, --type <type>', 'live-muxing|live-transcoding')
22 .parse(process.argv)
23
24run()
25 .catch(err => {
26 console.error(err)
27 process.exit(-1)
28 })
29
30async function run () {
31 const commandType: CommandType = command['type']
32 if (!commandType) {
33 console.error('Miss command type')
34 process.exit(-1)
35 }
36
37 console.log('Starting server.')
38
39 const server = await createSingleServer(1, {}, [], { hideLogs: false, execArgv: [ '--inspect' ] })
40
41 const cleanup = async () => {
42 console.log('Killing server')
43 await killallServers([ server ])
44 }
45
46 process.on('exit', cleanup)
47 process.on('SIGINT', cleanup)
48
49 await setAccessTokensToServers([ server ])
50 await setDefaultVideoChannel([ server ])
51
52 await buildConfig(server, commandType)
53
54 const attributes: LiveVideoCreate = {
55 name: 'live',
56 saveReplay: true,
57 channelId: server.store.channel.id,
58 privacy: VideoPrivacy.PUBLIC
59 }
60
61 console.log('Creating live.')
62
63 const { uuid: liveVideoUUID } = await server.live.create({ fields: attributes })
64
65 const live = await server.live.get({ videoId: liveVideoUUID })
66
67 console.log('Sending RTMP stream.')
68
69 const ffmpegCommand = sendRTMPStream(live.rtmpUrl, live.streamKey)
70
71 ffmpegCommand.on('error', err => {
72 console.error(err)
73 process.exit(-1)
74 })
75
76 ffmpegCommand.on('end', () => {
77 console.log('ffmpeg ended')
78 process.exit(0)
79 })
80}
81
82// ----------------------------------------------------------------------------
83
84async function buildConfig (server: PeerTubeServer, commandType: CommandType) {
85 await server.config.updateCustomSubConfig({
86 newConfig: {
87 instance: {
88 customizations: {
89 javascript: '',
90 css: ''
91 }
92 },
93 live: {
94 enabled: true,
95 allowReplay: true,
96 transcoding: {
97 enabled: commandType === 'live-transcoding'
98 }
99 }
100 }
101 })
102}