Commit 3060ff08 authored by Gautam Chitnis's avatar Gautam Chitnis

Fix (1/2) (playlist): Implementing polling for playlist

This commit starts the implementation of polling the playlist population proces.

Gautam C.
parent 3c3f7d0c
--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;
......@@ -45,7 +46,7 @@ Vue.component('playlist', {
}
},
refreshPlaylist: function() {
sendCommand(1);
poll(1,null,2000,150);//.then(poll(1,null,2000,150));
},
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