1 import { program } from 'commander'
2 import { LiveVideoCreate, VideoPrivacy } from '@shared/models'
8 setAccessTokensToServers,
10 } from '../../shared/extra-utils'
11 import { registerTSPaths } from '../helpers/register-ts-paths'
15 type CommandType = 'live-mux' | 'live-transcoding'
19 const command = program
21 .option('-t, --type <type>', 'live-muxing|live-transcoding')
30 async function run () {
31 const commandType: CommandType = command['type']
33 console.error('Miss command type')
37 console.log('Starting server.')
39 const server = await flushAndRunServer(1, {}, [], { hideLogs: false, execArgv: [ '--inspect' ] })
41 const cleanup = async () => {
42 console.log('Killing server')
43 await killallServers([ server ])
46 process.on('exit', cleanup)
47 process.on('SIGINT', cleanup)
49 await setAccessTokensToServers([ server ])
50 await setDefaultVideoChannel([ server ])
52 await buildConfig(server, commandType)
54 const attributes: LiveVideoCreate = {
57 channelId: server.videoChannel.id,
58 privacy: VideoPrivacy.PUBLIC
61 console.log('Creating live.')
63 const { uuid: liveVideoUUID } = await server.liveCommand.create({ fields: attributes })
65 const live = await server.liveCommand.get({ videoId: liveVideoUUID })
67 console.log('Sending RTMP stream.')
69 const ffmpegCommand = sendRTMPStream(live.rtmpUrl, live.streamKey)
71 ffmpegCommand.on('error', err => {
76 ffmpegCommand.on('end', () => {
77 console.log('ffmpeg ended')
82 // ----------------------------------------------------------------------------
84 async function buildConfig (server: ServerInfo, commandType: CommandType) {
85 await server.configCommand.updateCustomSubConfig({
97 enabled: commandType === 'live-transcoding'