diff options
author | Trygve Aaberge <trygveaa@gmail.com> | 2019-03-13 12:13:25 +0100 |
---|---|---|
committer | Trygve Aaberge <trygveaa@gmail.com> | 2019-03-13 12:13:25 +0100 |
commit | 55dfe7442183912339d5e08740a133fd333268b2 (patch) | |
tree | bd99457b4d78627da88bc1d5f12b3ae73b65009a /wee_slack.py | |
parent | 05657c23c1e74e90a2e0588df75fe0a535ac6323 (diff) | |
download | wee-slack-55dfe7442183912339d5e08740a133fd333268b2.tar.gz |
Ping websocket connection every five seconds
Thanks to @celsworth and @micolous for pointing out that Slack now
requires this for some teams.
From https://github.com/slackapi/python-slackclient/issues/118#issuecomment-348731791:
I've observed that some Slack teams have (recently) been opted into
an experiment (by SlackHQ) which requires that ping messages are
sent by RTM clients, otherwise they will be disconnected after 2-3
minutes. This is more frequently than the other reporters, and has
only become an issue in the last 4 days for me.
However, this experiment has only been applied to a limited number
of teams (I see only one team with the issue and all others without,
even when running the same bot code), which don't appear to
correlate with age of the team.
May partly fix #679, but that seems to also be caused by an issue in
websocket-client.
Diffstat (limited to 'wee_slack.py')
-rw-r--r-- | wee_slack.py | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/wee_slack.py b/wee_slack.py index 8d19190..0efc7b0 100644 --- a/wee_slack.py +++ b/wee_slack.py @@ -689,6 +689,14 @@ def receive_ws_callback(*args): @utf8_decode +def ws_ping_cb(data, remaining_calls): + for team in EVENTROUTER.teams.values(): + if team.ws: + team.ws.ping() + return w.WEECHAT_RC_OK + + +@utf8_decode def reconnect_callback(*args): EVENTROUTER.reconnect_if_disconnected() return w.WEECHAT_RC_OK @@ -1033,7 +1041,7 @@ class SlackTeam(object): self.ws_url = websocket_url self.connected = False self.connecting = False - # self.ws = None + self.ws = None self.ws_counter = 0 self.ws_replies = {} self.eventrouter = eventrouter @@ -3983,6 +3991,7 @@ def load_emoji(): def setup_hooks(): w.bar_item_new('slack_typing_notice', '(extra)typing_bar_item_cb', '') + w.hook_timer(5000, 0, 0, "ws_ping_cb", "") w.hook_timer(1000, 0, 0, "typing_update_cb", "") w.hook_timer(1000, 0, 0, "buffer_list_update_callback", "EVENTROUTER") w.hook_timer(3000, 0, 0, "reconnect_callback", "EVENTROUTER") |