Bowser-Fehler beachtet

This commit is contained in:
Robert Richter 2018-12-19 14:27:20 +01:00
parent 62274c33fd
commit b299cd5142
5 changed files with 105 additions and 23 deletions

View File

@ -1,4 +1,4 @@
// TODO: Remote-Reload per Socket
// TODO: Remote-Reload per Socket
// TODO: Client-Server-Version abgleichen
// TODO: Modal bei Chrome, dass Audio erst bei interaktion aktiv
@ -56,7 +56,9 @@ function setup_inactivcheck() {
this.addEventListener("mousedown", resetActivTimer, false);
this.addEventListener("keypress", resetActivTimer, false);
this.addEventListener("DOMMouseScroll", resetActivTimer, false);
this.addEventListener("mousewheel", resetActivTimer, {passive: true}, false);
this.addEventListener("mousewheel", resetActivTimer, {
passive: true
}, false);
this.addEventListener("touchmove", resetActivTimer, false);
this.addEventListener("MSPointerMove", resetActivTimer, false);
start_inactivtimer();
@ -152,7 +154,7 @@ socket.on('connect', function() {
socket.on('connect_error', function(err) {
$('#waipModalTitle').html('FEHLER');
$('#waipModalBody').html(`Verbindung zum Server getrennt!`);
$('#waipModalBody').html('Verbindung zum Server getrennt!');
$('#waipModal').modal('show');
});
@ -161,10 +163,14 @@ socket.on('io.version', function(server_id) {
var client_id = $('#app_id').html();
//console.log('server_id: ' + server_id);
//console.log('client_id: ' + client_id);
// TODO: socket.emit(lade client xxx neu)
if (client_id != server_id) {
$('#waipModalTitle').html('ACHTUNG');
$('#waipModalBody').html(`Neue Server-Version. Seite wird in 10 Sekunden neu geladen!`);
$('#waipModal').modal('toggle');
$('#waipModalBody').html('Neue Server-Version. Seite wird in 10 Sekunden neu geladen!');
if ($('#waipModal').hasClass('in')) {
$('#waipModal').modal('hide');
};
$('#waipModal').modal('show');
setTimeout(function() {
location.reload();
}, 10000);
@ -176,6 +182,12 @@ socket.on('io.error', function(data) {
console.log('Error:', data);
});
// Sounds abspielen
socket.on('io.stopaudio', function(data) {
var audio = document.getElementById('audio');
audio.pause;
});
// Sounds abspielen
socket.on('io.playtts', function(data) {
var audio = document.getElementById('audio');
@ -347,3 +359,19 @@ function set_clock() {
// Uhrzeit jede Sekunden anpassen
setInterval(set_clock, 1000);
/* ########################### */
/* ######## SONSTIGES ######## */
/* ########################### */
// Audio-Blockade des Browsers erkennen
var promise = document.querySelector('audio').play();
if (promise !== undefined) {
promise.catch(function(error) {
if (error && error.toString().toLowerCase().includes('play() request was interrupted')) {
$('#waipModalTitle').html('Audio-Fehler');
$('#waipModalBody').html('Die Audio-Wiedergabe wird aktuell durch Ihren Browser blockiert. Wenn Sie Chrome-Desktop benutzen, genügt es wenn Sie nur einmal irgendwo hinklicken. Fehlermeldung: ' + error.message);
$('#waipModal').modal('show');
};
});
};

View File

@ -21,23 +21,30 @@ module.exports = function(app, sql, app_cfg) {
// get /waip
app.get('/waip', function(req, res) {
res.render('waip', {
title: 'Wachalarm-IP-Web'
});
res.redirect('/waip/0');
});
// get /waip/<wachennummer>
app.get('/waip/:wachen_id', function(req, res) {
sql.db_wache_vorhanden(req.params.wachen_id, function(result) {
res.render('waip', {
title: 'Alarmmonitor',
wachen_id: req.params.wachen_id,
data_wache: ' '+ result.name,
app_id: app_cfg.global.app_id
});
// TODO: Abstruz bei unbekannter/falscher Wachennummer
app.get('/waip/:wachen_id', function(req, res, next) {
var parmeter_id = req.params.wachen_id;
sql.db_wache_vorhanden(parmeter_id, function(result) {
if (result) {
res.render('waip', {
title: 'Alarmmonitor',
wachen_id: parmeter_id,
data_wache: ' ' + result.name,
app_id: app_cfg.global.app_id
});
} else {
var err = new Error('Wache '+ parmeter_id +' nicht vorhanden');
err.status = 404;
next (err);
}
});
});
// get /ueber
app.get('/ueber', function(req, res) {
res.render('ueber', {

View File

@ -71,7 +71,8 @@ module.exports = function(app_cfg) {
connect_time DATETIME DEFAULT CURRENT_TIMESTAMP,
socket_id TEXT,
client_ip TEXT,
room_name TEXT)`);
room_name TEXT,
client_status TEXT)`);
// Ersetzungs-Tabelle fuer Einsatzmittelnamen erstellen
db.run(`CREATE TABLE waip_ttsreplace (
id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT UNIQUE,
@ -81,6 +82,7 @@ module.exports = function(app_cfg) {
db.run(`INSERT OR REPLACE INTO waip_wachen (
nr_wache, nr_traeger, nr_kreis, name_wache, name_traeger, name_kreis)
VALUES
(0,\'0\',0,\'Global - Alle Einsätze\',\'Global\',\'Global\'),
(520101,\'01\',52,\'CB FW Cottbus 1\',\'Stadt Cottbus\',\'Stadt Cottbus\'),
(520201,\'02\',52,\'CB FW Cottbus 2\',\'Stadt Cottbus\',\'Stadt Cottbus\'),
(521101,\'11\',52,\'CB FW Branitz\',\'Stadt Cottbus\',\'Stadt Cottbus\'),

View File

@ -2,6 +2,7 @@ module.exports = function(db) {
function db_einsatz_vorhanden(content, callback) {
// ermittelt den letzten vorhanden Einsatz zu einer Wache
if (parseInt(content) == 0) {content = '%'};
db.all('select em.waip_einsaetze_id from waip_einsatzmittel em ' +
'left join waip_wachen wa on wa.id = em.waip_wachen_id ' +
'where wa.nr_wache like ?||\'%\' ' +
@ -88,11 +89,20 @@ module.exports = function(db) {
} else {
var len = content.toString().length
// content muss 2, 4 oder 6 Zeichen lang sein
if (len != 2 && len != 4 && len != 6) {
if (parseInt(content) != 0 && len != 2 && len != 4 && len != 6) {
// Fehler: Wachennummer nicht plausibel.
callback && callback(null);
} else {
// je nach laenge andere SQL ausfuehren
if (parseInt(content) == 0) {
db.get('select \'1\' length, nr_wache nr, name_wache name from waip_wachen where nr_wache like ?', [content], function(err, row) {
if (err == null && row) {
callback && callback(row);
} else {
callback && callback(null);
};
});
};
if (len == 2) {
db.get('select \'2\' length, nr_kreis nr, name_kreis name from waip_wachen where nr_kreis like SUBSTR(?,-2, 2) group by name_kreis LIMIT 1', [content], function(err, row) {
if (err == null && row) {
@ -150,6 +160,8 @@ module.exports = function(db) {
where em.waip_einsaetze_ID = ? group by w.nr_wache`, [waip_id, waip_id, waip_id],
function(err, rows) {
if (err == null && rows.length > 0) {
// falls einsätze vorhanden, auch die null hinzufuegen
rows.push({"room":0});
callback && callback(rows);
} else {
callback && callback(null);
@ -230,9 +242,10 @@ module.exports = function(db) {
} else {
var len = wachen_nr.toString().length
// wachen_nr muss 2, 4 oder 6 Zeichen lang sein
if (len != 2 && len != 4 && len != 6) {
if (parseInt(wachen_nr) != 0 && len != 2 && len != 4 && len != 6 && len == null) {
callback && callback(null);
} else {
if (parseInt(wachen_nr) == 0) {wachen_nr = '%'};
// je nach laenge andere SQL ausfuehren
db.get('SELECT e.EINSATZART, e.STICHWORT, e.SONDERSIGNAL, e.OBJEKT, e.ORT,e.ORTSTEIL, e.STRASSE, e.BESONDERHEITEN, e.wgs84_x, e.wgs84_y, em1.EM_ALARMIERT, em0.EM_WEITERE ' +
'FROM WAIP_EINSAETZE e ' +
@ -305,6 +318,26 @@ module.exports = function(db) {
});
};
function db_update_client_status(socket_id, client_status) {
db.run('UPDATE waip_clients '+
'SET client_status=\'' + client_status + '\'' +
'WHERE socket_id=\'' + socket_id + '\'');
};
function db_check_client_waipid(socketId, waip_id, callback) {
db.get('SELECT client_status id from waip_clients where socket_id like ?', [socketId], function(err, row) {
if (err == null && row) {
if (row.id == waip_id) {
callback && callback(row);
} else {
callback && callback(null);
};
} else {
callback && callback(null);
};
});
};
return {
db_einsatz_speichern: db_einsatz_speichern,
db_einsatz_laden: db_einsatz_laden,
@ -323,7 +356,9 @@ module.exports = function(db) {
db_client_save: db_client_save,
db_client_delete: db_client_delete,
db_tts_einsatzmittel: db_tts_einsatzmittel,
db_get_socket_by_id:db_get_socket_by_id
db_get_socket_by_id: db_get_socket_by_id,
db_update_client_status: db_update_client_status,
db_check_client_waipid: db_check_client_waipid
};
};

View File

@ -26,10 +26,12 @@ module.exports = function(io, sql, async, app_cfg) {
console.log('Einsatz ' + result_einsatz[0].waip_einsaetze_ID + ' fuer Wache ' + wachen_id + ' vorhanden');
//letzten Einsatz verteilen
einsatz_verteilen(result_einsatz[0].waip_einsaetze_ID, socket.id, wachen_id);
sql.db_update_client_status(socket.id, result_einsatz[0].waip_einsaetze_ID);
} else {
console.log('Kein Einsatz fuer Wache ' + wachen_id + ' vorhanden, Standby');
//oder falls kein Einsatz vorhanden ist, dann
io.sockets.to(socket.id).emit('io.standby', null);
sql.db_update_client_status(socket.id, 'standby');
};
});
});
@ -75,6 +77,7 @@ module.exports = function(io, sql, async, app_cfg) {
// Einsatz senden
console.log('Einsatz ' + waip_id + ' fuer Wache ' + wachen_nr + ' an Socket ' + socket_id + ' gesendet');
io.sockets.to(socket_id).emit('io.neuerEinsatz', einsatzdaten);
sql.db_update_client_status(socket_id, waip_id);
// Sound erstellen
tts_erstellen(app_cfg, socket_id, einsatzdaten, function(tts) {
// Sound senden
@ -84,7 +87,8 @@ module.exports = function(io, sql, async, app_cfg) {
} else {
// Standby senden
io.sockets.to(socket_id).emit('io.standby', null);
console.log('Kein Einsatz fuer Wache ' + wachen_nr + ' vorhanden, Standby an Socket ' + socket_id + ' gesendet');
console.log('Kein Einsatz fuer Wache ' + wachen_nr + ' vorhanden, Standby an Socket ' + socket_id + ' gesendet..');
sql.db_update_client_status(socket_id, 'standby');
};
});
};
@ -179,8 +183,14 @@ module.exports = function(io, sql, async, app_cfg) {
Object.keys(room_stockets.sockets).forEach(function(socketId) {
// Standby senden
// TODO: Standby nur senden, wenn kein anderer (als der zu löschende) Einsatz angezeigt wird
io.sockets.to(socketId).emit('io.standby', null);
console.log('Standby an Socket ' + socketId + ' gesendet');
sql.db_check_client_waipid(socketId, waip_id, function(same_id){
if (same_id) {
io.sockets.to(socketId).emit('io.standby', null);
io.sockets.to(socketId).emit('io.stopaudio', null);
console.log('Standby an Socket ' + socketId + ' gesendet');
sql.db_update_client_status(socketId, 'standby');
};
});
});
};
});