commit e4153485c6737a5eb2b5f415364c78e36246075d
parent 0c1744751f96822b8a3df6743e2d67ed7eecc65d
Author: finwo <finwo@pm.me>
Date: Thu, 15 Nov 2018 16:46:18 +0100
Prevent unauthenticated calls on reconnect
Diffstat:
1 file changed, 9 insertions(+), 1 deletion(-)
diff --git a/src/custom/wsrpc.js b/src/custom/wsrpc.js
@@ -38,8 +38,15 @@ module.exports = function (location, options, callback) {
}
// handle rpc output
+ let queue = [];
rpcStream.on('data', function(chunk) {
- if (ws) ws.send(chunk);
+ if (ws && ws.readyState === ws.OPEN) {
+ while(queue.length)
+ ws.send(queue.shift());
+ ws.send(chunk);
+ } else {
+ queue.push(chunk);
+ }
});
@@ -65,6 +72,7 @@ module.exports = function (location, options, callback) {
// Handle auth & callback
ws.on('open', function() {
+ if (auth && queue.length) queue = [];
if (auth) return db.auth(auth,cb);
cb();
});