call back with error if an RPC is made while disconnected

pull/1/head
ansuz 8 years ago
parent 410a9dfb17
commit 7573b86946

@ -102,9 +102,16 @@ types of messages:
timeouts: {}, // timeouts
pending: {}, // callbacks
cookie: null,
connected: true,
};
var send = function (type, msg, cb) {
if (!ctx.connected && type !== 'COOKIE') {
return void window.setTimeout(function () {
cb('DISCONNECTED');
});
}
// construct a signed message...
var data = [type, msg];
@ -127,6 +134,17 @@ types of messages:
onMsg(ctx, msg);
});
network.on('disconnect', function (reason) {
ctx.connected = false;
});
network.on('reconnect', function (uid) {
send('COOKIE', "", function (e, msg) {
if (e) { return void cb(e); }
ctx.connected = true;
});
});
send('COOKIE', "", function (e, msg) {
if (e) { return void cb(e); }
// callback to provide 'send' method to whatever needs it

Loading…
Cancel
Save