mirror of
https://github.com/Tautulli/Tautulli.git
synced 2025-08-14 10:36:57 -07:00
Add quick websocket test when verifying server
This commit is contained in:
parent
d8298a12eb
commit
5108e1bb09
2 changed files with 34 additions and 19 deletions
|
@ -666,12 +666,7 @@
|
|||
<label for="pms_url">Plex Server URL</label>
|
||||
<div class="row">
|
||||
<div class="col-md-9">
|
||||
<div class="input-group">
|
||||
<input type="text" class="form-control" id="pms_url" name="pms_url" value="${config['pms_url']}" size="30" readonly>
|
||||
<span class="input-group-btn">
|
||||
<button class="btn btn-form" type="button" id="test_pms_url_button">Test URL</button>
|
||||
</span>
|
||||
</div>
|
||||
<input type="text" class="form-control" id="pms_url" name="pms_url" value="${config['pms_url']}" size="30" readonly>
|
||||
</div>
|
||||
</div>
|
||||
<p class="help-block">
|
||||
|
@ -1937,11 +1932,11 @@ $(document).ready(function() {
|
|||
data: {
|
||||
hostname: pms_ip,
|
||||
port: pms_port,
|
||||
identifier: pms_identifier,
|
||||
ssl: pms_ssl,
|
||||
remote: pms_is_remote,
|
||||
manual: pms_url_manual,
|
||||
get_url: serverChanged
|
||||
get_url: true,
|
||||
test_websocket: true
|
||||
},
|
||||
cache: true,
|
||||
async: true,
|
||||
|
@ -1954,15 +1949,23 @@ $(document).ready(function() {
|
|||
var result = xhr;
|
||||
var identifier = result.identifier;
|
||||
var url = result.url;
|
||||
var ws = result.ws;
|
||||
if (identifier) {
|
||||
$("#pms_identifier").val(identifier);
|
||||
|
||||
if (url) {
|
||||
$("#pms_url").val(url);
|
||||
}
|
||||
$("#pms_verify").html('<i class="fa fa-check"></i>').fadeIn('fast');
|
||||
$("#pms_ip_group").removeClass("has-error");
|
||||
|
||||
serverChanged = false;
|
||||
if (ws === false) {
|
||||
$("#pms_verify").html('<i class="fa fa-close"></i>').fadeIn('fast');
|
||||
$("#pms_ip_group").addClass("has-error");
|
||||
showMsg('<i class="fa fa-exclamation-circle"></i> Server found but unable to connect websocket.<br>Check the <a href="logs">logs</a> for errors.', false, true, 5000, true)
|
||||
} else {
|
||||
$("#pms_verify").html('<i class="fa fa-check"></i>').fadeIn('fast');
|
||||
$("#pms_ip_group").removeClass("has-error");
|
||||
serverChanged = false;
|
||||
}
|
||||
|
||||
if (_callback) {
|
||||
_callback();
|
||||
|
@ -1990,13 +1993,6 @@ $(document).ready(function() {
|
|||
$("#pms_web_url").val(pms_web_url || 'https://app.plex.tv/desktop');
|
||||
}
|
||||
|
||||
$('#test_pms_url_button').on('click', function(){
|
||||
var pms_url = $.trim($("#pms_url").val());
|
||||
if (pms_url.startsWith('http')) {
|
||||
window.open(pms_url + '/web', '_blank');
|
||||
}
|
||||
});
|
||||
|
||||
$('#test_pms_web_button').on('click', function(){
|
||||
var pms_web_url = $.trim($("#pms_web_url").val());
|
||||
window.open(pms_web_url, '_blank');
|
||||
|
|
|
@ -27,6 +27,8 @@ from hashing_passwords import make_hash
|
|||
from mako.lookup import TemplateLookup
|
||||
from mako import exceptions
|
||||
|
||||
import websocket
|
||||
|
||||
import plexpy
|
||||
import activity_pinger
|
||||
import common
|
||||
|
@ -3463,7 +3465,7 @@ class WebInterface(object):
|
|||
@requireAuth(member_of("admin"))
|
||||
@addtoapi()
|
||||
def get_server_id(self, hostname=None, port=None, identifier=None, ssl=0, remote=0, manual=0,
|
||||
get_url=False, **kwargs):
|
||||
get_url=False, test_websocket=False, **kwargs):
|
||||
""" Get the PMS server identifier.
|
||||
|
||||
```
|
||||
|
@ -3519,6 +3521,23 @@ class WebInterface(object):
|
|||
pms_url_manual=manual,
|
||||
pms_identifier=identifier)
|
||||
result['url'] = server['pms_url']
|
||||
result['ws'] = None
|
||||
|
||||
if test_websocket == 'true':
|
||||
# Quick test websocket connection
|
||||
ws_url = result['url'].replace('http', 'ws', 1) + '/:/websockets/notifications'
|
||||
header = ['X-Plex-Token: %s' % plexpy.CONFIG.PMS_TOKEN]
|
||||
|
||||
logger.debug("Testing websocket connection...")
|
||||
try:
|
||||
test_ws = websocket.create_connection(ws_url, header=header)
|
||||
test_ws.close()
|
||||
logger.debug("Websocket test connection successful.")
|
||||
result['ws'] = True
|
||||
except (websocket.WebSocketException, IOError, Exception) as e:
|
||||
logger.error("Websocket test connection failed: %s" % e)
|
||||
result['ws'] = False
|
||||
|
||||
return result
|
||||
else:
|
||||
logger.warn('Unable to retrieve the PMS identifier.')
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue