66
77
88class 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 )
0 commit comments