Skip to content

Commit

Permalink
change protocol message action to enum
Browse files Browse the repository at this point in the history
  • Loading branch information
mohyour committed Sep 14, 2022
1 parent fce2edf commit 4f661ee
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
11 changes: 8 additions & 3 deletions ably/realtime/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ class ConnectionState(Enum):
FAILED = 'failed'


class ProtocolMessageAction(Enum):
CONNECTED = 4
ERROR = 9


class RealtimeConnection:
def __init__(self, realtime):
self.options = realtime.options
Expand Down Expand Up @@ -60,13 +65,13 @@ async def ws_read_loop(self):
raw = await self.__websocket.recv()
msg = json.loads(raw)
action = msg['action']
if action == 4: # CONNECTED
if action == ProtocolMessageAction.CONNECTED: # CONNECTED
if self.__connected_future:
self.__connected_future.set_result(None)
self.__connected_future = None
else:
log.warn('CONNECTED message receieved but connected_future not set')
if action == 9: # ERROR
log.warn('CONNECTED message received but connected_future not set')
if action == ProtocolMessageAction.ERROR: # ERROR
error = msg["error"]
if error['nonfatal'] is False:
self.__state = ConnectionState.FAILED
Expand Down
2 changes: 1 addition & 1 deletion ably/realtime/realtime.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def __init__(self, key=None, **kwargs):
if key is not None:
options = Options(key=key, **kwargs)
else:
raise ValueError("Key is missing. Provide an API key")
raise ValueError("Key is missing. Provide an API key.")

self.__auth = Auth(self, options)
self.__options = options
Expand Down

0 comments on commit 4f661ee

Please sign in to comment.