fix linting issues and add servers to web config

This commit is contained in:
dkanada 2020-09-12 09:12:40 +09:00
parent 4553215841
commit 982ae411c5
5 changed files with 23 additions and 14 deletions

View File

@ -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();

View File

@ -1,5 +1,6 @@
{
"multiserver": false,
"servers": [],
"themes": [
{
"name": "Apple TV",

View File

@ -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();
});

View File

@ -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;

View File

@ -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;