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

4
Vagrantfile vendored
View File

@ -9,8 +9,10 @@ Vagrant.configure("2") do |config|
config.vm.network "forwarded_port", guest: 8000, host:8000
# liquidsoap input harbors for instreaming (ie. /master)
config.vm.network "forwarded_port", guest: 8001, host:8001
# mkdics documentation
config.vm.network "forwarded_port", guest: 8002, host:8002
# mkdocs documentation
config.vm.network "forwarded_port", guest: 8888, host:8888
# make sure we are using nfs (doesn't work out of the box with debian)
config.vm.synced_folder ".", "/vagrant", type: "nfs"

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>

View File

@ -169,6 +169,17 @@ select {
right:7px;
line-height:16px !important;
}
#connection_url_override {
position: relative;
display: inline-block;
float: left;
margin-left: 5px;
}
#master_dj_connection_url_actions {
float:left;
}
#auto_switch_help, #auto_transition_help {
right: 200px;

View File

@ -111,18 +111,17 @@ function checkLiquidsoapStatus(){
function setLiveSourceConnectionOverrideListener(){
$("[id=connection_url_override]").click(function(event){
var url_input = $(this).parent().find("#stream_url").children();
var url_input = $(this).parent().find("dd[id$='_source_host-element']").children();
url_input.removeAttr("readonly");
$(this).parent().find("div[id$='_dj_connection_url_actions']").show();
event.preventDefault();
});
// set action for "OK" and "X"
var live_dj_actions = $("#live_dj_connection_url_actions");
var live_dj_input = live_dj_actions.parent().find("#stream_url").children();
var live_dj_input = live_dj_actions.parent().find("dd[id$='_source_host-element']").children();
var master_dj_actions = $("#master_dj_connection_url_actions");
var master_dj_input = master_dj_actions.parent().find("#stream_url").children();
var master_dj_input = master_dj_actions.parent().find("dd[id$='_source_host-element']").children();
live_dj_actions.find("#ok").click(function(event){
event.preventDefault();
@ -130,18 +129,18 @@ function setLiveSourceConnectionOverrideListener(){
live_dj_input.val(url);
live_dj_input.attr("readonly", "readonly");
live_dj_actions.hide();
$.get(baseUrl+"Preference/set-source-connection-url/", {format: "json", type: "livedj", url:encodeURIComponent(url), override: 1});
$.get(baseUrl+"Preference/set-source-connection-url", {format: "json", type: "livedj", url:encodeURIComponent(url), override: 1});
event.preventDefault();
});
live_dj_actions.find("#reset").click(function(event){
event.preventDefault();
var port = $("#dj_harbor_input_port").val();
var mount = $("#dj_harbor_input_mount_point").val();
var url = "http://"+location.hostname+":"+port+"/"+mount;
if (port == '' || mount == '') {
url = 'N/A';
var port = $("#show_source_port").val();
var mount = $("#show_source_mount").val();
if (mount.charAt(0) != '/') {
mount = ('/').concat(mount);
}
var url = "http://"+location.hostname+":"+port+mount;
live_dj_input.val(url);
live_dj_input.attr("readonly", "readonly");
live_dj_actions.hide();
@ -159,12 +158,12 @@ function setLiveSourceConnectionOverrideListener(){
});
master_dj_actions.find("#reset").click(function(event){
var port = $("#master_harbor_input_port").val();
var mount = $("#master_harbor_input_mount_point").val();
var url = "http://"+location.hostname+":"+port+"/"+mount;
if (port == '' || mount == '') {
url = 'N/A';
var port = $("#master_source_port").val();
var mount = $("#master_source_mount").val();
if (mount.charAt(0) != '/') {
mount = ('/').concat(mount);
}
var url = "http://"+location.hostname+":"+port+mount;
master_dj_input.val(url);
master_dj_input.attr("readonly", "readonly");
master_dj_actions.hide();
@ -479,11 +478,13 @@ $(document).ready(function() {
var url = baseUrl+'Preference/stream-setting';
$.post(url, {format:"json", data: data}, function(json){
window.location.reload();
//$('#content').empty().append(json.html);
//setupEventListeners();
//setSliderForReplayGain();
//setPseudoAdminPassword(json.s1_set_admin_pass, json.s2_set_admin_pass, json.s3_set_admin_pass, json.s4_set_admin_pass);
$('#content').empty().append(json.html);
if (json.valid) {
window.location.reload();
}
setupEventListeners();
setSliderForReplayGain();
getAdminPasswordStatus();
});
} else {
if (e.prop('checked')) {

View File

@ -205,7 +205,7 @@ class PypoFetch(Thread):
self.telnet_lock.release()
"""
TODO: This function needs to be way shorter, and refactored :/ - MK
NOTE: This function is quite short after it was refactored.
"""
def regenerate_liquidsoap_conf(self, setting):
self.restart_liquidsoap()