Skip to content

Commit

Permalink
Revert "On message for keep-alived pusher socket" (#1205)
Browse files Browse the repository at this point in the history
Reverts #1204
  • Loading branch information
beastoin authored Oct 29, 2024
2 parents 3d9c1e5 + 5cdddc1 commit cf1e1a6
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 34 deletions.
40 changes: 8 additions & 32 deletions backend/utils/pusher.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
import uuid
import os
from datetime import datetime, timezone, timedelta
from enum import Enum

import opuslib
import webrtcvad
from fastapi import APIRouter
from fastapi.websockets import WebSocketDisconnect, WebSocket
from pydub import AudioSegment
from starlette.websockets import WebSocketState
Expand All @@ -20,25 +26,10 @@

async def connect_to_transcript_pusher(uid: str):
try:
print("Connecting to Pusher transcripts WebSocket...")
print("Connecting to Pusher transcripts trigger WebSocket...")
ws_host = PusherAPI.replace("http", "ws")
socket = await websockets.connect(f"{ws_host}/v1/trigger/transcript/listen?uid={uid}")
print("Connected to Pusher transcripts WebSocket.")

async def on_message():
try:
async for message in socket:
print(f"Pusher transcripts WebSocket recived {message} ")
except websockets.exceptions.ConnectionClosedOK:
print("Pusher transcripts WebSocket connection closed normally.")
except Exception as e:
print(f"Error receiving from Pusher transcripts WebSocket: {e}")
finally:
if not socket.closed:
await socket.close()
print("Pusher transcripts WebSocket closed in on_message.")

asyncio.create_task(on_message())
print("Connected to Pusher transcripts trigger WebSocket.")
return socket
except Exception as e:
print(f"Exception in connect_to_transcript_pusher: {e}")
Expand All @@ -50,21 +41,6 @@ async def connect_to_audio_bytes_pusher(uid: str, sample_rate: int = 8000):
ws_host = PusherAPI.replace("http", "ws")
socket = await websockets.connect(f"{ws_host}/v1/trigger/audio-bytes/listen?uid={uid}&sample_rate={sample_rate}")
print("Connected to Pusher audio bytes trigger WebSocket.")

async def on_message():
try:
async for message in socket:
print(f"Pusher audio bytes WebSocket recived {message} ")
except websockets.exceptions.ConnectionClosedOK:
print("Pusher audio bytes WebSocket connection closed normally.")
except Exception as e:
print(f"Error receiving from Pusher audio bytes WebSocket: {e}")
finally:
if not socket.closed:
await socket.close()
print("Pusher audio bytes WebSocket closed in on_message.")

asyncio.create_task(on_message())
return socket
except Exception as e:
print(f"Exception in connect_to_audio_bytes_pusher: {e}")
Expand Down
4 changes: 2 additions & 2 deletions backend/utils/webhooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ async def realtime_transcript_webhook(uid, segments: List[dict]):
headers={'Content-Type': 'application/json'},
timeout=15,
)
print('realtime_transcript_webhook:', webhook_url, response.status_code)
print('realtime_transcript_webhook:', response.status_code)
except Exception as e:
print(f"Error sending realtime transcript to developer webhook: {e}")
else:
Expand Down Expand Up @@ -99,7 +99,7 @@ async def send_audio_bytes_developer_webhook(uid: str, sample_rate: int, data: b
webhook_url += f'?sample_rate={sample_rate}&uid={uid}'
try:
response = requests.post(webhook_url, data=data, headers={'Content-Type': 'application/octet-stream'}, timeout=15)
print('send_audio_bytes_developer_webhook:', webhook_url, response.status_code)
print('send_audio_bytes_developer_webhook:', response.status_code)
except Exception as e:
print(f"Error sending audio bytes to developer webhook: {e}")
else:
Expand Down

0 comments on commit cf1e1a6

Please sign in to comment.