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

Merge pull request #1693 from Camc314/migrate-to-ES6-49

Migration of playqueuemanager to ES6 module
This commit is contained in:
dkanada 2020-07-31 17:15:36 +09:00 committed by GitHub
commit b1e116885a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 89 additions and 89 deletions

View file

@ -139,6 +139,7 @@
"src/components/playback/playerSelectionMenu.js", "src/components/playback/playerSelectionMenu.js",
"src/components/playback/playersettingsmenu.js", "src/components/playback/playersettingsmenu.js",
"src/components/playback/playmethodhelper.js", "src/components/playback/playmethodhelper.js",
"src/components/playback/playqueuemanager.js",
"src/components/playback/remotecontrolautoplay.js", "src/components/playback/remotecontrolautoplay.js",
"src/components/playback/volumeosd.js", "src/components/playback/volumeosd.js",
"src/components/playbackSettings/playbackSettings.js", "src/components/playbackSettings/playbackSettings.js",

View file

@ -1,6 +1,8 @@
define(['events', 'datetime', 'appSettings', 'itemHelper', 'pluginManager', 'playQueueManager', 'userSettings', 'globalize', 'connectionManager', 'loading', 'apphost', 'screenfull'], function (events, datetime, appSettings, itemHelper, pluginManager, PlayQueueManager, userSettings, globalize, connectionManager, loading, apphost, screenfull) { define(['events', 'datetime', 'appSettings', 'itemHelper', 'pluginManager', 'playQueueManager', 'userSettings', 'globalize', 'connectionManager', 'loading', 'apphost', 'screenfull'], function (events, datetime, appSettings, itemHelper, pluginManager, PlayQueueManager, userSettings, globalize, connectionManager, loading, apphost, screenfull) {
'use strict'; 'use strict';
PlayQueueManager = PlayQueueManager.default || PlayQueueManager;
function enableLocalPlaylistManagement(player) { function enableLocalPlaylistManagement(player) {
if (player.getPlaylist) { if (player.getPlaylist) {
return false; return false;

View file

@ -1,56 +1,56 @@
define([], function () { /*eslint prefer-const: "error"*/
'use strict';
var currentId = 0; let currentId = 0;
function addUniquePlaylistItemId(item) { function addUniquePlaylistItemId(item) {
if (!item.PlaylistItemId) { if (!item.PlaylistItemId) {
item.PlaylistItemId = 'playlistItem' + currentId; item.PlaylistItemId = 'playlistItem' + currentId;
currentId++; currentId++;
}
}
function findPlaylistIndex(playlistItemId, list) {
for (let i = 0, length = list.length; i < length; i++) {
if (list[i].PlaylistItemId === playlistItemId) {
return i;
} }
} }
function findPlaylistIndex(playlistItemId, list) { return -1;
for (var i = 0, length = list.length; i < length; i++) { }
if (list[i].PlaylistItemId === playlistItemId) {
return i;
}
}
return -1; class PlayQueueManager {
} constructor() {
function PlayQueueManager() {
this._sortedPlaylist = []; this._sortedPlaylist = [];
this._playlist = []; this._playlist = [];
this._repeatMode = 'RepeatNone'; this._repeatMode = 'RepeatNone';
this._shuffleMode = 'Sorted'; this._shuffleMode = 'Sorted';
} }
PlayQueueManager.prototype.getPlaylist = function () { getPlaylist() {
return this._playlist.slice(0); return this._playlist.slice(0);
}; }
PlayQueueManager.prototype.setPlaylist = function (items) { setPlaylist(items) {
items = items.slice(0); items = items.slice(0);
for (var i = 0, length = items.length; i < length; i++) { for (let i = 0, length = items.length; i < length; i++) {
addUniquePlaylistItemId(items[i]); addUniquePlaylistItemId(items[i]);
} }
this._currentPlaylistItemId = null; this._currentPlaylistItemId = null;
this._playlist = items; this._playlist = items;
this._repeatMode = 'RepeatNone'; this._repeatMode = 'RepeatNone';
}; }
PlayQueueManager.prototype.queue = function (items) { queue(items) {
for (var i = 0, length = items.length; i < length; i++) { for (let i = 0, length = items.length; i < length; i++) {
addUniquePlaylistItemId(items[i]); addUniquePlaylistItemId(items[i]);
this._playlist.push(items[i]); this._playlist.push(items[i]);
} }
}; }
PlayQueueManager.prototype.shufflePlaylist = function () { shufflePlaylist() {
this._sortedPlaylist = []; this._sortedPlaylist = [];
for (const item of this._playlist) { for (const item of this._playlist) {
this._sortedPlaylist.push(item); this._sortedPlaylist.push(item);
@ -65,42 +65,31 @@ define([], function () {
} }
this._playlist.unshift(currentPlaylistItem); this._playlist.unshift(currentPlaylistItem);
this._shuffleMode = 'Shuffle'; this._shuffleMode = 'Shuffle';
}; }
PlayQueueManager.prototype.sortShuffledPlaylist = function () { sortShuffledPlaylist() {
this._playlist = []; this._playlist = [];
for (let item of this._sortedPlaylist) { for (const item of this._sortedPlaylist) {
this._playlist.push(item); this._playlist.push(item);
} }
this._sortedPlaylist = []; this._sortedPlaylist = [];
this._shuffleMode = 'Sorted'; this._shuffleMode = 'Sorted';
}; }
PlayQueueManager.prototype.clearPlaylist = function (clearCurrentItem = false) { clearPlaylist(clearCurrentItem = false) {
const currentPlaylistItem = this._playlist.splice(this.getCurrentPlaylistIndex(), 1)[0]; const currentPlaylistItem = this._playlist.splice(this.getCurrentPlaylistIndex(), 1)[0];
this._playlist = []; this._playlist = [];
if (!clearCurrentItem) { if (!clearCurrentItem) {
this._playlist.push(currentPlaylistItem); this._playlist.push(currentPlaylistItem);
} }
};
function arrayInsertAt(destArray, pos, arrayToInsert) {
var args = [];
args.push(pos); // where to insert
args.push(0); // nothing to remove
args = args.concat(arrayToInsert); // add on array to insert
destArray.splice.apply(destArray, args); // splice it in
} }
PlayQueueManager.prototype.queueNext = function (items) { queueNext(items) {
var i; for (let i = 0, length = items.length; i < length; i++) {
var length;
for (i = 0, length = items.length; i < length; i++) {
addUniquePlaylistItemId(items[i]); addUniquePlaylistItemId(items[i]);
} }
var currentIndex = this.getCurrentPlaylistIndex(); let currentIndex = this.getCurrentPlaylistIndex();
if (currentIndex === -1) { if (currentIndex === -1) {
currentIndex = this._playlist.length; currentIndex = this._playlist.length;
@ -109,43 +98,43 @@ define([], function () {
} }
arrayInsertAt(this._playlist, currentIndex, items); arrayInsertAt(this._playlist, currentIndex, items);
}; }
PlayQueueManager.prototype.getCurrentPlaylistIndex = function () { getCurrentPlaylistIndex() {
return findPlaylistIndex(this.getCurrentPlaylistItemId(), this._playlist); return findPlaylistIndex(this.getCurrentPlaylistItemId(), this._playlist);
}; }
PlayQueueManager.prototype.getCurrentItem = function () { getCurrentItem() {
var index = findPlaylistIndex(this.getCurrentPlaylistItemId(), this._playlist); const index = findPlaylistIndex(this.getCurrentPlaylistItemId(), this._playlist);
return index === -1 ? null : this._playlist[index]; return index === -1 ? null : this._playlist[index];
}; }
PlayQueueManager.prototype.getCurrentPlaylistItemId = function () { getCurrentPlaylistItemId() {
return this._currentPlaylistItemId; return this._currentPlaylistItemId;
}; }
PlayQueueManager.prototype.setPlaylistState = function (playlistItemId, playlistIndex) { setPlaylistState(playlistItemId, playlistIndex) {
this._currentPlaylistItemId = playlistItemId; this._currentPlaylistItemId = playlistItemId;
}; }
PlayQueueManager.prototype.setPlaylistIndex = function (playlistIndex) { setPlaylistIndex(playlistIndex) {
if (playlistIndex < 0) { if (playlistIndex < 0) {
this.setPlaylistState(null); this.setPlaylistState(null);
} else { } else {
this.setPlaylistState(this._playlist[playlistIndex].PlaylistItemId); this.setPlaylistState(this._playlist[playlistIndex].PlaylistItemId);
} }
}; }
PlayQueueManager.prototype.removeFromPlaylist = function (playlistItemIds) { removeFromPlaylist(playlistItemIds) {
if (this._playlist.length <= playlistItemIds.length) { if (this._playlist.length <= playlistItemIds.length) {
return { return {
result: 'empty' result: 'empty'
}; };
} }
var currentPlaylistItemId = this.getCurrentPlaylistItemId(); const currentPlaylistItemId = this.getCurrentPlaylistItemId();
var isCurrentIndex = playlistItemIds.indexOf(currentPlaylistItemId) !== -1; const isCurrentIndex = playlistItemIds.indexOf(currentPlaylistItemId) !== -1;
this._sortedPlaylist = this._sortedPlaylist.filter(function (item) { this._sortedPlaylist = this._sortedPlaylist.filter(function (item) {
return !playlistItemIds.includes(item.PlaylistItemId); return !playlistItemIds.includes(item.PlaylistItemId);
@ -159,17 +148,13 @@ define([], function () {
result: 'removed', result: 'removed',
isCurrentIndex: isCurrentIndex isCurrentIndex: isCurrentIndex
}; };
};
function moveInArray(array, from, to) {
array.splice(to, 0, array.splice(from, 1)[0]);
} }
PlayQueueManager.prototype.movePlaylistItem = function (playlistItemId, newIndex) { movePlaylistItem(playlistItemId, newIndex) {
var playlist = this.getPlaylist(); const playlist = this.getPlaylist();
var oldIndex; let oldIndex;
for (var i = 0, length = playlist.length; i < length; i++) { for (let i = 0, length = playlist.length; i < length; i++) {
if (playlist[i].PlaylistItemId === playlistItemId) { if (playlist[i].PlaylistItemId === playlistItemId) {
oldIndex = i; oldIndex = i;
break; break;
@ -195,30 +180,30 @@ define([], function () {
playlistItemId: playlistItemId, playlistItemId: playlistItemId,
newIndex: newIndex newIndex: newIndex
}; };
}; }
PlayQueueManager.prototype.reset = function () { reset() {
this._sortedPlaylist = []; this._sortedPlaylist = [];
this._playlist = []; this._playlist = [];
this._currentPlaylistItemId = null; this._currentPlaylistItemId = null;
this._repeatMode = 'RepeatNone'; this._repeatMode = 'RepeatNone';
this._shuffleMode = 'Sorted'; this._shuffleMode = 'Sorted';
}; }
PlayQueueManager.prototype.setRepeatMode = function (value) { setRepeatMode(value) {
const repeatModes = ['RepeatOne', 'RepeatAll', 'RepeatNone']; const repeatModes = ['RepeatOne', 'RepeatAll', 'RepeatNone'];
if (repeatModes.includes(value)) { if (repeatModes.includes(value)) {
this._repeatMode = value; this._repeatMode = value;
} else { } else {
throw new TypeError('invalid value provided for setRepeatMode'); throw new TypeError('invalid value provided for setRepeatMode');
} }
}; }
PlayQueueManager.prototype.getRepeatMode = function () { getRepeatMode() {
return this._repeatMode; return this._repeatMode;
}; }
PlayQueueManager.prototype.setShuffleMode = function (value) { setShuffleMode(value) {
switch (value) { switch (value) {
case 'Shuffle': case 'Shuffle':
this.shufflePlaylist(); this.shufflePlaylist();
@ -229,9 +214,9 @@ define([], function () {
default: default:
throw new TypeError('invalid value provided to setShuffleMode'); throw new TypeError('invalid value provided to setShuffleMode');
} }
}; }
PlayQueueManager.prototype.toggleShuffleMode = function () { toggleShuffleMode() {
switch (this._shuffleMode) { switch (this._shuffleMode) {
case 'Shuffle': case 'Shuffle':
this.setShuffleMode('Sorted'); this.setShuffleMode('Sorted');
@ -242,16 +227,16 @@ define([], function () {
default: default:
throw new TypeError('current value for shufflequeue is invalid'); throw new TypeError('current value for shufflequeue is invalid');
} }
}; }
PlayQueueManager.prototype.getShuffleMode = function () { getShuffleMode() {
return this._shuffleMode; return this._shuffleMode;
}; }
PlayQueueManager.prototype.getNextItemInfo = function () { getNextItemInfo() {
var newIndex; let newIndex;
var playlist = this.getPlaylist(); const playlist = this.getPlaylist();
var playlistLength = playlist.length; const playlistLength = playlist.length;
switch (this.getRepeatMode()) { switch (this.getRepeatMode()) {
case 'RepeatOne': case 'RepeatOne':
@ -272,7 +257,7 @@ define([], function () {
return null; return null;
} }
var item = playlist[newIndex]; const item = playlist[newIndex];
if (!item) { if (!item) {
return null; return null;
@ -282,7 +267,19 @@ define([], function () {
item: item, item: item,
index: newIndex index: newIndex
}; };
}; }
}
return PlayQueueManager; function arrayInsertAt(destArray, pos, arrayToInsert) {
}); let args = [];
args.push(pos); // where to insert
args.push(0); // nothing to remove
args = args.concat(arrayToInsert); // add on array to insert
destArray.splice.apply(destArray, args); // splice it in
}
function moveInArray(array, from, to) {
array.splice(to, 0, array.splice(from, 1)[0]);
}
export default PlayQueueManager;