mirror of
https://gitlab.com/eql/lqml.git
synced 2026-01-04 00:02:51 -08:00
make 'clog-demo' work on latest android (ditch websocket, use direct JS calls)
This commit is contained in:
parent
78a0f300da
commit
94abc457c1
11 changed files with 80 additions and 189 deletions
|
|
@ -1,72 +1,17 @@
|
|||
/*static version*/
|
||||
var ws;
|
||||
var adr;
|
||||
var clog={};
|
||||
var pingerid;
|
||||
|
||||
if (typeof clog_debug == 'undefined') {
|
||||
clog_debug = false;
|
||||
}
|
||||
|
||||
function Ping_ws() {
|
||||
if (ws.readyState == 1) {
|
||||
ws.send ('0');
|
||||
const ws = {
|
||||
send: function(message) {
|
||||
// hack: notify QML (see 'onTitleChanged()')
|
||||
document.title = message;
|
||||
document.title = "-"; // reset (not empty!)
|
||||
}
|
||||
}
|
||||
|
||||
function Shutdown_ws(event) {
|
||||
if (ws != null) {
|
||||
ws.onerror = null;
|
||||
ws.onclose = null;
|
||||
ws.close ();
|
||||
ws = null;
|
||||
}
|
||||
clearInterval (pingerid);
|
||||
if (clog['html_on_close'] != '') {
|
||||
$(document.body).html(clog['html_on_close']);
|
||||
}
|
||||
}
|
||||
|
||||
function Setup_ws() {
|
||||
ws.onmessage = function (event) {
|
||||
try {
|
||||
if (clog_debug == true) {
|
||||
console.log ('eval data = ' + event.data);
|
||||
}
|
||||
eval (event.data);
|
||||
} catch (e) {
|
||||
console.error (e.message);
|
||||
}
|
||||
}
|
||||
|
||||
ws.onerror = function (event) {
|
||||
console.log ('onerror: reconnect');
|
||||
ws = null;
|
||||
ws = new WebSocket (adr + '?r=' + clog['connection_id']);
|
||||
ws.onopen = function (event) {
|
||||
console.log ('onerror: reconnect successful');
|
||||
Setup_ws();
|
||||
}
|
||||
ws.onclose = function (event) {
|
||||
console.log ('onerror: reconnect failure');
|
||||
Shutdown_ws(event);
|
||||
}
|
||||
}
|
||||
|
||||
ws.onclose = function (event) {
|
||||
console.log ('onclose: reconnect');
|
||||
ws = null;
|
||||
ws = new WebSocket (adr + '?r=' + clog['connection_id']);
|
||||
ws.onopen = function (event) {
|
||||
console.log ('onclose: reconnect successful');
|
||||
Setup_ws();
|
||||
}
|
||||
ws.onclose = function (event) {
|
||||
console.log ('onclose: reconnect failure');
|
||||
Shutdown_ws(event);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
$( document ).ready(function() {
|
||||
var s = document.location.search;
|
||||
|
|
@ -80,32 +25,4 @@ $( document ).ready(function() {
|
|||
clog['navigator']=navigator;
|
||||
clog['document']=window.document;
|
||||
clog['location']=window.location;
|
||||
|
||||
if (location.protocol == 'https:') {
|
||||
adr = 'wss://' + location.hostname;
|
||||
} else {
|
||||
adr = 'ws://' + location.hostname;
|
||||
}
|
||||
|
||||
if (location.port != '') { adr = adr + ':' + location.port; }
|
||||
//adr = adr + '/clog';
|
||||
adr = adr + '127.0.0.1:8080/'; // for LQML
|
||||
|
||||
try {
|
||||
console.log ('connecting to ' + adr);
|
||||
ws = new WebSocket (adr);
|
||||
} catch (e) {
|
||||
console.log ('trying again, connecting to ' + adr);
|
||||
ws = new WebSocket (adr);
|
||||
}
|
||||
|
||||
if (ws != null) {
|
||||
ws.onopen = function (event) {
|
||||
console.log ('connection successful');
|
||||
Setup_ws();
|
||||
}
|
||||
pingerid = setInterval (function () {Ping_ws ();}, 10000);
|
||||
} else {
|
||||
document.writeln ('If you are seeing this your browser or your connection to the internet is blocking websockets.');
|
||||
}
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue