Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions lib/client/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ var units = require('../units')();
var levels = require('../levels');
var times = require('../times');
var receiveDData = require('./receiveddata');
var pako = require('pako');
var Buffer = require('buffer').Buffer;

var brushing = false;

Expand Down Expand Up @@ -1069,7 +1071,8 @@ client.load = function load (serverSettings, callback) {
}
};

socket.on('retroUpdate', function retroUpdate (retroData) {
socket.on('retroUpdate', function retroUpdate (retroDataStr) {
var retroData = inflate(retroDataStr)
console.info('got retroUpdate', retroData, new Date(client.now));
client.retro = {
loadedMills: Date.now()
Expand Down Expand Up @@ -1274,7 +1277,8 @@ client.load = function load (serverSettings, callback) {
});
}

function dataUpdate (received, headless) {
function dataUpdate (received_str, headless) {
var received = inflate(received_str);
console.info('got dataUpdate', new Date(client.now));

var lastUpdated = Date.now();
Expand Down Expand Up @@ -1327,6 +1331,12 @@ client.load = function load (serverSettings, callback) {
chart.updateContext();
}
}

function inflate(str) {
var b = new Buffer(str, 'base64');
const json = pako.inflate(b, { to: 'string' });
return JSON.parse(json);
}
};

module.exports = client;
14 changes: 10 additions & 4 deletions lib/server/websocket.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
var times = require('../times');
var calcData = require('../data/calcdelta');
var ObjectID = require('mongodb').ObjectID;
var Buffer = require('buffer').Buffer;
var pako = require('pako');
const forwarded = require('forwarded-for');

function init (env, ctx, server) {
Expand Down Expand Up @@ -117,10 +119,15 @@ function init (env, ctx, server) {
delta.status = status(ctx.ddata.profiles);
lastProfileSwitch = ctx.ddata.lastProfileFromSwitch;
}
io.to('DataReceivers').emit('dataUpdate', delta);
io.to('DataReceivers').emit('dataUpdate', deflate(delta));
}
}

function deflate(obj) {
var gzip_obj = Buffer.from(pako.deflate(JSON.stringify(obj)));
return gzip_obj.toString('base64');
}

function listeners () {
io.sockets.on('connection', function onConnection (socket) {
var socketAuthorization = null;
Expand Down Expand Up @@ -179,7 +186,7 @@ function init (env, ctx, server) {
callback({ result: 'success' });
}
//TODO: use opts to only send delta for retro data
socket.emit('retroUpdate', { devicestatus: lastData.devicestatus });
socket.emit('retroUpdate', deflate({ devicestatus: lastData.devicestatus }));
console.info('sent retroUpdate', opts);
});

Expand Down Expand Up @@ -549,8 +556,7 @@ function init (env, ctx, server) {
if (message.status) {
data.status = status(data.profiles);
}

socket.emit('dataUpdate', data);
socket.emit('dataUpdate', deflate(data));
}
}
// console.log(LOG_WS + 'Authetication ID: ', socket.client.id, ' client: ', clientType, ' history: ' + history);
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@
"mongodb": "^3.6.0",
"mongomock": "^0.1.2",
"node-cache": "^4.2.1",
"pako": "^2.1.0",
"parse-duration": "^0.1.3",
"pem": "^1.14.4",
"process": "^0.11.10",
Expand Down