commit d4c99e3f3f67b1f964da961ab4c25b08fed52050
parent 92b2091dd973488341df10bec34e600189533c16
Author: finwo <finwo@pm.me>
Date: Thu, 15 Nov 2018 15:48:37 +0000
Merge branch 'automatic-reconnect-wsrpc' into 'master'
Automatic reconnect wsrpc
See merge request finwo/autolevel!2
Diffstat:
3 files changed, 11 insertions(+), 3 deletions(-)
diff --git a/package-lock.json b/package-lock.json
@@ -1,6 +1,6 @@
{
"name": "autolevel",
- "version": "0.1.10",
+ "version": "0.2.0",
"lockfileVersion": 1,
"requires": true,
"dependencies": {
diff --git a/package.json b/package.json
@@ -1,6 +1,6 @@
{
"name": "autolevel",
- "version": "0.1.10",
+ "version": "0.2.0",
"description": "automatically connect levelup using database url",
"main": "src/index.js",
"homepage": "https://gitlab.com/finwo/autolevel",
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();
});