From 078f17e6d90376050f43ce639e88e11869b49ee7 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Fri, 9 Jul 2021 15:03:44 +0200 Subject: Fix CLI tools --- server/tools/test-live.ts | 102 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 102 insertions(+) create mode 100644 server/tools/test-live.ts (limited to 'server/tools/test-live.ts') 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 @@ +import { program } from 'commander' +import { LiveVideoCreate, VideoPrivacy } from '@shared/models' +import { + flushAndRunServer, + killallServers, + sendRTMPStream, + ServerInfo, + setAccessTokensToServers, + setDefaultVideoChannel +} from '../../shared/extra-utils' +import { registerTSPaths } from '../helpers/register-ts-paths' + +registerTSPaths() + +type CommandType = 'live-mux' | 'live-transcoding' + +registerTSPaths() + +const command = program + .name('test-live') + .option('-t, --type ', 'live-muxing|live-transcoding') + .parse(process.argv) + +run() + .catch(err => { + console.error(err) + process.exit(-1) + }) + +async function run () { + const commandType: CommandType = command['type'] + if (!commandType) { + console.error('Miss command type') + process.exit(-1) + } + + console.log('Starting server.') + + const server = await flushAndRunServer(1, {}, [], { hideLogs: false, execArgv: [ '--inspect' ] }) + + const cleanup = () => { + console.log('Killing server') + killallServers([ server ]) + } + + process.on('exit', cleanup) + process.on('SIGINT', cleanup) + + await setAccessTokensToServers([ server ]) + await setDefaultVideoChannel([ server ]) + + await buildConfig(server, commandType) + + const attributes: LiveVideoCreate = { + name: 'live', + saveReplay: true, + channelId: server.videoChannel.id, + privacy: VideoPrivacy.PUBLIC + } + + console.log('Creating live.') + + const { uuid: liveVideoUUID } = await server.liveCommand.create({ fields: attributes }) + + const live = await server.liveCommand.get({ videoId: liveVideoUUID }) + + console.log('Sending RTMP stream.') + + const ffmpegCommand = sendRTMPStream(live.rtmpUrl, live.streamKey) + + ffmpegCommand.on('error', err => { + console.error(err) + process.exit(-1) + }) + + ffmpegCommand.on('end', () => { + console.log('ffmpeg ended') + process.exit(0) + }) +} + +// ---------------------------------------------------------------------------- + +async function buildConfig (server: ServerInfo, commandType: CommandType) { + await server.configCommand.updateCustomSubConfig({ + newConfig: { + instance: { + customizations: { + javascript: '', + css: '' + } + }, + live: { + enabled: true, + allowReplay: true, + transcoding: { + enabled: commandType === 'live-transcoding' + } + } + } + }) +} -- cgit v1.2.3