2020-04-03 03:20:06 +09:00
|
|
|
/* eslint-disable indent */
|
2020-09-08 02:05:02 -04:00
|
|
|
import { AppStorage, Events } from 'jellyfin-apiclient';
|
2018-10-23 01:05:09 +03:00
|
|
|
|
|
|
|
function getKey(name, userId) {
|
2019-01-10 15:39:37 +03:00
|
|
|
if (userId) {
|
|
|
|
name = userId + '-' + name;
|
|
|
|
}
|
|
|
|
|
|
|
|
return name;
|
2018-10-23 01:05:09 +03:00
|
|
|
}
|
|
|
|
|
2020-04-03 03:16:06 +09:00
|
|
|
export function enableAutoLogin(val) {
|
2020-04-26 16:49:21 +02:00
|
|
|
if (val !== undefined) {
|
2020-10-18 14:19:41 +01:00
|
|
|
set('enableAutoLogin', val.toString());
|
2019-01-10 15:39:37 +03:00
|
|
|
}
|
2020-01-24 02:57:29 +09:00
|
|
|
|
2020-10-18 14:19:41 +01:00
|
|
|
return get('enableAutoLogin') !== 'false';
|
2020-04-03 03:16:06 +09:00
|
|
|
}
|
2019-01-10 15:39:37 +03:00
|
|
|
|
2020-04-03 03:16:06 +09:00
|
|
|
export function enableSystemExternalPlayers(val) {
|
2020-04-26 16:49:21 +02:00
|
|
|
if (val !== undefined) {
|
2020-10-18 14:19:41 +01:00
|
|
|
set('enableSystemExternalPlayers', val.toString());
|
2020-02-16 22:11:36 +09:00
|
|
|
}
|
|
|
|
|
2020-10-18 14:19:41 +01:00
|
|
|
return get('enableSystemExternalPlayers') === 'true';
|
2020-04-03 03:16:06 +09:00
|
|
|
}
|
2020-02-16 22:11:36 +09:00
|
|
|
|
2020-04-03 03:16:06 +09:00
|
|
|
export function enableAutomaticBitrateDetection(isInNetwork, mediaType, val) {
|
2020-07-17 11:30:56 +01:00
|
|
|
const key = 'enableautobitratebitrate-' + mediaType + '-' + isInNetwork;
|
2020-04-26 16:49:21 +02:00
|
|
|
if (val !== undefined) {
|
2019-01-10 15:39:37 +03:00
|
|
|
if (isInNetwork && mediaType === 'Audio') {
|
|
|
|
val = true;
|
|
|
|
}
|
|
|
|
|
2020-10-18 14:19:41 +01:00
|
|
|
set(key, val.toString());
|
2019-01-10 15:39:37 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if (isInNetwork && mediaType === 'Audio') {
|
|
|
|
return true;
|
|
|
|
} else {
|
2020-10-18 14:19:41 +01:00
|
|
|
return get(key) !== 'false';
|
2019-01-10 15:39:37 +03:00
|
|
|
}
|
2020-04-03 03:16:06 +09:00
|
|
|
}
|
2019-01-10 15:39:37 +03:00
|
|
|
|
2020-04-03 03:16:06 +09:00
|
|
|
export function maxStreamingBitrate(isInNetwork, mediaType, val) {
|
2020-07-17 11:30:56 +01:00
|
|
|
const key = 'maxbitrate-' + mediaType + '-' + isInNetwork;
|
2020-04-26 16:49:21 +02:00
|
|
|
if (val !== undefined) {
|
2019-01-10 15:39:37 +03:00
|
|
|
if (isInNetwork && mediaType === 'Audio') {
|
|
|
|
// nothing to do, this is always a max value
|
|
|
|
} else {
|
2020-10-18 14:19:41 +01:00
|
|
|
set(key, val);
|
2019-01-10 15:39:37 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (isInNetwork && mediaType === 'Audio') {
|
|
|
|
// return a huge number so that it always direct plays
|
|
|
|
return 150000000;
|
|
|
|
} else {
|
2020-10-18 14:19:41 +01:00
|
|
|
return parseInt(get(key) || '0') || 1500000;
|
2019-01-10 15:39:37 +03:00
|
|
|
}
|
2020-04-03 03:16:06 +09:00
|
|
|
}
|
2019-01-10 15:39:37 +03:00
|
|
|
|
2020-04-03 03:16:06 +09:00
|
|
|
export function maxStaticMusicBitrate(val) {
|
2020-04-26 16:49:21 +02:00
|
|
|
if (val !== undefined) {
|
2020-10-18 14:19:41 +01:00
|
|
|
set('maxStaticMusicBitrate', val);
|
2019-01-10 15:39:37 +03:00
|
|
|
}
|
|
|
|
|
2020-07-17 11:30:56 +01:00
|
|
|
const defaultValue = 320000;
|
2020-10-18 14:19:41 +01:00
|
|
|
return parseInt(get('maxStaticMusicBitrate') || defaultValue.toString()) || defaultValue;
|
2020-04-03 03:16:06 +09:00
|
|
|
}
|
2019-01-10 15:39:37 +03:00
|
|
|
|
2020-04-03 03:16:06 +09:00
|
|
|
export function maxChromecastBitrate(val) {
|
2020-04-26 16:49:21 +02:00
|
|
|
if (val !== undefined) {
|
2020-10-18 14:19:41 +01:00
|
|
|
set('chromecastBitrate1', val);
|
2019-01-10 15:39:37 +03:00
|
|
|
}
|
|
|
|
|
2020-10-18 14:19:41 +01:00
|
|
|
val = get('chromecastBitrate1');
|
2019-01-10 15:39:37 +03:00
|
|
|
return val ? parseInt(val) : null;
|
2020-04-03 03:16:06 +09:00
|
|
|
}
|
2019-01-10 15:39:37 +03:00
|
|
|
|
2020-04-03 03:16:06 +09:00
|
|
|
export function set(name, value, userId) {
|
2020-10-18 14:19:41 +01:00
|
|
|
const currentValue = get(name, userId);
|
2020-09-08 02:05:02 -04:00
|
|
|
AppStorage.setItem(getKey(name, userId), value);
|
2019-01-10 15:39:37 +03:00
|
|
|
|
|
|
|
if (currentValue !== value) {
|
2020-09-08 02:05:02 -04:00
|
|
|
Events.trigger(this, 'change', [name]);
|
2019-01-10 15:39:37 +03:00
|
|
|
}
|
2020-04-03 03:16:06 +09:00
|
|
|
}
|
2019-01-10 15:39:37 +03:00
|
|
|
|
2020-04-03 03:16:06 +09:00
|
|
|
export function get(name, userId) {
|
2020-09-08 02:05:02 -04:00
|
|
|
return AppStorage.getItem(getKey(name, userId));
|
2020-04-03 03:16:06 +09:00
|
|
|
}
|
2019-01-10 15:39:37 +03:00
|
|
|
|
2020-04-09 00:36:44 +09:00
|
|
|
/* eslint-enable indent */
|
|
|
|
|
|
|
|
export default {
|
|
|
|
enableAutoLogin: enableAutoLogin,
|
|
|
|
enableSystemExternalPlayers: enableSystemExternalPlayers,
|
|
|
|
enableAutomaticBitrateDetection: enableAutomaticBitrateDetection,
|
|
|
|
maxStreamingBitrate: maxStreamingBitrate,
|
|
|
|
maxStaticMusicBitrate: maxStaticMusicBitrate,
|
|
|
|
maxChromecastBitrate: maxChromecastBitrate,
|
|
|
|
set: set,
|
|
|
|
get: get
|
|
|
|
};
|