Skip to content

Commit

Permalink
don't send to ws when it is already closed (vocodedev#565)
Browse files Browse the repository at this point in the history
  • Loading branch information
ajar98 committed Jun 18, 2024
1 parent 261d29e commit 479ab54
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
3 changes: 3 additions & 0 deletions vocode/streaming/output_device/twilio_output_device.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from typing import Optional

from fastapi import WebSocket
from fastapi.websockets import WebSocketState

from vocode.streaming.output_device.base_output_device import BaseOutputDevice
from vocode.streaming.telephony.constants import DEFAULT_AUDIO_ENCODING, DEFAULT_SAMPLING_RATE
Expand All @@ -24,6 +25,8 @@ def __init__(self, ws: Optional[WebSocket] = None, stream_sid: Optional[str] = N
async def process(self):
while self.active:
message = await self.queue.get()
if self.ws.application_state == WebSocketState.DISCONNECTED:
break
await self.ws.send_text(message)

def consume_nonblocking(self, chunk: bytes):
Expand Down
3 changes: 3 additions & 0 deletions vocode/streaming/output_device/vonage_output_device.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from typing import Optional

from fastapi import WebSocket
from fastapi.websockets import WebSocketState

from vocode.streaming.output_device.base_output_device import BaseOutputDevice
from vocode.streaming.output_device.blocking_speaker_output import BlockingSpeakerOutput
Expand Down Expand Up @@ -34,6 +35,8 @@ def __init__(
async def process(self):
while self.active:
chunk = await self.queue.get()
if self.ws.application_state == WebSocketState.DISCONNECTED:
break
if self.output_to_speaker:
self.output_speaker.consume_nonblocking(chunk)
for i in range(0, len(chunk), VONAGE_CHUNK_SIZE):
Expand Down

0 comments on commit 479ab54

Please sign in to comment.