1 import { registerTSPaths } from '../helpers/register-ts-paths'
4 import { LiveVideo, LiveVideoCreate, VideoPrivacy } from '@shared/models'
5 import * as program from 'commander'
13 setAccessTokensToServers,
14 setDefaultVideoChannel,
16 } from '../../shared/extra-utils'
18 type CommandType = 'live-mux' | 'live-transcoding'
22 const command = program
24 .option('-t, --type <type>', 'live-muxing|live-transcoding')
33 async function run () {
34 const commandType: CommandType = command['type']
36 console.error('Miss command type')
40 console.log('Starting server.')
42 const server = await flushAndRunServer(1, {}, [], false)
44 const cleanup = () => {
45 console.log('Killing server')
46 killallServers([ server ])
49 process.on('exit', cleanup)
50 process.on('SIGINT', cleanup)
52 await setAccessTokensToServers([ server ])
53 await setDefaultVideoChannel([ server ])
55 await buildConfig(server, commandType)
57 const attributes: LiveVideoCreate = {
60 channelId: server.videoChannel.id,
61 privacy: VideoPrivacy.PUBLIC
64 console.log('Creating live.')
66 const res = await createLive(server.url, server.accessToken, attributes)
67 const liveVideoUUID = res.body.video.uuid
69 const resLive = await getLive(server.url, server.accessToken, liveVideoUUID)
70 const live: LiveVideo = resLive.body
72 console.log('Sending RTMP stream.')
74 const ffmpegCommand = sendRTMPStream(live.rtmpUrl, live.streamKey)
76 ffmpegCommand.on('error', err => {
81 ffmpegCommand.on('end', () => {
82 console.log('ffmpeg ended')
87 // ----------------------------------------------------------------------------
89 async function buildConfig (server: ServerInfo, commandType: CommandType) {
90 await updateCustomSubConfig(server.url, server.accessToken, {
101 enabled: commandType === 'live-transcoding'