Reconnect when disconnected from whatsapp
This commit is contained in:
parent
ba54217377
commit
f2cadb7492
10
session.py
10
session.py
|
@ -78,7 +78,7 @@ class Session():
|
||||||
self.timer = None
|
self.timer = None
|
||||||
self.password = None
|
self.password = None
|
||||||
self.initialized = False
|
self.initialized = False
|
||||||
|
self.loggedin = False
|
||||||
|
|
||||||
self.bot = Bot(self)
|
self.bot = Bot(self)
|
||||||
|
|
||||||
|
@ -117,6 +117,7 @@ class Session():
|
||||||
self.stack.broadcastEvent(YowLayerEvent(method, **kwargs))
|
self.stack.broadcastEvent(YowLayerEvent(method, **kwargs))
|
||||||
|
|
||||||
def logout(self):
|
def logout(self):
|
||||||
|
self.loggedin = False
|
||||||
self.stack.broadcastEvent(YowLayerEvent(YowNetworkLayer.EVENT_STATE_DISCONNECT))
|
self.stack.broadcastEvent(YowLayerEvent(YowNetworkLayer.EVENT_STATE_DISCONNECT))
|
||||||
|
|
||||||
def login(self, password):
|
def login(self, password):
|
||||||
|
@ -129,6 +130,8 @@ class Session():
|
||||||
self.stack.setProp(YowCoderLayer.PROP_RESOURCE,
|
self.stack.setProp(YowCoderLayer.PROP_RESOURCE,
|
||||||
env.CURRENT_ENV.getResource())
|
env.CURRENT_ENV.getResource())
|
||||||
self.stack.setProp(YowIqProtocolLayer.PROP_PING_INTERVAL, 5)
|
self.stack.setProp(YowIqProtocolLayer.PROP_PING_INTERVAL, 5)
|
||||||
|
self.loggedin = True
|
||||||
|
self.password = password
|
||||||
try:
|
try:
|
||||||
self.stack.broadcastEvent(
|
self.stack.broadcastEvent(
|
||||||
YowLayerEvent(YowNetworkLayer.EVENT_STATE_CONNECT))
|
YowLayerEvent(YowNetworkLayer.EVENT_STATE_CONNECT))
|
||||||
|
@ -399,7 +402,10 @@ class SpectrumLayer(YowInterfaceLayer):
|
||||||
elif layerEvent.getName() == YowNetworkLayer.EVENT_STATE_DISCONNECTED:
|
elif layerEvent.getName() == YowNetworkLayer.EVENT_STATE_DISCONNECTED:
|
||||||
reason = layerEvent.getArg("reason")
|
reason = layerEvent.getArg("reason")
|
||||||
self.logger.info("Disconnected: %s (%s)", self.user, reason)
|
self.logger.info("Disconnected: %s (%s)", self.user, reason)
|
||||||
|
if not self.session.loggedin or self.session.password is None:
|
||||||
self.backend.handleDisconnected(self.user, 0, reason)
|
self.backend.handleDisconnected(self.user, 0, reason)
|
||||||
|
else:
|
||||||
|
self.session.login(self.session.password)
|
||||||
elif layerEvent.getName() == 'presence_sendAvailable':
|
elif layerEvent.getName() == 'presence_sendAvailable':
|
||||||
entity = AvailablePresenceProtocolEntity()
|
entity = AvailablePresenceProtocolEntity()
|
||||||
self.toLower(entity)
|
self.toLower(entity)
|
||||||
|
@ -454,7 +460,7 @@ class SpectrumLayer(YowInterfaceLayer):
|
||||||
def onAuthFailed(self, entity):
|
def onAuthFailed(self, entity):
|
||||||
self.logger.info("Auth failed: %s (%s)", self.user, entity.getReason())
|
self.logger.info("Auth failed: %s (%s)", self.user, entity.getReason())
|
||||||
self.backend.handleDisconnected(self.user, 0, entity.getReason())
|
self.backend.handleDisconnected(self.user, 0, entity.getReason())
|
||||||
self.password = None
|
self.session.password = None
|
||||||
|
|
||||||
def updateRoster(self):
|
def updateRoster(self):
|
||||||
self.logger.debug("Update roster")
|
self.logger.debug("Update roster")
|
||||||
|
|
Loading…
Reference in a new issue