SAAS-876 - Initial commit

This commit is contained in:
Duncan Sommerville 2015-07-03 13:32:41 -04:00
parent e3101e90b2
commit 457230ba07
9 changed files with 125 additions and 99 deletions

View file

@ -148,9 +148,6 @@ class PreferenceController extends Zend_Controller_Action
session_start(); //Open session for writing. session_start(); //Open session for writing.
// get current settings
$setting = Application_Model_StreamSetting::getStreamSetting();
$name_map = array( $name_map = array(
'ogg' => 'Ogg Vorbis', 'ogg' => 'Ogg Vorbis',
'fdkaac' => 'AAC+', 'fdkaac' => 'AAC+',
@ -159,55 +156,14 @@ class PreferenceController extends Zend_Controller_Action
'mp3' => 'MP3', 'mp3' => 'MP3',
); );
// get predefined type and bitrate from pref table
$temp_types = Application_Model_Preference::GetStreamType();
$stream_types = array();
foreach ($temp_types as $type) {
$type = strtolower(trim($type));
if (isset($name_map[$type])) {
$name = $name_map[$type];
} else {
$name = $type;
}
$stream_types[$type] = $name;
}
$temp_bitrate = Application_Model_Preference::GetStreamBitrate();
$max_bitrate = intval(Application_Model_Preference::GetMaxBitrate());
$stream_bitrates = array();
foreach ($temp_bitrate as $type) {
if (intval($type) <= $max_bitrate) {
$stream_bitrates[trim($type)] = strtoupper(trim($type))." kbit/s";
}
}
$num_of_stream = intval(Application_Model_Preference::GetNumOfStreams()); $num_of_stream = intval(Application_Model_Preference::GetNumOfStreams());
$form = new Application_Form_StreamSetting(); $form = new Application_Form_StreamSetting();
// $form->addElement('hash', 'csrf', array(
// 'salt' => 'unique'
// ));
$csrf_namespace = new Zend_Session_Namespace('csrf_namespace'); $csrf_namespace = new Zend_Session_Namespace('csrf_namespace');
$csrf_element = new Zend_Form_Element_Hidden('csrf'); $csrf_element = new Zend_Form_Element_Hidden('csrf');
$csrf_element->setValue($csrf_namespace->authtoken)->setRequired('true')->removeDecorator('HtmlTag')->removeDecorator('Label'); $csrf_element->setValue($csrf_namespace->authtoken)->setRequired('true')->removeDecorator('HtmlTag')->removeDecorator('Label');
$form->addElement($csrf_element); $form->addElement($csrf_element);
$form->setSetting($setting);
$form->startFrom();
$live_stream_subform = new Application_Form_LiveStreamingPreferences();
$form->addSubForm($live_stream_subform, "live_stream_subform");
for ($i=1; $i<=$num_of_stream; $i++) {
$subform = new Application_Form_StreamSettingSubForm();
$subform->setPrefix($i);
$subform->setSetting($setting);
$subform->setStreamTypes($stream_types);
$subform->setStreamBitrates($stream_bitrates);
$subform->startForm();
$form->addSubForm($subform, "s".$i."_subform");
}
if ($request->isPost()) { if ($request->isPost()) {
$params = $request->getPost(); $params = $request->getPost();
/* Parse through post data and put in format /* Parse through post data and put in format
@ -245,7 +201,6 @@ class PreferenceController extends Zend_Controller_Action
$values["s3_data"] = $s3_data; $values["s3_data"] = $s3_data;
$values["s4_data"] = $s4_data; $values["s4_data"] = $s4_data;
$error = false;
if ($form->isValid($values)) { if ($form->isValid($values)) {
$values['icecast_vorbis_metadata'] = $form->getValue('icecast_vorbis_metadata'); $values['icecast_vorbis_metadata'] = $form->getValue('icecast_vorbis_metadata');
@ -262,6 +217,7 @@ class PreferenceController extends Zend_Controller_Action
$s4_set_admin_pass = !empty($values["s4_data"]["admin_pass"]); $s4_set_admin_pass = !empty($values["s4_data"]["admin_pass"]);
// this goes into cc_pref table // this goes into cc_pref table
Application_Model_Preference::setUsingCustomStreamSettings($values['customStreamSettings']);
Application_Model_Preference::SetStreamLabelFormat($values['streamFormat']); Application_Model_Preference::SetStreamLabelFormat($values['streamFormat']);
Application_Model_Preference::SetLiveStreamMasterUsername($values["master_username"]); Application_Model_Preference::SetLiveStreamMasterUsername($values["master_username"]);
Application_Model_Preference::SetLiveStreamMasterPassword($values["master_password"]); Application_Model_Preference::SetLiveStreamMasterPassword($values["master_password"]);
@ -292,35 +248,73 @@ class PreferenceController extends Zend_Controller_Action
Application_Model_StreamSetting::setLiquidsoapError($i, "waiting"); Application_Model_StreamSetting::setLiquidsoapError($i, "waiting");
} }
Application_Model_RabbitMq::SendMessageToPypo("update_stream_setting", $data); if (Application_Model_Preference::getUsingCustomStreamSettings()) {
Application_Model_RabbitMq::SendMessageToPypo("update_stream_setting", $data);
$live_stream_subform->updateVariables(); }
$this->view->enable_stream_conf = Application_Model_Preference::GetEnableStreamConf();
$this->view->form = $form;
$this->view->num_stream = $num_of_stream;
$this->view->statusMsg = "<div class='success'>"._("Stream Setting Updated.")."</div>"; $this->view->statusMsg = "<div class='success'>"._("Stream Setting Updated.")."</div>";
$this->_helper->json->sendJson(array(
"valid"=>"true",
"html"=>$this->view->render('preference/stream-setting.phtml'),
"s1_set_admin_pass"=>$s1_set_admin_pass,
"s2_set_admin_pass"=>$s2_set_admin_pass,
"s3_set_admin_pass"=>$s3_set_admin_pass,
"s4_set_admin_pass"=>$s4_set_admin_pass,
));
} else {
$live_stream_subform->updateVariables();
$this->view->enable_stream_conf = Application_Model_Preference::GetEnableStreamConf();
$this->view->form = $form;
$this->view->num_stream = $num_of_stream;
$this->_helper->json->sendJson(array("valid"=>"false", "html"=>$this->view->render('preference/stream-setting.phtml')));
} }
} }
// get predefined type and bitrate from pref table
$temp_types = Application_Model_Preference::GetStreamType();
$stream_types = array();
foreach ($temp_types as $type) {
$type = strtolower(trim($type));
if (isset($name_map[$type])) {
$name = $name_map[$type];
} else {
$name = $type;
}
$stream_types[$type] = $name;
}
$temp_bitrate = Application_Model_Preference::GetStreamBitrate();
$max_bitrate = intval(Application_Model_Preference::GetMaxBitrate());
$stream_bitrates = array();
foreach ($temp_bitrate as $type) {
if (intval($type) <= $max_bitrate) {
$stream_bitrates[trim($type)] = strtoupper(trim($type))." kbit/s";
}
}
// get current settings
$setting = Application_Model_StreamSetting::getStreamSetting();
$form->setSetting($setting);
$form->startFrom();
$live_stream_subform = new Application_Form_LiveStreamingPreferences();
$form->addSubForm($live_stream_subform, "live_stream_subform");
for ($i=1; $i<=$num_of_stream; $i++) {
$subform = new Application_Form_StreamSettingSubForm();
$subform->setPrefix($i);
$subform->setSetting($setting);
$subform->setStreamTypes($stream_types);
$subform->setStreamBitrates($stream_bitrates);
$subform->startForm();
$form->addSubForm($subform, "s".$i."_subform");
}
$live_stream_subform->updateVariables(); $live_stream_subform->updateVariables();
$this->view->num_stream = $num_of_stream; $this->view->num_stream = $num_of_stream;
$this->view->enable_stream_conf = Application_Model_Preference::GetEnableStreamConf(); $this->view->enable_stream_conf = Application_Model_Preference::GetEnableStreamConf();
$this->view->form = $form; $this->view->form = $form;
if ($request->isPost()) {
if ($form->isValid($values)) {
$this->_helper->json->sendJson(array(
"valid" => "true",
"html" => $this->view->render('preference/stream-setting.phtml'),
"s1_set_admin_pass" => $s1_set_admin_pass,
"s2_set_admin_pass" => $s2_set_admin_pass,
"s3_set_admin_pass" => $s3_set_admin_pass,
"s4_set_admin_pass" => $s4_set_admin_pass,
));
} else {
$this->_helper->json->sendJson(array("valid" => "false", "html" => $this->view->render('preference/stream-setting.phtml')));
}
}
} }
public function serverBrowseAction() public function serverBrowseAction()

View file

@ -7,7 +7,6 @@ class Application_Form_LiveStreamingPreferences extends Zend_Form_SubForm
{ {
$CC_CONFIG = Config::getConfig(); $CC_CONFIG = Config::getConfig();
$isDemo = isset($CC_CONFIG['demo']) && $CC_CONFIG['demo'] == 1; $isDemo = isset($CC_CONFIG['demo']) && $CC_CONFIG['demo'] == 1;
$isStreamConfigable = Application_Model_Preference::GetEnableStreamConf() == "true";
$defaultFade = Application_Model_Preference::GetDefaultTransitionFade(); $defaultFade = Application_Model_Preference::GetDefaultTransitionFade();
@ -103,7 +102,7 @@ class Application_Form_LiveStreamingPreferences extends Zend_Form_SubForm
$this->addElement($showSourceMount); $this->addElement($showSourceMount);
// demo only code // demo only code
if (!$isStreamConfigable) { if ($isDemo) {
$elements = $this->getElements(); $elements = $this->getElements();
foreach ($elements as $element) { foreach ($elements as $element) {
if ($element->getType() != 'Zend_Form_Element_Hidden') { if ($element->getType() != 'Zend_Form_Element_Hidden') {

View file

@ -16,6 +16,10 @@ class Application_Form_StreamSetting extends Zend_Form
public function startFrom() public function startFrom()
{ {
$this->setDecorators(array(
array('ViewScript', array('viewScript' => 'preference/stream-setting.phtml'))
));
$setting = $this->setting; $setting = $this->setting;
$icecast_vorbis_metadata = new Zend_Form_Element_Checkbox('icecast_vorbis_metadata'); $icecast_vorbis_metadata = new Zend_Form_Element_Checkbox('icecast_vorbis_metadata');
@ -55,6 +59,13 @@ class Application_Form_StreamSetting extends Zend_Form
->setAttribs(array('style' => "border: 0; color: #f6931f; font-weight: bold;")) ->setAttribs(array('style' => "border: 0; color: #f6931f; font-weight: bold;"))
->setDecorators(array('ViewHelper')); ->setDecorators(array('ViewHelper'));
$this->addElement($replay_gain); $this->addElement($replay_gain);
$custom = Application_Model_Preference::getUsingCustomStreamSettings();
$customSettings = new Zend_Form_Element_Radio('customStreamSettings');
$customSettings->setLabel(_('Stream Settings:'));
$customSettings->setMultiOptions(array(_("Default"), _("Use Custom")));
$customSettings->setValue(!empty($custom) ? $custom : 0);
$this->addElement($customSettings);
} }
public function isValid($data) public function isValid($data)

View file

@ -42,7 +42,7 @@ class Application_Form_StreamSettingSubForm extends Zend_Form_SubForm
$this->setIsArray(true); $this->setIsArray(true);
$this->setElementsBelongTo($prefix."_data"); $this->setElementsBelongTo($prefix."_data");
$disable_all = Application_Model_Preference::GetEnableStreamConf() == "false"; $disable_all = !Application_Model_Preference::getUsingCustomStreamSettings();
$enable = new Zend_Form_Element_Checkbox('enable'); $enable = new Zend_Form_Element_Checkbox('enable');
$enable->setLabel(_('Enabled:')) $enable->setLabel(_('Enabled:'))
@ -221,10 +221,10 @@ class Application_Form_StreamSettingSubForm extends Zend_Form_SubForm
$adminPass->setAttrib('alt', 'regular_text'); $adminPass->setAttrib('alt', 'regular_text');
$this->addElement($adminPass); $this->addElement($adminPass);
$liquidsopa_error_msg = '<div class="stream-status status-info"><h3>'._('Getting information from the server...').'</h3></div>'; $liquidsoap_error_msg = '<div class="stream-status status-info"><h3>'._('Getting information from the server...').'</h3></div>';
$this->setDecorators(array( $this->setDecorators(array(
array('ViewScript', array('viewScript' => 'form/stream-setting-form.phtml', "stream_number"=>$stream_number, "enabled"=>$enable->getValue(), "liquidsoap_error_msg"=>$liquidsopa_error_msg)) array('ViewScript', array('viewScript' => 'form/stream-setting-form.phtml', "stream_number"=>$stream_number, "enabled"=>$enable->getValue(), "liquidsoap_error_msg"=>$liquidsoap_error_msg))
)); ));
} }
@ -232,23 +232,25 @@ class Application_Form_StreamSettingSubForm extends Zend_Form_SubForm
{ {
$f_data = $data['s'.$this->prefix."_data"]; $f_data = $data['s'.$this->prefix."_data"];
$isValid = parent::isValid($f_data); $isValid = parent::isValid($f_data);
if ($f_data['enable'] == 1) { if ($f_data) {
if ($f_data['host'] == '') { if ($f_data['enable'] == 1) {
$element = $this->getElement("host"); if ($f_data['host'] == '') {
$element->addError(_("Server cannot be empty.")); $element = $this->getElement("host");
$isValid = false; $element->addError(_("Server cannot be empty."));
}
if ($f_data['port'] == '') {
$element = $this->getElement("port");
$element->addError(_("Port cannot be empty."));
$isValid = false;
}
if ($f_data['output'] == 'icecast') {
if ($f_data['mount'] == '') {
$element = $this->getElement("mount");
$element->addError(_("Mount cannot be empty with Icecast server."));
$isValid = false; $isValid = false;
} }
if ($f_data['port'] == '') {
$element = $this->getElement("port");
$element->addError(_("Port cannot be empty."));
$isValid = false;
}
if ($f_data['output'] == 'icecast') {
if ($f_data['mount'] == '') {
$element = $this->getElement("mount");
$element->addError(_("Mount cannot be empty with Icecast server."));
$isValid = false;
}
}
} }
} }

View file

@ -1489,4 +1489,14 @@ class Application_Model_Preference
self::setValue("task_manager_lock", $value); self::setValue("task_manager_lock", $value);
} }
// SAAS-876 - Toggle indicating whether user is using custom stream settings
public static function getUsingCustomStreamSettings() {
return self::getValue("using_custom_stream_settings");
}
public static function setUsingCustomStreamSettings($value) {
self::setValue("using_custom_stream_settings", $value);
}
} }

View file

@ -1,7 +1,7 @@
<?php <?php
$s_name = "s".$this->stream_number; $s_name = "s".$this->stream_number;
?> ?>
<h3 class="collapsible-header <?php echo $this->stream_number == '1'?"closed":""?>"><span class="arrow-icon"></span><?php echo _("Stream "); ?><?php echo $this->stream_number?></h3> <h3 class="collapsible-header <?php echo $this->enabled == 0?"closed":""?>"><span class="arrow-icon"></span><?php echo _("Stream "); ?><?php echo $this->stream_number?></h3>
<div class="stream-setting-content" <?php echo $this->enabled == 0?'style="display: none;':''?> id="<?php echo $s_name?>-config"> <div class="stream-setting-content" <?php echo $this->enabled == 0?'style="display: none;':''?> id="<?php echo $s_name?>-config">
<fieldset class="padded"> <fieldset class="padded">
<dl class="zend_form clearfix"> <dl class="zend_form clearfix">

View file

@ -1,12 +1,10 @@
<div class="ui-widget ui-widget-content block-shadow simple-formblock clearfix padded-strong stream-config"> <div class="ui-widget ui-widget-content block-shadow simple-formblock clearfix padded-strong stream-config">
<h2 <?php if($this->enable_stream_conf == "true"){?>style="float:left"<?php }?>><?php echo _("Stream Settings") ?></h2> <h2 style="float:left"><?php echo _("Stream Settings") ?></h2>
<?php $baseUrl = Application_Common_OsPath::getBaseDir(); ?> <?php $baseUrl = Application_Common_OsPath::getBaseDir(); ?>
<?php if($this->enable_stream_conf == "true"){?>
<form method="post" id="stream_form" enctype="application/x-www-form-urlencoded"> <form method="post" id="stream_form" enctype="application/x-www-form-urlencoded">
<button name="stream_save" id="stream_save" type="button" class="btn btn-small right-floated"><?php echo _("Save") ?></button> <button name="stream_save" id="stream_save_top" type="button" class="btn btn-small right-floated"><?php echo _("Save") ?></button>
<?php echo $this->form->getElement('csrf') ?> <?php echo $this->form->getElement('csrf') ?>
<div style="clear:both"></div> <div style="clear:both"></div>
<?php }?>
<?php echo $this->statusMsg;?> <?php echo $this->statusMsg;?>
<div style="float: left; margin-right: 10px; width: 490px; overflow: auto;"> <div style="float: left; margin-right: 10px; width: 490px; overflow: auto;">
<fieldset class="padded stream-setting-global"> <fieldset class="padded stream-setting-global">
@ -39,6 +37,12 @@
<dd id="vorbisMetadata-element"> <dd id="vorbisMetadata-element">
<?php echo $this->form->getElement('icecast_vorbis_metadata') ?> <?php echo $this->form->getElement('icecast_vorbis_metadata') ?>
</dd> </dd>
<?php
// TODO: replace this with something that looks good
echo $this->form->getElement('customStreamSettings')->render();
?>
<dt id="streamFormat-label"> <dt id="streamFormat-label">
<label class="optional"><?php echo $this->form->getElement('streamFormat')->getLabel() ?></label> <label class="optional"><?php echo $this->form->getElement('streamFormat')->getLabel() ?></label>
</dt> </dt>
@ -105,16 +109,18 @@
<div style="float: left; width: 600px;"> <div style="float: left; width: 600px;">
<fieldset class="padded"> <fieldset class="padded">
<legend><?php echo _("Output Stream Settings") ?></legend> <legend><?php echo _("Output Stream Settings") ?></legend>
<?php <?php
for($i=1;$i<=$this->num_stream;$i++){ if (Application_Model_Preference::getUsingCustomStreamSettings()) {
echo $this->form->getSubform("s".$i."_subform"); for($i=1;$i<=$this->num_stream;$i++){
} echo $this->form->getSubform("s".$i."_subform");
?> }
} else {
// TODO: replace this with something that looks good
}
?>
</fieldset> </fieldset>
<?php if($this->enable_stream_conf == "true"){?>
<br /> <br />
<button name="stream_save" id="stream_save" type="button" class="btn btn-small right-floated"><?php echo _("Save") ?></button> <button name="stream_save" id="stream_save_bottom" type="button" class="btn btn-small right-floated"><?php echo _("Save") ?></button>
<?php }?>
</div> </div>
</form> </form>
</div> </div>

View file

@ -2252,6 +2252,10 @@ span.errors.sp-errors{
width: 1100px; width: 1100px;
} }
#stream_save_bottom {
bottom: 0;
}
.preferences .padded { .preferences .padded {
margin-top: 5px; /* Firefox needs this */ margin-top: 5px; /* Firefox needs this */
} }

