2020-08-16 20:24:45 +02:00
|
|
|
import globalize from '../../scripts/globalize';
|
2020-10-17 19:08:56 +01:00
|
|
|
import ServerConnections from '../../components/ServerConnections';
|
2020-10-18 15:18:15 +01:00
|
|
|
import alert from '../../components/alert';
|
2023-03-08 11:03:48 -05:00
|
|
|
import { PluginType } from '../../types/plugin.ts';
|
2018-10-23 01:05:09 +03:00
|
|
|
|
2020-08-07 07:42:09 +01:00
|
|
|
function showErrorMessage() {
|
2020-10-18 15:18:15 +01:00
|
|
|
return alert(globalize.translate('MessagePlayAccessRestricted'));
|
2020-08-07 07:42:09 +01:00
|
|
|
}
|
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';
|
2023-03-08 11:03:48 -05:00
|
|
|
this.type = PluginType.PreplayIntercept;
|
2019-01-10 15:39:37 +03:00
|
|
|
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-10-17 19:08:56 +01:00
|
|
|
return ServerConnections.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();
|
|
|
|
}
|
|
|
|
|
2021-02-03 09:49:08 +01:00
|
|
|
return showErrorMessage().finally(Promise.reject);
|
2019-01-10 15:39:37 +03:00
|
|
|
});
|
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;
|