2023-08-30 15:59:51 -07:00
|
|
|
from typing import Any, Dict, List, Type, TypeVar, Union
|
2023-08-17 12:48:13 -07:00
|
|
|
|
|
|
|
import attr
|
2023-11-28 23:50:50 -08:00
|
|
|
from pydantic import BaseModel, GetCoreSchemaHandler
|
|
|
|
from pydantic_core import CoreSchema, core_schema
|
2023-08-17 12:48:13 -07:00
|
|
|
|
2023-11-28 23:50:50 -08:00
|
|
|
from ..models.ice_server import IceServer
|
|
|
|
from ..models.ok_modeling_cmd_response import OkModelingCmdResponse
|
|
|
|
from ..models.raw_file import RawFile
|
|
|
|
from ..models.rtc_ice_candidate_init import RtcIceCandidateInit
|
|
|
|
from ..models.rtc_session_description import RtcSessionDescription
|
2023-08-17 12:48:13 -07:00
|
|
|
|
2023-11-27 16:01:20 -08:00
|
|
|
|
2023-11-28 23:50:50 -08:00
|
|
|
class IceServerInfoData(BaseModel):
|
|
|
|
""""""
|
2023-08-17 12:48:13 -07:00
|
|
|
|
2023-11-28 23:50:50 -08:00
|
|
|
ice_servers: List[IceServer]
|
2023-08-17 12:48:13 -07:00
|
|
|
|
|
|
|
|
2023-11-28 23:50:50 -08:00
|
|
|
class ice_server_info(BaseModel):
|
|
|
|
"""Information about the ICE servers."""
|
2023-08-17 12:48:13 -07:00
|
|
|
|
2023-11-28 23:50:50 -08:00
|
|
|
data: IceServerInfoData
|
2023-08-17 12:48:13 -07:00
|
|
|
|
2023-11-28 23:50:50 -08:00
|
|
|
type: str = "ice_server_info"
|
2023-08-17 12:48:13 -07:00
|
|
|
|
|
|
|
|
2023-11-28 23:50:50 -08:00
|
|
|
class TrickleIceData(BaseModel):
|
|
|
|
""""""
|
2023-08-17 12:48:13 -07:00
|
|
|
|
2023-11-28 23:50:50 -08:00
|
|
|
candidate: RtcIceCandidateInit
|
2023-08-17 12:48:13 -07:00
|
|
|
|
|
|
|
|
2023-11-28 23:50:50 -08:00
|
|
|
class trickle_ice(BaseModel):
|
|
|
|
"""The trickle ICE candidate response."""
|
2023-09-29 16:05:40 -07:00
|
|
|
|
2023-11-28 23:50:50 -08:00
|
|
|
data: TrickleIceData
|
2023-08-17 12:48:13 -07:00
|
|
|
|
2023-11-27 16:01:20 -08:00
|
|
|
type: str = "trickle_ice"
|
2023-08-17 12:48:13 -07:00
|
|
|
|
|
|
|
|
2023-11-28 23:50:50 -08:00
|
|
|
class SdpAnswerData(BaseModel):
|
|
|
|
""""""
|
2023-08-17 12:48:13 -07:00
|
|
|
|
2023-11-28 23:50:50 -08:00
|
|
|
answer: RtcSessionDescription
|
2023-08-17 12:48:13 -07:00
|
|
|
|
|
|
|
|
2023-11-28 23:50:50 -08:00
|
|
|
class sdp_answer(BaseModel):
|
|
|
|
"""The SDP answer response."""
|
2023-08-17 12:48:13 -07:00
|
|
|
|
2023-11-28 23:50:50 -08:00
|
|
|
data: SdpAnswerData
|
2023-08-17 12:48:13 -07:00
|
|
|
|
2023-11-27 16:01:20 -08:00
|
|
|
type: str = "sdp_answer"
|
2023-08-17 12:48:13 -07:00
|
|
|
|
|
|
|
|
2023-11-28 23:50:50 -08:00
|
|
|
class ModelingData(BaseModel):
|
|
|
|
""""""
|
2023-08-17 12:48:13 -07:00
|
|
|
|
2023-11-28 23:50:50 -08:00
|
|
|
modeling_response: OkModelingCmdResponse
|
2023-08-17 12:48:13 -07:00
|
|
|
|
|
|
|
|
2023-11-28 23:50:50 -08:00
|
|
|
class modeling(BaseModel):
|
|
|
|
"""The modeling command response."""
|
2023-08-17 12:48:13 -07:00
|
|
|
|
2023-11-28 23:50:50 -08:00
|
|
|
data: ModelingData
|
2023-08-17 12:48:13 -07:00
|
|
|
|
2023-11-27 16:01:20 -08:00
|
|
|
type: str = "modeling"
|
2023-08-17 12:48:13 -07:00
|
|
|
|
|
|
|
|
2023-11-28 23:50:50 -08:00
|
|
|
class ExportData(BaseModel):
|
|
|
|
""""""
|
2023-08-17 12:48:13 -07:00
|
|
|
|
2023-11-28 23:50:50 -08:00
|
|
|
files: List[RawFile]
|
2023-08-17 12:48:13 -07:00
|
|
|
|
|
|
|
|
2023-11-28 23:50:50 -08:00
|
|
|
class export(BaseModel):
|
|
|
|
"""The exported files."""
|
2023-08-17 12:48:13 -07:00
|
|
|
|
2023-11-28 23:50:50 -08:00
|
|
|
data: ExportData
|
2023-08-17 12:48:13 -07:00
|
|
|
|
2023-11-27 16:01:20 -08:00
|
|
|
type: str = "export"
|
2023-08-17 12:48:13 -07:00
|
|
|
|
2023-09-29 16:05:40 -07:00
|
|
|
|
2023-11-28 23:50:50 -08:00
|
|
|
class MetricsRequestData(BaseModel):
|
|
|
|
""""""
|
2023-08-17 12:48:13 -07:00
|
|
|
|
|
|
|
|
2023-11-28 23:50:50 -08:00
|
|
|
class metrics_request(BaseModel):
|
|
|
|
"""Request a collection of metrics, to include WebRTC."""
|
2023-08-17 12:48:13 -07:00
|
|
|
|
2023-11-28 23:50:50 -08:00
|
|
|
data: MetricsRequestData
|
2023-09-29 15:51:03 -07:00
|
|
|
|
2023-11-27 16:01:20 -08:00
|
|
|
type: str = "metrics_request"
|
2023-09-29 15:51:03 -07:00
|
|
|
|
|
|
|
|
2023-11-28 14:29:16 -08:00
|
|
|
GY = TypeVar("GY", bound="OkWebSocketResponseData")
|
|
|
|
|
|
|
|
|
|
|
|
@attr.s(auto_attribs=True)
|
2023-11-28 14:16:05 -08:00
|
|
|
class OkWebSocketResponseData:
|
|
|
|
|
|
|
|
"""The websocket messages this server sends."""
|
|
|
|
|
|
|
|
type: Union[
|
|
|
|
ice_server_info,
|
|
|
|
trickle_ice,
|
|
|
|
sdp_answer,
|
|
|
|
modeling,
|
|
|
|
export,
|
|
|
|
metrics_request,
|
2023-11-28 14:29:16 -08:00
|
|
|
]
|
2023-11-28 14:16:05 -08:00
|
|
|
|
|
|
|
def __init__(
|
|
|
|
self,
|
|
|
|
type: Union[
|
2023-11-28 14:29:16 -08:00
|
|
|
ice_server_info,
|
|
|
|
trickle_ice,
|
|
|
|
sdp_answer,
|
|
|
|
modeling,
|
|
|
|
export,
|
|
|
|
metrics_request,
|
2023-11-28 14:16:05 -08:00
|
|
|
],
|
|
|
|
):
|
|
|
|
self.type = type
|
|
|
|
|
2023-11-28 23:50:50 -08:00
|
|
|
def model_dump(self) -> Dict[str, Any]:
|
2023-11-28 14:16:05 -08:00
|
|
|
if isinstance(self.type, ice_server_info):
|
2023-11-28 23:50:50 -08:00
|
|
|
VY: ice_server_info = self.type
|
|
|
|
return VY.model_dump()
|
2023-11-28 14:16:05 -08:00
|
|
|
elif isinstance(self.type, trickle_ice):
|
2023-11-28 23:50:50 -08:00
|
|
|
MC: trickle_ice = self.type
|
|
|
|
return MC.model_dump()
|
2023-11-28 14:16:05 -08:00
|
|
|
elif isinstance(self.type, sdp_answer):
|
2023-11-28 23:50:50 -08:00
|
|
|
BR: sdp_answer = self.type
|
|
|
|
return BR.model_dump()
|
2023-11-28 14:16:05 -08:00
|
|
|
elif isinstance(self.type, modeling):
|
2023-11-28 23:50:50 -08:00
|
|
|
OK: modeling = self.type
|
|
|
|
return OK.model_dump()
|
2023-11-28 14:16:05 -08:00
|
|
|
elif isinstance(self.type, export):
|
2023-11-28 23:50:50 -08:00
|
|
|
OP: export = self.type
|
|
|
|
return OP.model_dump()
|
2023-11-28 14:16:05 -08:00
|
|
|
elif isinstance(self.type, metrics_request):
|
2023-11-28 23:50:50 -08:00
|
|
|
LV: metrics_request = self.type
|
|
|
|
return LV.model_dump()
|
2023-11-28 14:16:05 -08:00
|
|
|
|
|
|
|
raise Exception("Unknown type")
|
|
|
|
|
2023-11-28 14:29:16 -08:00
|
|
|
@classmethod
|
|
|
|
def from_dict(cls: Type[GY], d: Dict[str, Any]) -> GY:
|
2023-11-28 14:16:05 -08:00
|
|
|
if d.get("type") == "ice_server_info":
|
2023-11-28 23:50:50 -08:00
|
|
|
DW: ice_server_info = ice_server_info(**d)
|
|
|
|
return cls(type=DW)
|
2023-11-28 14:16:05 -08:00
|
|
|
elif d.get("type") == "trickle_ice":
|
2023-11-28 23:50:50 -08:00
|
|
|
AV: trickle_ice = trickle_ice(**d)
|
|
|
|
return cls(type=AV)
|
2023-11-28 14:16:05 -08:00
|
|
|
elif d.get("type") == "sdp_answer":
|
2023-11-28 23:50:50 -08:00
|
|
|
WM: sdp_answer = sdp_answer(**d)
|
|
|
|
return cls(type=WM)
|
2023-11-28 14:16:05 -08:00
|
|
|
elif d.get("type") == "modeling":
|
2023-11-28 23:50:50 -08:00
|
|
|
MU: modeling = modeling(**d)
|
|
|
|
return cls(type=MU)
|
2023-11-28 14:16:05 -08:00
|
|
|
elif d.get("type") == "export":
|
2023-11-28 23:50:50 -08:00
|
|
|
WW: export = export(**d)
|
|
|
|
return cls(type=WW)
|
2023-11-28 14:16:05 -08:00
|
|
|
elif d.get("type") == "metrics_request":
|
2023-11-28 23:50:50 -08:00
|
|
|
II: metrics_request = metrics_request(**d)
|
|
|
|
return cls(type=II)
|
2023-11-28 14:16:05 -08:00
|
|
|
|
|
|
|
raise Exception("Unknown type")
|
2023-11-28 23:50:50 -08:00
|
|
|
|
|
|
|
@classmethod
|
|
|
|
def __get_pydantic_core_schema__(
|
|
|
|
cls, source_type: Any, handler: GetCoreSchemaHandler
|
|
|
|
) -> CoreSchema:
|
|
|
|
return core_schema.no_info_after_validator_function(
|
|
|
|
cls,
|
|
|
|
handler(
|
|
|
|
Union[
|
|
|
|
ice_server_info,
|
|
|
|
trickle_ice,
|
|
|
|
sdp_answer,
|
|
|
|
modeling,
|
|
|
|
export,
|
|
|
|
metrics_request,
|
|
|
|
]
|
|
|
|
),
|
|
|
|
)
|