diff --git a/.eslintrc.js b/.eslintrc.js
index e7861b18..1ed7f8a2 100644
--- a/.eslintrc.js
+++ b/.eslintrc.js
@@ -21,6 +21,7 @@ module.exports = {
ignoreTemplateLiterals: true,
},
],
+
'no-console': process.env.NODE_ENV === 'production' ? 'warn' : 'off',
'no-debugger': process.env.NODE_ENV === 'production' ? 'warn' : 'off',
'import/no-extraneous-dependencies': ['error', { devDependencies: true }],
diff --git a/src/components/application/plexbrowser.vue b/src/components/application/plexbrowser.vue
index 6f5e384e..a46d23a1 100644
--- a/src/components/application/plexbrowser.vue
+++ b/src/components/application/plexbrowser.vue
@@ -221,7 +221,10 @@
v-if="Object.keys(getPlex.servers).length === 0"
xs12
>
-
No Plex Media Servers found. Make sure your server owner has shared their libraries with you!
+
+ No Plex Servers found.
+ Make sure your server owner has shared libraries with you!
+
{
+ if (server.chosenConnection) {
+ return true;
+ }
+ return false;
+ });
+ return servers;
+ },
+
+ onDeckUpStyle() {
+ if (this.onDeckOffset + 3 >= this.onDeck.MediaContainer.Metadata.length) {
+ return {
+ opacity: 0.5,
+ };
+ }
+
+ return {};
+ },
+
+ onDeckDownStyle() {
+ if (this.onDeckOffset === 0) {
+ return {
+ opacity: 0.5,
+ };
+ }
+
+ return {};
+ },
+
+ filteredShows() {
+ return this.results.filter((item) => {
+ if (!item) {
+ return false;
+ }
+ if (item.type === 'show') {
+ return true;
+ }
+ return false;
+ });
+ },
+
+ filteredEpisodes() {
+ return this.results.filter((item) => {
+ if (!item) {
+ return false;
+ }
+ if (item.type === 'episode') {
+ return true;
+ }
+ return false;
+ });
+ },
+
+ filteredMovies() {
+ return this.results.filter((item) => {
+ if (!item) {
+ return false;
+ }
+ if (item.type === 'movie') {
+ return true;
+ }
+ return false;
+ });
+ },
+
+ filteredSeasons() {
+ return this.results.filter((item) => {
+ if (!item) {
+ return false;
+ }
+ if (item.type === 'series') {
+ return true;
+ }
+ return false;
+ });
+ },
+ },
+ watch: {
+ searchWord() {
+ if (this.searchWord === '') {
+ this.results = [];
+ this.searchStatus = 'Search your available Plex Media Servers';
+ return;
+ }
+ this.searchAllServers();
+ },
+ },
+
mounted() {
this.updateOnDeck();
},
@@ -324,7 +452,7 @@ export default {
this.onDeck = await this.GET_LASTSERVER.getOnDeck(0, 10);
}
},
- subsetOnDeck(size) {
+ subsetOnDeck() {
if (
!this.onDeck
|| !this.onDeck.MediaContainer
@@ -347,44 +475,51 @@ export default {
this.setBackground();
// this.$store.commit('SET_BACKGROUND',null)
},
+
onDeckDown() {
if (
!this.onDeck
|| !this.onDeck.MediaContainer
|| !this.onDeck.MediaContainer.Metadata
) {
- return false;
+ return;
}
+
if (this.onDeckOffset - 4 < 0) {
this.onDeckOffset = 0;
} else {
this.onDeckOffset -= 4;
}
},
+
onDeckUp() {
if (
!this.onDeck
|| !this.onDeck.MediaContainer
|| !this.onDeck.MediaContainer.Metadata
) {
- return false;
+ return;
}
+
if (this.onDeckOffset + 4 >= this.onDeck.MediaContainer.Metadata.length) {
// This would overflow!
} else {
this.onDeckOffset += 4;
}
},
+
ownerOfServer(server) {
if (server.owned === '1') {
return 'you';
}
return server.sourceTitle;
},
+
setBackground() {
// this.$store.commit('SET_RANDOMBACKROUND')
// this.$store.commit('SET_BACKROUND',null)
},
+
getThumb(object) {
const w = Math.round(
Math.max(document.documentElement.clientWidth, window.innerWidth || 0),
@@ -394,6 +529,7 @@ export default {
);
return object.server.getUrlForLibraryLoc(object.thumb, w / 4, h / 4);
},
+
getArt(object) {
const w = Math.round(
Math.max(document.documentElement.clientWidth, window.innerWidth || 0),
@@ -403,164 +539,57 @@ export default {
);
return object.server.getUrlForLibraryLoc(object.art, w / 4, h / 4);
},
+
getTitleMovie(movie) {
if (movie.year) {
return `${movie.title} (${movie.year})`;
}
return movie.title;
},
+
heardBack(server) {
- for (let i = 0; i < this.serversHeardBack.length; i++) {
- const tempserver = this.serversHeardBack[i];
- if (tempserver.clientIdentifier === server.clientIdentifier) {
- return true;
- }
- }
- return false;
+ return this.serversHeardBack
+ .find((serv) => serv.clientIdentifier === server.clientIdentifier);
},
- searchAllServers: _.debounce(function () {
+
+ searchAllServers: _.debounce(() => {
if (this.searchWord === '') {
this.results = [];
this.searchStatus = 'Search your available Plex Media Servers';
return;
}
+
this.searching = true;
this.results = [];
this.serversResponded = 0;
const storedWord = this.searchWord;
- for (const i in this.getPlex.servers) {
- const server = this.getPlex.servers[i];
+
+ this.getPlex.servers.forEach((server) => {
server.search(this.searchWord).then((serverSearchResults) => {
if (storedWord !== this.searchWord) {
// Old data
return;
}
- this.serversResponded++;
+ this.serversResponded += 1;
this.serversHeardBack.push(server);
+
if (serverSearchResults) {
- for (let j = 0; j < serverSearchResults.length; j++) {
- serverSearchResults[j].server = server;
- }
- this.results = this.results.concat(serverSearchResults);
+ this.results = this.results.concat(serverSearchResults.map((results) => ({
+ ...results,
+ server,
+ })));
}
+
this.searchStatus = `Found ${this.results.length} results from ${
this.serversResponded
} servers`;
+
if (this.serversResponded === Object.keys(this.getPlex.servers).length) {
this.searching = false;
}
});
- }
+ });
}, 1000),
},
- data() {
- return {
- browsingServer: null,
- selectedItem: null,
- browsingContent: null,
-
- results: [],
- onDeckOffset: 0,
- onDeck: null,
- searchWord: '',
- searchStatus: 'Search your available Plex Media Servers',
- searching: false,
- serversHeardBack: [],
- };
- },
- watch: {
- searchWord() {
- if (this.searchWord === '') {
- this.results = [];
- this.searchStatus = 'Search your available Plex Media Servers';
- return;
- }
- this.searchAllServers();
- },
- },
- computed: {
- ...mapGetters(['GET_LASTSERVER', 'getPlex']),
- onDeckItemsPer() {
- switch (this.$vuetify.breakpoint.name) {
- case 'xs':
- return 1;
- case 'sm':
- return 2;
- case 'md':
- return 4;
- case 'lg':
- return 4;
- case 'xl':
- return 4;
- }
- },
- availableServers() {
- const servers = this.getPlex.servers.filter((server) => {
- if (server.chosenConnection) {
- return true;
- }
- return false;
- });
- return servers;
- },
- onDeckUpStyle() {
- if (this.onDeckOffset + 3 >= this.onDeck.MediaContainer.Metadata.length) {
- return {
- opacity: 0.5,
- };
- }
- },
- onDeckDownStyle() {
- if (this.onDeckOffset === 0) {
- return {
- opacity: 0.5,
- };
- }
- },
- filteredShows() {
- return this.results.filter((item) => {
- if (!item) {
- return false;
- }
- if (item.type === 'show') {
- return true;
- }
- return false;
- });
- },
- filteredEpisodes() {
- return this.results.filter((item) => {
- if (!item) {
- return false;
- }
- if (item.type === 'episode') {
- return true;
- }
- return false;
- });
- },
- filteredMovies() {
- return this.results.filter((item) => {
- if (!item) {
- return false;
- }
- if (item.type === 'movie') {
- return true;
- }
- return false;
- });
- },
- filteredSeasons() {
- return this.results.filter((item) => {
- if (!item) {
- return false;
- }
- if (item.type === 'series') {
- return true;
- }
- return false;
- });
- },
- },
};
diff --git a/src/components/application/plexbrowser/plexartist.vue b/src/components/application/plexbrowser/plexartist.vue
index 98d16cff..c5f9dc74 100644
--- a/src/components/application/plexbrowser/plexartist.vue
+++ b/src/components/application/plexbrowser/plexartist.vue
@@ -70,8 +70,8 @@
wrap
>
@@ -105,8 +105,8 @@
diff --git a/src/components/application/plexbrowser/plexlibrary.vue b/src/components/application/plexbrowser/plexlibrary.vue
index ff1b02c3..c9986b91 100644
--- a/src/components/application/plexbrowser/plexlibrary.vue
+++ b/src/components/application/plexbrowser/plexlibrary.vue
@@ -61,23 +61,15 @@
diff --git a/src/components/application/plexbrowser/plexthumb.vue b/src/components/application/plexbrowser/plexthumb.vue
index 1fe74627..dd3de649 100644
--- a/src/components/application/plexbrowser/plexthumb.vue
+++ b/src/components/application/plexbrowser/plexthumb.vue
@@ -120,21 +120,48 @@
import VanillaTilt from 'vanilla-tilt';
export default {
- components: {},
- props: [
- 'library',
- 'showServer',
- 'content',
- 'type',
- 'server',
- 'height',
- 'fullTitle',
- 'search',
- 'locked',
- 'img',
- 'bottomOnly',
- 'spoilerFilter',
- ],
+ props: {
+ showServer: {
+ type: Boolean,
+ },
+
+ content: {
+ type: Object,
+ default: () => {},
+ },
+
+ type: {
+ type: String,
+ default: '',
+ },
+
+ server: {
+ type: Object,
+ default: () => {},
+ },
+
+ height: {
+ type: Number,
+ default: 0,
+ },
+
+ fullTitle: {
+ type: Boolean,
+ },
+
+ img: {
+ type: String,
+ default: '',
+ },
+
+ bottomOnly: {
+ type: Boolean,
+ },
+
+ spoilerFilter: {
+ type: Boolean,
+ },
+ },
data() {
return {
fullheight: null,
diff --git a/src/components/application/plexclient.vue b/src/components/application/plexclient.vue
index b69d3c59..86781d24 100644
--- a/src/components/application/plexclient.vue
+++ b/src/components/application/plexclient.vue
@@ -23,7 +23,9 @@
{{ label[0] }}
- {{ object.product }} - last seen {{ lastSeenAgo }}
+
+ {{ object.product }} - last seen {{ lastSeenAgo }}
+
@@ -33,7 +35,21 @@ const moment = require('moment');
export default {
name: 'Plexclient',
- props: ['object', 'selected', 'startup', 'sidebar'],
+ props: {
+ object: {
+ type: Object,
+ default: () => {},
+ },
+
+ selected: {
+ type: Boolean,
+ },
+
+ sidebar: {
+ type: Boolean,
+ },
+ },
+
data: () => ({
platformMap: {
android: 'android',
@@ -97,7 +113,7 @@ export default {
},
lastSeenAgo() {
const now = moment(new Date().getTime());
- const end = moment.unix(parseInt(this.object.lastSeenAt));
+ const end = moment.unix(parseInt(this.object.lastSeenAt, 10));
const difference = moment.duration(now.diff(end));
return `${difference.humanize()} ago`;
},
diff --git a/src/components/application/plexsettings.vue b/src/components/application/plexsettings.vue
index cb97bfa9..58da0037 100644
--- a/src/components/application/plexsettings.vue
+++ b/src/components/application/plexsettings.vue
@@ -4,8 +4,11 @@
Blocked Plex Servers
- Used for autoplay functionality. Use this list to block SyncLounge from searching certain
- servers when attempting to autoplay content.
+
+ Used for autoplay functionality.
+ Use this list to block SyncLounge from searching certain servers when attempting to
+ autoplay content.
+
({
+ server: server.name,
+ id: server.clientIdentifier,
+ }));
},
},
+
+ methods: {
+ ...mapMutations('settings', [
+ 'SET_HIDEUSERNAME',
+ 'SET_ALTUSERNAME',
+ 'SET_BLOCKEDSERVERS',
+ ]),
+ },
};
diff --git a/src/components/application/settings.vue b/src/components/application/settings.vue
index 36d3f790..41cc90e3 100644
--- a/src/components/application/settings.vue
+++ b/src/components/application/settings.vue
@@ -83,7 +83,9 @@
:input-value="GET_SLPLAYERFORCETRANSCODE"
@change="SET_SLPLAYERFORCETRANSCODE"
/>
- WARNING: EXPERIMENTAL SETTING! DO NOT CHANGE IF YOU DO NOT UNDERSTAND THE RAMIFICATIONS.
+
+ WARNING: EXPERIMENTAL SETTING! DO NOT CHANGE IF YOU DO NOT UNDERSTAND THE RAMIFICATIONS.
+
diff --git a/src/components/application/walkthrough.vue b/src/components/application/walkthrough.vue
index ba18210a..cac72347 100644
--- a/src/components/application/walkthrough.vue
+++ b/src/components/application/walkthrough.vue
@@ -252,7 +252,7 @@ export default {
components: {
plexclient,
},
- props: ['object'],
+
data() {
return {
testClient: null,
@@ -313,11 +313,11 @@ export default {
}
},
isHttps() {
- return location.protocol === 'https:';
+ return window.location.protocol === 'https:';
},
platform() {
if (!this.testClient || !this.testClient.platform) {
- return;
+ return '';
}
return (
this.platformMap[this.testClient.platform.toLowerCase()]
@@ -392,7 +392,7 @@ export default {
this.CHOOSE_CLIENT(client);
this.gotResponse = true;
})
- .catch((e) => {
+ .catch(() => {
if (client.clientIdentifier !== this.testClient.clientIdentifier) {
return;
}
@@ -408,7 +408,7 @@ export default {
},
lastSeenAgo(clientTime) {
const now = moment(new Date().getTime());
- const end = moment.unix(parseInt(clientTime));
+ const end = moment.unix(parseInt(clientTime, 10));
const difference = moment.duration(now.diff(end));
return `${difference.humanize()} ago`;
},
diff --git a/src/components/join.vue b/src/components/join.vue
index 18f1b597..f70c5240 100644
--- a/src/components/join.vue
+++ b/src/components/join.vue
@@ -69,7 +69,9 @@
style="opacity:0.7"
class="text-center pt-3"
>
- SyncLounge is a tool to sync Plex content with your family and friends. For more info click here.
@@ -97,21 +99,7 @@ export default {
owner: null,
};
},
- watch: {
- gotDevices(to) {
- if (to) {
- if (this.$route.query.autojoin) {
- this.letsGo();
- }
- }
- },
- },
- mounted() {
- this.password = this.$route.query.password || '';
- this.room = this.$route.query.room;
- this.server = this.$route.query.server;
- this.owner = this.$route.query.owner;
- },
+
computed: {
...mapGetters('settings', [
'GET_PLEX_AUTH_TOKEN',
@@ -129,6 +117,22 @@ export default {
return !this.$store.state.plex.gotDevices;
},
},
+
+ watch: {
+ gotDevices(to) {
+ if (to) {
+ if (this.$route.query.autojoin) {
+ this.letsGo();
+ }
+ }
+ },
+ },
+ mounted() {
+ this.password = this.$route.query.password || '';
+ this.room = this.$route.query.room;
+ this.server = this.$route.query.server;
+ this.owner = this.$route.query.owner;
+ },
methods: {
async letsGo() {
this.$store.commit('SET_AUTOJOIN', true);
diff --git a/src/components/signin.vue b/src/components/signin.vue
index b042d100..2af410e0 100644
--- a/src/components/signin.vue
+++ b/src/components/signin.vue
@@ -246,6 +246,7 @@ export default {
let authToken = null;
// Check for PlexToken set via SyncLounge or Plex
if ($cookies.get('mpt')) {
+ console.log('WTFFFFFFFFFFF');
authToken = $cookies.get('mpt');
}
diff --git a/src/leftsidebar.vue b/src/leftsidebar.vue
index ad792507..6c72180f 100644
--- a/src/leftsidebar.vue
+++ b/src/leftsidebar.vue
@@ -175,7 +175,7 @@
>
@@ -302,20 +302,20 @@ export default {
return user.role === 'host';
},
percent(user) {
- let perc = (parseInt(user.time) / parseInt(user.maxTime)) * 100;
- if (isNaN(perc)) {
+ let perc = (parseInt(user.time, 10) / parseInt(user.maxTime, 10)) * 100;
+ if (Number.isNaN(perc)) {
perc = 0;
}
return perc;
},
getCurrent(user) {
- if (isNaN(user.time)) {
+ if (Number.isNaN(user.time)) {
return this.getTimeFromMs(0);
}
return this.getTimeFromMs(user.time);
},
getMax(user) {
- if (isNaN(user.maxTime)) {
+ if (Number.isNaN(user.maxTime)) {
return this.getTimeFromMs(0);
}
return this.getTimeFromMs(user.maxTime);
diff --git a/src/main.js b/src/main.js
index cc34a6c0..24af4897 100644
--- a/src/main.js
+++ b/src/main.js
@@ -152,9 +152,3 @@ new Vue({
vuetify,
render: (h) => h(App),
}).$mount('#app');
-
-global.waitFor = async (ms) => new Promise((resolve) => {
- setTimeout(() => resolve, ms);
-});
-
-global.to = (promise) => promise.then((data) => [null, data]).catch((err) => [err]);
diff --git a/src/store/modules/plex/helpers/PlexClient.js b/src/store/modules/plex/helpers/PlexClient.js
index 10cde887..9682baf9 100644
--- a/src/store/modules/plex/helpers/PlexClient.js
+++ b/src/store/modules/plex/helpers/PlexClient.js
@@ -7,55 +7,59 @@ const _PlexAuth = require('./PlexAuth.js');
const PlexAuth = new _PlexAuth();
const stringSimilarity = require('string-similarity');
-module.exports = function PlexClient() {
- this.commandId = 0;
- this.name = null;
- this.product = null;
- this.productVersion = null;
- this.platform = null;
- this.platformVersion = null;
- this.device = null;
- this.clientIdentifier = null;
- this.createdAt = null;
- this.lastSeenAt = null;
- this.provides = null;
- this.owned = null;
- this.publicAddressMatches = null;
- this.presence = null;
- this.plexConnections = null;
- this.chosenConnection = null;
- this.httpServer = null;
- this.tempId = null;
- this.events = new EventEmitter();
- this.labels = [];
+class PlexClient {
+ constructor() {
+ this.commandId = 0;
+ this.name = null;
+ this.product = null;
+ this.productVersion = null;
+ this.platform = null;
+ this.platformVersion = null;
+ this.device = null;
+ this.clientIdentifier = null;
+ this.createdAt = null;
+ this.lastSeenAt = null;
+ this.provides = null;
+ this.owned = null;
+ this.publicAddressMatches = null;
+ this.presence = null;
+ this.plexConnections = null;
+ this.chosenConnection = null;
+ this.httpServer = null;
+ this.tempId = null;
+ this.events = new EventEmitter();
+ this.labels = [];
- this.lastSyncCommand = 0;
+ this.lastSyncCommand = 0;
- this.userData = null;
+ this.userData = null;
- // Latest objects for reference in the future
- this.lastRatingKey = null;
- this.lastTimelineObject = null;
- this.oldTimelineObject = null;
- this.lastTimeline = null;
- this.oldTimeline = null;
- this.clientPlayingMetadata = null;
- this.lastSubscribe = 0;
- this.connectedstatus = 'fresh';
+ // Latest objects for reference in the future
+ this.lastRatingKey = null;
+ this.lastTimelineObject = null;
+ this.oldTimelineObject = null;
+ this.lastTimeline = null;
+ this.oldTimeline = null;
+ this.clientPlayingMetadata = null;
+ this.lastSubscribe = 0;
+ this.connectedstatus = 'fresh';
- this.eventbus = window.EventBus; // We will use this to communicate with the SLPlayer
- this.commit = null;
- this.dispatch = null;
+ this.eventbus = window.EventBus; // We will use this to communicate with the SLPlayer
+ this.commit = null;
+ this.dispatch = null;
- let previousTimeline = {};
- const differenceCache = [];
+ let previousTimeline = {};
+ const differenceCache = [];
- this.setValue = function (key, value) {
+ this.uuid = this.generateGuid();
+ }
+
+ setValue (key, value) {
this[key] = value;
this.commit('PLEX_CLIENT_SET_VALUE', [this, key, value]);
};
- this.generateGuid = function () {
+ generateGuid () {
function s4() {
return Math.floor((1 + Math.random()) * 0x10000)
.toString(16)
@@ -64,9 +68,8 @@ module.exports = function PlexClient() {
return `${s4() + s4()}-${s4()}`;
};
- this.uuid = this.generateGuid();
- this.hitApi = async function (command, params, connection, needResponse, dontSub) {
+ async hitApi (command, params, connection, needResponse, dontSub) {
if (this.clientIdentifier === 'PTPLAYER9PLUS10') {
return new Promise(async (resolve, reject) => {
// We are using the SyncLounge Player
@@ -110,7 +113,7 @@ module.exports = function PlexClient() {
return true;
};
- this.getTimeline = function () {
+ getTimeline () {
return new Promise(async (resolve, reject) => {
let data;
try {
@@ -126,7 +129,7 @@ module.exports = function PlexClient() {
// Get the timeline object from the client
};
- this.updateTimelineObject = function (result) {
+ updateTimelineObject (result) {
// Check if we are the SLPlayer
if (this.clientIdentifier === 'PTPLAYER9PLUS10') {
// SLPLAYER
@@ -164,24 +167,28 @@ module.exports = function PlexClient() {
// this.setValue('lastTimelineObject', videoTimeline)
return videoTimeline;
};
- this.pressPlay = function () {
+
+ pressPlay () {
// Press play on the client
return this.hitApi('/player/playback/play', { wait: 0 });
};
- this.pressPause = function () {
+ pressPause () {
// Press pause on the client
return this.hitApi('/player/playback/pause', { wait: 0 });
};
- this.pressStop = function () {
+
+ pressStop () {
// Press pause on the client
return this.hitApi('/player/playback/stop', { wait: 0 });
};
- this.seekTo = function (time, params) {
+
+ seekTo (time, params) {
// Seek to a time (in ms)
return this.hitApi('/player/playback/seekTo', { wait: 0, offset: Math.round(time), ...params });
};
- this.waitForMovement = function (startTime) {
+
+ waitForMovement (startTime) {
return new Promise((resolve, reject) => {
let time = 500;
if (this.clientIdentifier === 'PTPLAYER9PLUS10') {
@@ -197,7 +204,8 @@ module.exports = function PlexClient() {
}, time);
});
};
- this.skipAhead = function (current, duration) {
+
+ skipAhead (current, duration) {
return new Promise(async (resolve, reject) => {
const startedAt = new Date().getTime();
const now = this.lastTimelineObject.time;
@@ -212,13 +220,15 @@ module.exports = function PlexClient() {
resolve();
});
};
- this.cleanSeek = function (time, isSoft) {
+
+ cleanSeek (time, isSoft) {
if (isSoft && this.clientIdentifier === 'PTPLAYER9PLUS10') {
return this.seekTo(time, { softSeek: true });
}
return this.seekTo(time);
};
- this.sync = function sync(hostTimeline, SYNCFLEXIBILITY, SYNCMODE, POLLINTERVAL) {
+
+ sync (hostTimeline, SYNCFLEXIBILITY, SYNCMODE, POLLINTERVAL) {
return new Promise(async (resolve, reject) => {
if (this.clientIdentifier === 'PTPLAYER9PLUS10') {
await this.getTimeline();
@@ -268,7 +278,8 @@ module.exports = function PlexClient() {
return resolve('No sync needed');
});
};
- this.playMedia = async function (data) {
+
+ async playMedia (data) {
// Play a media item given a mediaId key and a server to play from
// We need the following variables to build our paramaters:
// MediaId Key, Offset, server MachineId,
@@ -309,7 +320,7 @@ module.exports = function PlexClient() {
});
};
- this.playContentAutomatically = function (client, hostData, servers, offset) {
+ playContentAutomatically (client, hostData, servers, offset) {
// Automatically play content on the client searching all servers based on the title
return new Promise(async (resolve, reject) => {
// First lets find all of our playable items
@@ -387,9 +398,4 @@ module.exports = function PlexClient() {
}
});
};
- const wait = (ms) => new Promise((resolve, reject) => {
- setTimeout(() => {
- resolve(ms);
- }, ms);
- });
};
diff --git a/src/store/modules/plex/helpers/PlexServer.js b/src/store/modules/plex/helpers/PlexServer.js
index f1cab6df..9c2f6187 100644
--- a/src/store/modules/plex/helpers/PlexServer.js
+++ b/src/store/modules/plex/helpers/PlexServer.js
@@ -5,38 +5,40 @@ const _PlexAuth = require('./PlexAuth.js');
const PlexAuth = new _PlexAuth();
-module.exports = function PlexServer() {
- this.name = '';
- this.product = '';
- this.productVersion = '';
- this.platform = '';
- this.platformVersion = '';
- this.device = '';
- this.clientIdentifier = '';
- this.createdAt = '';
- this.lastSeenAt = '';
- this.provides = '';
- this.owned = '';
- this.httpsRequired = '';
- this.ownerId = '';
- this.accessToken = '';
- this.sourceTitle = '';
- this.synced = '';
- this.relay = '';
- this.publicAddressMatches = '';
- this.presence = '';
- this.plexConnections = '';
- this.chosenConnection = null;
+class PlexServer {
+ constructor() {
+ this.name = '';
+ this.product = '';
+ this.productVersion = '';
+ this.platform = '';
+ this.platformVersion = '';
+ this.device = '';
+ this.clientIdentifier = '';
+ this.createdAt = '';
+ this.lastSeenAt = '';
+ this.provides = '';
+ this.owned = '';
+ this.httpsRequired = '';
+ this.ownerId = '';
+ this.accessToken = '';
+ this.sourceTitle = '';
+ this.synced = '';
+ this.relay = '';
+ this.publicAddressMatches = '';
+ this.presence = '';
+ this.plexConnections = '';
+ this.chosenConnection = null;
- this.commit = null;
+ this.commit = null;
+ }
- this.setValue = function (key, value) {
+ setValue(key, value) {
this[key] = value;
this.commit('PLEX_SERVER_SET_VALUE', [this, key, value]);
- };
+ }
// Functions
- this.hitApi = function (command, params) {
+ hitApi(command, params) {
return new Promise(async (resolve, reject) => {
try {
if (!this.chosenConnection) {
@@ -62,17 +64,20 @@ module.exports = function PlexServer() {
reject(e);
}
});
- };
- this.hitApiTestConnection = async function (command, connection) {
+ }
+
+ async hitApiTestConnection(command, connection) {
const _url = connection.uri + command;
const config = PlexAuth.getRequestConfig(this.accessToken, 7500);
const { data } = await axios.get(_url, config);
return data;
- };
- this.setChosenConnection = function (con) {
+ }
+
+ setChosenConnection(con) {
this.chosenConnection = con;
- };
- this.findConnection = function () {
+ }
+
+ findConnection() {
// This function iterates through all available connections and
// if any of them return a valid response we'll set that connection
// as the chosen connection for future use.
@@ -104,26 +109,26 @@ module.exports = function PlexServer() {
reject(new Error('Unable to find a connection'));
}
});
- };
+ }
// Functions for dealing with media
- this.search = async function (searchTerm) {
+ async search(searchTerm) {
// This function hits the PMS using the /search endpoint and returns what the server returns if valid
- return new Promise(async (resolve, reject) => {
+ return new Promise(async (resolve) => {
const result = await this.hitApi('/search', { query: searchTerm });
const validResults = [];
if (result && result.MediaContainer) {
if (result.MediaContainer.Metadata) {
- for (let i = 0; i < result.MediaContainer.Metadata.length; i++) {
+ for (let i = 0; i < result.MediaContainer.Metadata.length; i += 1) {
validResults.push(result.MediaContainer.Metadata[i]);
}
}
}
return resolve(validResults);
});
- };
+ }
- this.getMediaByRatingKey = async function (ratingKey) {
+ async getMediaByRatingKey(ratingKey) {
// This function hits the PMS and returns the item at the ratingKey
try {
const data = await this.hitApi(`/library/metadata/${ratingKey}`, {});
@@ -140,19 +145,22 @@ module.exports = function PlexServer() {
return false;
}
// return this.handleMetadata(data)
- };
- this.markWatchedByRatingKey = function (ratingKey) {
+ }
+
+ markWatchedByRatingKey(ratingKey) {
return this.hitApi('/:/scrobble', {
identifier: 'com.plexapp.plugins.library',
key: ratingKey,
});
- };
- this.getPostplay = function (ratingKey) {
+ }
+
+ getPostplay(ratingKey) {
return this.hitApi(`/hubs/metadata/${ratingKey}/postplay`, {
'X-Plex-Token': this.accessToken,
});
- };
- this.getUrlForLibraryLoc = function (location, width, height, blur) {
+ }
+
+ getUrlForLibraryLoc(location, width, height, blur) {
if (!(blur > 0)) {
blur = 0;
}
@@ -162,8 +170,9 @@ module.exports = function PlexServer() {
}&height=${Math.floor(height)}&width=${Math.floor(width)}&blur=${blur}`;
}
return '';
- };
- this.getRandomItem = async function () {
+ }
+
+ async getRandomItem() {
try {
const data = await this.getAllLibraries();
if (!data || !data.MediaContainer || !data.MediaContainer.Directory) {
@@ -182,8 +191,9 @@ module.exports = function PlexServer() {
} catch (e) {
throw new Error(e);
}
- };
- this.getAllLibraries = async function () {
+ }
+
+ async getAllLibraries() {
try {
const data = await this.hitApi('/library/sections', {});
if (data && data.MediaContainer) {
@@ -195,8 +205,9 @@ module.exports = function PlexServer() {
} catch (e) {
return false;
}
- };
- this.getLibraryContents = async function (key, start, size) {
+ }
+
+ async getLibraryContents(key, start, size) {
try {
const data = await this.hitApi(`/library/sections/${key}/all`, {
'X-Plex-Container-Start': start,
@@ -212,24 +223,28 @@ module.exports = function PlexServer() {
} catch (e) {
return false;
}
- };
- this.getRecentlyAddedAll = function (start, size) {
+ }
+
+ getRecentlyAddedAll() {
return this.hitApi('/library/recentlyAdded', {});
- };
- this.getOnDeck = function (start, size) {
+ }
+
+ getOnDeck(start, size) {
return this.hitApi('/library/onDeck', {
'X-Plex-Container-Start': start,
'X-Plex-Container-Size': size,
});
- };
- this.getRelated = function (ratingKey, size) {
+ }
+
+ getRelated(ratingKey, size) {
ratingKey = ratingKey.replace('/library/metadata/', '');
return this.hitApi(`/hubs/metadata/${ratingKey}/related`, {
excludeFields: 'summary',
count: size,
});
- };
- this.getSeriesData = function (ratingKey) {
+ }
+
+ getSeriesData(ratingKey) {
return this.hitApi(`/library/metadata/${ratingKey}`, {
includeConcerts: 1,
includeExtras: 1,
@@ -239,9 +254,9 @@ module.exports = function PlexServer() {
asyncRefreshAnalysis: 1,
asyncRefreshLocalMediaAgent: 1,
});
- };
+ }
- this.getSeriesChildren = async function (ratingKey, start, size, excludeAllLeaves, library) {
+ async getSeriesChildren(ratingKey, start, size, excludeAllLeaves, library) {
try {
const data = await this.hitApi(`/library/metadata/${ratingKey}/children`, {
'X-Plex-Container-Start': start,
@@ -249,7 +264,7 @@ module.exports = function PlexServer() {
excludeAllLeaves,
});
if (library) {
- for (let i = 0; i < data.MediaContainer.Metadata.length; i++) {
+ for (let i = 0; i < data.MediaContainer.Metadata.length; i += 1) {
data.MediaContainer.Metadata[i].librarySectionID = library;
// this.commit('SET_ITEMCACHE', [data.MediaContainer.Metadata[i].ratingKey,
// data.MediaContainer.Metadata[i]])
@@ -259,9 +274,9 @@ module.exports = function PlexServer() {
} catch (e) {
return false;
}
- };
+ }
- this.handleMetadata = function (result) {
+ handleMetadata(result) {
// This data is used in our router breadcrumbs
if (result) {
if (
@@ -269,7 +284,7 @@ module.exports = function PlexServer() {
&& result.MediaContainer.Metadata
&& result.MediaContainer.Metadata.length > 0
) {
- for (let i = 0; i < result.MediaContainer.Metadata.length; i++) {
+ for (let i = 0; i < result.MediaContainer.Metadata.length; i += 1) {
result.MediaContainer.Metadata[i].machineIdentifier = this.clientIdentifier;
const item = result.MediaContainer.Metadata[i];
if (result.MediaContainer.Metadata[i].ratingKey) {
@@ -313,5 +328,7 @@ module.exports = function PlexServer() {
}
return result.MediaContainer.Metadata;
}
- };
-};
+ }
+}
+
+export default PlexServer;