1
0
Fork 0
peertube/server/tools/test-live.ts

103 lines
2.3 KiB
TypeScript
Raw Normal View History

2021-06-25 11:48:27 -04:00
import { program } from 'commander'
2021-07-09 09:03:44 -04:00
import { LiveVideoCreate, VideoPrivacy } from '@shared/models'
2020-11-24 08:08:23 -05:00
import {
2021-07-16 03:47:51 -04:00
createSingleServer,
2020-11-24 08:08:23 -05:00
killallServers,
sendRTMPStream,
2021-07-16 03:47:51 -04:00
PeerTubeServer,
2020-11-24 08:08:23 -05:00
setAccessTokensToServers,
2021-07-09 09:03:44 -04:00
setDefaultVideoChannel
2020-11-24 08:08:23 -05:00
} from '../../shared/extra-utils'
2021-07-09 09:03:44 -04:00
import { registerTSPaths } from '../helpers/register-ts-paths'
registerTSPaths()
2020-11-24 08:08:23 -05:00
type CommandType = 'live-mux' | 'live-transcoding'
registerTSPaths()
const command = program
2021-07-09 09:03:44 -04:00
.name('test-live')
2020-11-24 08:08:23 -05:00
.option('-t, --type <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.')
2021-07-22 06:07:26 -04:00
const server = await createSingleServer(1, {}, { hideLogs: false, nodeArgs: [ '--inspect' ] })
2020-11-24 08:08:23 -05:00
2021-07-12 10:06:57 -04:00
const cleanup = async () => {
2020-11-24 08:08:23 -05:00
console.log('Killing server')
2021-07-09 09:37:43 -04:00
await killallServers([ server ])
2020-11-24 08:08:23 -05:00
}
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,
2021-07-16 03:04:35 -04:00
channelId: server.store.channel.id,
2020-11-24 08:08:23 -05:00
privacy: VideoPrivacy.PUBLIC
}
console.log('Creating live.')
2021-07-16 03:04:35 -04:00
const { uuid: liveVideoUUID } = await server.live.create({ fields: attributes })
2020-11-24 08:08:23 -05:00
2021-07-16 03:04:35 -04:00
const live = await server.live.get({ videoId: liveVideoUUID })
2020-11-24 08:08:23 -05:00
console.log('Sending RTMP stream.')
2021-08-06 08:39:28 -04:00
const ffmpegCommand = sendRTMPStream({ rtmpBaseUrl: live.rtmpUrl, streamKey: live.streamKey })
2020-11-24 08:08:23 -05:00
ffmpegCommand.on('error', err => {
console.error(err)
process.exit(-1)
})
ffmpegCommand.on('end', () => {
console.log('ffmpeg ended')
process.exit(0)
})
}
// ----------------------------------------------------------------------------
2021-07-16 03:47:51 -04:00
async function buildConfig (server: PeerTubeServer, commandType: CommandType) {
2021-07-16 03:04:35 -04:00
await server.config.updateCustomSubConfig({
2021-07-09 09:03:44 -04:00
newConfig: {
instance: {
customizations: {
javascript: '',
css: ''
}
},
live: {
enabled: true,
allowReplay: true,
transcoding: {
enabled: commandType === 'live-transcoding'
}
2020-11-24 08:08:23 -05:00
}
}
})
}