handle no-messages

This commit is contained in:
Matias Alejo Garcia 2014-08-28 18:43:04 -03:00
parent 534a5f6349
commit 9888bc9448
2 changed files with 12 additions and 1 deletions

View File

@ -310,6 +310,12 @@ Wallet.prototype.updateTimestamp = function(ts) {
this.store();
};
Wallet.prototype._onNoMessages = function() {
console.log('No messages at the server. Requesting sync'); //TODO
this.sendWalletReady(senderId);
};
Wallet.prototype._onData = function(senderId, data, ts) {
preconditions.checkArgument(senderId);
preconditions.checkArgument(data);
@ -355,9 +361,10 @@ Wallet.prototype._onData = function(senderId, data, ts) {
case 'disconnect':
this._onDisconnect(senderId, data);
break;
default:
throw new Error('unknown message type received: '+ data.type + ' from: ' + senderId)
}
this.updateTimestamp(ts);
};
Wallet.prototype._onConnect = function(newCopayerId) {
@ -433,6 +440,7 @@ Wallet.prototype.netStart = function(callback) {
net.removeAllListeners();
net.on('connect', self._onConnect.bind(self));
net.on('data', self._onData.bind(self));
net.on('no messages', self._onNoMessages.bind(self));
var myId = self.getMyCopayerId();
var myIdPriv = self.getMyCopayerIdPriv();

View File

@ -220,6 +220,8 @@ Network.prototype._setupConnectionHandlers = function(cb) {
});
self.socket.on('error', self._onError.bind(self));
self.socket.on('no messages', self.bind(self, 'no messages'));
self.socket.on('connect', function() {
self.socket.on('disconnect', function() {
@ -302,6 +304,7 @@ Network.prototype.start = function(opts, openCallback) {
}, 500);
});
self.socket.emit('sync', opts.lastTimestamp);
self.started = true;
};