diff options
author | Chocobozzz <me@florianbigard.com> | 2021-07-21 15:51:30 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2021-07-21 15:51:30 +0200 |
commit | a24bd1ed41b43790bab6ba789580bb4e85f07d85 (patch) | |
tree | a54b0f6c921ba83a6e909cd0ced325b2d4b8863c /server/tools/test-live.ts | |
parent | 5f26f13b3c16ac5ae0a3b0a7142d84a9528cf565 (diff) | |
parent | c63830f15403ac4e750829f27d8bbbdc9a59282c (diff) | |
download | PeerTube-a24bd1ed41b43790bab6ba789580bb4e85f07d85.tar.gz PeerTube-a24bd1ed41b43790bab6ba789580bb4e85f07d85.tar.zst PeerTube-a24bd1ed41b43790bab6ba789580bb4e85f07d85.zip |
Merge branch 'next' into develop
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..0cb0c3668 --- /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 | createSingleServer, | ||
5 | killallServers, | ||
6 | sendRTMPStream, | ||
7 | PeerTubeServer, | ||
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 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 | |||
84 | async 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 | } | ||