Fix #316 . Opening a large channel in the UI causes playback to freeze for a second.
This commit is contained in:
parent
df382f26f7
commit
f134a75e98
@ -16,6 +16,7 @@
|
||||
"author": "Dan Ferguson",
|
||||
"license": "ISC",
|
||||
"dependencies": {
|
||||
"JSONStream": "1.0.5",
|
||||
"angular": "^1.7.9",
|
||||
"angular-router-browserify": "0.0.2",
|
||||
"angular-vs-repeat": "2.0.13",
|
||||
|
||||
68
src/api.js
68
src/api.js
@ -5,6 +5,7 @@ const fs = require('fs')
|
||||
const databaseMigration = require('./database-migration');
|
||||
const channelCache = require('./channel-cache')
|
||||
const constants = require('./constants');
|
||||
const JSONStream = require('JSONStream');
|
||||
const FFMPEGInfo = require('./ffmpeg-info');
|
||||
const PlexServerDB = require('./dao/plex-server-db');
|
||||
const Plex = require("./plex.js");
|
||||
@ -232,9 +233,10 @@ function api(db, channelDB, fillerDB, customShowDB, xmltvInterval, guideService
|
||||
try {
|
||||
let number = parseInt(req.params.number, 10);
|
||||
let channel = await channelCache.getChannelConfig(channelDB, number);
|
||||
|
||||
if (channel.length == 1) {
|
||||
channel = channel[0];
|
||||
res.send( channel );
|
||||
channel = channel[0];
|
||||
res.send(channel);
|
||||
} else {
|
||||
return res.status(404).send("Channel not found");
|
||||
}
|
||||
@ -243,6 +245,61 @@ function api(db, channelDB, fillerDB, customShowDB, xmltvInterval, guideService
|
||||
res.status(500).send("error");
|
||||
}
|
||||
})
|
||||
router.get('/api/channel/programless/:number', async (req, res) => {
|
||||
try {
|
||||
let number = parseInt(req.params.number, 10);
|
||||
let channel = await channelCache.getChannelConfig(channelDB, number);
|
||||
|
||||
if (channel.length == 1) {
|
||||
channel = channel[0];
|
||||
let copy = {};
|
||||
Object.keys(channel).forEach( (key) => {
|
||||
if (key != 'programs') {
|
||||
copy[key] = channel[key];
|
||||
}
|
||||
} );
|
||||
res.send(copy);
|
||||
} else {
|
||||
return res.status(404).send("Channel not found");
|
||||
}
|
||||
} catch(err) {
|
||||
console.error(err);
|
||||
res.status(500).send("error");
|
||||
}
|
||||
})
|
||||
|
||||
router.get('/api/channel/programs/:number', async (req, res) => {
|
||||
try {
|
||||
let number = parseInt(req.params.number, 10);
|
||||
let channel = await channelCache.getChannelConfig(channelDB, number);
|
||||
|
||||
if (channel.length == 1) {
|
||||
channel = channel[0];
|
||||
let programs = channel.programs;
|
||||
if (typeof(programs) === 'undefined') {
|
||||
return res.status(404).send("Channel doesn't have programs?");
|
||||
}
|
||||
res.writeHead(200, {
|
||||
'Content-Type': 'application.json'
|
||||
});
|
||||
|
||||
let transformStream = JSONStream.stringify(); //false makes it not add 'separators'
|
||||
transformStream.pipe(res);
|
||||
|
||||
for (let i = 0; i < programs.length; i++) {
|
||||
transformStream.write( programs[i] );
|
||||
await throttle();
|
||||
}
|
||||
transformStream.end();
|
||||
|
||||
} else {
|
||||
return res.status(404).send("Channel not found");
|
||||
}
|
||||
} catch(err) {
|
||||
console.error(err);
|
||||
res.status(500).send("error");
|
||||
}
|
||||
})
|
||||
router.get('/api/channel/description/:number', async (req, res) => {
|
||||
try {
|
||||
let number = parseInt(req.params.number, 10);
|
||||
@ -1014,3 +1071,10 @@ function api(db, channelDB, fillerDB, customShowDB, xmltvInterval, guideService
|
||||
|
||||
return router
|
||||
}
|
||||
|
||||
|
||||
async function throttle() {
|
||||
return new Promise((resolve) => {
|
||||
setImmediate(() => resolve());
|
||||
});
|
||||
}
|
||||
|
||||
@ -80,7 +80,12 @@ module.exports = function ($scope, dizquetv) {
|
||||
$scope.showChannelConfig = true
|
||||
} else {
|
||||
$scope.channels[index].pending = true;
|
||||
let ch = await dizquetv.getChannel($scope.channels[index].number);
|
||||
let p = await Promise.all([
|
||||
dizquetv.getChannelProgramless($scope.channels[index].number),
|
||||
dizquetv.getChannelPrograms($scope.channels[index].number),
|
||||
]);
|
||||
let ch = p[0];
|
||||
ch.programs = p[1];
|
||||
let newObj = ch;
|
||||
newObj.startTime = new Date(newObj.startTime)
|
||||
$scope.originalChannelNumber = newObj.number;
|
||||
|
||||
@ -137,6 +137,13 @@ module.exports = function ($http, $q) {
|
||||
return $http.get(`/api/channel/description/${number}`).then( (d) => { return d.data } )
|
||||
},
|
||||
|
||||
getChannelProgramless: (number) => {
|
||||
return $http.get(`/api/channel/programless/${number}`).then( (d) => { return d.data })
|
||||
},
|
||||
getChannelPrograms: (number) => {
|
||||
return $http.get(`/api/channel/programs/${number}`).then( (d) => { return d.data } )
|
||||
},
|
||||
|
||||
|
||||
getChannelNumbers: () => {
|
||||
return $http.get('/api/channelNumbers').then( (d) => { return d.data } )
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user