call back with error if an RPC is made while disconnected
This commit is contained in:
parent
410a9dfb17
commit
7573b86946
@ -102,9 +102,16 @@ types of messages:
|
|||||||
timeouts: {}, // timeouts
|
timeouts: {}, // timeouts
|
||||||
pending: {}, // callbacks
|
pending: {}, // callbacks
|
||||||
cookie: null,
|
cookie: null,
|
||||||
|
connected: true,
|
||||||
};
|
};
|
||||||
|
|
||||||
var send = function (type, msg, cb) {
|
var send = function (type, msg, cb) {
|
||||||
|
if (!ctx.connected && type !== 'COOKIE') {
|
||||||
|
return void window.setTimeout(function () {
|
||||||
|
cb('DISCONNECTED');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
// construct a signed message...
|
// construct a signed message...
|
||||||
|
|
||||||
var data = [type, msg];
|
var data = [type, msg];
|
||||||
@ -127,6 +134,17 @@ types of messages:
|
|||||||
onMsg(ctx, msg);
|
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) {
|
send('COOKIE', "", function (e, msg) {
|
||||||
if (e) { return void cb(e); }
|
if (e) { return void cb(e); }
|
||||||
// callback to provide 'send' method to whatever needs it
|
// callback to provide 'send' method to whatever needs it
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user