transports(daily): expose dialin-ready and handle timeouts
This commit is contained in:
@@ -9,6 +9,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||||||
|
|
||||||
### Added
|
### Added
|
||||||
|
|
||||||
|
- Exposed `on_dialin_ready` for Daily transport SIP endpoint handling. This
|
||||||
|
notifies when the Daily room SIP endpoints are ready. This allows integrating
|
||||||
|
with third-party services like Twilio.
|
||||||
|
|
||||||
- Exposed Daily transport `on_app_message` event.
|
- Exposed Daily transport `on_app_message` event.
|
||||||
|
|
||||||
- Added Daily transport `on_call_state_updated` event.
|
- Added Daily transport `on_call_state_updated` event.
|
||||||
@@ -27,6 +31,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||||||
|
|
||||||
### Fixed
|
### Fixed
|
||||||
|
|
||||||
|
- Daily tranport `dialin-ready` doesn't not block anymore and it now handles
|
||||||
|
timeouts.
|
||||||
|
|
||||||
- Fixed AzureLLMService.
|
- Fixed AzureLLMService.
|
||||||
|
|
||||||
## [0.0.23] - 2024-05-23
|
## [0.0.23] - 2024-05-23
|
||||||
|
|||||||
@@ -104,7 +104,7 @@ class DailyTranscriptionSettings(BaseModel):
|
|||||||
class DailyParams(TransportParams):
|
class DailyParams(TransportParams):
|
||||||
api_url: str = "https://api.daily.co"
|
api_url: str = "https://api.daily.co"
|
||||||
api_key: str = ""
|
api_key: str = ""
|
||||||
dialin_settings: DailyDialinSettings = DailyDialinSettings()
|
dialin_settings: DailyDialinSettings | None = None
|
||||||
transcription_enabled: bool = False
|
transcription_enabled: bool = False
|
||||||
transcription_settings: DailyTranscriptionSettings = DailyTranscriptionSettings()
|
transcription_settings: DailyTranscriptionSettings = DailyTranscriptionSettings()
|
||||||
|
|
||||||
@@ -673,6 +673,7 @@ class DailyTransport(BaseTransport):
|
|||||||
self._register_event_handler("on_left")
|
self._register_event_handler("on_left")
|
||||||
self._register_event_handler("on_app_message")
|
self._register_event_handler("on_app_message")
|
||||||
self._register_event_handler("on_call_state_updated")
|
self._register_event_handler("on_call_state_updated")
|
||||||
|
self._register_event_handler("on_dialin_ready")
|
||||||
self._register_event_handler("on_dialout_connected")
|
self._register_event_handler("on_dialout_connected")
|
||||||
self._register_event_handler("on_dialout_stopped")
|
self._register_event_handler("on_dialout_stopped")
|
||||||
self._register_event_handler("on_dialout_error")
|
self._register_event_handler("on_dialout_error")
|
||||||
@@ -759,6 +760,9 @@ class DailyTransport(BaseTransport):
|
|||||||
self.on_call_state_updated(state)
|
self.on_call_state_updated(state)
|
||||||
|
|
||||||
async def _handle_dialin_ready(self, sip_endpoint: str):
|
async def _handle_dialin_ready(self, sip_endpoint: str):
|
||||||
|
if not self._params.dialin_settings:
|
||||||
|
return
|
||||||
|
|
||||||
async with aiohttp.ClientSession() as session:
|
async with aiohttp.ClientSession() as session:
|
||||||
headers = {
|
headers = {
|
||||||
"Authorization": f"Bearer {self._params.api_key}",
|
"Authorization": f"Bearer {self._params.api_key}",
|
||||||
@@ -772,19 +776,24 @@ class DailyTransport(BaseTransport):
|
|||||||
|
|
||||||
url = f"{self._params.api_url}/dialin/pinlessCallUpdate"
|
url = f"{self._params.api_url}/dialin/pinlessCallUpdate"
|
||||||
|
|
||||||
async with session.post(url, headers=headers, data=data) as r:
|
try:
|
||||||
if r.status != 200:
|
async with session.post(url, headers=headers, data=data, timeout=10) as r:
|
||||||
text = await r.text()
|
if r.status != 200:
|
||||||
logger.error(
|
text = await r.text()
|
||||||
f"Unable to handle dialin-ready event (status: {r.status}, error: {text})")
|
logger.error(
|
||||||
return
|
f"Unable to handle dialin-ready event (status: {r.status}, error: {text})")
|
||||||
|
return
|
||||||
|
|
||||||
logger.debug("dialin-ready event handled successfully")
|
logger.debug("Event dialin-ready was handled successfully")
|
||||||
|
except asyncio.TimeoutError:
|
||||||
|
logger.error(f"Timeout handling dialin-ready event ({url})")
|
||||||
|
except BaseException as e:
|
||||||
|
logger.error(f"Error handling dialin-ready event ({url}): {e}")
|
||||||
|
|
||||||
def _on_dialin_ready(self, sip_endpoint):
|
def _on_dialin_ready(self, sip_endpoint):
|
||||||
future = asyncio.run_coroutine_threadsafe(
|
if self._params.dialin_settings:
|
||||||
self._handle_dialin_ready(sip_endpoint), self._loop)
|
asyncio.run_coroutine_threadsafe(self._handle_dialin_ready(sip_endpoint), self._loop)
|
||||||
future.result()
|
self.on_dialin_ready(sip_endpoint)
|
||||||
|
|
||||||
def _on_dialout_connected(self, data):
|
def _on_dialout_connected(self, data):
|
||||||
self.on_dialout_connected(data)
|
self.on_dialout_connected(data)
|
||||||
@@ -836,6 +845,9 @@ class DailyTransport(BaseTransport):
|
|||||||
def on_call_state_updated(self, state):
|
def on_call_state_updated(self, state):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
def on_dialin_ready(self, sip_endpoint):
|
||||||
|
pass
|
||||||
|
|
||||||
def on_dialout_connected(self, data):
|
def on_dialout_connected(self, data):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user