mirror of https://github.com/MISP/misp-dashboard
Auto-reconnect if event source connection lost
parent
13305e627f
commit
366f1d826e
|
@ -103,29 +103,34 @@ sources.addSource('global');
|
||||||
|
|
||||||
var curNumLog = 0;
|
var curNumLog = 0;
|
||||||
var curMaxDataNumLog = 0;
|
var curMaxDataNumLog = 0;
|
||||||
|
var source_log;
|
||||||
|
|
||||||
|
function connect_source_log() {
|
||||||
|
source_log = new EventSource(urlForLogs);
|
||||||
|
|
||||||
|
source_log.onopen = function(){
|
||||||
|
//console.log('connection is opened. '+source_log.readyState);
|
||||||
|
};
|
||||||
|
|
||||||
|
source_log.onerror = function(){
|
||||||
|
console.log('error: '+source_log.readyState);
|
||||||
|
setTimeout(function() { connect_source_log(); }, 5000);
|
||||||
|
};
|
||||||
|
|
||||||
|
source_log.onmessage = function(event) {
|
||||||
|
var json = jQuery.parseJSON( event.data );
|
||||||
|
updateLogTable(json.feedName, json.log);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
$(document).ready(function () {
|
$(document).ready(function () {
|
||||||
createHead(function() {
|
createHead(function() {
|
||||||
if (!!window.EventSource) {
|
if (!!window.EventSource) {
|
||||||
var source_log = new EventSource(urlForLogs);
|
connect_source_log();
|
||||||
|
|
||||||
source_log.onopen = function(){
|
|
||||||
//console.log('connection is opened. '+source_log.readyState);
|
|
||||||
};
|
|
||||||
|
|
||||||
source_log.onerror = function(){
|
|
||||||
console.log('error: '+source_log.readyState);
|
|
||||||
setTimeout(function() { location.reload(); }, 5000);
|
|
||||||
};
|
|
||||||
|
|
||||||
source_log.onmessage = function(event) {
|
|
||||||
var json = jQuery.parseJSON( event.data );
|
|
||||||
updateLogTable(json.feedName, json.log);
|
|
||||||
};
|
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
console.log("No event source_log");
|
console.log("No event source_log");
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
$( "#rotation_wait_time_selector" ).change(function() {
|
$( "#rotation_wait_time_selector" ).change(function() {
|
||||||
|
|
|
@ -89,7 +89,6 @@ class MapEventManager {
|
||||||
|
|
||||||
$("#textMap1").fadeOut(400, function(){ $(this).text(mapEvent.text); }).fadeIn(400);
|
$("#textMap1").fadeOut(400, function(){ $(this).text(mapEvent.text); }).fadeIn(400);
|
||||||
if(ROTATIONWAITTIME != 0) {
|
if(ROTATIONWAITTIME != 0) {
|
||||||
console.log(ROTATIONWAITTIME);
|
|
||||||
this._timeoutRotate = setTimeout(function(){ mapEventManager.rotateMap(); }, ROTATIONWAITTIME);
|
this._timeoutRotate = setTimeout(function(){ mapEventManager.rotateMap(); }, ROTATIONWAITTIME);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -159,18 +158,22 @@ $(function(){
|
||||||
});
|
});
|
||||||
|
|
||||||
// Subscribe to the flask eventStream
|
// Subscribe to the flask eventStream
|
||||||
var source_map = new EventSource(urlForMaps);
|
var source_map;
|
||||||
source_map.onmessage = function(event) {
|
function connect_source_map() {
|
||||||
var json = jQuery.parseJSON( event.data );
|
source_map = new EventSource(urlForMaps);
|
||||||
var marker = L.marker([json.coord.lat, json.coord.lon]).addTo(myOpenStreetMap);
|
source_map.onmessage = function(event) {
|
||||||
var mapEvent = new MapEvent(json, marker);
|
var json = jQuery.parseJSON( event.data );
|
||||||
mapEventManager.addMapEvent(mapEvent);
|
var marker = L.marker([json.coord.lat, json.coord.lon]).addTo(myOpenStreetMap);
|
||||||
|
var mapEvent = new MapEvent(json, marker);
|
||||||
};
|
mapEventManager.addMapEvent(mapEvent);
|
||||||
source_map.onopen = function(){
|
|
||||||
console.log('connection is opened. '+source_map.readyState);
|
};
|
||||||
};
|
source_map.onopen = function(){
|
||||||
source_map.onerror = function(){
|
console.log('connection is opened. '+source_map.readyState);
|
||||||
console.log('error: '+source_map.readyState);
|
};
|
||||||
setTimeout(function() { location.reload(); }, 5000);
|
source_map.onerror = function(){
|
||||||
};
|
console.log('error: '+source_map.readyState);
|
||||||
|
setTimeout(function() { connect_source_map(); }, 5000);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
connect_source_map()
|
||||||
|
|
Loading…
Reference in New Issue