diff --git a/hippolyzer/lib/voice/client.py b/hippolyzer/lib/voice/client.py index 23770ff..47bd361 100644 --- a/hippolyzer/lib/voice/client.py +++ b/hippolyzer/lib/voice/client.py @@ -46,8 +46,8 @@ class VoiceClient: self._host = host self._port = port - self.logged_in = Event() - self.ready = Event() + self.logged_in = asyncio.Event() + self.ready = asyncio.Event() self.session_added = Event() self.channel_info_updated = Event() self.participant_added = Event() @@ -138,7 +138,7 @@ class VoiceClient: client = cls(host, port) await client.create_vivox_connection() - await client.ready + await client.ready.wait() return client async def create_vivox_connection(self): @@ -174,7 +174,7 @@ class VoiceClient: }) self._connector_handle = connector_resp['Results']['ConnectorHandle'] - self.ready.notify(None) + self.ready.set() async def login(self, username: Union[uuid.UUID, str], password: str): # UUID, convert to Vivox format @@ -202,7 +202,7 @@ class VoiceClient: raise Exception(resp) self._display_name = urllib.parse.unquote(resp["Results"]["DisplayName"]) - await self.logged_in + await self.logged_in.wait() return resp @@ -215,6 +215,7 @@ class VoiceClient: "AccountHandle": self._account_handle, }) self._account_handle = None + self.logged_in.clear() async def join_session(self, uri: str, region_handle: Optional[int] = None): if self._session_handle: @@ -371,7 +372,7 @@ class VoiceClient: elif event_type == "AccountLoginStateChangeEvent": if dict_msg.get('StatusString') == "OK" and dict_msg['State'] == '1': self._account_handle = dict_msg['AccountHandle'] - self.logged_in.notify(self._account_handle) + self.logged_in.set() elif event_type == "SessionAddedEvent": self._session_handle = dict_msg["SessionHandle"] self._session_group_handle = dict_msg["SessionGroupHandle"] diff --git a/tests/voice/test_voice.py b/tests/voice/test_voice.py index 2a8a634..d165766 100644 --- a/tests/voice/test_voice.py +++ b/tests/voice/test_voice.py @@ -205,7 +205,7 @@ class TestVoiceClient(unittest.IsolatedAsyncioTestCase): "ConnectorHandle": 2, } }) - await self.client.ready + await self.client.ready.wait() async def test_create_connector(self): await self._serve_connector_setup() @@ -216,6 +216,12 @@ class TestVoiceClient(unittest.IsolatedAsyncioTestCase): async def _handle_login(): msg = await self._expect_message("Account.Login.1") self.assertEqual("foo", msg.data["AccountName"]) + await self.server_connection.send_event("AccountLoginStateChangeEvent", { + "AccountHandle": 2, + "StatusCode": 200, + "StatusString": "OK", + "State": 1, + }) await self.server_connection.send_response(msg.request_id, msg.name, { "ReturnCode": 0, "Results": { @@ -225,12 +231,6 @@ class TestVoiceClient(unittest.IsolatedAsyncioTestCase): "DisplayName": "foo", } }) - await self.server_connection.send_event("AccountLoginStateChangeEvent", { - "AccountHandle": 2, - "StatusCode": 200, - "StatusString": "OK", - "State": 1, - }) login_task = asyncio.get_event_loop().create_task(_handle_login())