update Di 26. Mai 18:01:01 CEST 2020

This commit is contained in:
Robert Richter 2020-05-26 18:01:01 +02:00
parent 73ba6855df
commit 6e31ad712a
3 changed files with 36 additions and 68 deletions

View File

@ -1,17 +1,21 @@
module.exports = function (io, io_api, sql, app_cfg, waip) {
module.exports = function (io, sql, app_cfg, waip) {
// Module laden
const io_api = require('socket.io-client');
// Socket.IO API (anderer Server stellt Verbindung her und sendet Daten)
// Namespace API festlegen
var nsp_api = io.of('/api');
// Socket.IO Empfangs-API (anderer Server stellt Verbindung her und sendet Daten)
if (app_cfg.api.enabled) {
// Namespace API
var nsp_api = io.of('/api');
nsp_api.on('connection', function (socket) {
// versuche Remote-IP zu ermitteln
var remote_ip = socket.handshake.headers["x-real-ip"] || socket.handshake.headers['x-forwarded-for'] || socket.request.connection.remoteAddress;
// TODO Connect loggen
//TODO pruefen ob Verbindung mit passendem Geheimnis und aus IP-Bereich
// in Liste der Clients mit aufnehmen
@ -40,75 +44,41 @@ module.exports = function (io, io_api, sql, app_cfg, waip) {
});
};
// Socket.IO Sende-API (Daten an Server senden, die Verbindung hergestellt haben)
// Endpoint-API
if (app_cfg.endpoint.enabled) {
const remote_api = io_api.connect(app_cfg.global.remoteapi, {
var remote_api = io_api.connect(app_cfg.endpoint.host, {
reconnect: true
});
// Add a connect listener
remote_api.on('connect', function () {
console.log('Connected!');
});
remote_api.on('connect_error', function (err) {
console.log('Fehler! ' + err);
});
// 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
} else {
const remote_api;
};
// Module laden
//client.js
// Add a connect listener
remote_api.on('connect', function (remote_api) {
console.log('Connected!');
});
socket.on('connect_error', function (err) {
$('#waipModalTitle').html('FEHLER');
$('#waipModalBody').html('Verbindung zum Server getrennt!');
$('#waipModal').modal('show');
});
remote_api.emit('CH01', 'me', 'test msg');
// Funktion um zu pruefen, ob Nachricht im JSON-Format ist
function isValidJSON(text) {
try {
JSON.parse(text);
return true;
} catch (error) {
return false;
}
};
//client.js
// Add a connect listener
remote_api.on('connect', function (remote_api) {
console.log('Connected!');
});
socket.on('connect_error', function (err) {
$('#waipModalTitle').html('FEHLER');
$('#waipModalBody').html('Verbindung zum Server getrennt!');
$('#waipModal').modal('show');
});
remote_api.emit('CH01', 'me', 'test msg');
return {
einsatz_speichern: einsatz_speichern,
waip_verteilen: waip_verteilen,
dbrd_verteilen: dbrd_verteilen,
rmld_verteilen_for_one_client: rmld_verteilen_for_one_client,
rmld_verteilen_by_uuid: rmld_verteilen_by_uuid
send_new_waip: send_new_waip,
send_new_rmld: send_new_rmld
};
};

View File

@ -47,9 +47,7 @@ app_cfg.api = {
// Daten an andere Server senden
app_cfg.endpoint = {
enabled: true,
host: '192.168.1.25',
port: '8090',
nsp: '/api',
host: 'https://192.168.1.25:8090/api',
secret: 'asdfwert1234567890#',
send_mission_type: ['Brandeinsatz', 'Hilfeleistung'],
send_data_type: ['uuid', 'nummer', 'alarmzeit', 'art', 'stichwort', 'sondersignal', 'ort', 'ortsteil', 'wgs84_area']

View File

@ -923,7 +923,7 @@ module.exports = function (db, uuidv4, app_cfg) {
function db_get_vmtl_list(waip_id, callback) {
// Pruefen ob fuer eine Wache in diesem Einsatz ein Twitter-Account mit Liste hinterlegt ist
db.get(`select t.waip_wachen_id, t.tw_account_id, t.tw_account_list from waip_twitter_wachen t
db.get(`select t.waip_wachen_id, t.tw_account_id, t.tw_account_list from waip_vmlt_tw_wachen t
where waip_wachen_id = (select distinct w.id wachen_id from waip_wachen w left join waip_einsatzmittel em on em.wachenname = w.name_wache
where em.waip_einsaetze_ID = ?)`, [waip_id], function (err, twitter_liste) {
if (err == null && twitter_liste) {