diff --git a/dashboard-ui/connectlogin.html b/dashboard-ui/connectlogin.html index 012dc4d554..ae9584fd69 100644 --- a/dashboard-ui/connectlogin.html +++ b/dashboard-ui/connectlogin.html @@ -4,8 +4,7 @@ ${TitleSignIn} -
-
+
@@ -24,15 +23,23 @@
- @@ -45,7 +52,7 @@ diff --git a/dashboard-ui/scripts/connectlogin.js b/dashboard-ui/scripts/connectlogin.js index 873abb8545..10af0ab7df 100644 --- a/dashboard-ui/scripts/connectlogin.js +++ b/dashboard-ui/scripts/connectlogin.js @@ -56,6 +56,14 @@ loadMode(page, 'welcome'); } break; + case MediaBrowser.ConnectionState.Unavailable: + { + Dashboard.alert({ + message: Globalize.translate("MessageUnableToConnectToServer"), + title: Globalize.translate("HeaderConnectionFailure") + }); + } + break; default: break; } @@ -76,9 +84,9 @@ function loadPage(page) { - var mode = getParameterByName('mode'); + var mode = getParameterByName('mode') || 'auto'; - if (!mode) { + if (mode == 'auto') { if (Dashboard.isRunningInCordova()) { loadAppConnection(page); @@ -91,6 +99,9 @@ } function loadMode(page, mode) { + $(document.body).prepend('
'); + $(page).addClass('lightBackdropPage backdropPage staticBackdropPage'); + if (mode == 'welcome') { $('.connectLoginForm', page).hide(); $('.welcomeContainer', page).show(); @@ -145,6 +156,14 @@ handleConnectionResult(page, result); + }).fail(function () { + + Dashboard.hideLoadingMsg(); + + handleConnectionResult(page, { + State: MediaBrowser.ConnectionState.Unavailable + }); + }); } diff --git a/dashboard-ui/scripts/site.js b/dashboard-ui/scripts/site.js index 5e871e86e4..96bb9b5438 100644 --- a/dashboard-ui/scripts/site.js +++ b/dashboard-ui/scripts/site.js @@ -44,6 +44,7 @@ var Dashboard = { isConnectMode: function () { + return true; if (Dashboard.isRunningInCordova()) { return true; } @@ -56,6 +57,7 @@ var Dashboard = { isRunningInCordova: function () { + return true; return window.appMode == 'cordova'; }, diff --git a/dashboard-ui/thirdparty/apiclient/apiclient.js b/dashboard-ui/thirdparty/apiclient/apiclient.js index 4f1e4eab9f..356dcfd9ce 100644 --- a/dashboard-ui/thirdparty/apiclient/apiclient.js +++ b/dashboard-ui/thirdparty/apiclient/apiclient.js @@ -2477,7 +2477,9 @@ self.authenticateUserByName = function (name, password) { if (!name) { - throw new Error("null name"); + var deferred = DeferredBuilder.Deferred(); + deferred.reject(); + return deferred.promise(); } var url = self.getUrl("Users/authenticatebyname"); diff --git a/dashboard-ui/thirdparty/apiclient/connectionmanager.js b/dashboard-ui/thirdparty/apiclient/connectionmanager.js index 2d796f5eb1..3064437f6b 100644 --- a/dashboard-ui/thirdparty/apiclient/connectionmanager.js +++ b/dashboard-ui/thirdparty/apiclient/connectionmanager.js @@ -944,10 +944,15 @@ self.connectToAddress = function (address) { - address = normalizeAddress(address); - var deferred = DeferredBuilder.Deferred(); + if (!address) { + deferred.reject(); + return deferred.promise(); + } + + address = normalizeAddress(address); + tryConnect(address, 15000).done(function (publicInfo) { logger.log('connectToAddress ' + address + ' succeeded'); @@ -976,10 +981,14 @@ self.loginToConnect = function (username, password) { if (!username) { - throw new Error("null username"); + var deferred = DeferredBuilder.Deferred(); + deferred.reject(); + return deferred.promise(); } if (!password) { - throw new Error("null password"); + var deferred = DeferredBuilder.Deferred(); + deferred.reject(); + return deferred.promise(); } var md5 = self.getConnectPasswordHash(password); diff --git a/dashboard-ui/thirdparty/apiclient/cordova/serverdiscovery.js b/dashboard-ui/thirdparty/apiclient/cordova/serverdiscovery.js new file mode 100644 index 0000000000..590bf25e01 --- /dev/null +++ b/dashboard-ui/thirdparty/apiclient/cordova/serverdiscovery.js @@ -0,0 +1,19 @@ +(function (globalScope) { + + globalScope.ServerDiscovery = { + + findServers: function (timeoutMs) { + + var deferred = DeferredBuilder.Deferred(); + + var servers = []; + + // Expected server properties + // Name, Id, Address, EndpointAddress (optional) + + deferred.resolveWith(null, [servers]); + return deferred.promise(); + } + }; + +})(window); \ No newline at end of file diff --git a/dashboard-ui/thirdparty/apiclient/serverdiscovery.js b/dashboard-ui/thirdparty/apiclient/serverdiscovery.js index 9fcd5d4ef3..bcb7f1946c 100644 --- a/dashboard-ui/thirdparty/apiclient/serverdiscovery.js +++ b/dashboard-ui/thirdparty/apiclient/serverdiscovery.js @@ -1,16 +1,87 @@ (function (globalScope) { + function stringToArrayBuffer(string) { + // UTF-16LE + var buf = new ArrayBuffer(string.length * 2); + var bufView = new Uint16Array(buf); + for (var i = 0, strLen = string.length; i < strLen; i++) { + bufView[i] = string.charCodeAt(i); + } + return buf; + } + globalScope.ServerDiscovery = { findServers: function (timeoutMs) { var deferred = DeferredBuilder.Deferred(); + var servers = []; // Expected server properties // Name, Id, Address, EndpointAddress (optional) - deferred.resolveWith(null, [servers]); + var chrome = globalScope.chrome; + + if (!chrome) { + deferred.resolveWith(null, [servers]); + return deferred.promise(); + } + + var data = stringToArrayBuffer('who is EmbyServer?'); + var isTimedOut = false; + var socketId; + + var timeout = setTimeout(function () { + + isTimedOut = true; + deferred.resolveWith(null, [servers]); + + if (socketId) { + chrome.sockets.udp.onReceive.removeListener(onReceive); + chrome.sockets.udp.close(socketId); + } + + }, timeoutMs); + + function onReceive(info) { + + if (info.socketId == socketId) { + + //expect(info.remotePort).toBeTruthy(); + //expect(info.remoteAddress).toBeTruthy(); + //expect(info).toBeValidUdpReadResultEqualTo(data); + } + } + + var port = 7359; + chrome.sockets.udp.create(function (createInfo) { + + socketId = createInfo.socketId; + + chrome.sockets.udp.bind(createInfo.socketId, '0.0.0.0', port, function (result) { + chrome.sockets.udp.send(createInfo.socketId, data, '255.255.255.255', port, function (result) { + if (result < 0) { + console.log('send fail: ' + result); + chrome.sockets.udp.close(createInfo.socketId); + + if (!isTimedOut) { + clearTimeout(timeout); + deferred.resolveWith(null, [servers]); + } + + } else { + + console.log('sendTo: success ' + port); + + if (!isTimedOut) { + chrome.sockets.udp.onReceive.addListener(onReceive); + } + } + }); + }); + }); + return deferred.promise(); } };