Browse Source

Improved single instance checks

master
Igor Zhukov 7 years ago
parent
commit
c9723f5723
  1. 4
      app/js/lib/mtproto.js
  2. 23
      app/js/lib/mtproto_wrapper.js

4
app/js/lib/mtproto.js

@ -802,8 +802,8 @@ angular.module('izhukov.mtproto', ['izhukov.utils'])
var isClean = this.cleanupSent() var isClean = this.cleanupSent()
// console.log('Check lp', this.longPollPending, tsNow(), this.dcID, isClean) // console.log('Check lp', this.longPollPending, tsNow(), this.dcID, isClean)
if (this.longPollPending && tsNow() < this.longPollPending || if (this.longPollPending && tsNow() < this.longPollPending ||
this.offline || this.offline ||
akStopped) { akStopped) {
return false return false
} }
var self = this var self = this

23
app/js/lib/mtproto_wrapper.js

@ -760,7 +760,10 @@ angular.module('izhukov.mtproto.wrapper', ['izhukov.utils', 'izhukov.mtproto'])
} }
function clearInstance () { function clearInstance () {
Storage.remove(masterInstance ? 'xt_instance' : 'xt_idle_instance') if (masterInstance && !deactivated) {
console.warn('clear master instance');
Storage.remove('xt_instance')
}
} }
function deactivateInstance () { function deactivateInstance () {
@ -799,19 +802,12 @@ angular.module('izhukov.mtproto.wrapper', ['izhukov.utils', 'izhukov.mtproto'])
var idle = $rootScope.idle && $rootScope.idle.isIDLE var idle = $rootScope.idle && $rootScope.idle.isIDLE
var newInstance = {id: instanceID, idle: idle, time: time} var newInstance = {id: instanceID, idle: idle, time: time}
Storage.get('xt_instance', 'xt_idle_instance').then(function (result) { Storage.get('xt_instance').then(function (curInstance) {
var curInstance = result[0] console.log(dT(), 'check instance', newInstance, curInstance)
var idleInstance = result[1]
// console.log(dT(), 'check instance', newInstance, curInstance, idleInstance)
if (!idle || if (!idle ||
!curInstance || !curInstance ||
curInstance.id == instanceID || curInstance.id == instanceID ||
curInstance.time < time - 60000) { curInstance.time < time - 20000) {
if (idleInstance &&
idleInstance.id == instanceID) {
Storage.remove('xt_idle_instance')
}
Storage.set({xt_instance: newInstance}) Storage.set({xt_instance: newInstance})
if (!masterInstance) { if (!masterInstance) {
MtpNetworkerFactory.startAll() MtpNetworkerFactory.startAll()
@ -820,22 +816,21 @@ angular.module('izhukov.mtproto.wrapper', ['izhukov.utils', 'izhukov.mtproto'])
} else { } else {
console.warn(dT(), 'now master instance', newInstance) console.warn(dT(), 'now master instance', newInstance)
} }
masterInstance = true
} }
masterInstance = true
if (deactivatePromise) { if (deactivatePromise) {
$timeout.cancel(deactivatePromise) $timeout.cancel(deactivatePromise)
deactivatePromise = false deactivatePromise = false
} }
} else { } else {
Storage.set({xt_idle_instance: newInstance})
if (masterInstance) { if (masterInstance) {
MtpNetworkerFactory.stopAll() MtpNetworkerFactory.stopAll()
console.warn(dT(), 'now idle instance', newInstance) console.warn(dT(), 'now idle instance', newInstance)
if (!deactivatePromise) { if (!deactivatePromise) {
deactivatePromise = $timeout(deactivateInstance, 30000) deactivatePromise = $timeout(deactivateInstance, 30000)
} }
masterInstance = false
} }
masterInstance = false
} }
}) })
} }

Loading…
Cancel
Save