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