Skip to content

Commit

Permalink
Fixed issue where the heartbeat timer wasn't re-scheduled
Browse files Browse the repository at this point in the history
  • Loading branch information
fuzeman committed Jul 2, 2014
1 parent a586c10 commit 5755be7
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions spotify/components/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
from ws4py.client.threadedclient import WebSocketClient
import json
import logging
import time

log = logging.getLogger(__name__)

Expand Down Expand Up @@ -168,6 +167,20 @@ def send_heartbeat(self):
.pipe('error', self)\
.send()

def schedule_heartbeat(self):
if not self.connected:
pass

def heartbeat_trigger():
# Send heartbeat ('sp/echo')
self.send_heartbeat()

# Schedule next heartbeat
self.schedule_heartbeat()

self.heartbeat_timer = Timer(self.heartbeat_interval, heartbeat_trigger)
self.heartbeat_timer.start()

def on_connect(self, message):
log.debug('SpotifyConnection "connect" event: %s', message)

Expand All @@ -179,9 +192,8 @@ def on_connect(self, message):
log.debug('connected')
self.connected = True

# Start heartbeats ('sp/echo')
self.heartbeat_timer = Timer(self.heartbeat_interval, self.send_heartbeat)
self.heartbeat_timer.start()
# Schedule initial heartbeat
self.schedule_heartbeat()

self.emit('connect')

Expand Down

0 comments on commit 5755be7

Please sign in to comment.