Improved check connection
This commit is contained in:
parent
1e917a7118
commit
af58efd56a
@ -863,7 +863,7 @@ angular.module('izhukov.mtproto', ['izhukov.utils'])
|
|||||||
};
|
};
|
||||||
|
|
||||||
var self = this;
|
var self = this;
|
||||||
this.sendEncryptedRequest(pingMessage).then(function (result) {
|
this.sendEncryptedRequest(pingMessage, {timeout: 15000}).then(function (result) {
|
||||||
delete $rootScope.offlineConnecting;
|
delete $rootScope.offlineConnecting;
|
||||||
self.toggleOffline(false);
|
self.toggleOffline(false);
|
||||||
}, function () {
|
}, function () {
|
||||||
@ -895,18 +895,18 @@ angular.module('izhukov.mtproto', ['izhukov.utils'])
|
|||||||
}
|
}
|
||||||
|
|
||||||
this.checkConnectionPromise = $timeout(this.checkConnection.bind(this), parseInt(this.checkConnectionPeriod * 1000));
|
this.checkConnectionPromise = $timeout(this.checkConnection.bind(this), parseInt(this.checkConnectionPeriod * 1000));
|
||||||
this.checkConnectionPeriod = Math.min(60, (1 + this.checkConnectionPeriod) * 1.5);
|
this.checkConnectionPeriod = Math.min(30, (1 + this.checkConnectionPeriod) * 1.5);
|
||||||
|
|
||||||
this.onOnlineCb = this.checkConnection.bind(this);
|
this.onOnlineCb = this.checkConnection.bind(this);
|
||||||
|
|
||||||
$(document.body).on('online', this.onOnlineCb);
|
$(document.body).on('online focus', this.onOnlineCb);
|
||||||
} else {
|
} else {
|
||||||
delete this.longPollPending;
|
delete this.longPollPending;
|
||||||
this.checkLongPoll();
|
this.checkLongPoll();
|
||||||
this.sheduleRequest();
|
this.sheduleRequest();
|
||||||
|
|
||||||
if (this.onOnlineCb) {
|
if (this.onOnlineCb) {
|
||||||
$(document.body).off('online', this.onOnlineCb);
|
$(document.body).off('online focus', this.onOnlineCb);
|
||||||
}
|
}
|
||||||
$timeout.cancel(this.checkConnectionPromise);
|
$timeout.cancel(this.checkConnectionPromise);
|
||||||
}
|
}
|
||||||
@ -1095,8 +1095,9 @@ angular.module('izhukov.mtproto', ['izhukov.utils'])
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
MtpNetworker.prototype.sendEncryptedRequest = function (message) {
|
MtpNetworker.prototype.sendEncryptedRequest = function (message, options) {
|
||||||
var self = this;
|
var self = this;
|
||||||
|
options = options || {};
|
||||||
// console.log(dT(), 'Send encrypted'/*, message*/);
|
// console.log(dT(), 'Send encrypted'/*, message*/);
|
||||||
// console.trace();
|
// console.trace();
|
||||||
var data = new TLSerialization({startMaxLength: message.body.length + 64});
|
var data = new TLSerialization({startMaxLength: message.body.length + 64});
|
||||||
@ -1127,10 +1128,11 @@ angular.module('izhukov.mtproto', ['izhukov.utils'])
|
|||||||
|
|
||||||
var requestPromise;
|
var requestPromise;
|
||||||
try {
|
try {
|
||||||
requestPromise = $http.post('http://' + MtpDcConfigurator.chooseServer(self.dcID) + '/apiw1', resultArray, {
|
options = angular.copy(options || {}, {
|
||||||
responseType: 'arraybuffer',
|
responseType: 'arraybuffer',
|
||||||
transformRequest: null
|
transformRequest: null
|
||||||
});
|
});
|
||||||
|
requestPromise = $http.post('http://' + MtpDcConfigurator.chooseServer(self.dcID) + '/apiw1', resultArray, options);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
requestPromise = $q.reject(e);
|
requestPromise = $q.reject(e);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user