From 5a547f69d5dc5867e253f7721513479c754b4f15 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Tue, 24 Nov 2020 14:08:23 +0100 Subject: Support encoding profiles --- server/tools/test.ts | 105 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 105 insertions(+) create mode 100644 server/tools/test.ts (limited to 'server/tools') diff --git a/server/tools/test.ts b/server/tools/test.ts new file mode 100644 index 000000000..23bf0120f --- /dev/null +++ b/server/tools/test.ts @@ -0,0 +1,105 @@ +import { registerTSPaths } from '../helpers/register-ts-paths' +registerTSPaths() + +import { LiveVideo, LiveVideoCreate, VideoPrivacy } from '@shared/models' +import * as program from 'commander' +import { + createLive, + flushAndRunServer, + getLive, + killallServers, + sendRTMPStream, + ServerInfo, + setAccessTokensToServers, + setDefaultVideoChannel, + updateCustomSubConfig +} from '../../shared/extra-utils' + +type CommandType = 'live-mux' | 'live-transcoding' + +registerTSPaths() + +const command = program + .name('test') + .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, {}, [], false) + + 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 res = await createLive(server.url, server.accessToken, attributes) + const liveVideoUUID = res.body.video.uuid + + const resLive = await getLive(server.url, server.accessToken, liveVideoUUID) + const live: LiveVideo = resLive.body + + 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 updateCustomSubConfig(server.url, server.accessToken, { + instance: { + customizations: { + javascript: '', + css: '' + } + }, + live: { + enabled: true, + allowReplay: true, + transcoding: { + enabled: commandType === 'live-transcoding' + } + } + }) +} -- cgit v1.2.3