View file

@ -469,7 +469,7 @@ $(document).ready(function() {
setSliderForReplayGain(); setSliderForReplayGain();
getAdminPasswordStatus(); getAdminPasswordStatus();
$('#stream_save').live('click', function(){ $("[id^='stream_save']").live('click', function(){
var confirm_pypo_restart_text = sprintf($.i18n._("If you change the username or password values for an enabled stream the playout engine will be rebooted and your listeners will hear silence for 5-10 seconds. Changing the following fields will NOT cause a reboot: Stream Label (Global Settings), and Switch Transition Fade(s), Master Username, and Master Password (Input Stream Settings). If %s is recording, and if the change causes a playout engine restart, the recording will be interrupted."), PRODUCT_NAME); var confirm_pypo_restart_text = sprintf($.i18n._("If you change the username or password values for an enabled stream the playout engine will be rebooted and your listeners will hear silence for 5-10 seconds. Changing the following fields will NOT cause a reboot: Stream Label (Global Settings), and Switch Transition Fade(s), Master Username, and Master Password (Input Stream Settings). If %s is recording, and if the change causes a playout engine restart, the recording will be interrupted."), PRODUCT_NAME);
if (confirm(confirm_pypo_restart_text)) { if (confirm(confirm_pypo_restart_text)) {
var data = $('#stream_form').serialize(); var data = $('#stream_form').serialize();