Add live CEO briefing, Wereldexport CRM, halal engine, and realtime cockpit.
Ship export intel with contact filters and CRM push, Herman live digest with Telegram briefing, halal recommendation engine, revenue cockpit, and dashboard polling/WebSocket fixes.
This commit is contained in:
@@ -9,19 +9,41 @@ window.CockpitLive = (function () {
|
||||
return function () { clearInterval(id); };
|
||||
}
|
||||
|
||||
function eventFingerprint(data) {
|
||||
var ev = (data && data.events) || [];
|
||||
if (!ev.length) return '';
|
||||
return ev.slice(0, 5).map(function (e) {
|
||||
return String(e.created_at || '') + '#' + String(e.agent_name || '') + '#' + String(e.title || e.event_type || '');
|
||||
}).join('|');
|
||||
}
|
||||
|
||||
function connectFeed(onMessage) {
|
||||
if (typeof WebSocket === 'undefined') return function () {};
|
||||
var proto = location.protocol === 'https:' ? 'wss:' : 'ws:';
|
||||
var lastFp = '';
|
||||
var booted = false;
|
||||
function connect() {
|
||||
try {
|
||||
ws = new WebSocket(proto + '//' + location.host + '/ws/feed');
|
||||
ws.onmessage = function (ev) {
|
||||
try {
|
||||
var data = JSON.parse(ev.data);
|
||||
if (onMessage) onMessage(data);
|
||||
var fp = eventFingerprint(data);
|
||||
if (!booted) {
|
||||
booted = true;
|
||||
lastFp = fp;
|
||||
if (onMessage) onMessage(data, { reason: 'connect' });
|
||||
return;
|
||||
}
|
||||
if (fp && fp !== lastFp) {
|
||||
lastFp = fp;
|
||||
if (onMessage) onMessage(data, { reason: 'events' });
|
||||
}
|
||||
} catch (e) {}
|
||||
};
|
||||
ws.onclose = function () {
|
||||
booted = false;
|
||||
lastFp = '';
|
||||
reconnectTimer = setTimeout(connect, 5000);
|
||||
};
|
||||
} catch (e) {
|
||||
|
||||
Reference in New Issue
Block a user