1
0
Fork 0
mirror of https://github.com/jellyfin/jellyfin-web synced 2025-03-30 19:56:21 +00:00

Fix code issues reported by Sonar

This commit is contained in:
Ionut Andrei Oanca 2020-11-23 14:27:54 +01:00
parent 66303bdbe5
commit bbef2197dd
16 changed files with 90 additions and 89 deletions

View file

@ -1,21 +1,21 @@
/** /**
* Module that exposes SyncPlay calls to external modules. * Module that exposes SyncPlay calls to external modules.
* @module components/syncPlay/core/controller * @module components/syncPlay/core/Controller
*/ */
import * as Helper from './helper'; import * as Helper from './Helper';
/** /**
* Class that exposes SyncPlay calls to external modules. * Class that exposes SyncPlay calls to external modules.
*/ */
class SyncPlayController { class Controller {
constructor() { constructor() {
this.manager = null; this.manager = null;
} }
/** /**
* Initializes the controller. * Initializes the controller.
* @param {SyncPlayManager} syncPlayManager The SyncPlay manager. * @param {Manager} syncPlayManager The SyncPlay manager.
*/ */
init(syncPlayManager) { init(syncPlayManager) {
this.manager = syncPlayManager; this.manager = syncPlayManager;
@ -218,4 +218,4 @@ class SyncPlayController {
} }
} }
export default SyncPlayController; export default Controller;

View file

@ -1,6 +1,6 @@
/** /**
* Module that offers some utility functions. * Module that offers some utility functions.
* @module components/syncPlay/core/helper * @module components/syncPlay/core/Helper
*/ */
import { Events } from 'jellyfin-apiclient'; import { Events } from 'jellyfin-apiclient';
@ -156,9 +156,7 @@ export function translateItemsForPlayback(apiClient, items, options) {
SortBy: options.shuffle ? 'Random' : 'SortName', SortBy: options.shuffle ? 'Random' : 'SortName',
MediaTypes: 'Photo,Video' MediaTypes: 'Photo,Video'
}).then(function (result) { }).then(function (result) {
const items = result.Items; let index = result.Items.map(function (i) {
let index = items.map(function (i) {
return i.Id; return i.Id;
}).indexOf(firstItem.Id); }).indexOf(firstItem.Id);

View file

@ -1,27 +1,31 @@
/** /**
* Module that manages the SyncPlay feature. * Module that manages the SyncPlay feature.
* @module components/syncPlay/core/manager * @module components/syncPlay/core/Manager
*/ */
import { Events } from 'jellyfin-apiclient'; import { Events } from 'jellyfin-apiclient';
import * as Helper from './helper'; import * as Helper from './Helper';
import PlayerFactory from './players/factory'; import TimeSyncCore from './timeSync/TimeSyncCore';
import TimeSyncCore from './timeSync/core'; import PlaybackCore from './PlaybackCore';
import SyncPlayPlaybackCore from './playbackCore'; import QueueCore from './QueueCore';
import SyncPlayQueueCore from './queueCore'; import Controller from './Controller';
import SyncPlayController from './controller';
/** /**
* Class that manages the SyncPlay feature. * Class that manages the SyncPlay feature.
*/ */
class SyncPlayManager { class Manager {
constructor() { /**
* Creates an instance of SyncPlay Manager.
* @param {PlayerFactory} playerFactory The PlayerFactory instance.
*/
constructor(playerFactory) {
this.playerFactory = playerFactory;
this.apiClient = null; this.apiClient = null;
this.timeSyncCore = new TimeSyncCore(); this.timeSyncCore = new TimeSyncCore();
this.playbackCore = new SyncPlayPlaybackCore(); this.playbackCore = new PlaybackCore();
this.queueCore = new SyncPlayQueueCore(); this.queueCore = new QueueCore();
this.controller = new SyncPlayController(); this.controller = new Controller();
this.syncMethod = 'None'; // Used for stats. this.syncMethod = 'None'; // Used for stats.
@ -49,7 +53,7 @@ class SyncPlayManager {
this.apiClient = apiClient; this.apiClient = apiClient;
// Get default player wrapper. // Get default player wrapper.
this.playerWrapper = PlayerFactory.getDefaultWrapper(this); this.playerWrapper = this.playerFactory.getDefaultWrapper(this);
// Initialize components. // Initialize components.
this.timeSyncCore.init(this); this.timeSyncCore.init(this);
@ -77,7 +81,7 @@ class SyncPlayManager {
/** /**
* Gets the playback core. * Gets the playback core.
* @returns {SyncPlayPlaybackCore} The playback core. * @returns {PlaybackCore} The playback core.
*/ */
getPlaybackCore() { getPlaybackCore() {
return this.playbackCore; return this.playbackCore;
@ -85,7 +89,7 @@ class SyncPlayManager {
/** /**
* Gets the queue core. * Gets the queue core.
* @returns {SyncPlayQueueCore} The queue core. * @returns {QueueCore} The queue core.
*/ */
getQueueCore() { getQueueCore() {
return this.queueCore; return this.queueCore;
@ -93,7 +97,7 @@ class SyncPlayManager {
/** /**
* Gets the controller used to manage SyncPlay playback. * Gets the controller used to manage SyncPlay playback.
* @returns {SyncPlayController} The controller. * @returns {Controller} The controller.
*/ */
getController() { getController() {
return this.controller; return this.controller;
@ -144,7 +148,7 @@ class SyncPlayManager {
this.playerWrapper.unbindFromPlayer(); this.playerWrapper.unbindFromPlayer();
this.currentPlayer = player; this.currentPlayer = player;
this.playerWrapper = PlayerFactory.getWrapper(player, this); this.playerWrapper = this.playerFactory.getWrapper(player, this);
if (this.isSyncPlayEnabled()) { if (this.isSyncPlayEnabled()) {
this.playerWrapper.bindToPlayer(); this.playerWrapper.bindToPlayer();
@ -160,7 +164,7 @@ class SyncPlayManager {
this.currentPlayer = null; this.currentPlayer = null;
this.playerWrapper.unbindFromPlayer(); this.playerWrapper.unbindFromPlayer();
this.playerWrapper = PlayerFactory.getDefaultWrapper(this); this.playerWrapper = this.playerFactory.getDefaultWrapper(this);
if (this.isSyncPlayEnabled()) { if (this.isSyncPlayEnabled()) {
this.playerWrapper.bindToPlayer(); this.playerWrapper.bindToPlayer();
} }
@ -474,6 +478,4 @@ class SyncPlayManager {
} }
} }
/** SyncPlayManager singleton. */ export default Manager;
const syncPlayManager = new SyncPlayManager();
export default syncPlayManager;

View file

@ -1,15 +1,15 @@
/** /**
* Module that manages the playback of SyncPlay. * Module that manages the playback of SyncPlay.
* @module components/syncPlay/core/playbackCore * @module components/syncPlay/core/PlaybackCore
*/ */
import { Events } from 'jellyfin-apiclient'; import { Events } from 'jellyfin-apiclient';
import * as Helper from './helper'; import * as Helper from './Helper';
/** /**
* Class that manages the playback of SyncPlay. * Class that manages the playback of SyncPlay.
*/ */
class SyncPlayPlaybackCore { class PlaybackCore {
constructor() { constructor() {
this.manager = null; this.manager = null;
this.timeSyncCore = null; this.timeSyncCore = null;
@ -29,7 +29,7 @@ class SyncPlayPlaybackCore {
/** /**
* Initializes the core. * Initializes the core.
* @param {SyncPlayManager} syncPlayManager The SyncPlay manager. * @param {Manager} syncPlayManager The SyncPlay manager.
*/ */
init(syncPlayManager) { init(syncPlayManager) {
this.manager = syncPlayManager; this.manager = syncPlayManager;
@ -574,4 +574,4 @@ class SyncPlayPlaybackCore {
} }
} }
export default SyncPlayPlaybackCore; export default PlaybackCore;

View file

@ -1,14 +1,14 @@
/** /**
* Module that manages the queue of SyncPlay. * Module that manages the queue of SyncPlay.
* @module components/syncPlay/core/queueCore * @module components/syncPlay/core/QueueCore
*/ */
import * as Helper from './helper'; import * as Helper from './Helper';
/** /**
* Class that manages the queue of SyncPlay. * Class that manages the queue of SyncPlay.
*/ */
class SyncPlayQueueCore { class QueueCore {
constructor() { constructor() {
this.manager = null; this.manager = null;
this.lastPlayQueueUpdate = null; this.lastPlayQueueUpdate = null;
@ -17,7 +17,7 @@ class SyncPlayQueueCore {
/** /**
* Initializes the core. * Initializes the core.
* @param {SyncPlayManager} syncPlayManager The SyncPlay manager. * @param {Manager} syncPlayManager The SyncPlay manager.
*/ */
init(syncPlayManager) { init(syncPlayManager) {
this.manager = syncPlayManager; this.manager = syncPlayManager;
@ -369,4 +369,4 @@ class SyncPlayQueueCore {
} }
} }
export default SyncPlayQueueCore; export default QueueCore;

View file

@ -1,7 +1,10 @@
import * as Helper from './helper'; import * as Helper from './Helper';
import Manager from './manager'; import ManagerClass from './Manager';
import PlayerFactory from './players/factory'; import PlayerFactoryClass from './players/PlayerFactory';
import GenericPlayer from './players/genericPlayer'; import GenericPlayer from './players/GenericPlayer';
const PlayerFactory = new PlayerFactoryClass();
const Manager = new ManagerClass(PlayerFactory);
export default { export default {
Helper, Helper,

View file

@ -1,6 +1,6 @@
/** /**
* Module that translates events from a player to SyncPlay events. * Module that translates events from a player to SyncPlay events.
* @module components/syncPlay/core/players/genericPlayer * @module components/syncPlay/core/players/GenericPlayer
*/ */
import { Events } from 'jellyfin-apiclient'; import { Events } from 'jellyfin-apiclient';
@ -8,7 +8,7 @@ import { Events } from 'jellyfin-apiclient';
/** /**
* Class that translates events from a player to SyncPlay events. * Class that translates events from a player to SyncPlay events.
*/ */
class SyncPlayGenericPlayer { class GenericPlayer {
static type = 'generic'; static type = 'generic';
constructor(player, syncPlayManager) { constructor(player, syncPlayManager) {
@ -302,4 +302,4 @@ class SyncPlayGenericPlayer {
} }
} }
export default SyncPlayGenericPlayer; export default GenericPlayer;

View file

@ -1,22 +1,22 @@
/** /**
* Module that creates wrappers for known players. * Module that creates wrappers for known players.
* @module components/syncPlay/core/players/factory * @module components/syncPlay/core/players/PlayerFactory
*/ */
import SyncPlayGenericPlayer from './genericPlayer'; import GenericPlayer from './GenericPlayer';
/** /**
* Class that creates wrappers for known players. * Class that creates wrappers for known players.
*/ */
class SyncPlayPlayerFactory { class PlayerFactory {
constructor() { constructor() {
this.wrappers = {}; this.wrappers = {};
this.DefaultWrapper = SyncPlayGenericPlayer; this.DefaultWrapper = GenericPlayer;
} }
/** /**
* Registers a wrapper to the list of players that can be managed. * Registers a wrapper to the list of players that can be managed.
* @param {SyncPlayGenericPlayer} wrapperClass The wrapper to register. * @param {GenericPlayer} wrapperClass The wrapper to register.
*/ */
registerWrapper(wrapperClass) { registerWrapper(wrapperClass) {
console.debug('SyncPlay WrapperFactory registerWrapper:', wrapperClass.type); console.debug('SyncPlay WrapperFactory registerWrapper:', wrapperClass.type);
@ -25,7 +25,7 @@ class SyncPlayPlayerFactory {
/** /**
* Sets the default player wrapper. * Sets the default player wrapper.
* @param {SyncPlayGenericPlayer} wrapperClass The wrapper. * @param {GenericPlayer} wrapperClass The wrapper.
*/ */
setDefaultWrapper(wrapperClass) { setDefaultWrapper(wrapperClass) {
console.debug('SyncPlay WrapperFactory setDefaultWrapper:', wrapperClass.type); console.debug('SyncPlay WrapperFactory setDefaultWrapper:', wrapperClass.type);
@ -68,6 +68,4 @@ class SyncPlayPlayerFactory {
} }
} }
/** SyncPlayPlayerFactory singleton. */ export default PlayerFactory;
const playerFactory = new SyncPlayPlayerFactory();
export default playerFactory;

View file

@ -1,6 +1,6 @@
/** /**
* Module that manages time syncing with another device. * Module that manages time syncing with another device.
* @module components/syncPlay/core/timeSync/timeSync * @module components/syncPlay/core/timeSync/TimeSync
*/ */
import { Events } from 'jellyfin-apiclient'; import { Events } from 'jellyfin-apiclient';

View file

@ -1,10 +1,10 @@
/** /**
* Module that manages time syncing with several devices. * Module that manages time syncing with several devices.
* @module components/syncPlay/core/timeSync/core * @module components/syncPlay/core/timeSync/TimeSyncCore
*/ */
import { Events } from 'jellyfin-apiclient'; import { Events } from 'jellyfin-apiclient';
import TimeSyncServer from './server'; import TimeSyncServer from './TimeSyncServer';
/** /**
* Class that manages time syncing with several devices. * Class that manages time syncing with several devices.

View file

@ -1,9 +1,9 @@
/** /**
* Module that manages time syncing with server. * Module that manages time syncing with server.
* @module components/syncPlay/core/timeSync/server * @module components/syncPlay/core/timeSync/TimeSyncServer
*/ */
import TimeSync from './timeSync'; import TimeSync from './TimeSync';
/** /**
* Class that manages time syncing with server. * Class that manages time syncing with server.

View file

@ -1,14 +1,14 @@
/** /**
* Module that manages the HtmlAudioPlayer for SyncPlay. * Module that manages the HtmlAudioPlayer for SyncPlay.
* @module components/syncPlay/players/htmlAudioPlayer * @module components/syncPlay/ui/players/HtmlAudioPlayer
*/ */
import SyncPlayHtmlVideoPlayer from './htmlVideoPlayer'; import HtmlVideoPlayer from './HtmlVideoPlayer';
/** /**
* Class that manages the HtmlAudioPlayer for SyncPlay. * Class that manages the HtmlAudioPlayer for SyncPlay.
*/ */
class SyncPlayHtmlAudioPlayer extends SyncPlayHtmlVideoPlayer { class HtmlAudioPlayer extends HtmlVideoPlayer {
static type = 'htmlaudioplayer'; static type = 'htmlaudioplayer';
constructor(player, syncPlayManager) { constructor(player, syncPlayManager) {
@ -16,4 +16,4 @@ class SyncPlayHtmlAudioPlayer extends SyncPlayHtmlVideoPlayer {
} }
} }
export default SyncPlayHtmlAudioPlayer; export default HtmlAudioPlayer;

View file

@ -1,15 +1,15 @@
/** /**
* Module that manages the HtmlVideoPlayer for SyncPlay. * Module that manages the HtmlVideoPlayer for SyncPlay.
* @module components/syncPlay/players/htmlVideoPlayer * @module components/syncPlay/ui/players/HtmlVideoPlayer
*/ */
import { Events } from 'jellyfin-apiclient'; import { Events } from 'jellyfin-apiclient';
import SyncPlayNoActivePlayer from './noActivePlayer'; import NoActivePlayer from './NoActivePlayer';
/** /**
* Class that manages the HtmlVideoPlayer for SyncPlay. * Class that manages the HtmlVideoPlayer for SyncPlay.
*/ */
class SyncPlayHtmlVideoPlayer extends SyncPlayNoActivePlayer { class HtmlVideoPlayer extends NoActivePlayer {
static type = 'htmlvideoplayer'; static type = 'htmlvideoplayer';
constructor(player, syncPlayManager) { constructor(player, syncPlayManager) {
@ -152,4 +152,4 @@ class SyncPlayHtmlVideoPlayer extends SyncPlayNoActivePlayer {
} }
} }
export default SyncPlayHtmlVideoPlayer; export default HtmlVideoPlayer;

View file

@ -1,18 +1,18 @@
/** /**
* Module that manages the PlaybackManager when there's no active player. * Module that manages the PlaybackManager when there's no active player.
* @module components/syncPlay/players/genericPlayer * @module components/syncPlay/ui/players/NoActivePlayer
*/ */
import { playbackManager } from '../../../playback/playbackmanager'; import { playbackManager } from '../../../playback/playbackmanager';
import SyncPlay from 'SyncPlay'; import SyncPlay from 'SyncPlay';
import QueueManager from './queueManager'; import QueueManager from './QueueManager';
let syncPlayManager; let syncPlayManager;
/** /**
* Class that manages the PlaybackManager when there's no active player. * Class that manages the PlaybackManager when there's no active player.
*/ */
class SyncPlayNoActivePlayer extends SyncPlay.Players.GenericPlayer { class NoActivePlayer extends SyncPlay.Players.GenericPlayer {
static type = 'default'; static type = 'default';
constructor(player, _syncPlayManager) { constructor(player, _syncPlayManager) {
@ -143,25 +143,25 @@ class SyncPlayNoActivePlayer extends SyncPlay.Players.GenericPlayer {
/** /**
* Overrides PlaybackManager's sendCommand method. * Overrides PlaybackManager's sendCommand method.
*/ */
sendCommandRequest(cmd, player) { sendCommandRequest(command, player) {
console.debug('SyncPlay sendCommand:', cmd.Name, cmd); console.debug('SyncPlay sendCommand:', command.Name, command);
const controller = syncPlayManager.getController(); const controller = syncPlayManager.getController();
const playerWrapper = syncPlayManager.getPlayerWrapper(); const playerWrapper = syncPlayManager.getPlayerWrapper();
const defaultAction = (command, player) => { const defaultAction = (_command, _player) => {
playerWrapper.localSendCommand(command); playerWrapper.localSendCommand(_command);
}; };
const ignoreCallback = (command, player) => { const ignoreCallback = (_command, _player) => {
// Do nothing. // Do nothing.
}; };
const SetRepeatModeCallback = (command, player) => { const SetRepeatModeCallback = (_command, _player) => {
controller.setRepeatMode(command.Arguments.RepeatMode); controller.setRepeatMode(_command.Arguments.RepeatMode);
}; };
const SetShuffleQueueCallback = (command, player) => { const SetShuffleQueueCallback = (_command, _player) => {
controller.setShuffleMode(command.Arguments.ShuffleMode); controller.setShuffleMode(_command.Arguments.ShuffleMode);
}; };
// Commands to override. // Commands to override.
@ -172,11 +172,11 @@ class SyncPlayNoActivePlayer extends SyncPlay.Players.GenericPlayer {
}; };
// Handle command. // Handle command.
const commandHandler = overrideCommands[cmd.Name]; const commandHandler = overrideCommands[command.Name];
if (typeof commandHandler === 'function') { if (typeof commandHandler === 'function') {
commandHandler(cmd, player); commandHandler(command, player);
} else { } else {
defaultAction(cmd, player); defaultAction(command, player);
} }
} }
@ -441,4 +441,4 @@ class SyncPlayNoActivePlayer extends SyncPlay.Players.GenericPlayer {
} }
} }
export default SyncPlayNoActivePlayer; export default NoActivePlayer;

View file

@ -1,6 +1,6 @@
/** /**
* Module that replaces the PlaybackManager's queue. * Module that replaces the PlaybackManager's queue.
* @module components/syncPlay/players/queueManager * @module components/syncPlay/ui/players/QueueManager
*/ */
/** /**

View file

@ -33,9 +33,9 @@ import '../components/playback/playerSelectionMenu';
import SyncPlay from 'SyncPlay'; import SyncPlay from 'SyncPlay';
import { playbackManager } from '../components/playback/playbackmanager'; import { playbackManager } from '../components/playback/playbackmanager';
import SyncPlayToasts from '../components/syncPlay/ui/syncPlayToasts'; import SyncPlayToasts from '../components/syncPlay/ui/syncPlayToasts';
import SyncPlayNoActivePlayer from '../components/syncPlay/ui/players/noActivePlayer'; import SyncPlayNoActivePlayer from '../components/syncPlay/ui/players/NoActivePlayer';
import SyncPlayHtmlVideoPlayer from '../components/syncPlay/ui/players/htmlVideoPlayer'; import SyncPlayHtmlVideoPlayer from '../components/syncPlay/ui/players/HtmlVideoPlayer';
import SyncPlayHtmlAudioPlayer from '../components/syncPlay/ui/players/htmlAudioPlayer'; import SyncPlayHtmlAudioPlayer from '../components/syncPlay/ui/players/HtmlAudioPlayer';
// TODO: Move this elsewhere // TODO: Move this elsewhere
window.getWindowLocationSearch = function(win) { window.getWindowLocationSearch = function(win) {