Skip to content

Commit 6ad4ef1

Browse files
authored
Update socket.io and uuid packages (nightscout#7793)
* 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
1 parent 6834822 commit 6ad4ef1

File tree

5 files changed

+253
-489
lines changed

5 files changed

+253
-489
lines changed

lib/api3/shared/operationTools.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

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

@@ -103,7 +103,7 @@ function calculateIdentifier (doc) {
103103
key += '_' + doc.eventType;
104104
}
105105

106-
return uuidv5(key, uuidNamespace);
106+
return uuid.v5(key, uuidNamespace);
107107
}
108108

109109

lib/client/index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1033,7 +1033,7 @@ client.load = function load (serverSettings, callback) {
10331033
// Client-side code to connect to server and handle incoming data
10341034
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
10351035
/* global io */
1036-
client.socket = socket = io.connect();
1036+
client.socket = socket = io.connect({ transports: ["polling"] });
10371037

10381038
socket.on('dataUpdate', dataUpdate);
10391039

lib/server/websocket.js

+10-4
Original file line numberDiff line numberDiff line change
@@ -69,13 +69,19 @@ function init (env, ctx, server) {
6969

7070
function start () {
7171
io = require('socket.io')({
72-
'transports': ['xhr-polling']
73-
, 'log level': 0
72+
'log level': 0
7473
}).listen(server, {
7574
//these only effect the socket.io.js file that is sent to the client, but better than nothing
7675
'browser client minification': true
7776
, 'browser client etag': true
7877
, 'browser client gzip': false
78+
, 'perMessageDeflate': {
79+
threshold: 512
80+
}
81+
, transports: ["polling", "websocket"]
82+
, httpCompression: {
83+
threshold: 512
84+
}
7985
});
8086

8187
ctx.bus.on('teardown', function serverTeardown () {
@@ -117,7 +123,7 @@ function init (env, ctx, server) {
117123
delta.status = status(ctx.ddata.profiles);
118124
lastProfileSwitch = ctx.ddata.lastProfileFromSwitch;
119125
}
120-
io.to('DataReceivers').emit('dataUpdate', delta);
126+
io.to('DataReceivers').compress(true).emit('dataUpdate', delta);
121127
}
122128
}
123129

@@ -179,7 +185,7 @@ function init (env, ctx, server) {
179185
callback({ result: 'success' });
180186
}
181187
//TODO: use opts to only send delta for retro data
182-
socket.emit('retroUpdate', { devicestatus: lastData.devicestatus });
188+
socket.compress(true).emit('retroUpdate', { devicestatus: lastData.devicestatus });
183189
console.info('sent retroUpdate', opts);
184190
});
185191

0 commit comments

Comments
 (0)