Optimize websocket imports
This commit is contained in:
parent
17fc11d8bb
commit
9d2cf86091
1 changed files with 12 additions and 12 deletions
|
@ -2,12 +2,12 @@
|
||||||
|
|
||||||
###############################################################################
|
###############################################################################
|
||||||
import logging
|
import logging
|
||||||
from json import loads
|
|
||||||
import threading
|
|
||||||
import websocket
|
import websocket
|
||||||
import ssl
|
from json import loads
|
||||||
|
from threading import Thread
|
||||||
|
from ssl import CERT_NONE
|
||||||
|
|
||||||
import xbmc
|
from xbmc import sleep
|
||||||
|
|
||||||
from utils import window, settings, ThreadMethodsAdditionalSuspend, \
|
from utils import window, settings, ThreadMethodsAdditionalSuspend, \
|
||||||
ThreadMethods
|
ThreadMethods
|
||||||
|
@ -21,14 +21,14 @@ log = logging.getLogger("PLEX."+__name__)
|
||||||
|
|
||||||
@ThreadMethodsAdditionalSuspend('suspend_LibraryThread')
|
@ThreadMethodsAdditionalSuspend('suspend_LibraryThread')
|
||||||
@ThreadMethods
|
@ThreadMethods
|
||||||
class WebSocket(threading.Thread):
|
class WebSocket(Thread):
|
||||||
opcode_data = (websocket.ABNF.OPCODE_TEXT, websocket.ABNF.OPCODE_BINARY)
|
opcode_data = (websocket.ABNF.OPCODE_TEXT, websocket.ABNF.OPCODE_BINARY)
|
||||||
|
|
||||||
def __init__(self, queue):
|
def __init__(self, queue):
|
||||||
self.ws = None
|
self.ws = None
|
||||||
# Communication with librarysync
|
# Communication with librarysync
|
||||||
self.queue = queue
|
self.queue = queue
|
||||||
threading.Thread.__init__(self)
|
Thread.__init__(self)
|
||||||
|
|
||||||
def process(self, opcode, message):
|
def process(self, opcode, message):
|
||||||
if opcode not in self.opcode_data:
|
if opcode not in self.opcode_data:
|
||||||
|
@ -91,7 +91,7 @@ class WebSocket(threading.Thread):
|
||||||
uri += '?X-Plex-Token=%s' % token
|
uri += '?X-Plex-Token=%s' % token
|
||||||
sslopt = {}
|
sslopt = {}
|
||||||
if settings('sslverify') == "false":
|
if settings('sslverify') == "false":
|
||||||
sslopt["cert_reqs"] = ssl.CERT_NONE
|
sslopt["cert_reqs"] = CERT_NONE
|
||||||
log.debug("Uri: %s, sslopt: %s" % (uri, sslopt))
|
log.debug("Uri: %s, sslopt: %s" % (uri, sslopt))
|
||||||
return uri, sslopt
|
return uri, sslopt
|
||||||
|
|
||||||
|
@ -116,7 +116,7 @@ class WebSocket(threading.Thread):
|
||||||
# Abort was requested while waiting. We should exit
|
# Abort was requested while waiting. We should exit
|
||||||
log.info("##===---- WebSocketClient Stopped ----===##")
|
log.info("##===---- WebSocketClient Stopped ----===##")
|
||||||
return
|
return
|
||||||
xbmc.sleep(1000)
|
sleep(1000)
|
||||||
try:
|
try:
|
||||||
self.process(*self.receive(self.ws))
|
self.process(*self.receive(self.ws))
|
||||||
except websocket.WebSocketTimeoutException:
|
except websocket.WebSocketTimeoutException:
|
||||||
|
@ -142,11 +142,11 @@ class WebSocket(threading.Thread):
|
||||||
"declaring the connection dead")
|
"declaring the connection dead")
|
||||||
window('plex_online', value='false')
|
window('plex_online', value='false')
|
||||||
counter = 0
|
counter = 0
|
||||||
xbmc.sleep(1000)
|
sleep(1000)
|
||||||
except websocket.WebSocketTimeoutException:
|
except websocket.WebSocketTimeoutException:
|
||||||
log.info("timeout while connecting, trying again")
|
log.info("timeout while connecting, trying again")
|
||||||
self.ws = None
|
self.ws = None
|
||||||
xbmc.sleep(1000)
|
sleep(1000)
|
||||||
except websocket.WebSocketException as e:
|
except websocket.WebSocketException as e:
|
||||||
log.info('WebSocketException: %s' % e)
|
log.info('WebSocketException: %s' % e)
|
||||||
if 'Handshake Status 401' in e.args:
|
if 'Handshake Status 401' in e.args:
|
||||||
|
@ -156,14 +156,14 @@ class WebSocket(threading.Thread):
|
||||||
'WebSocketClient now')
|
'WebSocketClient now')
|
||||||
break
|
break
|
||||||
self.ws = None
|
self.ws = None
|
||||||
xbmc.sleep(1000)
|
sleep(1000)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
log.error("Unknown exception encountered in connecting: %s"
|
log.error("Unknown exception encountered in connecting: %s"
|
||||||
% e)
|
% e)
|
||||||
import traceback
|
import traceback
|
||||||
log.error("Traceback:\n%s" % traceback.format_exc())
|
log.error("Traceback:\n%s" % traceback.format_exc())
|
||||||
self.ws = None
|
self.ws = None
|
||||||
xbmc.sleep(1000)
|
sleep(1000)
|
||||||
else:
|
else:
|
||||||
counter = 0
|
counter = 0
|
||||||
handshake_counter = 0
|
handshake_counter = 0
|
||||||
|
|
Loading…
Reference in a new issue