|
17 | 17 | import ctypes |
18 | 18 | import asyncio |
19 | 19 | import datetime |
| 20 | +import enum |
20 | 21 | import os |
21 | 22 | import mimetypes |
22 | 23 | import aiofiles |
|
29 | 30 | from ._proto.room_pb2 import ( |
30 | 31 | TrackPublishOptions, |
31 | 32 | ) |
| 33 | +from ._proto.room_pb2 import ( |
| 34 | + ConnectionQuality as ProtoConnectionQuality, |
| 35 | +) |
32 | 36 | from ._proto.room_pb2 import ( |
33 | 37 | TranscriptionSegment as ProtoTranscriptionSegment, |
34 | 38 | ) |
@@ -89,10 +93,29 @@ def __init__(self, message: str) -> None: |
89 | 93 | self.message = message |
90 | 94 |
|
91 | 95 |
|
| 96 | +class ConnectionQuality(enum.IntEnum): |
| 97 | + """Connection quality reported for a participant.""" |
| 98 | + |
| 99 | + QUALITY_UNKNOWN = -1 |
| 100 | + """No connection-quality update has been reported yet (no proto equivalent).""" |
| 101 | + QUALITY_POOR = ProtoConnectionQuality.QUALITY_POOR |
| 102 | + QUALITY_GOOD = ProtoConnectionQuality.QUALITY_GOOD |
| 103 | + QUALITY_EXCELLENT = ProtoConnectionQuality.QUALITY_EXCELLENT |
| 104 | + QUALITY_LOST = ProtoConnectionQuality.QUALITY_LOST |
| 105 | + |
| 106 | + |
| 107 | +def _connection_quality_from_proto(value: int) -> ConnectionQuality: |
| 108 | + try: |
| 109 | + return ConnectionQuality(value) |
| 110 | + except ValueError: |
| 111 | + return ConnectionQuality.QUALITY_UNKNOWN |
| 112 | + |
| 113 | + |
92 | 114 | class Participant(ABC): |
93 | 115 | def __init__(self, owned_info: proto_participant.OwnedParticipant) -> None: |
94 | 116 | self._info = owned_info.info |
95 | 117 | self._ffi_handle = FfiHandle(owned_info.handle.id) |
| 118 | + self._connection_quality = ConnectionQuality.QUALITY_UNKNOWN |
96 | 119 |
|
97 | 120 | @property |
98 | 121 | @abstractmethod |
@@ -152,6 +175,16 @@ def permissions(self) -> proto_participant.ParticipantPermission: |
152 | 175 | """The participant's permissions within the room.""" |
153 | 176 | return self._info.permission |
154 | 177 |
|
| 178 | + @property |
| 179 | + def connection_quality(self) -> ConnectionQuality: |
| 180 | + """The participant's most recently reported connection quality. |
| 181 | +
|
| 182 | + Returns ``ConnectionQuality.QUALITY_UNKNOWN`` until the first |
| 183 | + connection-quality update is received. Updated automatically whenever a |
| 184 | + ``connection_quality_changed`` event fires for this participant. |
| 185 | + """ |
| 186 | + return self._connection_quality |
| 187 | + |
155 | 188 | @property |
156 | 189 | def disconnect_reason( |
157 | 190 | self, |
|
0 commit comments