Linting and changes to adapt to v1.0
This commit is contained in:
committed by
asilvestre
parent
e3abb4b6d7
commit
18368d047e
@@ -8,12 +8,12 @@
|
|||||||
import asyncio
|
import asyncio
|
||||||
import itertools
|
import itertools
|
||||||
import threading
|
import threading
|
||||||
from collections.abc import Coroutine
|
from collections.abc import Awaitable, Callable, Coroutine
|
||||||
from concurrent.futures import ThreadPoolExecutor
|
from concurrent.futures import ThreadPoolExecutor
|
||||||
from dataclasses import dataclass, replace
|
from dataclasses import dataclass, replace
|
||||||
from datetime import datetime, timedelta
|
from datetime import datetime, timedelta
|
||||||
from enum import StrEnum
|
from enum import StrEnum
|
||||||
from typing import Any, Awaitable, Callable, Optional, TypeVar
|
from typing import Any, Optional, TypeVar
|
||||||
|
|
||||||
import numpy as np
|
import numpy as np
|
||||||
from loguru import logger
|
from loguru import logger
|
||||||
@@ -96,8 +96,8 @@ class VonageVideoConnectorTransportParams(TransportParams):
|
|||||||
audio_in_auto_subscribe: bool = True
|
audio_in_auto_subscribe: bool = True
|
||||||
video_in_auto_subscribe: bool = False
|
video_in_auto_subscribe: bool = False
|
||||||
video_connector_log_level: str = "INFO"
|
video_connector_log_level: str = "INFO"
|
||||||
video_in_preferred_resolution: Optional[tuple[int, int]] = None
|
video_in_preferred_resolution: tuple[int, int] | None = None
|
||||||
video_in_preferred_framerate: Optional[int] = None
|
video_in_preferred_framerate: int | None = None
|
||||||
clear_buffers_on_interruption: bool = True
|
clear_buffers_on_interruption: bool = True
|
||||||
|
|
||||||
|
|
||||||
@@ -114,8 +114,8 @@ class SubscribeSettings:
|
|||||||
|
|
||||||
subscribe_to_audio: bool = True
|
subscribe_to_audio: bool = True
|
||||||
subscribe_to_video: bool = False
|
subscribe_to_video: bool = False
|
||||||
preferred_resolution: Optional[tuple[int, int]] = None
|
preferred_resolution: tuple[int, int] | None = None
|
||||||
preferred_framerate: Optional[int] = None
|
preferred_framerate: int | None = None
|
||||||
|
|
||||||
|
|
||||||
class VonageException(Exception):
|
class VonageException(Exception):
|
||||||
@@ -211,7 +211,7 @@ SimpleCoroutine = Coroutine[Any, Any, None]
|
|||||||
DUMMY_CONNECTION = Connection(id="", creation_time=datetime.min)
|
DUMMY_CONNECTION = Connection(id="", creation_time=datetime.min)
|
||||||
|
|
||||||
|
|
||||||
def _to_enum(value: Optional[str], enum_cls: type[TE]) -> Optional[TE]:
|
def _to_enum(value: str | None, enum_cls: type[TE]) -> TE | None:
|
||||||
"""Convert a string value to the specified StrEnum type, returning None if invalid."""
|
"""Convert a string value to the specified StrEnum type, returning None if invalid."""
|
||||||
try:
|
try:
|
||||||
return enum_cls(value or "")
|
return enum_cls(value or "")
|
||||||
@@ -259,25 +259,25 @@ class VonageClient:
|
|||||||
|
|
||||||
self._connected: bool = False
|
self._connected: bool = False
|
||||||
self._connection_counter: int = 0
|
self._connection_counter: int = 0
|
||||||
self._connecting_future: Optional[asyncio.Future[None]] = None
|
self._connecting_future: asyncio.Future[None] | None = None
|
||||||
self._disconnecting_future: Optional[asyncio.Future[None]] = None
|
self._disconnecting_future: asyncio.Future[None] | None = None
|
||||||
|
|
||||||
self._listener_id_gen: itertools.count[int] = itertools.count()
|
self._listener_id_gen: itertools.count[int] = itertools.count()
|
||||||
self._listeners: dict[int, VonageClientListener] = {}
|
self._listeners: dict[int, VonageClientListener] = {}
|
||||||
|
|
||||||
self._publisher: Optional[Publisher] = None
|
self._publisher: Publisher | None = None
|
||||||
self._session = Session(id=session_id)
|
self._session = Session(id=session_id)
|
||||||
|
|
||||||
self._resampler = create_stream_resampler()
|
self._resampler = create_stream_resampler()
|
||||||
|
|
||||||
self._task_manager: Optional[BaseTaskManager] = None
|
self._task_manager: BaseTaskManager | None = None
|
||||||
self._loop_thread_id = threading.get_ident()
|
self._loop_thread_id = threading.get_ident()
|
||||||
self._event_queue: Optional[asyncio.Queue[SimpleCoroutine]] = None
|
self._event_queue: asyncio.Queue[SimpleCoroutine] | None = None
|
||||||
self._event_task: Optional[asyncio.Task[None]] = None
|
self._event_task: asyncio.Task[None] | None = None
|
||||||
self._audio_queue: Optional[asyncio.Queue[SimpleCoroutine]] = None
|
self._audio_queue: asyncio.Queue[SimpleCoroutine] | None = None
|
||||||
self._audio_task: Optional[asyncio.Task[None]] = None
|
self._audio_task: asyncio.Task[None] | None = None
|
||||||
self._video_queue: Optional[asyncio.Queue[SimpleCoroutine]] = None
|
self._video_queue: asyncio.Queue[SimpleCoroutine] | None = None
|
||||||
self._video_task: Optional[asyncio.Task[None]] = None
|
self._video_task: asyncio.Task[None] | None = None
|
||||||
|
|
||||||
# used for blocking calls to connect and disconnect
|
# used for blocking calls to connect and disconnect
|
||||||
self._executor = ThreadPoolExecutor(max_workers=1)
|
self._executor = ThreadPoolExecutor(max_workers=1)
|
||||||
@@ -366,7 +366,7 @@ class VonageClient:
|
|||||||
"""
|
"""
|
||||||
self._listeners.pop(listener_id, None)
|
self._listeners.pop(listener_id, None)
|
||||||
|
|
||||||
async def connect(self, frame: Optional[StartFrame] = None) -> None:
|
async def connect(self, frame: StartFrame | None = None) -> None:
|
||||||
"""Connect to the Vonage session.
|
"""Connect to the Vonage session.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
@@ -698,7 +698,7 @@ class VonageClient:
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
await asyncio.wait_for(async_proc(), timeout=VIDEO_CONNECTOR_TIMEOUT.total_seconds())
|
await asyncio.wait_for(async_proc(), timeout=VIDEO_CONNECTOR_TIMEOUT.total_seconds())
|
||||||
except asyncio.TimeoutError as exc:
|
except TimeoutError as exc:
|
||||||
logger.error(f"Timeout connecting to Vonage session {self._session_id}")
|
logger.error(f"Timeout connecting to Vonage session {self._session_id}")
|
||||||
|
|
||||||
raise exc
|
raise exc
|
||||||
@@ -715,7 +715,7 @@ class VonageClient:
|
|||||||
self._get_event_loop().run_in_executor(self._executor, disconnect_proc),
|
self._get_event_loop().run_in_executor(self._executor, disconnect_proc),
|
||||||
timeout=VIDEO_CONNECTOR_TIMEOUT.total_seconds(),
|
timeout=VIDEO_CONNECTOR_TIMEOUT.total_seconds(),
|
||||||
)
|
)
|
||||||
except asyncio.TimeoutError:
|
except TimeoutError:
|
||||||
logger.error(f"Timeout disconnecting from Vonage session {self._session_id}")
|
logger.error(f"Timeout disconnecting from Vonage session {self._session_id}")
|
||||||
raise
|
raise
|
||||||
|
|
||||||
@@ -800,7 +800,7 @@ class VonageClient:
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
await asyncio.wait_for(process(), timeout=VIDEO_CONNECTOR_TIMEOUT.total_seconds())
|
await asyncio.wait_for(process(), timeout=VIDEO_CONNECTOR_TIMEOUT.total_seconds())
|
||||||
except asyncio.TimeoutError:
|
except TimeoutError:
|
||||||
logger.error(f"Timeout subscribing to Vonage stream {stream.id}")
|
logger.error(f"Timeout subscribing to Vonage stream {stream.id}")
|
||||||
self._session_subscriptions.pop(stream.id, None)
|
self._session_subscriptions.pop(stream.id, None)
|
||||||
raise
|
raise
|
||||||
@@ -856,7 +856,7 @@ class VonageClient:
|
|||||||
self._loop_thread_id = threading.get_ident()
|
self._loop_thread_id = threading.get_ident()
|
||||||
# if we allow concurrent tasks, process them as they come in
|
# if we allow concurrent tasks, process them as they come in
|
||||||
if allow_concurrent:
|
if allow_concurrent:
|
||||||
active_tasks = set()
|
active_tasks: set[asyncio.Task[Any]] = set()
|
||||||
|
|
||||||
async def wrapped_task(coroutine: SimpleCoroutine) -> None:
|
async def wrapped_task(coroutine: SimpleCoroutine) -> None:
|
||||||
try:
|
try:
|
||||||
@@ -907,7 +907,7 @@ class VonageClient:
|
|||||||
def _sdk_cb_to_loop(
|
def _sdk_cb_to_loop(
|
||||||
self,
|
self,
|
||||||
queue_type_name: str,
|
queue_type_name: str,
|
||||||
queue: Optional[asyncio.Queue[SimpleCoroutine]],
|
queue: asyncio.Queue[SimpleCoroutine] | None,
|
||||||
async_task: SimpleCoroutine,
|
async_task: SimpleCoroutine,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""From an SDK thread queue a coroutine to be asynchronously executed in the task manager event loop.
|
"""From an SDK thread queue a coroutine to be asynchronously executed in the task manager event loop.
|
||||||
|
|||||||
@@ -360,8 +360,8 @@ class VonageVideoConnectorTransport(BaseTransport):
|
|||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
self._input: Optional[VonageVideoConnectorInputTransport] = None
|
self._input: VonageVideoConnectorInputTransport | None = None
|
||||||
self._output: Optional[VonageVideoConnectorOutputTransport] = None
|
self._output: VonageVideoConnectorOutputTransport | None = None
|
||||||
self._one_stream_received: bool = False
|
self._one_stream_received: bool = False
|
||||||
|
|
||||||
def input(self) -> FrameProcessor:
|
def input(self) -> FrameProcessor:
|
||||||
|
|||||||
@@ -8,10 +8,11 @@ import asyncio
|
|||||||
import inspect
|
import inspect
|
||||||
import sys
|
import sys
|
||||||
import threading
|
import threading
|
||||||
|
from collections.abc import Awaitable, Callable
|
||||||
from concurrent.futures import ThreadPoolExecutor
|
from concurrent.futures import ThreadPoolExecutor
|
||||||
from dataclasses import dataclass
|
from dataclasses import dataclass
|
||||||
from datetime import datetime, timedelta
|
from datetime import datetime, timedelta
|
||||||
from typing import Any, Awaitable, Callable, Optional
|
from typing import Any, Optional
|
||||||
from unittest.mock import ANY, AsyncMock, MagicMock, Mock, call, patch
|
from unittest.mock import ANY, AsyncMock, MagicMock, Mock, call, patch
|
||||||
|
|
||||||
import numpy as np
|
import numpy as np
|
||||||
@@ -76,7 +77,7 @@ class MockPublisher:
|
|||||||
|
|
||||||
@dataclass(eq=True, frozen=True)
|
@dataclass(eq=True, frozen=True)
|
||||||
class MockSubscriber:
|
class MockSubscriber:
|
||||||
stream: Optional[MockStream] = None
|
stream: MockStream | None = None
|
||||||
|
|
||||||
|
|
||||||
@dataclass(eq=True, frozen=True)
|
@dataclass(eq=True, frozen=True)
|
||||||
@@ -100,9 +101,9 @@ class MockSessionVideoPublisherSettings:
|
|||||||
|
|
||||||
@dataclass(eq=True, frozen=True)
|
@dataclass(eq=True, frozen=True)
|
||||||
class MockSessionAVSettings:
|
class MockSessionAVSettings:
|
||||||
audio_publisher: Optional[MockSessionAudioSettings] = None
|
audio_publisher: MockSessionAudioSettings | None = None
|
||||||
audio_subscribers_mix: Optional[MockSessionAudioSettings] = None
|
audio_subscribers_mix: MockSessionAudioSettings | None = None
|
||||||
video_publisher: Optional[MockSessionVideoPublisherSettings] = None
|
video_publisher: MockSessionVideoPublisherSettings | None = None
|
||||||
|
|
||||||
|
|
||||||
@dataclass(eq=True, frozen=True)
|
@dataclass(eq=True, frozen=True)
|
||||||
@@ -113,8 +114,8 @@ class MockLoggingSettings:
|
|||||||
@dataclass(eq=True, frozen=True)
|
@dataclass(eq=True, frozen=True)
|
||||||
class MockSessionSettings:
|
class MockSessionSettings:
|
||||||
enable_migration: bool = False
|
enable_migration: bool = False
|
||||||
av: Optional[MockSessionAVSettings] = None
|
av: MockSessionAVSettings | None = None
|
||||||
logging: Optional[MockLoggingSettings] = None
|
logging: MockLoggingSettings | None = None
|
||||||
|
|
||||||
|
|
||||||
@dataclass(eq=True, frozen=True)
|
@dataclass(eq=True, frozen=True)
|
||||||
@@ -128,7 +129,7 @@ class MockPublisherSettings:
|
|||||||
name: str
|
name: str
|
||||||
has_audio: bool
|
has_audio: bool
|
||||||
has_video: bool
|
has_video: bool
|
||||||
audio_settings: Optional[MockPublisherAudioSettings] = None
|
audio_settings: MockPublisherAudioSettings | None = None
|
||||||
|
|
||||||
|
|
||||||
@dataclass(eq=True, frozen=True)
|
@dataclass(eq=True, frozen=True)
|
||||||
@@ -140,15 +141,15 @@ class MockVideoFrame:
|
|||||||
|
|
||||||
@dataclass(eq=True, frozen=True)
|
@dataclass(eq=True, frozen=True)
|
||||||
class MockSubscriberVideoSettings:
|
class MockSubscriberVideoSettings:
|
||||||
preferred_resolution: Optional[MockVideoResolution] = None
|
preferred_resolution: MockVideoResolution | None = None
|
||||||
preferred_framerate: Optional[int] = None
|
preferred_framerate: int | None = None
|
||||||
|
|
||||||
|
|
||||||
@dataclass(eq=True, frozen=True)
|
@dataclass(eq=True, frozen=True)
|
||||||
class MockSubscriberSettings:
|
class MockSubscriberSettings:
|
||||||
subscribe_to_audio: bool = True
|
subscribe_to_audio: bool = True
|
||||||
subscribe_to_video: bool = True
|
subscribe_to_video: bool = True
|
||||||
video_settings: Optional[MockSubscriberVideoSettings] = None
|
video_settings: MockSubscriberVideoSettings | None = None
|
||||||
|
|
||||||
|
|
||||||
# Set up the mock module structure
|
# Set up the mock module structure
|
||||||
@@ -232,11 +233,11 @@ class TestVonageVideoConnectorTransport:
|
|||||||
self.application_id = "test-app-id"
|
self.application_id = "test-app-id"
|
||||||
self.session_id = "test-session-id"
|
self.session_id = "test-session-id"
|
||||||
self.token = "test-token"
|
self.token = "test-token"
|
||||||
self._frame_processor_setup: Optional[FrameProcessorSetup] = None
|
self._frame_processor_setup: FrameProcessorSetup | None = None
|
||||||
self._executor = ThreadPoolExecutor(max_workers=1)
|
self._executor = ThreadPoolExecutor(max_workers=1)
|
||||||
|
|
||||||
# subscriber state
|
# subscriber state
|
||||||
self._connect_callbacks: Optional[ConnectCallbacks] = None
|
self._connect_callbacks: ConnectCallbacks | None = None
|
||||||
self._subscriber_callbacks: dict[str, SubscriberCallbacks] = {}
|
self._subscriber_callbacks: dict[str, SubscriberCallbacks] = {}
|
||||||
|
|
||||||
def _get_frame_processor_setup(self) -> FrameProcessorSetup:
|
def _get_frame_processor_setup(self) -> FrameProcessorSetup:
|
||||||
@@ -271,7 +272,7 @@ class TestVonageVideoConnectorTransport:
|
|||||||
|
|
||||||
while not condition():
|
while not condition():
|
||||||
if asyncio.get_event_loop().time() - start_time > timeout_seconds:
|
if asyncio.get_event_loop().time() - start_time > timeout_seconds:
|
||||||
raise asyncio.TimeoutError(f"Condition not met within {timeout}")
|
raise TimeoutError(f"Condition not met within {timeout}")
|
||||||
await asyncio.sleep(check_interval_seconds)
|
await asyncio.sleep(check_interval_seconds)
|
||||||
|
|
||||||
def test_vonage_client_listener_defaults(self) -> None:
|
def test_vonage_client_listener_defaults(self) -> None:
|
||||||
@@ -399,7 +400,7 @@ class TestVonageVideoConnectorTransport:
|
|||||||
|
|
||||||
async def _create_client(
|
async def _create_client(
|
||||||
self,
|
self,
|
||||||
params: Optional[VonageVideoConnectorTransportParams] = None,
|
params: VonageVideoConnectorTransportParams | None = None,
|
||||||
setup_connect_mock: bool = True,
|
setup_connect_mock: bool = True,
|
||||||
) -> VonageClient:
|
) -> VonageClient:
|
||||||
params = params or VonageVideoConnectorTransportParams()
|
params = params or VonageVideoConnectorTransportParams()
|
||||||
@@ -788,7 +789,7 @@ class TestVonageVideoConnectorTransport:
|
|||||||
)
|
)
|
||||||
|
|
||||||
def connect_side_effect(
|
def connect_side_effect(
|
||||||
*_: Any, on_ready_for_audio_cb: Optional[Callable[[Any], None]] = None, **__: Any
|
*_: Any, on_ready_for_audio_cb: Callable[[Any], None] | None = None, **__: Any
|
||||||
) -> bool:
|
) -> bool:
|
||||||
assert on_ready_for_audio_cb is not None
|
assert on_ready_for_audio_cb is not None
|
||||||
connecting_future.set_result(on_ready_for_audio_cb)
|
connecting_future.set_result(on_ready_for_audio_cb)
|
||||||
|
|||||||
Reference in New Issue
Block a user