Skip to content

Commit 6987182

Browse files
authored
Merge pull request #408 from zSeriesGuy/Update-websockets-client
Update websockets client
2 parents cae44e4 + b68ace1 commit 6987182

File tree

3 files changed

+23
-11
lines changed

3 files changed

+23
-11
lines changed

plexapi/alert.py

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66

77

88
class AlertListener(threading.Thread):
9-
""" Creates a websocket connection to the PlexServer to optionally recieve alert notifications.
9+
""" Creates a websocket connection to the PlexServer to optionally receive alert notifications.
1010
These often include messages from Plex about media scans as well as updates to currently running
11-
Transcode Sessions. This class implements threading.Thread, therfore to start monitoring
11+
Transcode Sessions. This class implements threading.Thread, therefore to start monitoring
1212
alerts you must call .start() on the object once it's created. When calling
1313
`PlexServer.startAlertListener()`, the thread will be started for you.
1414
@@ -26,9 +26,9 @@ class AlertListener(threading.Thread):
2626
2727
Parameters:
2828
server (:class:`~plexapi.server.PlexServer`): PlexServer this listener is connected to.
29-
callback (func): Callback function to call on recieved messages. The callback function
29+
callback (func): Callback function to call on received messages. The callback function
3030
will be sent a single argument 'data' which will contain a dictionary of data
31-
recieved from the server. :samp:`def my_callback(data): ...`
31+
received from the server. :samp:`def my_callback(data): ...`
3232
"""
3333
key = '/:/websockets/notifications'
3434

@@ -48,15 +48,21 @@ def run(self):
4848
self._ws.run_forever()
4949

5050
def stop(self):
51-
""" Stop the AlertListener thread. Once the notifier is stopped, it cannot be diractly
51+
""" Stop the AlertListener thread. Once the notifier is stopped, it cannot be directly
5252
started again. You must call :func:`plexapi.server.PlexServer.startAlertListener()`
5353
from a PlexServer instance.
5454
"""
5555
log.info('Stopping AlertListener.')
5656
self._ws.close()
5757

58-
def _onMessage(self, ws, message):
59-
""" Called when websocket message is recieved. """
58+
def _onMessage(self, *args):
59+
""" Called when websocket message is received.
60+
In earlier releases, websocket-client returned a tuple of two parameters: a websocket.app.WebSocketApp object
61+
and the message as a STR. Current releases appear to only return the message.
62+
We are assuming the last argument in the tuple is the message.
63+
This is to support compatibility with current and previous releases of websocket-client.
64+
"""
65+
message = args[-1]
6066
try:
6167
data = json.loads(message)['NotificationContainer']
6268
log.debug('Alert: %s %s %s', *data)
@@ -65,6 +71,12 @@ def _onMessage(self, ws, message):
6571
except Exception as err: # pragma: no cover
6672
log.error('AlertListener Msg Error: %s', err)
6773

68-
def _onError(self, ws, err): # pragma: no cover
69-
""" Called when websocket error is recieved. """
74+
def _onError(self, *args): # pragma: no cover
75+
""" Called when websocket error is received.
76+
In earlier releases, websocket-client returned a tuple of two parameters: a websocket.app.WebSocketApp object
77+
and the error. Current releases appear to only return the error.
78+
We are assuming the last argument in the tuple is the message.
79+
This is to support compatibility with current and previous releases of websocket-client.
80+
"""
81+
err = args[-1]
7082
log.error('AlertListener Error: %s' % err)

requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@
44
#---------------------------------------------------------
55
requests
66
tqdm
7-
websocket-client==0.48.0
7+
websocket-client

requirements_dev.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ requests
1414
sphinx
1515
sphinxcontrib-napoleon
1616
tqdm
17-
websocket-client==0.48.0
17+
websocket-client
1818

1919
# Installing sphinx-rtd-theme directly from github above is used until a point release
2020
# above 0.4.3 is released. https://github.com/readthedocs/sphinx_rtd_theme/issues/739

0 commit comments

Comments
 (0)