@nolawnchairs/chromecast
Version:
Chromecast Abstraction
117 lines (116 loc) • 3.99 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var tslib_1 = require("tslib");
var ItemChangeActor;
(function (ItemChangeActor) {
ItemChangeActor[ItemChangeActor["Automatic"] = 0] = "Automatic";
ItemChangeActor[ItemChangeActor["User"] = 1] = "User";
})(ItemChangeActor || (ItemChangeActor = {}));
var MediaQueue = (function () {
function MediaQueue() {
this._started = false;
this._items = [];
this._currentItem = -1;
this._nextActor = ItemChangeActor.Automatic;
}
Object.defineProperty(MediaQueue.prototype, "started", {
get: function () {
return this._started;
},
enumerable: false,
configurable: true
});
Object.defineProperty(MediaQueue.prototype, "items", {
get: function () {
return this._items;
},
enumerable: false,
configurable: true
});
Object.defineProperty(MediaQueue.prototype, "length", {
get: function () {
return this._items.length;
},
enumerable: false,
configurable: true
});
Object.defineProperty(MediaQueue.prototype, "currentItem", {
get: function () {
return this._currentItem;
},
enumerable: false,
configurable: true
});
Object.defineProperty(MediaQueue.prototype, "current", {
get: function () {
return this._items[this._currentItem];
},
enumerable: false,
configurable: true
});
MediaQueue.prototype.start = function () {
this._started = true;
this._currentItem = 0;
};
MediaQueue.prototype.resume = function (state) {
this._items = state.items;
this._currentItem = state.currentItem;
this._started = true;
};
MediaQueue.prototype.isNextItemUserSelected = function () {
return this._nextActor == ItemChangeActor.User;
};
MediaQueue.prototype.setNextItemUserSelected = function (is) {
this._nextActor = is ? ItemChangeActor.User : ItemChangeActor.Automatic;
};
MediaQueue.prototype.end = function (clear) {
this._started = false;
if (clear)
this.clear();
};
MediaQueue.prototype.next = function (isUserAction) {
if (isUserAction === void 0) { isUserAction = false; }
if (this._currentItem < this.length) {
var nextItem = this._currentItem + 1;
this._currentItem = nextItem;
if (isUserAction)
this._nextActor = ItemChangeActor.User;
return this._items[nextItem];
}
return null;
};
MediaQueue.prototype.previous = function () {
if (this._currentItem > 0) {
var nextItem = this._currentItem - 1;
this._currentItem = nextItem;
this._nextActor = ItemChangeActor.User;
return this._items[nextItem];
}
return null;
};
MediaQueue.prototype.drain = function () {
this._items.splice(this._currentItem + 1, this._items.length - this._currentItem);
};
MediaQueue.prototype.clear = function () {
this._started = false;
this._currentItem = -1;
this._items = [];
};
MediaQueue.prototype.add = function (items) {
var _a;
(_a = this._items).push.apply(_a, items);
};
MediaQueue.prototype.append = function (item) {
this._items.push(item);
};
MediaQueue.prototype.removeItem = function (id) {
this._items.splice(id, 1);
return id == this._currentItem;
};
MediaQueue.prototype.reorderItem = function (from, to) {
var _a;
(_a = this._items).splice.apply(_a, tslib_1.__spreadArrays([to, 0], this._items.splice(from, 1)));
};
return MediaQueue;
}());
exports.default = MediaQueue;