From 22b71ad007e387020b7f9c80b11cb43c7940c092 Mon Sep 17 00:00:00 2001 From: "Alex M. Sielicki" Date: Wed, 24 Aug 2016 23:08:16 +0000 Subject: [PATCH] Adding remote session status check. Addresses #633 --- web-server/js/slycat-remotes.js | 66 ++++++++++++++++++++++-------- web-server/js/slycat-web-client.js | 20 +++++++++ 2 files changed, 68 insertions(+), 18 deletions(-) diff --git a/web-server/js/slycat-remotes.js b/web-server/js/slycat-remotes.js index 10872fce0..1b4f1eda9 100644 --- a/web-server/js/slycat-remotes.js +++ b/web-server/js/slycat-remotes.js @@ -62,31 +62,61 @@ define("slycat-remotes", ["slycat-server-root", "slycat-web-client", "knockout", var pool = {}; - pool.get_remote = function(params) + pool.check_remote = function(params) { - if(params.hostname in remotes) - { - if(params.success) - params.success(params.hostname); - return; - } - - module.login( - { + client.get_remotes({ hostname: params.hostname, - title: params.title, - message: params.message, - success: function(sid) + success: function(result) { - remotes[params.hostname] = sid; if(params.success) - params.success(params.hostname); + params.success(result); }, - cancel: function() + error: function(request, status, reason_phrase) + { + if(params.error) + params.error(request, status, reason_phrase); + } + }); + } + + pool.get_remote = function(params) + { + pool.check_remote({ + hostname: params.hostname, + get_remote_params: params, + success: function(result) { - if(params.cancel) - params.cancel(); + if(result.status) + { + if(params.success) + params.success(params.hostname); + return; + } + else + { + module.login( + { + hostname: params.hostname, + title: params.title, + message: params.message, + success: function(sid) + { + if(params.success) + params.success(params.hostname); + }, + cancel: function() + { + if(params.cancel) + params.cancel(); + }, + }); + } }, + error: function(request, status, reason_phrase) + { + console.log("Unable to check status of remote session."); + return; + } }); } diff --git a/web-server/js/slycat-web-client.js b/web-server/js/slycat-web-client.js index 8c227fa15..a41e89a04 100644 --- a/web-server/js/slycat-web-client.js +++ b/web-server/js/slycat-web-client.js @@ -543,6 +543,26 @@ define("slycat-web-client", ["slycat-server-root", "jquery", "URI"], function(se }); } + module.get_remotes = function(params) + { + $.ajax( + { + dataType: "json", + type: "GET", + url: server_root + "remotes/" + params.hostname, + success: function(result) + { + if(params.success) + params.success(result); + }, + error: function(request, status, reason_phrase) + { + if(params.error) + params.error(request, status, reason_phrase); + } + }); + }; + module.get_remote_video_status = function(params) { $.ajax(