From 814d7744671aaa8c166f490d38df24c909e7f3ff Mon Sep 17 00:00:00 2001
From: Paul Pettit
Date: Thu, 8 Jan 2015 15:48:37 +0000
Subject: [PATCH] make sure everything happens in the right order when
reconnecting.
previously a login and/or subscription could happen before the connect method call
was sent, sometimes resulting in errors, because the 'reconnected' event was fired
as soon as the socket was connected rather than when a reply was received from the
'connect' ddp call.
also the 'connected' event was fired for reconnects as well as the 'reconnected'
event. this patch makes sure only one or the the other event is fired so you can
really tell whether you just connected or reconnected.
---
DDPClient.py | 12 +++++++++---
1 file changed, 9 insertions(+), 3 deletions(-)
diff --git a/DDPClient.py b/DDPClient.py
index 7fabc4d..ccfa428 100644
--- a/DDPClient.py
+++ b/DDPClient.py
@@ -75,6 +75,7 @@ def __init__(self, url, auto_reconnect=True, auto_reconnect_timeout=0.5, debug=F
EventEmitter.__init__(self)
self.ddpsocket = None
self._is_closing = False
+ self._is_reconnecting = False
self.url = url
self.auto_reconnect = auto_reconnect
self.auto_reconnect_timeout = auto_reconnect_timeout
@@ -111,8 +112,7 @@ def _recover_network_failure(self):
try:
self.connect()
connected = True
- self.ddpsocket._debug_log("* RECONNECTED")
- self.emit('reconnected')
+ self._is_reconnecting = True
except (socket.error, WebSocketException):
pass
@@ -165,7 +165,13 @@ def received_message(self, data):
elif data['msg'] == 'connected':
self._session = data.get('session')
- self.emit('connected')
+ if self._is_reconnecting:
+ self.ddpsocket._debug_log("* RECONNECTED")
+ self.emit('reconnected')
+ self._is_reconnecting = False
+ else:
+ self.ddpsocket._debug_log("* CONNECTED")
+ self.emit('connected')
# method result
elif data['msg'] == 'result':