Merge pull request #229 from rafaelvieiras/fix/web-errors

Improvements on Add Plex Server UX and fixed 'of null' common errors
This commit is contained in:
vexorian 2021-01-10 18:49:09 -04:00 committed by GitHub
commit 4d3998b5a6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 59 additions and 30 deletions

View File

@ -19,7 +19,7 @@
"angular": "^1.7.9",
"angular-router-browserify": "0.0.2",
"angular-vs-repeat": "2.0.13",
"random-js" : "2.1.0",
"random-js": "2.1.0",
"axios": "^0.19.2",
"body-parser": "^1.19.0",
"diskdb": "^0.1.17",
@ -27,7 +27,7 @@
"node-ssdp": "^4.0.0",
"request": "^2.88.2",
"uuid": "^8.0.0",
"node-graceful-shutdown" : "1.1.0",
"node-graceful-shutdown": "1.1.0",
"xml-writer": "^1.7.0"
},
"bin": "dist/index.js",
@ -41,7 +41,7 @@
"del-cli": "^3.0.0",
"nodemon": "^2.0.3",
"watchify": "^3.11.1",
"nexe" : "^3.3.7"
"nexe": "^3.3.7"
},
"babel": {
"plugins": [

View File

@ -18,14 +18,16 @@ module.exports = function (plex, dizquetv, $timeout) {
let servers = await dizquetv.getPlexServers();
scope.serversPending = false;
scope.servers = servers;
for (let i = 0; i < scope.servers.length; i++) {
scope.servers[i].uiStatus = 0;
scope.servers[i].backendStatus = 0;
let t = (new Date()).getTime();
scope.servers[i].uiPending = t;
scope.servers[i].backendPending = t;
scope.refreshUIStatus(t, i);
scope.refreshBackendStatus(t, i);
if(servers) {
for (let i = 0; i < scope.servers.length; i++) {
scope.servers[i].uiStatus = 0;
scope.servers[i].backendStatus = 0;
let t = (new Date()).getTime();
scope.servers[i].uiPending = t;
scope.servers[i].backendPending = t;
scope.refreshUIStatus(t, i);
scope.refreshBackendStatus(t, i);
}
}
setTimeout( () => { scope.$apply() }, 31000 );
scope.$apply();
@ -51,13 +53,15 @@ module.exports = function (plex, dizquetv, $timeout) {
scope.isAnyUIBad = () => {
let t = (new Date()).getTime();
for (let i = 0; i < scope.servers.length; i++) {
let s = scope.servers[i];
if (
(s.uiStatus == -1)
|| ( (s.uiStatus == 0) && (s.uiPending + 30000 < t) )
) {
return true;
if(scope.servers) {
for (let i = 0; i < scope.servers.length; i++) {
let s = scope.servers[i];
if (
(s.uiStatus == -1)
|| ( (s.uiStatus == 0) && (s.uiPending + 30000 < t) )
) {
return true;
}
}
}
return false;
@ -65,13 +69,15 @@ module.exports = function (plex, dizquetv, $timeout) {
scope.isAnyBackendBad = () => {
let t = (new Date()).getTime();
for (let i = 0; i < scope.servers.length; i++) {
let s = scope.servers[i];
if (
(s.backendStatus == -1)
|| ( (s.backendStatus == 0) && (s.backendPending + 30000 < t) )
) {
return true;
if(scope.servers) {
for (let i = 0; i < scope.servers.length; i++) {
let s = scope.servers[i];
if (
(s.backendStatus == -1)
|| ( (s.backendStatus == 0) && (s.backendPending + 30000 < t) )
) {
return true;
}
}
}
return false;
@ -146,7 +152,7 @@ module.exports = function (plex, dizquetv, $timeout) {
}
scope.shouldDisableSubtitles = () => {
return scope.settings.forceDirectPlay || (scope.settings.streamPath === "direct" );
return scope.settings && (scope.settings.forceDirectPlay || (scope.settings.streamPath === "direct" ));
}
scope.addPlexServer = async () => {
@ -216,10 +222,10 @@ module.exports = function (plex, dizquetv, $timeout) {
{id:"direct",description:"Direct"}
];
scope.hideIfNotPlexPath = () => {
return scope.settings.streamPath != 'plex'
return scope.settings && scope.settings.streamPath != 'plex'
};
scope.hideIfNotDirectPath = () => {
return scope.settings.streamPath != 'direct'
return scope.settings && scope.settings.streamPath != 'direct'
};
scope.maxAudioChannelsOptions=[
{id:"1",description:"1.0"},

View File

@ -17,7 +17,21 @@ module.exports = function ($http, $window, $interval) {
url: 'https://plex.tv/api/v2/pins?strong=true',
headers: headers
}).then((res) => {
$window.open('https://app.plex.tv/auth/#!?clientID=rg14zekk3pa5zp4safjwaa8z&context[device][version]=Plex OAuth&context[device][model]=Plex OAuth&code=' + res.data.code + '&context[device][product]=Plex Web')
const plexWindowSizes = {
width: 800,
height: 700
}
const plexWindowPosition = {
width: window.innerWidth / 2 + plexWindowSizes.width,
height: window.innerHeight / 2 - plexWindowSizes.height
}
const authModal = $window.open(
`https://app.plex.tv/auth/#!?clientID=rg14zekk3pa5zp4safjwaa8z&context[device][version]=Plex OAuth&context[device][model]=Plex OAuth&code=${res.data.code}&context[device][product]=Plex Web`,
"_blank",
`height=${plexWindowSizes.height}, width=${plexWindowSizes.width}, top=${plexWindowPosition.height}, left=${plexWindowPosition.width}`
);
let limit = 120000 // 2 minute time out limit
let poll = 2000 // check every 2 seconds for token
let interval = $interval(() => {
@ -29,11 +43,17 @@ module.exports = function ($http, $window, $interval) {
limit -= poll
if (limit <= 0) {
$interval.cancel(interval)
if(authModal) {
authModal.close();
}
reject('Timed Out. Failed to sign in a timely manner (2 mins)')
}
if (r2.data.authToken !== null) {
$interval.cancel(interval)
if(authModal) {
authModal.close();
}
headers['X-Plex-Token'] = r2.data.authToken
$http({
@ -63,6 +83,9 @@ module.exports = function ($http, $window, $interval) {
}
}, (err) => {
$interval.cancel(interval)
if(authModal) {
authModal.close();
}
reject(err)
})