diff --git a/src/components/appRouter.js b/src/components/appRouter.js index 1d25543c35..0c3c1d4533 100644 --- a/src/components/appRouter.js +++ b/src/components/appRouter.js @@ -507,7 +507,7 @@ class AppRouter { this.firstConnectionResult = null; if (firstResult && firstResult.State === 'ServerSignIn' && !route.anonymous) { - let url = ApiClient.serverAddress() + '/System/Info/Public'; + const url = ApiClient.serverAddress() + '/System/Info/Public'; fetch(url).then(response => { if (!response.ok) return Promise.reject('fetch failed'); return response.json(); diff --git a/src/config.template.json b/src/config.template.json index 0f308ccc11..2ea8f89457 100644 --- a/src/config.template.json +++ b/src/config.template.json @@ -1,5 +1,6 @@ { "multiserver": false, + "servers": [], "themes": [ { "name": "Apple TV", diff --git a/src/scripts/clientUtils.js b/src/scripts/clientUtils.js index 097abc4c91..d165666734 100644 --- a/src/scripts/clientUtils.js +++ b/src/scripts/clientUtils.js @@ -12,7 +12,7 @@ export async function serverAddress() { return Promise.resolve(apiClient.serverAddress()); } - let current = await window.connectionManager.getAvailableServers().then(servers => { + const current = await window.connectionManager.getAvailableServers().then(servers => { if (servers.length !== 0) { return Promise.resolve(servers[0].ManualAddress); } @@ -20,19 +20,20 @@ export async function serverAddress() { if (current) return Promise.resolve(current); - let urls = []; - urls.push(`${window.location.origin}/System/Info/Public`); - urls.push(`${window.location.protocol}//${window.location.hostname}:8096/System/Info/Public`); + const urls = []; + urls.push(window.location.origin); + urls.push(`${window.location.protocol}//${window.location.hostname}:8096`); + urls.push(await webSettings.getServers()); - let promises = urls.map(url => { - return fetch(url).catch(error => { + const promises = urls.map(url => { + return fetch(`${url}/System/Info/Public`).catch(error => { return Promise.resolve(); }); }); return Promise.all(promises).then(responses => { return responses.find(response => response && response.ok); - }).then(response => response.url).catch(error => { + }).then(response => response.url.replace('/System/Info/Public', '')).catch(error => { console.log(error); return Promise.resolve(); }); diff --git a/src/scripts/settings/webSettings.js b/src/scripts/settings/webSettings.js index 2ffe290d88..be28ae730f 100644 --- a/src/scripts/settings/webSettings.js +++ b/src/scripts/settings/webSettings.js @@ -46,6 +46,15 @@ export function getMultiServer() { }); } +export function getServers() { + return getConfig().then(config => { + return config.servers; + }).catch(error => { + console.log('cannot get web config:', error); + return []; + }); +} + export function getThemes() { return getConfig().then(config => { return config.themes; diff --git a/src/scripts/site.js b/src/scripts/site.js index adb0d65215..0123eceed2 100644 --- a/src/scripts/site.js +++ b/src/scripts/site.js @@ -86,11 +86,11 @@ function initClient() { return require(['connectionManagerFactory', 'apphost', 'credentialprovider', 'events', 'userSettings', 'apiclient', 'clientUtils'], function (ConnectionManager, appHost, credentialProvider, events, userSettings, apiClientFactory, clientUtils) { appHost = appHost.default || appHost; - var credentialProviderInstance = new credentialProvider(); - var promises = [appHost.init()]; + const credentialProviderInstance = new credentialProvider(); + const promises = [appHost.init()]; return Promise.all(promises).then(responses => { - var capabilities = Dashboard.capabilities(appHost); + const capabilities = Dashboard.capabilities(appHost); window.connectionManager = new ConnectionManager(credentialProviderInstance, appHost.appName(), appHost.appVersion(), appHost.deviceName(), appHost.deviceId(), capabilities); @@ -102,9 +102,7 @@ function initClient() { } console.debug('creating apiclient singleton'); - let parts = server.split('/'); - let url = parts[0] + '//' + parts[2]; - var apiClient = new apiClientFactory(url, appHost.appName(), appHost.appVersion(), appHost.deviceName(), appHost.deviceId()); + const apiClient = new apiClientFactory(server, appHost.appName(), appHost.appVersion(), appHost.deviceName(), appHost.deviceId()); apiClient.enableAutomaticNetworking = false; apiClient.manualAddressOnly = true;