Fix a few issues

This commit is contained in:
Calvin Montgomery 2014-06-12 20:29:12 -07:00
parent 6f737349db
commit 7f4e2a8882
4 changed files with 21 additions and 4 deletions

View file

@ -957,6 +957,16 @@ PlaylistModule.prototype._addItem = function (media, data, user, cb) {
}
};
function isExpired(media) {
if (media.meta.expiration && media.meta.expiration < Date.now()) {
return true;
} else if (media.type === "gd") {
return !media.object;
} else if (media.type === "vi") {
return !media.direct;
}
}
PlaylistModule.prototype.startPlayback = function (time) {
var self = this;
@ -979,7 +989,7 @@ PlaylistModule.prototype.startPlayback = function (time) {
return;
}
if (media.type === "gd" && !media.meta.object && !media.meta.failed) {
if (media.type === "gd" && isExpired(media) && !media.meta.failed) {
self.channel.activeLock.lock();
this.refreshGoogleDocs(function () {
self.channel.activeLock.release();
@ -1028,6 +1038,9 @@ PlaylistModule.prototype.startPlayback = function (time) {
if (media.type === "gd") {
this._gdRefreshTimer = setInterval(this.refreshGoogleDocs.bind(this), 3600000);
if (media.meta.expiration && media.meta.expiration < Date.now() + 3600000) {
setTimeout(this.refreshGoogleDocs.bind(this), media.meta.expiration - Date.now());
}
}
}
@ -1107,6 +1120,7 @@ PlaylistModule.prototype.refreshGoogleDocs = function (cb) {
}
self.current.media.meta = media.meta;
self.current.media.meta.expiration = Date.now() + 3600000;
self.channel.logger.log("[playlist] Auto-refreshed Google Doc video");
cb && cb();
self.channel.activeLock.release();