Skip to content

Commit

Permalink
Restore heartbeat sending
Browse files Browse the repository at this point in the history
  • Loading branch information
bradtgmurray committed Jan 30, 2024
1 parent 31f2227 commit 3a9fade
Showing 1 changed file with 27 additions and 22 deletions.
49 changes: 27 additions & 22 deletions linkedin_messaging/linkedin.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ class LinkedInMessaging:
_realtime_connection_id: Optional[uuid.UUID] = None

def __init__(self):
self._heartbeat_task = None
self.session = aiohttp.ClientSession()
self.event_listeners = defaultdict(list)

Expand Down Expand Up @@ -574,7 +575,7 @@ async def _listen_to_event_stream(self):
continue
data = json.loads(line.decode("utf-8")[6:])

logging.debug("Got data from event stream")
logging.debug(f"Got data from event stream {data.keys()}")

# Special handling for ALL_EVENTS handler.
if all_events_handlers := self.event_listeners.get("ALL_EVENTS"):
Expand All @@ -599,27 +600,31 @@ async def _listen_to_event_stream(self):
logging.info("Event stream closed")

async def _send_heartbeat(self, user_urn: URN):
return

# logging.info("Starting heartbeat task")
# while True:
# await asyncio.sleep(60)
# logging.info("Sending heartbeat")

# await self._post(
# CONNECTIVITY_TRACKING_URL,
# params={"action": "sendHeartbeat"},
# json={
# "isFirstHeartbeat": False,
# "isLastHeartbeat": False,
# "realtimeSessionId": str(self._realtime_session_id),
# "mpName": "voyager-web",
# "mpVersion": "1.13.8094",
# "clientId": "voyager-web",
# "actorUrn": str(user_urn),
# "contextUrns": [str(user_urn)],
# },
# )
is_first = True
mp_version = json.loads(self.headers["x-li-track"])["mpVersion"]

logging.info(f"Starting heartbeat task with client version {mp_version}")

while True:
await asyncio.sleep(60)
logging.info("Sending heartbeat")

await self._post(
CONNECTIVITY_TRACKING_URL,
params={"action": "sendHeartbeat"},
json={
"isFirstHeartbeat": not is_first,
"isLastHeartbeat": False,
"realtimeSessionId": str(self._realtime_session_id),
"mpName": "voyager-web",
"mpVersion": mp_version,
"clientId": "voyager-web",
"actorUrn": str(user_urn),
"contextUrns": [str(user_urn)],
},
)

is_first = False

async def start_listener(self, user_urn: URN):
self._realtime_session_id = uuid.uuid4()
Expand Down

0 comments on commit 3a9fade

Please sign in to comment.