Skip to content

Commit

Permalink
Fix geo routing and catch undefined servers
Browse files Browse the repository at this point in the history
  • Loading branch information
Maxou44 committed Oct 6, 2018
1 parent ebe37a5 commit 5113f15
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 10 deletions.
4 changes: 2 additions & 2 deletions core/serverManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,9 @@ serverManager.geoIp = (url, ip) => {
console.log(ip, geo);

if (typeof (stats[url].routing) !== 'undefined') {
if (typeof (stats[url].routing[geo.country + '-' + geo.region])) // 'COUNTRY-REGION' tag like 'US-TX'
if (typeof (stats[url].routing[geo.country + '-' + geo.region]) !== 'undefined') // 'COUNTRY-REGION' tag like 'US-TX'
return (stats[url].routing[geo.country + '-' + geo.region])
if (typeof (stats[url].routing[geo.country])) // 'COUNTRY' tag like 'US'
if (typeof (stats[url].routing[geo.country]) !== 'undefined') // 'COUNTRY' tag like 'US'
return (stats[url].routing[geo.country])
}
return (url);
Expand Down
21 changes: 13 additions & 8 deletions routes/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,11 @@ router.get('/video/:/transcode/universal/start.mpd', (req, res) => {

if (sessionId !== false) {
const serverUrl = serverManager.chooseServer(sessionId, getIp(req));
request(serverUrl + '/video/:/transcode/universal/stop?session=' + sessionId, (err, httpResponse, body) => {
serverManager.saveSession(req);
redirect(req, res);
});
if (typeof(serverUrl) !== 'undefined')
request(serverUrl + '/video/:/transcode/universal/stop?session=' + sessionId, (err, httpResponse, body) => {
serverManager.saveSession(req);
redirect(req, res);
});
} else {
serverManager.saveSession(req);
redirect(req, res);
Expand Down Expand Up @@ -107,7 +108,8 @@ router.get('/video/:/transcode/universal/stop', (req, res) => {
const sessionId = serverManager.getSession(req);
const serverUrl = serverManager.chooseServer(sessionId, getIp(req));

request(serverUrl + '/video/:/transcode/universal/stop?session=' + sessionId);
if (typeof(serverUrl) !== 'undefined')
request(serverUrl + '/video/:/transcode/universal/stop?session=' + sessionId);

setTimeout(() => {
serverManager.removeSession(sessionId);
Expand All @@ -122,7 +124,8 @@ router.get('/video/:/transcode/universal/ping', (req, res) => {
const sessionId = serverManager.getSession(req);
const serverUrl = serverManager.chooseServer(sessionId, getIp(req));

request(serverUrl + '/video/:/transcode/universal/ping?session=' + sessionId);
if (typeof(serverUrl) !== 'undefined')
request(serverUrl + '/video/:/transcode/universal/ping?session=' + sessionId);
});

router.get('/:/timeline', (req, res) => {
Expand Down Expand Up @@ -164,7 +167,8 @@ router.get('/:/timeline', (req, res) => {
{
cproxy.web(req, res);

request(serverUrl + '/video/:/transcode/universal/stop?session=' + sessionId);
if (typeof(serverUrl) !== 'undefined')
request(serverUrl + '/video/:/transcode/universal/stop?session=' + sessionId);
setTimeout(() => {
serverManager.removeSession(sessionId);
if (typeof(serverManager.stoppedSessions[req.query['X-Plex-Session-Identifier']]) != 'undefined')
Expand All @@ -174,7 +178,8 @@ router.get('/:/timeline', (req, res) => {
else
{
proxy.web(req, res);
request(serverUrl + '/video/:/transcode/universal/ping?session=' + sessionId);
if (typeof(serverUrl) !== 'undefined')
request(serverUrl + '/video/:/transcode/universal/ping?session=' + sessionId);
}
});

Expand Down

0 comments on commit 5113f15

Please sign in to comment.