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 dfddd73
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
15 changes: 9 additions & 6 deletions ably/realtime/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ class ConnectionState(Enum):
CLOSED = 'closed'
FAILED = 'failed'

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

class RealtimeConnection:
def __init__(self, realtime):
Expand Down Expand Up @@ -60,13 +63,13 @@ async def ws_read_loop(self):
raw = await self.__websocket.recv()
msg = json.loads(raw)
action = msg['action']
if action == 4: # CONNECTED
if self.__connected_future:
self.__connected_future.set_result(None)
self.__connected_future = None
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 = 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 dfddd73

Please sign in to comment.