dayvson/hls-endless

View on GitHub
bin/hls-endless

Summary

Maintainability
Test Coverage
#!/usr/bin/env node
var program = require('commander');
var exec = require('child_process').exec;
var chalk = require('chalk');
program
  .version('1.1.0');

program
  .command('start')
  .description('Start the HLS server')
  .action(function(){
    console.log(chalk.blue('Starting the HLS server'));
    exec(__dirname + '/../node_modules/pm2/bin/pm2 start ' + __dirname +'/../app.js  --name=livehls',function(error, stdout, stderr){
        console.log("######################### RESOURCES AVAILABLE #################################");
        console.log('Variant Playlist:', chalk.green('http://localhost:6060/master.m3u8') );
        console.log('Single A/V bitrate:', chalk.green('HD: http://localhost:6060/bitrate_[1|4].m3u8') );
        console.log('Audio Only:', chalk.green('http://localhost:6060/bitrate_0.m3u8') );
        console.log("######################### RESOURCES AVAILABLE #################################");
        console.log(chalk.green('[OK]'));
    });
  });


program
  .command('vod')
  .description('Switch the stream from Live to VOD')
  .action(function(){
    console.log( chalk.red('Ending the Live stream') );
    exec(__dirname + '/../node_modules/pm2/bin/pm2 sendSignal SIGUSR1 livehls',function(error, stdout, stderr){
      console.log(chalk.red('Now your stream is a VOD'));
      console.log(chalk.green('[OK]'));
    });
  });

program
  .command('live')
  .description('Switch the stream from VOD to Live')  
  .action(function(){
    exec(__dirname + '/../node_modules/pm2/bin/pm2 sendSignal SIGUSR2 livehls',function(error, stdout, stderr){
      console.log( chalk.red('Now your stream is a Live') );
      console.log(chalk.green('[OK]'));
    });
  });

program
  .command('stop')
  .description('Stop the HLS server')
  .action(function(){
    console.log( chalk.red('Killing HLS endless') );
    exec(__dirname + '/../node_modules/pm2/bin/pm2 kill');
    console.log(chalk.green('[OK]'));
  });

program.parse(process.argv);

if (process.argv.length == 2) {
  program.parse(process.argv);
  program.outputHelp();
}