Commit a6bad603 authored by Gautam Chitnis's avatar Gautam Chitnis

Fix (2/2) (playlist):Implement polling for playlist

This commit completes implementation of polling for playlist generation.
It also removes some unnecessary code generated in the last fix.

Gautam C.
parent 3060ff08
--js ../share/lua/http/src/services/command.service.js
--js ../share/lua/http/src/services/bus.service.js
--js ../share/lua/http/src/services/initialize.service.js
--js ../share/lua/http/src/services/polling.service.js
--js ../share/lua/http/src/components/player/plyr.methods.js
--js ../share/lua/http/src/components/controls/sidenav.component.js
--js ../share/lua/http/src/components/playlist/playlist.component.js
......
import { bus } from '../../services/bus.service.js';
import { sendCommand } from '../../services/command.service.js';
import { player, playItem } from '../player/plyr.methods.js';
import { poll } from '../../services/polling.service.js';
let playlistData;
......@@ -40,13 +39,17 @@ Vue.component('playlist', {
}
if(playlistData)
{
this.$parent.playlistItems = [];
for (var i = 0; i < playlistData[0].children[0].children.length; i++) {
this.addItem(0,playlistData[0].children[0].children[i].id, playlistData[0].children[0].children[i].name, playlistData[0].children[0].children[i].uri);
}
}
},
refreshPlaylist: function() {
poll(1,null,2000,150);//.then(poll(1,null,2000,150));
sendCommand(1);
setInterval(function() {
sendCommand(1);
},5000);
},
clearPlaylist: function() {
this.$parent.playlistItems = [];
......
import { sendCommand } from './command.service.js';
import { bus } from './bus.service.js';
// The polling function
export function poll(mode, param, timeout, interval) {
var endTime = Number(new Date()) + (timeout || 2000);
interval = interval || 100;
var checkCondition = function(resolve, reject) {
// If the condition is met, we're done!
var result = $.ajax({
url: 'requests/playlist.json',
data: param,
success: function (data, status, jqXHR) {
jsonData = JSON.parse(data);
bus.$emit('populatePlaylist',[jsonData]);
}
});
if(result) {
//console.log("in success");
resolve(result);
}
// If the condition isn't met but the timeout hasn't elapsed, go again
else if (Number(new Date()) < endTime) {
setTimeout(checkCondition, interval, resolve, reject);
}
// Didn't match and too much time, reject!
else {
//console.log("failed")
reject(new Error('timed out'));
}
};
return new Promise(checkCondition);
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment