-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathpeer.py
More file actions
153 lines (116 loc) · 4.45 KB
/
peer.py
File metadata and controls
153 lines (116 loc) · 4.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
from collections.abc import Mapping
from typing import (
TYPE_CHECKING,
Any,
TypeVar,
Union,
cast,
)
from attrs import define as _attrs_define
from attrs import field as _attrs_field
from ..models.peer_status import PeerStatus
from ..models.peer_type import PeerType
from ..models.subscribe_mode import SubscribeMode
if TYPE_CHECKING:
from ..models.peer_metadata import PeerMetadata
from ..models.subscriptions import Subscriptions
from ..models.track import Track
T = TypeVar("T", bound="Peer")
@_attrs_define
class Peer:
"""Describes peer status
Attributes:
id (str): Assigned peer id Example: 4a1c1164-5fb7-425d-89d7-24cdb8fff1cf.
metadata (Union['PeerMetadata', None]): Custom metadata set by the peer Example: {'name': 'FishjamUser'}.
status (PeerStatus): Informs about the peer status Example: disconnected.
subscribe_mode (SubscribeMode): Configuration of peer's subscribing policy
subscriptions (Subscriptions): Describes peer's subscriptions in manual mode
tracks (list['Track']): List of all peer's tracks
type_ (PeerType): Peer type Example: webrtc.
"""
id: str
metadata: Union["PeerMetadata", None]
status: PeerStatus
subscribe_mode: SubscribeMode
subscriptions: "Subscriptions"
tracks: list["Track"]
type_: PeerType
additional_properties: dict[str, Any] = _attrs_field(init=False, factory=dict)
def to_dict(self) -> dict[str, Any]:
from ..models.peer_metadata import PeerMetadata
id = self.id
metadata: Union[None, dict[str, Any]]
if isinstance(self.metadata, PeerMetadata):
metadata = self.metadata.to_dict()
else:
metadata = self.metadata
status = self.status.value
subscribe_mode = self.subscribe_mode.value
subscriptions = self.subscriptions.to_dict()
tracks = []
for tracks_item_data in self.tracks:
tracks_item = tracks_item_data.to_dict()
tracks.append(tracks_item)
type_ = self.type_.value
field_dict: dict[str, Any] = {}
field_dict.update(self.additional_properties)
field_dict.update({
"id": id,
"metadata": metadata,
"status": status,
"subscribeMode": subscribe_mode,
"subscriptions": subscriptions,
"tracks": tracks,
"type": type_,
})
return field_dict
@classmethod
def from_dict(cls: type[T], src_dict: Mapping[str, Any]) -> T:
from ..models.peer_metadata import PeerMetadata
from ..models.subscriptions import Subscriptions
from ..models.track import Track
d = dict(src_dict)
id = d.pop("id")
def _parse_metadata(data: object) -> Union["PeerMetadata", None]:
if data is None:
return data
try:
if not isinstance(data, dict):
raise TypeError()
componentsschemas_peer_metadata_type_0 = PeerMetadata.from_dict(data)
return componentsschemas_peer_metadata_type_0
except: # noqa: E722
pass
return cast(Union["PeerMetadata", None], data)
metadata = _parse_metadata(d.pop("metadata"))
status = PeerStatus(d.pop("status"))
subscribe_mode = SubscribeMode(d.pop("subscribeMode"))
subscriptions = Subscriptions.from_dict(d.pop("subscriptions"))
tracks = []
_tracks = d.pop("tracks")
for tracks_item_data in _tracks:
tracks_item = Track.from_dict(tracks_item_data)
tracks.append(tracks_item)
type_ = PeerType(d.pop("type"))
peer = cls(
id=id,
metadata=metadata,
status=status,
subscribe_mode=subscribe_mode,
subscriptions=subscriptions,
tracks=tracks,
type_=type_,
)
peer.additional_properties = d
return peer
@property
def additional_keys(self) -> list[str]:
return list(self.additional_properties.keys())
def __getitem__(self, key: str) -> Any:
return self.additional_properties[key]
def __setitem__(self, key: str, value: Any) -> None:
self.additional_properties[key] = value
def __delitem__(self, key: str) -> None:
del self.additional_properties[key]
def __contains__(self, key: str) -> bool:
return key in self.additional_properties