Skip to content

Commit

Permalink
Update socket.io and uuid packages (#7793)
Browse files Browse the repository at this point in the history
* This commit updates the uuid and socket.io packages to latest versions and enables compression over websocket

* Drop the compression threshold down to 512 bytes

* Enable http compression down to 512 bytes and request long poll transport only, as per current release

* Add the socket.io-client back in

* Use polling with the NS client

* Update express to latest in 4.x line, fix tests
  • Loading branch information
sulkaharo authored and bewest committed Jan 22, 2023
1 parent d8e68fa commit 3ffd1bb
Show file tree
Hide file tree
Showing 5 changed files with 598 additions and 473 deletions.
4 changes: 2 additions & 2 deletions lib/api3/shared/operationTools.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

const apiConst = require('../const.json')
, stringTools = require('./stringTools')
, uuidv5 = require('uuid/v5')
, uuid = require('uuid')
, uuidNamespace = [...Buffer.from("NightscoutRocks!", "ascii")] // official namespace for NS :-)
;

Expand Down Expand Up @@ -103,7 +103,7 @@ function calculateIdentifier (doc) {
key += '_' + doc.eventType;
}

return uuidv5(key, uuidNamespace);
return uuid.v5(key, uuidNamespace);
}


Expand Down
2 changes: 1 addition & 1 deletion lib/client/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -1033,7 +1033,7 @@ client.load = function load (serverSettings, callback) {
// Client-side code to connect to server and handle incoming data
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/* global io */
client.socket = socket = io.connect();
client.socket = socket = io.connect({ transports: ["polling"] });

socket.on('dataUpdate', dataUpdate);

Expand Down
14 changes: 10 additions & 4 deletions lib/server/websocket.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,19 @@ function init (env, ctx, server) {

function start () {
io = require('socket.io')({
'transports': ['xhr-polling']
, 'log level': 0
'log level': 0
}).listen(server, {
//these only effect the socket.io.js file that is sent to the client, but better than nothing
'browser client minification': true
, 'browser client etag': true
, 'browser client gzip': false
, 'perMessageDeflate': {
threshold: 512
}
, transports: ["polling", "websocket"]
, httpCompression: {
threshold: 512
}
});

ctx.bus.on('teardown', function serverTeardown () {
Expand Down Expand Up @@ -117,7 +123,7 @@ function init (env, ctx, server) {
delta.status = status(ctx.ddata.profiles);
lastProfileSwitch = ctx.ddata.lastProfileFromSwitch;
}
io.to('DataReceivers').emit('dataUpdate', delta);
io.to('DataReceivers').compress(true).emit('dataUpdate', delta);
}
}

Expand Down Expand Up @@ -179,7 +185,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.compress(true).emit('retroUpdate', { devicestatus: lastData.devicestatus });
console.info('sent retroUpdate', opts);
});

Expand Down
Loading

0 comments on commit 3ffd1bb

Please sign in to comment.