mirror of
https://github.com/hyperion-project/hyperion.ng.git
synced 2023-10-10 13:36:59 +02:00
Fix: WebUI port switch reconnect
The WebUI will get now the new port for next reconnect It was necessary to add the Access-Control-Allow-Origin header with a wildcard for file serving
This commit is contained in:
parent
fcd11176f8
commit
7e324bb1d3
@ -26,6 +26,8 @@ performTranslation();
|
||||
var connectionLost = false;
|
||||
var connectionTimer;
|
||||
var count = 1;
|
||||
var reconnectInterval = 4000;
|
||||
var connURL = location.protocol+"//"+location.hostname+":"+window.jsonPort+location.pathname+location.hash;
|
||||
|
||||
function tryReconnect()
|
||||
{
|
||||
@ -34,12 +36,12 @@ function tryReconnect()
|
||||
window.clearInterval(connectionTimer);
|
||||
$('.reconstop').toggle();
|
||||
}
|
||||
|
||||
|
||||
$('#counter').html(count+'/100');
|
||||
|
||||
$.ajax({ url: "/" }).done(function(data) {
|
||||
|
||||
$.ajax({ url: connURL }).done(function(data) {
|
||||
window.clearInterval(connectionTimer);
|
||||
window.location.href ="/";
|
||||
window.location.href = connURL;
|
||||
})
|
||||
.fail( function( jqXHR, textStatus ) {
|
||||
count++;
|
||||
@ -52,10 +54,13 @@ function connectionLostAction()
|
||||
if(!connectionLost)
|
||||
{
|
||||
connectionLost = true;
|
||||
connectionTimer = window.setInterval(tryReconnect, 4000);
|
||||
// if we changed the webui port we connect faster
|
||||
if(window.fastReconnect){
|
||||
window.fastReconnect = false;
|
||||
reconnectInterval = 2000;
|
||||
}
|
||||
connectionTimer = window.setInterval(tryReconnect, reconnectInterval);
|
||||
}
|
||||
}
|
||||
|
||||
</script>
|
||||
|
||||
|
||||
|
@ -1,29 +1,32 @@
|
||||
$(document).ready( function() {
|
||||
performTranslation();
|
||||
|
||||
|
||||
var conf_editor = null;
|
||||
|
||||
|
||||
$('#conf_cont').append(createOptPanel('fa-wrench', $.i18n("edt_conf_webc_heading_title"), 'editor_container', 'btn_submit'));
|
||||
if(window.showOptHelp)
|
||||
{
|
||||
$('#conf_cont').append(createHelpTable(window.schema.webConfig.properties, $.i18n("edt_conf_webc_heading_title")));
|
||||
}
|
||||
|
||||
|
||||
conf_editor = createJsonEditor('editor_container', {
|
||||
webConfig : window.schema.webConfig
|
||||
}, true, true);
|
||||
|
||||
conf_editor.on('change',function() {
|
||||
conf_editor.validate().length ? $('#btn_submit').attr('disabled', true) : $('#btn_submit').attr('disabled', false);
|
||||
});
|
||||
});
|
||||
|
||||
$('#btn_submit').off().on('click',function() {
|
||||
requestWriteConfig(conf_editor.getValue());
|
||||
// store the last webui port for correct reconnect url (connection_lost.html)
|
||||
var val = conf_editor.getValue();
|
||||
window.fastReconnect = true;
|
||||
window.jsonPort = val.webConfig.port;
|
||||
requestWriteConfig(val);
|
||||
});
|
||||
|
||||
if(window.showOptHelp)
|
||||
createHint("intro", $.i18n('conf_webconfig_label_intro'), "editor_container");
|
||||
|
||||
|
||||
removeOverlay();
|
||||
});
|
||||
|
||||
|
@ -14,7 +14,7 @@ window.serverSchema = {};
|
||||
window.serverConfig = {};
|
||||
window.schema = {};
|
||||
window.sysInfo = {};
|
||||
window.jsonPort = 19444;
|
||||
window.jsonPort = 8090;
|
||||
window.websocket = null;
|
||||
window.hyperion = {};
|
||||
window.wsTan = 1;
|
||||
|
@ -30,6 +30,7 @@ const QByteArray & QtHttpHeader::Location = QByteArrayLiteral ("Loca
|
||||
const QByteArray & QtHttpHeader::SetCookie = QByteArrayLiteral ("Set-Cookie");
|
||||
const QByteArray & QtHttpHeader::TransferEncoding = QByteArrayLiteral ("Transfer-Encoding");
|
||||
const QByteArray & QtHttpHeader::ContentDisposition = QByteArrayLiteral ("Content-Disposition");
|
||||
const QByteArray & QtHttpHeader::AccessControlAllow = QByteArrayLiteral ("Access-Control-Allow-Origin");
|
||||
const QByteArray & QtHttpHeader::Upgrade = QByteArrayLiteral ("Upgrade");
|
||||
const QByteArray & QtHttpHeader::SecWebSocketKey = QByteArrayLiteral ("Sec-WebSocket-Key");
|
||||
const QByteArray & QtHttpHeader::SecWebSocketProtocol = QByteArrayLiteral ("Sec-WebSocket-Protocol");
|
||||
|
@ -32,6 +32,7 @@ public:
|
||||
static const QByteArray & SetCookie;
|
||||
static const QByteArray & TransferEncoding;
|
||||
static const QByteArray & ContentDisposition;
|
||||
static const QByteArray & AccessControlAllow;
|
||||
// Websocket specific headers
|
||||
static const QByteArray & Upgrade;
|
||||
static const QByteArray & SecWebSocketKey;
|
||||
|
@ -135,6 +135,7 @@ void StaticFileServing::onRequestNeedsReply (QtHttpRequest * request, QtHttpRepl
|
||||
if (file.open (QFile::ReadOnly)) {
|
||||
QByteArray data = file.readAll ();
|
||||
reply->addHeader ("Content-Type", mime.name ().toLocal8Bit ());
|
||||
reply->addHeader(QtHttpHeader::AccessControlAllow, "*" );
|
||||
reply->appendRawData (data);
|
||||
file.close ();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user