Skip to content

Commit

Permalink
Clean up duped Heartbeat code
Browse files Browse the repository at this point in the history
  • Loading branch information
abeisgoat committed Dec 4, 2014
1 parent ea198ae commit ed16e58
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 7 deletions.
3 changes: 1 addition & 2 deletions firebasin/connection.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from ws4py.client.threadedclient import WebSocketClient
from ws4py.websocket import Heartbeat
import threading
import time
import json
Expand Down Expand Up @@ -42,6 +41,7 @@ def set_url(d):
while not self.url:
time.sleep(0.1)

# Once we have the url connect
self.connect()

def connect(self):
Expand All @@ -56,7 +56,6 @@ def connect(self):
self.data.on_opened = self.send_outgoing

def on_connected():
Heartbeat(self.data,2).start()
self.connected = True

def on_received(o):
Expand Down
8 changes: 3 additions & 5 deletions firebasin/dataref.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
from structure import Structure
from debug import debug

from ws4py.websocket import Heartbeat

class DataRef(object):
'''Reference a specific location in a Firebase.'''

Expand Down Expand Up @@ -356,11 +358,7 @@ def _subscribe(self, path, query, callbacks=None):
def _keep_alive(self):
'''Send a keep-alive packet to Firebase'''

def send():
self._send({"t":"d", "d":{"r":0}})
Timer(60.0, send).start()

Timer(60.0, send).start()
Timer(10.0, lambda: Heartbeat(self.connection.data, 2).start()).start()

def _bind(self, path, event, callback):
'''Bind a single callback to an event on a path'''
Expand Down

0 comments on commit ed16e58

Please sign in to comment.