2020-08-16 20:24:45 +02:00
|
|
|
import { ConnectionManager } from 'jellyfin-apiclient';
|
|
|
|
import globalize from '../../scripts/globalize';
|
2018-10-23 01:05:09 +03:00
|
|
|
|
2020-08-07 07:42:09 +01:00
|
|
|
function showErrorMessage() {
|
2020-08-16 20:24:45 +02:00
|
|
|
return import('../../components/alert').then(({default: alert}) => {
|
2020-08-07 07:42:09 +01:00
|
|
|
return alert(globalize.translate('MessagePlayAccessRestricted'));
|
|
|
|
});
|
|
|
|
}
|
2018-10-23 01:05:09 +03:00
|
|
|
|
2020-08-07 07:42:09 +01:00
|
|
|
class PlayAccessValidation {
|
|
|
|
constructor() {
|
2019-01-10 15:39:37 +03:00
|
|
|
this.name = 'Playback validation';
|
|
|
|
this.type = 'preplayintercept';
|
|
|
|
this.id = 'playaccessvalidation';
|
|
|
|
this.order = -2;
|
2018-10-23 01:05:09 +03:00
|
|
|
}
|
2019-01-10 15:39:37 +03:00
|
|
|
|
2020-08-07 07:42:09 +01:00
|
|
|
intercept(options) {
|
|
|
|
const item = options.item;
|
2019-01-10 15:39:37 +03:00
|
|
|
if (!item) {
|
|
|
|
return Promise.resolve();
|
|
|
|
}
|
2020-08-07 07:42:09 +01:00
|
|
|
const serverId = item.ServerId;
|
2019-01-10 15:39:37 +03:00
|
|
|
if (!serverId) {
|
|
|
|
return Promise.resolve();
|
|
|
|
}
|
|
|
|
|
2020-08-16 20:24:45 +02:00
|
|
|
return ConnectionManager.getApiClient(serverId).getCurrentUser().then(function (user) {
|
2019-01-10 15:39:37 +03:00
|
|
|
if (user.Policy.EnableMediaPlayback) {
|
|
|
|
return Promise.resolve();
|
|
|
|
}
|
|
|
|
|
|
|
|
// reject but don't show an error message
|
|
|
|
if (!options.fullscreen) {
|
|
|
|
return Promise.reject();
|
|
|
|
}
|
|
|
|
|
|
|
|
return showErrorMessage();
|
|
|
|
});
|
2020-08-07 07:42:09 +01:00
|
|
|
}
|
|
|
|
}
|
2019-01-10 15:39:37 +03:00
|
|
|
|
2020-08-07 07:42:09 +01:00
|
|
|
export default PlayAccessValidation;
|