Merge pull request #84 from Robbt/fix/live-stream-source

[WIP] Making show and master source ports and mount points editable.
This commit is contained in:
Lucas Bickel 2017-03-20 02:06:58 +01:00 committed by GitHub
commit 81d3c3e2b8
9 changed files with 206 additions and 138 deletions

View file

@ -201,6 +201,49 @@ class PreferenceController extends Zend_Controller_Action
$csrf_element->setValue($csrf_namespace->authtoken)->setRequired('true')->removeDecorator('HtmlTag')->removeDecorator('Label');
$form->addElement($csrf_element);
$live_stream_subform = new Application_Form_LiveStreamingPreferences();
$form->addSubForm($live_stream_subform, "live_stream_subform");
// 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);
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();
$subform->toggleState();
$form->addSubForm($subform, "s".$i."_subform");
}
$live_stream_subform->updateVariables();
$form->startFrom();
if ($request->isPost()) {
$params = $request->getPost();
/* Parse through post data and put in format
@ -263,6 +306,35 @@ class PreferenceController extends Zend_Controller_Action
//Application_Model_RabbitMq::PushSchedule();
}
// pulling this from the 2.5.x branch
if (!Application_Model_Preference::GetMasterDjConnectionUrlOverride()) {
$master_connection_url = "http://".$_SERVER['SERVER_NAME'].":".$values["master_source_port"].$values["master_source_mount"];
if (empty($values["master_source_port"]) || empty($values["master_source_mount"])) {
Application_Model_Preference::SetMasterDJSourceConnectionURL('N/A');
} else {
Application_Model_Preference::SetMasterDJSourceConnectionURL($master_connection_url);
}
} else {
Application_Model_Preference::SetMasterDJSourceConnectionURL($values["master_source_host"]);
}
if (!Application_Model_Preference::GetLiveDjConnectionUrlOverride()) {
$live_connection_url = "http://".$_SERVER['SERVER_NAME'].":".$values["show_source_port"].$values["show_source_mount"];
if (empty($values["show_source_port"]) || empty($values["show_source_mount"])) {
Application_Model_Preference::SetLiveDJSourceConnectionURL('N/A');
} else {
Application_Model_Preference::SetLiveDJSourceConnectionURL($live_connection_url);
}
} else {
Application_Model_Preference::SetLiveDJSourceConnectionURL($values["show_source_host"]);
}
Application_Model_StreamSetting::setMasterLiveStreamPort($values["master_source_port"]);
Application_Model_StreamSetting::setMasterLiveStreamMountPoint($values["master_source_mount"]);
Application_Model_StreamSetting::setDjLiveStreamPort($values["show_source_port"]);
Application_Model_StreamSetting::setDjLiveStreamMountPoint($values["show_source_mount"]);
Application_Model_StreamSetting::setOffAirMeta($values['offAirMeta']);
// store stream update timestamp
@ -280,50 +352,6 @@ class PreferenceController extends Zend_Controller_Action
}
}
// 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();
$subform->toggleState();
$form->addSubForm($subform, "s".$i."_subform");
}
$live_stream_subform->updateVariables();
$this->view->num_stream = $num_of_stream;
$this->view->enable_stream_conf = Application_Model_Preference::GetEnableStreamConf();
$this->view->form = $form;
@ -356,6 +384,7 @@ class PreferenceController extends Zend_Controller_Action
Application_Model_Preference::SetDefaultTransitionFade($values["transition_fade"]);
Application_Model_Preference::SetAutoTransition($values["auto_transition"]);
Application_Model_Preference::SetAutoSwitch($values["auto_switch"]);
}
public function serverBrowseAction()

View file

@ -11,105 +11,113 @@ class Application_Form_LiveStreamingPreferences extends Zend_Form_SubForm
$defaultFade = Application_Model_Preference::GetDefaultTransitionFade();
$this->setDecorators(array(
array('ViewScript', array('viewScript' => 'form/preferences_livestream.phtml')),
));
array('ViewScript', array('viewScript' => 'form/preferences_livestream.phtml')),
));
// automatic trasition on source disconnection
$auto_transition = new Zend_Form_Element_Checkbox("auto_transition");
$auto_transition->setLabel(_("Auto Switch Off:"))
->setValue(Application_Model_Preference::GetAutoTransition());
->setValue(Application_Model_Preference::GetAutoTransition());
$this->addElement($auto_transition);
// automatic switch on upon source connection
$auto_switch = new Zend_Form_Element_Checkbox("auto_switch");
$auto_switch->setLabel(_("Auto Switch On:"))
->setValue(Application_Model_Preference::GetAutoSwitch());
->setValue(Application_Model_Preference::GetAutoSwitch());
$this->addElement($auto_switch);
// Default transition fade
$transition_fade = new Zend_Form_Element_Text("transition_fade");
$transition_fade->setLabel(_("Switch Transition Fade (s):"))
->setFilters(array('StringTrim'))
->addValidator('regex', false, array('/^\d*(\.\d+)?$/',
'messages' => _('Please enter a time in seconds (eg. 0.5)')))
->setValue($defaultFade);
->setFilters(array('StringTrim'))
->addValidator('regex', false, array('/^\d*(\.\d+)?$/',
'messages' => _('Please enter a time in seconds (eg. 0.5)')))
->setValue($defaultFade);
$this->addElement($transition_fade);
//Master username
$master_username = new Zend_Form_Element_Text('master_username');
$master_username->setAttrib('autocomplete', 'off')
->setAllowEmpty(true)
->setLabel(_('Username:'))
->setFilters(array('StringTrim'))
->setValue(Application_Model_Preference::GetLiveStreamMasterUsername());
->setAllowEmpty(true)
->setLabel(_('Username:'))
->setFilters(array('StringTrim'))
->setValue(Application_Model_Preference::GetLiveStreamMasterUsername());
$this->addElement($master_username);
//Master password
if ($isDemo) {
$master_password = new Zend_Form_Element_Text('master_password');
$master_password = new Zend_Form_Element_Text('master_password');
} else {
$master_password = new Zend_Form_Element_Password('master_password');
$master_password->setAttrib('renderPassword','true');
$master_password = new Zend_Form_Element_Password('master_password');
$master_password->setAttrib('renderPassword', 'true');
}
$master_password->setAttrib('autocomplete', 'off')
->setAttrib('renderPassword','true')
->setAllowEmpty(true)
->setValue(Application_Model_Preference::GetLiveStreamMasterPassword())
->setLabel(_('Password:'))
->setFilters(array('StringTrim'));
->setAttrib('renderPassword', 'true')
->setAllowEmpty(true)
->setValue(Application_Model_Preference::GetLiveStreamMasterPassword())
->setLabel(_('Password:'))
->setFilters(array('StringTrim'));
$this->addElement($master_password);
$masterSourceParams = parse_url(Application_Model_Preference::GetMasterDJSourceConnectionURL());
// Master source connection url parameters
$masterSourceHost = new Zend_Form_Element_Text('master_source_host');
$masterSourceHost->setAttrib('readonly', true)
->setLabel(_('Host:'))
->setValue(isset($masterSourceParams["host"])?$masterSourceParams["host"]:"");
$masterSourceHost->setLabel(_('Master Source Host:'))
->setAttrib('readonly', true)
->setValue(Application_Model_Preference::GetMasterDJSourceConnectionURL());
$this->addElement($masterSourceHost);
$masterSourcePort = new Zend_Form_Element_Text('master_source_port');
$masterSourcePort->setAttrib('readonly', true)
->setLabel(_('Port:'))
->setValue(isset($masterSourceParams["port"])?$masterSourceParams["port"]:"");
$this->addElement($masterSourcePort);
//liquidsoap harbor.input port
$betweenValidator = Application_Form_Helper_ValidationTypes::overrideBetweenValidator(1024, 49151);
$m_port = Application_Model_StreamSetting::getMasterLiveStreamPort();
$masterSourcePort = new Zend_Form_Element_Text('master_source_port');
$masterSourcePort->setLabel(_('Master Source Port:'))
->setValue($m_port)
->setValidators(array($betweenValidator))
->addValidator('regex', false, array('pattern'=>'/^[0-9]+$/', 'messages'=>array('regexNotMatch'=>_('Only numbers are allowed.'))));
$this->addElement($masterSourcePort);
$m_mount = Application_Model_StreamSetting::getMasterLiveStreamMountPoint();
$masterSourceMount = new Zend_Form_Element_Text('master_source_mount');
$masterSourceMount->setAttrib('readonly', true)
->setLabel(_('Mount:'))
->setValue(isset($masterSourceParams["path"])?$masterSourceParams["path"]:"");
$masterSourceMount->setLabel(_('Master Source Mount:'))
->setValue($m_mount)
->setValidators(array(
array('regex', false, array('/^[^ &<>]+$/', 'messages' => _('Invalid character entered')))));
$this->addElement($masterSourceMount);
$showSourceParams = parse_url(Application_Model_Preference::GetLiveDJSourceConnectionURL());
// Show source connection url parameters
$showSourceHost = new Zend_Form_Element_Text('show_source_host');
$showSourceHost->setAttrib('readonly', true)
->setLabel(_('Host:'))
->setValue(isset($showSourceParams["host"])?$showSourceParams["host"]:"");
$showSourceHost->setLabel(_('Show Source Host:'))
->setAttrib('readonly', true)
->setValue(Application_Model_Preference::GetLiveDJSourceConnectionURL());
$this->addElement($showSourceHost);
//liquidsoap harbor.input port
$l_port = Application_Model_StreamSetting::getDjLiveStreamPort();
$showSourcePort = new Zend_Form_Element_Text('show_source_port');
$showSourcePort->setAttrib('readonly', true)
->setLabel(_('Port:'))
->setValue(isset($showSourceParams["port"])?$showSourceParams["port"]:"");
$showSourcePort->setLabel(_('Show Source Port:'))
->setValue($l_port)
->setValidators(array($betweenValidator))
->addValidator('regex', false, array('pattern' => '/^[0-9]+$/', 'messages' => array('regexNotMatch' => _('Only numbers are allowed.'))));
$this->addElement($showSourcePort);
$l_mount = Application_Model_StreamSetting::getDjLiveStreamMountPoint();
$showSourceMount = new Zend_Form_Element_Text('show_source_mount');
$showSourceMount->setAttrib('readonly', true)
->setLabel(_('Mount:'))
->setValue(isset($showSourceParams["path"])?$showSourceParams["path"]:"");
$showSourceMount->setLabel(_('Show Source Mount:'))
->setValue($l_mount)
->setValidators(array(
array('regex', false, array('/^[^ &<>]+$/', 'messages' => _('Invalid character entered')))));
$this->addElement($showSourceMount);
// demo only code
if ($isDemo) {
$elements = $this->getElements();
foreach ($elements as $element) {
if ($element->getType() != 'Zend_Form_Element_Hidden') {
$element->setAttrib("disabled", "disabled");
}
}
}
}
public function updateVariables()
@ -121,26 +129,20 @@ class Application_Form_LiveStreamingPreferences extends Zend_Form_SubForm
$showSourceParams = parse_url(Application_Model_Preference::GetLiveDJSourceConnectionURL());
$this->setDecorators(
array (
array ('ViewScript',
array (
'viewScript' => 'form/preferences_livestream.phtml',
'master_source_host' => isset($masterSourceParams["host"])?$masterSourceParams["host"]:"",
'master_source_port' => isset($masterSourceParams["port"])?$masterSourceParams["port"]:"",
'master_source_mount' => isset($masterSourceParams["path"])?$masterSourceParams["path"]:"",
'show_source_host' => isset($showSourceParams["host"])?$showSourceParams["host"]:"",
'show_source_port' => isset($showSourceParams["port"])?$showSourceParams["port"]:"",
'show_source_mount' => isset($showSourceParams["path"])?$showSourceParams["path"]:"",
'isDemo' => $isDemo,
array(
array('ViewScript',
array(
'viewScript' => 'form/preferences_livestream.phtml',
'master_source_host' => isset($masterSourceHost) ? Application_Model_Preference::GetMasterDJSourceConnectionURL() : "",
'master_source_port' => isset($masterSourcePort) ? Application_Model_StreamSetting::getMasterLiveStreamPort() : "",
'master_source_mount' => isset($masterSourceMount) ? Application_Model_StreamSetting::getMasterLiveStreamMountPoint() : "",
'show_source_host' => isset($showSourceHost) ? Application_Model_Preference::GetLiveDJSourceConnectionURL() : "",
'show_source_port' => isset($showSourcePort) ? Application_Model_StreamSetting::getDjLiveStreamPort() : "",
'show_source_mount' => isset($showSourceMount) ? Application_Model_StreamSetting::getDjLiveStreamMountPoint() : "",
'isDemo' => $isDemo,
)
)
)
);
}
public function isValid($data)
{
return parent::isValid($data);
}
}

View file

@ -1113,7 +1113,13 @@ class Application_Model_Preference
public static function GetMasterDJSourceConnectionURL()
{
return self::getValue("master_dj_source_connection_url");
$master_connection_url = self::getValue("master_dj_source_connection_url");
if ($master_connection_url == "") {
$master_connection_url = "http://".$_SERVER['SERVER_NAME'].":". Application_Model_StreamSetting::getMasterLiveStreamPort() . Application_Model_StreamSetting::getMasterLiveStreamMountPoint();
}
return $master_connection_url;
}
public static function SetLiveDJSourceConnectionURL($value)
@ -1123,7 +1129,11 @@ class Application_Model_Preference
public static function GetLiveDJSourceConnectionURL()
{
return self::getValue("live_dj_source_connection_url");
$livedj_connection_url = self::getValue("live_dj_source_connection_url");
if ($livedj_connection_url == "") {
$livedj_connection_url = "http://".$_SERVER['SERVER_NAME'].":". Application_Model_StreamSetting::getDjLiveStreamPort() . Application_Model_StreamSetting::getDjLiveStreamMountPoint();
}
return $livedj_connection_url;
}
/* Source Connection URL override status starts */

View file

@ -464,7 +464,7 @@ class Application_Model_StreamSetting
public static function getDjLiveStreamPort()
{
return self::getValue("dj_live_stream_port", 8001);
return self::getValue("dj_live_stream_port", 8002);
}
public static function setDjLiveStreamMountPoint($value)

View file

@ -15,8 +15,13 @@
<?php echo $this->element->getElement('master_username')->render() ?>
<span class="master_username_help_icon"></span>
<?php echo $this->element->getElement('master_password')->render() ?>
<?php echo $this->element->getElement("master_source_host")->render() ?>
<span id="stream_url"><?php echo $this->element->getElement("master_source_host")->render() ?>
<a href=# id="connection_url_override" style="font-size: 12px;"><?php echo _("Override") ?></a>&nbsp;&nbsp;
<span class="override_help_icon"></span></br>
<div id="master_dj_connection_url_actions" style="display:none">
<a href=# id="ok" style="font-size: 12px;"><?php echo _("OK") ?></a> <a href=# id="reset" style="font-size: 12px;"><?php echo _("RESET"); ?></a>
</div>
</span>
<?php echo $this->element->getElement("master_source_port")->render() ?>
<?php echo $this->element->getElement("master_source_mount")->render() ?>
</fieldset>
@ -26,7 +31,15 @@
<p class="input-settings-inline-p">
<?php echo _("DJs can use these settings in their broadcasting software to broadcast live only during shows assigned to them.") ?>
</p>
<span id="stream_url">
<?php echo $this->element->getElement("show_source_host")->render() ?>
<a href=# id="connection_url_override" style="font-size: 12px;"><?php echo _("Override") ?></a>&nbsp;&nbsp;
<span class="override_help_icon"></span>
</br>
<div id="live_dj_connection_url_actions" style="display:none">
<a href=# id="ok" style="font-size: 12px;"><?php echo _("OK") ?></a> <a href=# id="reset" style="font-size: 12px;"><?php echo _("RESET"); ?></a>
</div>
</span>
<?php echo $this->element->getElement("show_source_port")->render() ?>
<?php echo $this->element->getElement("show_source_mount")->render() ?>
</fieldset>