diff options
Diffstat (limited to 'server/tools/test.ts')
-rw-r--r-- | server/tools/test.ts | 105 |
1 files changed, 0 insertions, 105 deletions
diff --git a/server/tools/test.ts b/server/tools/test.ts deleted file mode 100644 index fbdbae0b0..000000000 --- a/server/tools/test.ts +++ /dev/null | |||
@@ -1,105 +0,0 @@ | |||
1 | import { registerTSPaths } from '../helpers/register-ts-paths' | ||
2 | registerTSPaths() | ||
3 | |||
4 | import { LiveVideo, LiveVideoCreate, VideoPrivacy } from '@shared/models' | ||
5 | import { program } from 'commander' | ||
6 | import { | ||
7 | createLive, | ||
8 | flushAndRunServer, | ||
9 | getLive, | ||
10 | killallServers, | ||
11 | sendRTMPStream, | ||
12 | ServerInfo, | ||
13 | setAccessTokensToServers, | ||
14 | setDefaultVideoChannel, | ||
15 | updateCustomSubConfig | ||
16 | } from '../../shared/extra-utils' | ||
17 | |||
18 | type CommandType = 'live-mux' | 'live-transcoding' | ||
19 | |||
20 | registerTSPaths() | ||
21 | |||
22 | const command = program | ||
23 | .name('test') | ||
24 | .option('-t, --type <type>', 'live-muxing|live-transcoding') | ||
25 | .parse(process.argv) | ||
26 | |||
27 | run() | ||
28 | .catch(err => { | ||
29 | console.error(err) | ||
30 | process.exit(-1) | ||
31 | }) | ||
32 | |||
33 | async 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, {}, [], { hideLogs: false, execArgv: [ '--inspect' ] }) | ||
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 | |||
89 | async 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 | } | ||