2020-08-14 08:46:34 +02:00
|
|
|
import appSettings from '../../../scripts/settings/appSettings';
|
|
|
|
import loading from '../../../components/loading/loading';
|
|
|
|
import globalize from '../../../scripts/globalize';
|
|
|
|
import '../../../elements/emby-button/emby-button';
|
2022-04-10 02:22:13 -04:00
|
|
|
import Dashboard from '../../../utils/dashboard';
|
2020-10-17 19:08:56 +01:00
|
|
|
import ServerConnections from '../../../components/ServerConnections';
|
2022-10-21 15:05:50 -04:00
|
|
|
import { ConnectionState } from '../../../utils/jellyfin-apiclient/ConnectionState.ts';
|
2020-07-09 16:20:32 +01:00
|
|
|
|
|
|
|
/* eslint-disable indent */
|
2019-01-11 20:36:17 +09:00
|
|
|
|
|
|
|
function handleConnectionResult(page, result) {
|
2019-01-11 20:52:44 +09:00
|
|
|
loading.hide();
|
|
|
|
switch (result.State) {
|
2022-10-21 15:05:50 -04:00
|
|
|
case ConnectionState.SignedIn: {
|
2020-07-15 09:29:15 +01:00
|
|
|
const apiClient = result.ApiClient;
|
2019-08-25 00:29:12 -07:00
|
|
|
Dashboard.onServerChanged(apiClient.getCurrentUserId(), apiClient.accessToken(), apiClient);
|
2020-05-04 12:44:12 +02:00
|
|
|
Dashboard.navigate('home.html');
|
2019-01-11 20:36:17 +09:00
|
|
|
break;
|
2020-07-15 09:29:15 +01:00
|
|
|
}
|
2022-10-21 15:05:50 -04:00
|
|
|
case ConnectionState.ServerSignIn:
|
2020-05-04 12:44:12 +02:00
|
|
|
Dashboard.navigate('login.html?serverid=' + result.Servers[0].Id, false, 'none');
|
2019-01-11 20:36:17 +09:00
|
|
|
break;
|
2022-10-21 15:05:50 -04:00
|
|
|
case ConnectionState.ServerSelection:
|
2020-05-04 12:44:12 +02:00
|
|
|
Dashboard.navigate('selectserver.html', false, 'none');
|
2019-01-11 20:36:17 +09:00
|
|
|
break;
|
2022-10-21 15:05:50 -04:00
|
|
|
case ConnectionState.ServerUpdateNeeded:
|
2019-01-11 20:36:17 +09:00
|
|
|
Dashboard.alert({
|
2020-05-04 12:44:12 +02:00
|
|
|
message: globalize.translate('ServerUpdateNeeded', '<a href="https://github.com/jellyfin/jellyfin">https://github.com/jellyfin/jellyfin</a>')
|
2019-01-11 20:36:17 +09:00
|
|
|
});
|
|
|
|
break;
|
2022-10-21 15:05:50 -04:00
|
|
|
case ConnectionState.Unavailable:
|
2019-01-11 20:36:17 +09:00
|
|
|
Dashboard.alert({
|
2020-05-04 12:44:12 +02:00
|
|
|
message: globalize.translate('MessageUnableToConnectToServer'),
|
|
|
|
title: globalize.translate('HeaderConnectionFailure')
|
2019-01-11 20:52:44 +09:00
|
|
|
});
|
2019-01-11 20:36:17 +09:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-08-25 00:29:12 -07:00
|
|
|
function submitServer(page) {
|
2019-01-11 20:52:44 +09:00
|
|
|
loading.show();
|
2020-07-15 09:29:15 +01:00
|
|
|
const host = page.querySelector('#txtServerHost').value;
|
2020-10-17 19:08:56 +01:00
|
|
|
ServerConnections.connectToAddress(host, {
|
2019-01-11 20:36:17 +09:00
|
|
|
enableAutoLogin: appSettings.enableAutoLogin()
|
|
|
|
}).then(function(result) {
|
2019-01-11 20:52:44 +09:00
|
|
|
handleConnectionResult(page, result);
|
2019-01-11 20:36:17 +09:00
|
|
|
}, function() {
|
|
|
|
handleConnectionResult(page, {
|
2022-10-21 15:05:50 -04:00
|
|
|
State: ConnectionState.Unavailable
|
2019-01-11 20:52:44 +09:00
|
|
|
});
|
|
|
|
});
|
2019-01-11 20:36:17 +09:00
|
|
|
}
|
|
|
|
|
2021-01-26 22:20:12 -05:00
|
|
|
export default function(view) {
|
2020-05-04 12:44:12 +02:00
|
|
|
view.querySelector('.addServerForm').addEventListener('submit', onServerSubmit);
|
|
|
|
view.querySelector('.btnCancel').addEventListener('click', goBack);
|
2019-01-11 20:52:44 +09:00
|
|
|
|
2020-08-14 08:46:34 +02:00
|
|
|
import('../../../components/autoFocuser').then(({default: autoFocuser}) => {
|
2019-11-02 20:38:58 +03:00
|
|
|
autoFocuser.autoFocus(view);
|
|
|
|
});
|
|
|
|
|
2019-08-25 00:29:12 -07:00
|
|
|
function onServerSubmit(e) {
|
|
|
|
submitServer(view);
|
2019-01-11 20:52:44 +09:00
|
|
|
e.preventDefault();
|
|
|
|
return false;
|
2019-01-11 20:36:17 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
function goBack() {
|
2021-04-10 13:16:07 +03:00
|
|
|
import('../../../components/appRouter').then(({appRouter}) => {
|
2019-01-11 20:52:44 +09:00
|
|
|
appRouter.back();
|
|
|
|
});
|
2019-01-11 20:36:17 +09:00
|
|
|
}
|
2020-07-15 09:29:15 +01:00
|
|
|
}
|
2020-07-09 16:20:32 +01:00
|
|
|
|
|
|
|
/* eslint-enable indent */
|