update Mi 27. Mai 13:01:01 CEST 2020
This commit is contained in:
parent
9130b6f4b0
commit
61c5f8cd6d
@ -6,24 +6,23 @@ module.exports = function (io, sql, app_cfg, waip) {
|
|||||||
// Namespace API festlegen
|
// Namespace API festlegen
|
||||||
var nsp_api = io.of('/api');
|
var nsp_api = io.of('/api');
|
||||||
|
|
||||||
|
// ###
|
||||||
// Socket.IO Empfangs-API (anderer Server stellt Verbindung her und sendet Daten)
|
// Socket.IO Empfangs-API (anderer Server stellt Verbindung her und sendet Daten)
|
||||||
|
// ###
|
||||||
|
|
||||||
if (app_cfg.api.enabled) {
|
if (app_cfg.api.enabled) {
|
||||||
nsp_api.on('connection', function (socket) {
|
nsp_api.on('connection', function (socket) {
|
||||||
// versuche Remote-IP zu ermitteln
|
// versuche Remote-IP zu ermitteln
|
||||||
var remote_ip = socket.handshake.headers["x-real-ip"] || socket.handshake.headers['x-forwarded-for'] || socket.request.connection.remoteAddress;
|
var remote_ip = socket.handshake.headers["x-real-ip"] || socket.handshake.headers['x-forwarded-for'] || socket.request.connection.remoteAddress;
|
||||||
|
|
||||||
|
//TODO pruefen ob Verbindung mit passendem Geheimnis und aus IP-Bereich, das Ergebnis loggen
|
||||||
// TODO Connect loggen
|
|
||||||
|
|
||||||
//TODO pruefen ob Verbindung mit passendem Geheimnis und aus IP-Bereich
|
|
||||||
|
|
||||||
// in Liste der Clients mit aufnehmen
|
// in Liste der Clients mit aufnehmen
|
||||||
sql.db_update_client_status(socket, 'api');
|
sql.db_update_client_status(socket, 'api');
|
||||||
// Neuen Einsatz speichern
|
// Neuen Einsatz speichern
|
||||||
socket.on('new_waip', function (data) {
|
socket.on('new_waip', function (data) {
|
||||||
waip.einsatz_speichern(data);
|
waip.einsatz_speichern(data);
|
||||||
sql.db_log('API', 'Neuer Einsatz von ' + remote_ip + ': ' + data);
|
sql.db_log('API', 'Neuer Einsatz von ' + remote_ip + ': ' + data);
|
||||||
});
|
});
|
||||||
// neue externe Rueckmeldung speichern
|
// neue externe Rueckmeldung speichern
|
||||||
socket.on('new_rmld', function (data) {
|
socket.on('new_rmld', function (data) {
|
||||||
@ -44,51 +43,49 @@ module.exports = function (io, sql, app_cfg, waip) {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// ###
|
||||||
// Socket.IO Sende-API (Daten an Server senden, die Verbindung hergestellt haben)
|
// Socket.IO Sende-API (Daten an Server senden, die Verbindung hergestellt haben)
|
||||||
|
// ###
|
||||||
|
|
||||||
/*if (app_cfg.endpoint.enabled) {
|
if (app_cfg.endpoint.enabled) {
|
||||||
|
// Verbindung zu anderem Server aufbauen
|
||||||
} else {
|
// TODO Verbindungsaufbau mit passendem Geheimnis absichern
|
||||||
const remote_api;
|
|
||||||
};*/
|
|
||||||
|
|
||||||
var remote_api = io_api.connect(app_cfg.endpoint.host, {
|
var remote_api = io_api.connect(app_cfg.endpoint.host, {
|
||||||
reconnect: true
|
reconnect: true
|
||||||
});
|
});
|
||||||
|
|
||||||
// Add a connect listener
|
// Verbindungsaufbau protokollieren
|
||||||
remote_api.on('connect', function () {
|
remote_api.on('connect', function () {
|
||||||
console.log('Connected!');
|
sql.db_log('API', 'Verbindung mit ' + app_cfg.endpoint.host + ' ergestellt');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Fehler protokollieren
|
||||||
remote_api.on('connect_error', function (err) {
|
remote_api.on('connect_error', function (err) {
|
||||||
console.log('Fehler! ' + err);
|
sql.db_log('API', 'Verbindung zu ' + app_cfg.endpoint.host + ' verloren, Fehler: ' + err);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Verbindungsabbau protokollieren
|
||||||
|
remote_api.on('disconnect', function (reason) {
|
||||||
|
sql.db_log('API', 'Verbindung zu ' + app_cfg.endpoint.host + ' verloren, Fehler: ' + reason);
|
||||||
|
});
|
||||||
|
|
||||||
// Funktio daraus machen
|
};
|
||||||
remote_api.emit('new_waip', data);
|
|
||||||
|
|
||||||
//send_mission_type: ['Brandeinsatz', 'Hilfeleistung'],
|
|
||||||
//send_data_type: ['uuid', 'n
|
|
||||||
// data so wie bei udp
|
|
||||||
remote_api.emit('new_rmld', data);
|
|
||||||
// gibts nur im routing
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
function db_get_waipid_by_uuid(waip_uuid, callback) {
|
|
||||||
db.get(`SELECT id FROM WAIP_EINSAETZE WHERE uuid like ?`, [waip_uuid], function (err, row) {
|
|
||||||
if (err == null && row) {
|
|
||||||
callback && callback(row.id);
|
|
||||||
} else {
|
|
||||||
callback && callback(null);
|
|
||||||
};
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
|
function send_new_waip(data) {
|
||||||
|
// Alarm an Remote-Server senden, falls funktion aktiviert
|
||||||
|
if (app_cfg.endpoint.enabled) {
|
||||||
|
remote_api.emit('new_waip', data);
|
||||||
|
sql.db_log('API', 'Neuen Wachalarm an ' + app_cfg.endpoint.host + ' gesendet: ' + data);
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
function send_new_rmld(data) {
|
||||||
|
// Rückmeldung an Remote-Server senden, falls funktion aktiviert
|
||||||
|
if (app_cfg.endpoint.enabled) {
|
||||||
|
remote_api.emit('new_rmld', data);
|
||||||
|
sql.db_log('API', 'Rückmeldung an ' + app_cfg.endpoint.host + ' gesendet: ' + data);
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
return {
|
return {
|
||||||
send_new_waip: send_new_waip,
|
send_new_waip: send_new_waip,
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user