Skip to content
Snippets Groups Projects
Commit 61819657 authored by jkerdreu's avatar jkerdreu
Browse files

Fix android Chrome bug on refresh.

git-svn-id: https://redmine.imt-atlantique.fr/svn/xaal/code/Python/branches/fork@1820 b32b6428-25c9-4566-ad07-03861ab6144f
parent 622a8aad
No related branches found
No related tags found
No related merge requests found
var tags = {};
var evt_bus = new EventBus();
const sio = io.connect('ws://' + document.domain + ':' + location.port,{transports: ['websocket'],forceNew:true});
var evt_bus = null;
var sio = null;
//================ JS tools ==========================================
//================ JS tools ====================================================
// dumbs functions to mimic jQuery selectors
var _ = function ( elem ) {
return document.querySelector( elem );
......@@ -30,49 +29,40 @@ function detectMobile() {
}
}
//================ Event stuffs ================================================
//================ Event stuffs ===============================================
function EventBus () {
riot.observable(this);
this.mounted = false;
this.connected = false;
this.on('sio-connect',function() {
this.log('Event : connected ' + sio.io.engine.transport.name);
log('Event : connected ' + sio.io.engine.transport.name);
this.connected = true;
this.refresh_attributes();
});
this.on('sio-disconnect',function() {
this.log('Event : disconnected');
log('Event : disconnected');
this.connected = false;
});
this.on('tags-mount',function() {
this.log('Event : mounted');
log('Event : mounted');
this.mounted = true;
this.refresh_attributes();
run_sio();
//this.refresh_attributes();
});
this.on('visible',function() {
this.log('Event : visible');
log('Event : visible');
this.refresh_attributes();
});
this.refresh_attributes = function() {
if ((this.connected == true) && (this.mounted==true)) {
if ((this.connected == true) && (this.mounted == true)) {
sio_refresh_attributes();
this.log('refresh');
}
}
this.log = function(msg) {
console.log(msg);
elt = _('#messages');
//elt.style.color = 'green';
elt.innerText = elt.innerText +"\n" + msg;
}
};
function visibilityChanged(data) {
......@@ -83,29 +73,39 @@ function visibilityChanged(data) {
}
//================ SocketIO Events ==============================================
sio.on('connect', function() {
evt_bus.trigger('sio-connect');
});
function log(msg) {
//elt = _('#messages');
//elt.innerText = elt.innerText +"\n" + msg;
//elt.style.color = 'green';
console.log(msg)
}
sio.on('disconnect', function() {
evt_bus.trigger('sio-disconnect');
});
sio.on('event_attributeChanges', function(data) {
for (t in tags) {
var attrs = tags[t].root.attributes;
if (attrs.hasOwnProperty('xaal_addr')) {
if (attrs.xaal_addr.value == data['address']) {
tags[t].receive(data);
//console.log('Evt attr for : ' + data['address']);
//================ SocketIO ================================================
function run_sio() {
sio = io.connect('ws://' + document.domain + ':' + location.port,{transports: ['websocket'],forceNew:true});
sio.on('connect', function() {
evt_bus.trigger('sio-connect');
});
sio.on('disconnect', function() {
evt_bus.trigger('sio-disconnect');
});
sio.on('event_attributeChanges', function(data) {
for (t in tags) {
var attrs = tags[t].root.attributes;
if (attrs.hasOwnProperty('xaal_addr')) {
if (attrs.xaal_addr.value == data['address']) {
tags[t].receive(data);
//console.log('Evt attr for : ' + data['address']);
}
}
}
}
});
});
}
//================ SocketIO emit ================================================
function sio_refresh_attributes_old() {
console.log('refresh_attributes');
var addrs = [];
......@@ -118,7 +118,6 @@ function sio_refresh_attributes_old() {
sio.emit('refresh_attributes',addrs);
}
function sio_refresh_attributes() {
console.log('refresh_attributes');
for (t in tags) {
......@@ -129,8 +128,6 @@ function sio_refresh_attributes() {
}
}
function sio_send_request(addr,action,body) {
//console.log('Sending :' + addr + ' ' + action + ' ' + body);
sio.emit('send_request',addr,action,body);
......@@ -141,9 +138,10 @@ function sio_query_attributes(addr) {
sio.emit('query_attributes',addr);
}
//================ Main =========================================================
_('#messages').innerText = 'no messages';
evt_bus.log('riot_compile');
//================ Main ========================================================
evt_bus = new EventBus();
riot.compile(function() {
tags = riot.mount('*');
evt_bus.trigger('tags-mount');
......@@ -154,4 +152,3 @@ riot.compile(function() {
if (detectMobile() == true) {
document.addEventListener("visibilitychange", visibilityChanged);
}
This diff is collapsed.
......@@ -41,7 +41,7 @@
<!-- loading JS-->
<script src="/static/js/riot+compiler.min.js"></script>
<script src="/static/js/socket.io.min.js"></script>
<script src="/static/js/socket.io.slim.js"></script>
<script src="/static/js/site.js"></script>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment