@@ -373,8 +373,7 @@ def listen(self, callback):
373373 Raises:
374374 FirebaseError: If an error occurs while starting the initial HTTP connection.
375375 """
376- session = _sseclient .KeepAuthSession (self ._client .credential )
377- return self ._listen_with_session (callback , session )
376+ return self ._listen_with_session (callback )
378377
379378 def transaction (self , transaction_update ):
380379 """Atomically modifies the data at this location.
@@ -463,8 +462,11 @@ def order_by_value(self):
463462 def _add_suffix (self , suffix = '.json' ):
464463 return self ._pathurl + suffix
465464
466- def _listen_with_session (self , callback , session ):
465+ def _listen_with_session (self , callback , session = None ):
467466 url = self ._client .base_url + self ._add_suffix ()
467+ if not session :
468+ session = self ._client .create_listener_session ()
469+
468470 try :
469471 sse = _sseclient .SSEClient (url , session )
470472 return ListenerRegistration (callback , sse )
@@ -907,6 +909,7 @@ def __init__(self, credential, base_url, timeout, params=None):
907909 super ().__init__ (
908910 credential = credential , base_url = base_url ,
909911 timeout = timeout , headers = {'User-Agent' : _USER_AGENT })
912+ self .credential = credential
910913 self .params = params if params else {}
911914
912915 def request (self , method , url , ** kwargs ):
@@ -941,6 +944,9 @@ def request(self, method, url, **kwargs):
941944 except requests .exceptions .RequestException as error :
942945 raise _Client .handle_rtdb_error (error )
943946
947+ def create_listener_session (self ):
948+ return _sseclient .KeepAuthSession (self .credential )
949+
944950 @classmethod
945951 def handle_rtdb_error (cls , error ):
946952 """Converts an error encountered while calling RTDB into a FirebaseError."""
0 commit comments