diff options
Diffstat (limited to 'server/tools/test-live.ts')
-rw-r--r-- | server/tools/test-live.ts | 102 |
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..76fd69435 --- /dev/null +++ b/server/tools/test-live.ts | |||
@@ -0,0 +1,102 @@ | |||
1 | import { program } from 'commander' | ||
2 | import { LiveVideoCreate, VideoPrivacy } from '@shared/models' | ||
3 | import { | ||
4 | flushAndRunServer, | ||
5 | killallServers, | ||
6 | sendRTMPStream, | ||
7 | ServerInfo, | ||
8 | setAccessTokensToServers, | ||
9 | setDefaultVideoChannel | ||
10 | } from '../../shared/extra-utils' | ||
11 | import { registerTSPaths } from '../helpers/register-ts-paths' | ||
12 | |||
13 | registerTSPaths() | ||
14 | |||
15 | type CommandType = 'live-mux' | 'live-transcoding' | ||
16 | |||
17 | registerTSPaths() | ||
18 | |||
19 | const command = program | ||
20 | .name('test-live') | ||
21 | .option('-t, --type <type>', 'live-muxing|live-transcoding') | ||
22 | .parse(process.argv) | ||
23 | |||
24 | run() | ||
25 | .catch(err => { | ||
26 | console.error(err) | ||
27 | process.exit(-1) | ||
28 | }) | ||
29 | |||
30 | async 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 flushAndRunServer(1, {}, [], { hideLogs: false, execArgv: [ '--inspect' ] }) | ||
40 | |||
41 | const cleanup = () => { | ||
42 | console.log('Killing server') | ||
43 | 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.videoChannel.id, | ||
58 | privacy: VideoPrivacy.PUBLIC | ||
59 | } | ||
60 | |||
61 | console.log('Creating live.') | ||
62 | |||
63 | const { uuid: liveVideoUUID } = await server.liveCommand.create({ fields: attributes }) | ||
64 | |||
65 | const live = await server.liveCommand.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 | |||
84 | async function buildConfig (server: ServerInfo, commandType: CommandType) { | ||
85 | await server.configCommand.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 | } | ||