diff --git a/fbchat/_client.py b/fbchat/_client.py index 3243ef4..d639c74 100644 --- a/fbchat/_client.py +++ b/fbchat/_client.py @@ -77,6 +77,7 @@ class Client(object): self._default_thread_id = None self._default_thread_type = None self._req_url = ReqUrl() + self._pull_channel = 0 self._markAlive = True self._buddylist = dict() @@ -2378,7 +2379,12 @@ class Client(object): "viewer_uid": self._uid, "state": "active", } - self._get(self._req_url.PING, data, fix_request=True, as_json=False) + self._get( + self._req_url.PING.format(self._pull_channel), + data, + fix_request=True, + as_json=False, + ) def _pullMessage(self): """Call pull api with seq value to get message data.""" @@ -2390,7 +2396,12 @@ class Client(object): "clientid": self._client_id, "state": "active" if self._markAlive else "offline", } - return self._get(self._req_url.STICKY, data, fix_request=True, as_json=True) + return self._get( + self._req_url.STICKY.format(self._pull_channel), + data, + fix_request=True, + as_json=True, + ) def _parseDelta(self, m): def getThreadIdAndThreadType(msg_metadata): @@ -3082,7 +3093,8 @@ class Client(object): except FBchatFacebookError as e: # Fix 502 and 503 pull errors if e.request_status_code in [502, 503]: - self._req_url.change_pull_channel() + # Bump pull channel, while contraining withing 0-4 + self._pull_channel = (self._pull_channel + 1) % 5 self.startListening() else: raise e diff --git a/fbchat/_util.py b/fbchat/_util.py index 150411a..a009a60 100644 --- a/fbchat/_util.py +++ b/fbchat/_util.py @@ -69,8 +69,8 @@ class ReqUrl(object): MARK_SEEN = "https://www.facebook.com/ajax/mercury/mark_seen.php" BASE = "https://www.facebook.com" MOBILE = "https://m.facebook.com/" - STICKY = "https://0-edge-chat.facebook.com/pull" - PING = "https://0-edge-chat.facebook.com/active_ping" + STICKY = "https://{}-edge-chat.facebook.com/pull" + PING = "https://{}-edge-chat.facebook.com/active_ping" UPLOAD = "https://upload.facebook.com/ajax/mercury/upload.php" INFO = "https://www.facebook.com/chat/user_info/" CONNECT = "https://www.facebook.com/ajax/add_friend/action.php?dpr=1" @@ -116,18 +116,6 @@ class ReqUrl(object): UNSEND = "https://www.facebook.com/messaging/unsend_message/?dpr=1" FORWARD_ATTACHMENT = "https://www.facebook.com/mercury/attachments/forward/" - pull_channel = 0 - - def change_pull_channel(self, channel=None): - if channel is None: - self.pull_channel = (self.pull_channel + 1) % 5 # Pull channel will be 0-4 - else: - self.pull_channel = channel - self.STICKY = "https://{}-edge-chat.facebook.com/pull".format(self.pull_channel) - self.PING = "https://{}-edge-chat.facebook.com/active_ping".format( - self.pull_channel - ) - facebookEncoding = "UTF-8"