dash-shaka-playback
Advanced tools
Comparing version 3.1.0 to 3.2.0
@@ -109,3 +109,4 @@ (function webpackUniversalModuleDefinition(root, factory) { | ||
function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); } | ||
function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); } | ||
Object.defineProperty(exports, "__esModule", { | ||
@@ -115,38 +116,54 @@ value: true | ||
exports["default"] = void 0; | ||
var _clappr = __webpack_require__(/*! clappr */ "clappr"); | ||
var _shakaPlayer = _interopRequireDefault(__webpack_require__(/*! shaka-player */ "shaka-player")); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; } | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } } | ||
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; } | ||
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); } | ||
function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); } | ||
function _get() { if (typeof Reflect !== "undefined" && Reflect.get) { _get = Reflect.get.bind(); } else { _get = function _get(target, property, receiver) { var base = _superPropBase(target, property); if (!base) return; var desc = Object.getOwnPropertyDescriptor(base, property); if (desc.get) { return desc.get.call(arguments.length < 3 ? target : receiver); } return desc.value; }; } return _get.apply(this, arguments); } | ||
function _get(target, property, receiver) { if (typeof Reflect !== "undefined" && Reflect.get) { _get = Reflect.get; } else { _get = function _get(target, property, receiver) { var base = _superPropBase(target, property); if (!base) return; var desc = Object.getOwnPropertyDescriptor(base, property); if (desc.get) { return desc.get.call(receiver); } return desc.value; }; } return _get(target, property, receiver || target); } | ||
function _superPropBase(object, property) { while (!Object.prototype.hasOwnProperty.call(object, property)) { object = _getPrototypeOf(object); if (object === null) break; } return object; } | ||
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); } | ||
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); } | ||
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } | ||
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; } | ||
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); } | ||
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); } | ||
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; } | ||
function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); } | ||
function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); } | ||
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; } | ||
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } } | ||
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); } | ||
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } } | ||
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); } | ||
var SEND_STATS_INTERVAL_MS = 30 * 1e3; | ||
var DEFAULT_LEVEL_AUTO = -1; | ||
var DashShakaPlayback = /*#__PURE__*/function (_HTML5Video) { | ||
_inherits(DashShakaPlayback, _HTML5Video); | ||
var _super = _createSuper(DashShakaPlayback); | ||
function DashShakaPlayback() { | ||
var _this; | ||
_classCallCheck(this, DashShakaPlayback); | ||
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) { | ||
args[_key] = arguments[_key]; | ||
_createClass(DashShakaPlayback, [{ | ||
key: "getDuration", | ||
value: function getDuration() { | ||
return this._duration; | ||
} | ||
_this = _super.call.apply(_super, [this].concat(args)); | ||
_this._levels = []; | ||
_this._pendingAdaptationEvent = false; | ||
_this._isShakaReadyState = false; | ||
_this._minDvrSize = typeof _this.options.shakaMinimumDvrSize === 'undefined' ? 60 : _this.options.shakaMinimumDvrSize; | ||
return _this; | ||
} | ||
_createClass(DashShakaPlayback, [{ | ||
}, { | ||
key: "getCurrentTime", | ||
value: function getCurrentTime() { | ||
if (!this.shakaPlayerInstance) return 0; | ||
var shakaMediaElement = this.shakaPlayerInstance.getMediaElement(); | ||
return shakaMediaElement ? shakaMediaElement.currentTime - this.seekRange.start : 0; | ||
} | ||
}, { | ||
key: "name", | ||
@@ -182,10 +199,9 @@ get: function get() { | ||
key: "currentLevel", | ||
get: function get() { | ||
return this._currentLevelId || DEFAULT_LEVEL_AUTO; | ||
}, | ||
set: function set(id) { | ||
var _this2 = this; | ||
this._currentLevelId = id; | ||
var isAuto = this._currentLevelId === DEFAULT_LEVEL_AUTO; | ||
this.trigger(_clappr.Events.PLAYBACK_LEVEL_SWITCH_START); | ||
if (!isAuto) { | ||
@@ -197,2 +213,3 @@ this._player.configure({ | ||
}); | ||
this._pendingAdaptationEvent = true; | ||
@@ -208,4 +225,8 @@ this.selectTrack(this.videoTracks.filter(function (t) { | ||
}); | ||
this.trigger(_clappr.Events.PLAYBACK_LEVEL_SWITCH_END); | ||
} | ||
}, | ||
get: function get() { | ||
return this._currentLevelId || DEFAULT_LEVEL_AUTO; | ||
} | ||
@@ -218,7 +239,14 @@ }, { | ||
}, { | ||
key: "getDuration", | ||
value: function getDuration() { | ||
return this._duration; | ||
key: "latency", | ||
get: function get() { | ||
if (!this.shakaPlayerInstance) return 0; | ||
return this.shakaPlayerInstance.getStats().liveLatency; | ||
} | ||
}, { | ||
key: "currentProgramDateTime", | ||
get: function get() { | ||
if (!this.shakaPlayerInstance) return null; | ||
return this.shakaPlayerInstance.getPlayheadTimeAsDate(); | ||
} | ||
}, { | ||
key: "_duration", | ||
@@ -230,9 +258,2 @@ get: function get() { | ||
}, { | ||
key: "getCurrentTime", | ||
value: function getCurrentTime() { | ||
if (!this.shakaPlayerInstance) return 0; | ||
var shakaMediaElement = this.shakaPlayerInstance.getMediaElement(); | ||
return shakaMediaElement ? shakaMediaElement.currentTime - this.seekRange.start : 0; | ||
} | ||
}, { | ||
key: "_startTime", | ||
@@ -259,3 +280,46 @@ get: function get() { | ||
} | ||
}], [{ | ||
key: "canPlay", | ||
value: function canPlay(resource) { | ||
var mimeType = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : ''; | ||
_shakaPlayer["default"].polyfill.installAll(); | ||
var browserSupported = _shakaPlayer["default"].Player.isBrowserSupported(); | ||
var resourceParts = resource.split('?')[0].match(/.*\.(.*)$/) || []; | ||
return browserSupported && (resourceParts[1] === 'mpd' || mimeType.indexOf('application/dash+xml') > -1); | ||
} | ||
}, { | ||
key: "Events", | ||
get: function get() { | ||
return { | ||
SHAKA_READY: 'shaka:ready' | ||
}; | ||
} | ||
}, { | ||
key: "shakaPlayer", | ||
get: function get() { | ||
return _shakaPlayer["default"]; | ||
} | ||
}]); | ||
function DashShakaPlayback() { | ||
var _this; | ||
_classCallCheck(this, DashShakaPlayback); | ||
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) { | ||
args[_key] = arguments[_key]; | ||
} | ||
_this = _super.call.apply(_super, [this].concat(args)); | ||
_this._levels = []; | ||
_this._pendingAdaptationEvent = false; | ||
_this._isShakaReadyState = false; | ||
_this._minDvrSize = typeof _this.options.shakaMinimumDvrSize === 'undefined' ? 60 : _this.options.shakaMinimumDvrSize; | ||
return _this; | ||
} | ||
_createClass(DashShakaPlayback, [{ | ||
key: "getProgramDateTime", | ||
@@ -278,5 +342,7 @@ value: function getProgramDateTime() { | ||
_clappr.Log.warn('Attempt to seek to a negative time. Resetting to live point. Use seekToLivePoint() to seek to the live point.'); | ||
time = this._duration; | ||
} | ||
// assume live if time within 3 seconds of end of stream | ||
} // assume live if time within 3 seconds of end of stream | ||
this.dvrEnabled && this._updateDvr(time < this._duration - 3); | ||
@@ -296,2 +362,3 @@ time += this._startTime; | ||
if (!this._player) this.load(); | ||
if (!this.isReady) { | ||
@@ -301,4 +368,7 @@ this.once(DashShakaPlayback.Events.SHAKA_READY, this.play); | ||
} | ||
_get(_getPrototypeOf(DashShakaPlayback.prototype), "play", this).call(this); | ||
this._startTimeUpdateTimer(); | ||
this._stopped = false; | ||
@@ -311,2 +381,3 @@ this._src = this.el.src; | ||
if (source) this._options.src = source; | ||
this._setup(); | ||
@@ -345,3 +416,5 @@ } | ||
var _this3 = this; | ||
this._stopTimeUpdateTimer(); | ||
this._timeUpdateTimer = setInterval(function () { | ||
@@ -355,14 +428,11 @@ _this3._onTimeUpdate(); | ||
this._timeUpdateTimer && clearInterval(this._timeUpdateTimer); | ||
} | ||
} // skipping HTML5Video `_setupSrc` (on tag video) | ||
// skipping HTML5Video `_setupSrc` (on tag video) | ||
}, { | ||
key: "_setupSrc", | ||
value: function _setupSrc() {} | ||
value: function _setupSrc() {} // skipping ready event on video tag in favor of ready on shaka | ||
// skipping ready event on video tag in favor of ready on shaka | ||
}, { | ||
key: "_ready", | ||
value: function _ready() { | ||
// override with no-op | ||
value: function _ready() {// override with no-op | ||
} | ||
@@ -377,10 +447,4 @@ }, { | ||
}, { | ||
key: "isReady", | ||
get: function get() { | ||
return this._isShakaReadyState; | ||
} | ||
key: "error", | ||
// skipping error handling on video tag in favor of error on shaka | ||
}, { | ||
key: "error", | ||
value: function error(event) { | ||
@@ -398,9 +462,14 @@ _clappr.Log.error('an error was raised by the video tag', event, this.el.error); | ||
var _this4 = this; | ||
this._stopTimeUpdateTimer(); | ||
clearInterval(this.sendStatsId); | ||
this._stopped = true; | ||
if (this._player) { | ||
this._sendStats(); | ||
this._player.unload().then(function () { | ||
_get(_getPrototypeOf(DashShakaPlayback.prototype), "stop", _this4).call(_this4); | ||
_this4._player = null; | ||
@@ -416,21 +485,2 @@ _this4._isShakaReadyState = false; | ||
}, { | ||
key: "textTracks", | ||
get: function get() { | ||
return this.isReady && this._player.getTextTracks(); | ||
} | ||
}, { | ||
key: "audioTracks", | ||
get: function get() { | ||
return this.isReady && this._player.getVariantTracks().filter(function (t) { | ||
return t.mimeType.startsWith('audio/'); | ||
}); | ||
} | ||
}, { | ||
key: "videoTracks", | ||
get: function get() { | ||
return this.isReady && this._player.getVariantTracks().filter(function (t) { | ||
return t.mimeType.startsWith('video/'); | ||
}); | ||
} | ||
}, { | ||
key: "getPlaybackType", | ||
@@ -447,2 +497,3 @@ value: function getPlaybackType() { | ||
this._player.selectVariantTrack(track); | ||
if (track.mimeType.startsWith('video/')) { | ||
@@ -457,72 +508,7 @@ // we trigger the adaptation event here | ||
} | ||
/** | ||
* @override | ||
*/ | ||
}, { | ||
key: "closedCaptionsTracks", | ||
get: function get() { | ||
var id = 0; | ||
var trackId = function trackId() { | ||
return id++; | ||
}; | ||
var tracks = this.textTracks || []; | ||
return tracks.filter(function (track) { | ||
return track.kind === 'subtitle'; | ||
}).map(function (track) { | ||
return { | ||
id: trackId(), | ||
name: track.label || track.language, | ||
track: track | ||
}; | ||
}); | ||
} | ||
/** | ||
* @override | ||
*/ | ||
}, { | ||
key: "closedCaptionsTrackId", | ||
get: function get() { | ||
return _get(_getPrototypeOf(DashShakaPlayback.prototype), "closedCaptionsTrackId", this); | ||
} | ||
/** | ||
* @override | ||
*/, | ||
set: function set(trackId) { | ||
if (!this._player) { | ||
return; | ||
} | ||
var tracks = this.closedCaptionsTracks; | ||
var showingTrack; | ||
// Note: -1 is for hide all tracks | ||
if (trackId !== -1) { | ||
showingTrack = tracks.find(function (track) { | ||
return track.id === trackId; | ||
}); | ||
if (!showingTrack) { | ||
_clappr.Log.warn("Track id \"".concat(trackId, "\" not found")); | ||
return; | ||
} | ||
if (this._shakaTTVisible && showingTrack.track.active === true) { | ||
_clappr.Log.info("Track id \"".concat(trackId, "\" already showing")); | ||
return; | ||
} | ||
} | ||
if (showingTrack) { | ||
this._player.selectTextTrack(showingTrack.track); | ||
this._player.setTextTrackVisibility(true); | ||
this._enableShakaTextTrack(true); | ||
} else { | ||
this._player.setTextTrackVisibility(false); | ||
this._enableShakaTextTrack(false); | ||
} | ||
this._ccTrackId = trackId; | ||
this.trigger(_clappr.Events.PLAYBACK_SUBTITLE_CHANGED, { | ||
id: trackId | ||
}); | ||
} | ||
}, { | ||
key: "_enableShakaTextTrack", | ||
@@ -535,2 +521,3 @@ value: function _enableShakaTextTrack(isEnable) { | ||
} | ||
this._shakaTTVisible = isEnable; | ||
@@ -549,2 +536,3 @@ Array.from(this.el.textTracks).filter(function (track) { | ||
} | ||
if (this.hasClosedCaptionsTracks) { | ||
@@ -555,2 +543,3 @@ this.trigger(_clappr.Events.PLAYBACK_SUBTITLE_AVAILABLE); | ||
} | ||
this._ccIsSetup = true; | ||
@@ -562,4 +551,7 @@ } | ||
var _this5 = this; | ||
this._stopTimeUpdateTimer(); | ||
clearInterval(this.sendStatsId); | ||
if (this._player) { | ||
@@ -570,2 +562,3 @@ this._player.destroy().then(function () { | ||
_this5._destroy(); | ||
_clappr.Log.error('shaka could not be destroyed'); | ||
@@ -576,2 +569,3 @@ }); | ||
} | ||
_get(_getPrototypeOf(DashShakaPlayback.prototype), "destroy", this).call(this); | ||
@@ -583,9 +577,14 @@ } | ||
var _this6 = this; | ||
this._isShakaReadyState = false; | ||
this._ccIsSetup = false; | ||
var runAllSteps = function runAllSteps() { | ||
_this6._player = _this6._createPlayer(); | ||
_this6._setInitialConfig(); | ||
_this6._loadSource(); | ||
}; | ||
this._player ? this._player.destroy().then(function () { | ||
@@ -614,2 +613,3 @@ return runAllSteps(); | ||
var _this7 = this; | ||
this._player.load(this._options.src).then(function () { | ||
@@ -634,5 +634,4 @@ return _this7._loaded(); | ||
this.trigger(_clappr.Events.PLAYBACK_TIMEUPDATE, update, this.name); | ||
} | ||
} // skipping HTML5 `_handleBufferingEvents` in favor of shaka buffering events | ||
// skipping HTML5 `_handleBufferingEvents` in favor of shaka buffering events | ||
}, { | ||
@@ -664,4 +663,7 @@ key: "_handleBufferingEvents", | ||
this._onShakaReady(); | ||
this._startToSendStats(); | ||
this._fillLevels(); | ||
this._checkForClosedCaptions(); | ||
@@ -686,2 +688,3 @@ } | ||
var _this8 = this; | ||
var intervalMs = this._options.shakaSendStatsInterval || SEND_STATS_INTERVAL_MS; | ||
@@ -709,6 +712,8 @@ this.sendStatsId = setInterval(function () { | ||
}; | ||
var _ref = error.shakaError.detail || error.shakaError, | ||
category = _ref.category, | ||
code = _ref.code, | ||
severity = _ref.severity; | ||
category = _ref.category, | ||
code = _ref.code, | ||
severity = _ref.severity; | ||
if (error.videoError || !code && !category) return _get(_getPrototypeOf(DashShakaPlayback.prototype), "_onError", this).call(this); | ||
@@ -723,3 +728,5 @@ var isCritical = severity === _shakaPlayer["default"].util.Error.Severity.CRITICAL; | ||
var formattedError = this.createError(errorData); | ||
_clappr.Log.error('Shaka error event:', formattedError); | ||
this.trigger(_clappr.Events.PLAYBACK_ERROR, formattedError); | ||
@@ -733,7 +740,9 @@ } | ||
})[0]; | ||
this._fillLevels(); | ||
// update stats that may have changed before we trigger event | ||
this._fillLevels(); // update stats that may have changed before we trigger event | ||
// so that user can rely on stats data when handling event | ||
this._sendStats(); | ||
if (this._pendingAdaptationEvent) { | ||
@@ -743,3 +752,5 @@ this.trigger(_clappr.Events.PLAYBACK_LEVEL_SWITCH_END); | ||
} | ||
_clappr.Log.debug('an adaptation has happened:', activeVideo); | ||
this.highDefinition = activeVideo.height >= 720; | ||
@@ -766,28 +777,110 @@ this.trigger(_clappr.Events.PLAYBACK_HIGHDEFINITIONUPDATE, this.highDefinition); | ||
this._isShakaReadyState = false; | ||
_clappr.Log.debug('shaka was destroyed'); | ||
} | ||
}], [{ | ||
key: "Events", | ||
}, { | ||
key: "isReady", | ||
get: function get() { | ||
return { | ||
SHAKA_READY: 'shaka:ready' | ||
}; | ||
return this._isShakaReadyState; | ||
} | ||
}, { | ||
key: "shakaPlayer", | ||
key: "textTracks", | ||
get: function get() { | ||
return _shakaPlayer["default"]; | ||
return this.isReady && this._player.getTextTracks(); | ||
} | ||
}, { | ||
key: "canPlay", | ||
value: function canPlay(resource) { | ||
var mimeType = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : ''; | ||
_shakaPlayer["default"].polyfill.installAll(); | ||
var browserSupported = _shakaPlayer["default"].Player.isBrowserSupported(); | ||
var resourceParts = resource.split('?')[0].match(/.*\.(.*)$/) || []; | ||
return browserSupported && (resourceParts[1] === 'mpd' || mimeType.indexOf('application/dash+xml') > -1); | ||
key: "audioTracks", | ||
get: function get() { | ||
return this.isReady && this._player.getVariantTracks().filter(function (t) { | ||
return t.mimeType.startsWith('audio/'); | ||
}); | ||
} | ||
}, { | ||
key: "videoTracks", | ||
get: function get() { | ||
return this.isReady && this._player.getVariantTracks().filter(function (t) { | ||
return t.mimeType.startsWith('video/'); | ||
}); | ||
} | ||
}, { | ||
key: "closedCaptionsTracks", | ||
get: function get() { | ||
var id = 0; | ||
var trackId = function trackId() { | ||
return id++; | ||
}; | ||
var tracks = this.textTracks || []; | ||
return tracks.filter(function (track) { | ||
return track.kind === 'subtitle'; | ||
}).map(function (track) { | ||
return { | ||
id: trackId(), | ||
name: track.label || track.language, | ||
track: track | ||
}; | ||
}); | ||
} | ||
/** | ||
* @override | ||
*/ | ||
}, { | ||
key: "closedCaptionsTrackId", | ||
get: function get() { | ||
return _get(_getPrototypeOf(DashShakaPlayback.prototype), "closedCaptionsTrackId", this); | ||
} | ||
/** | ||
* @override | ||
*/ | ||
, | ||
set: function set(trackId) { | ||
if (!this._player) { | ||
return; | ||
} | ||
var tracks = this.closedCaptionsTracks; | ||
var showingTrack; // Note: -1 is for hide all tracks | ||
if (trackId !== -1) { | ||
showingTrack = tracks.find(function (track) { | ||
return track.id === trackId; | ||
}); | ||
if (!showingTrack) { | ||
_clappr.Log.warn("Track id \"".concat(trackId, "\" not found")); | ||
return; | ||
} | ||
if (this._shakaTTVisible && showingTrack.track.active === true) { | ||
_clappr.Log.info("Track id \"".concat(trackId, "\" already showing")); | ||
return; | ||
} | ||
} | ||
if (showingTrack) { | ||
this._player.selectTextTrack(showingTrack.track); | ||
this._player.setTextTrackVisibility(true); | ||
this._enableShakaTextTrack(true); | ||
} else { | ||
this._player.setTextTrackVisibility(false); | ||
this._enableShakaTextTrack(false); | ||
} | ||
this._ccTrackId = trackId; | ||
this.trigger(_clappr.Events.PLAYBACK_SUBTITLE_CHANGED, { | ||
id: trackId | ||
}); | ||
} | ||
}]); | ||
return DashShakaPlayback; | ||
}(_clappr.HTML5Video); | ||
var _default = DashShakaPlayback; | ||
@@ -794,0 +887,0 @@ exports["default"] = _default; |
@@ -1,2 +0,2 @@ | ||
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e(require("clappr"),require("shaka")):"function"==typeof define&&define.amd?define(["clappr","shaka"],e):"object"==typeof exports?exports.DashShakaPlayback=e(require("clappr"),require("shaka")):t.DashShakaPlayback=e(t.Clappr,t.shaka)}(window,(function(t,e){return function(t){var e={};function i(r){if(e[r])return e[r].exports;var n=e[r]={i:r,l:!1,exports:{}};return t[r].call(n.exports,n,n.exports,i),n.l=!0,n.exports}return i.m=t,i.c=e,i.d=function(t,e,r){i.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:r})},i.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},i.t=function(t,e){if(1&e&&(t=i(t)),8&e)return t;if(4&e&&"object"==typeof t&&t&&t.__esModule)return t;var r=Object.create(null);if(i.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var n in t)i.d(r,n,function(e){return t[e]}.bind(null,n));return r},i.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return i.d(e,"a",e),e},i.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},i.p="dist/",i(i.s=0)}([function(t,e,i){"use strict";function r(t){return(r="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}Object.defineProperty(e,"__esModule",{value:!0}),e.default=void 0;var n,a=i(1),s=(n=i(2))&&n.__esModule?n:{default:n};function o(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function u(t,e){for(var i=0;i<e.length;i++){var n=e[i];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,(a=n.key,s=void 0,s=function(t,e){if("object"!==r(t)||null===t)return t;var i=t[Symbol.toPrimitive];if(void 0!==i){var n=i.call(t,e||"default");if("object"!==r(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===e?String:Number)(t)}(a,"string"),"symbol"===r(s)?s:String(s)),n)}var a,s}function l(){return(l="undefined"!=typeof Reflect&&Reflect.get?Reflect.get.bind():function(t,e,i){var r=c(t,e);if(r){var n=Object.getOwnPropertyDescriptor(r,e);return n.get?n.get.call(arguments.length<3?t:i):n.value}}).apply(this,arguments)}function c(t,e){for(;!Object.prototype.hasOwnProperty.call(t,e)&&null!==(t=y(t)););return t}function h(t,e){return(h=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t})(t,e)}function f(t){var e=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(t){return!1}}();return function(){var i,r=y(t);if(e){var n=y(this).constructor;i=Reflect.construct(r,arguments,n)}else i=r.apply(this,arguments);return d(this,i)}}function d(t,e){if(e&&("object"===r(e)||"function"==typeof e))return e;if(void 0!==e)throw new TypeError("Derived constructors may only return object or undefined");return function(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}(t)}function y(t){return(y=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(t){return t.__proto__||Object.getPrototypeOf(t)})(t)}var p=function(t){!function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),Object.defineProperty(t,"prototype",{writable:!1}),e&&h(t,e)}(c,t);var e,i,r,n=f(c);function c(){var t;o(this,c);for(var e=arguments.length,i=new Array(e),r=0;r<e;r++)i[r]=arguments[r];return(t=n.call.apply(n,[this].concat(i)))._levels=[],t._pendingAdaptationEvent=!1,t._isShakaReadyState=!1,t._minDvrSize=void 0===t.options.shakaMinimumDvrSize?60:t.options.shakaMinimumDvrSize,t}return e=c,r=[{key:"Events",get:function(){return{SHAKA_READY:"shaka:ready"}}},{key:"shakaPlayer",get:function(){return s.default}},{key:"canPlay",value:function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"";s.default.polyfill.installAll();var i=s.default.Player.isBrowserSupported(),r=t.split("?")[0].match(/.*\.(.*)$/)||[];return i&&("mpd"===r[1]||e.indexOf("application/dash+xml")>-1)}}],(i=[{key:"name",get:function(){return"dash_shaka_playback"}},{key:"shakaVersion",get:function(){return s.default.player.Player.version}},{key:"shakaPlayerInstance",get:function(){return this._player}},{key:"levels",get:function(){return this._levels}},{key:"seekRange",get:function(){return this.shakaPlayerInstance?this.shakaPlayerInstance.seekRange():{start:0,end:0}}},{key:"currentLevel",get:function(){return this._currentLevelId||-1},set:function(t){var e=this;this._currentLevelId=t;var i=-1===this._currentLevelId;this.trigger(a.Events.PLAYBACK_LEVEL_SWITCH_START),i?(this._player.configure({abr:{enabled:!0}}),this.trigger(a.Events.PLAYBACK_LEVEL_SWITCH_END)):(this._player.configure({abr:{enabled:!1}}),this._pendingAdaptationEvent=!0,this.selectTrack(this.videoTracks.filter((function(t){return t.id===e._currentLevelId}))[0]))}},{key:"dvrEnabled",get:function(){return this._duration>=this._minDvrSize&&"live"===this.getPlaybackType()}},{key:"getDuration",value:function(){return this._duration}},{key:"_duration",get:function(){return this.shakaPlayerInstance?this.seekRange.end-this.seekRange.start:0}},{key:"getCurrentTime",value:function(){if(!this.shakaPlayerInstance)return 0;var t=this.shakaPlayerInstance.getMediaElement();return t?t.currentTime-this.seekRange.start:0}},{key:"_startTime",get:function(){return this.seekRange.start}},{key:"presentationStartTimeAsDate",get:function(){return this.shakaPlayerInstance&&this.shakaPlayerInstance.getPresentationStartTimeAsDate()?new Date(this.shakaPlayerInstance.getPresentationStartTimeAsDate().getTime()+1e3*this.seekRange.start):0}},{key:"bandwidthEstimate",get:function(){return this.shakaPlayerInstance?this.shakaPlayerInstance.getStats().estimatedBandwidth:null}},{key:"sourceMedia",get:function(){return this._options.src}},{key:"getProgramDateTime",value:function(){return this.presentationStartTimeAsDate}},{key:"_updateDvr",value:function(t){this.trigger(a.Events.PLAYBACK_DVR,t),this.trigger(a.Events.PLAYBACK_STATS_ADD,{dvr:t})}},{key:"seek",value:function(t){t<0&&(a.Log.warn("Attempt to seek to a negative time. Resetting to live point. Use seekToLivePoint() to seek to the live point."),t=this._duration),this.dvrEnabled&&this._updateDvr(t<this._duration-3),t+=this._startTime,this.el.currentTime=t}},{key:"pause",value:function(){this.el.pause(),this.dvrEnabled&&this._updateDvr(!0)}},{key:"play",value:function(){this._player||this.load(),this.isReady?(l(y(c.prototype),"play",this).call(this),this._startTimeUpdateTimer(),this._stopped=!1,this._src=this.el.src):this.once(c.Events.SHAKA_READY,this.play)}},{key:"load",value:function(t){t&&(this._options.src=t),this._setup()}},{key:"_onPlaying",value:function(){if(!this._isBuffering)return l(y(c.prototype),"_onPlaying",this).call(this)}},{key:"_onSeeking",value:function(){return this._isSeeking=!0,l(y(c.prototype),"_onSeeking",this).call(this)}},{key:"_onSeeked",value:function(){if(!this._isBuffering)return this._isSeeking=!1,l(y(c.prototype),"_onSeeked",this).call(this)}},{key:"_startTimeUpdateTimer",value:function(){var t=this;this._stopTimeUpdateTimer(),this._timeUpdateTimer=setInterval((function(){t._onTimeUpdate()}),100)}},{key:"_stopTimeUpdateTimer",value:function(){this._timeUpdateTimer&&clearInterval(this._timeUpdateTimer)}},{key:"_setupSrc",value:function(){}},{key:"_ready",value:function(){}},{key:"_onShakaReady",value:function(){this._isShakaReadyState=!0,this.trigger(c.Events.SHAKA_READY),this.trigger(a.Events.PLAYBACK_READY,this.name)}},{key:"isReady",get:function(){return this._isShakaReadyState}},{key:"error",value:function(t){a.Log.error("an error was raised by the video tag",t,this.el.error)}},{key:"isHighDefinitionInUse",value:function(){return!!this.highDefinition}},{key:"stop",value:function(){var t=this;this._stopTimeUpdateTimer(),clearInterval(this.sendStatsId),this._stopped=!0,this._player?(this._sendStats(),this._player.unload().then((function(){l(y(c.prototype),"stop",t).call(t),t._player=null,t._isShakaReadyState=!1})).catch((function(){a.Log.error("shaka could not be unloaded")}))):l(y(c.prototype),"stop",this).call(this)}},{key:"textTracks",get:function(){return this.isReady&&this._player.getTextTracks()}},{key:"audioTracks",get:function(){return this.isReady&&this._player.getVariantTracks().filter((function(t){return t.mimeType.startsWith("audio/")}))}},{key:"videoTracks",get:function(){return this.isReady&&this._player.getVariantTracks().filter((function(t){return t.mimeType.startsWith("video/")}))}},{key:"getPlaybackType",value:function(){return(this.isReady&&this._player.isLive()?"live":"vod")||""}},{key:"selectTrack",value:function(t){if("text"===t.type)this._player.selectTextTrack(t);else{if("variant"!==t.type)throw new Error("Unhandled track type:",t.type);this._player.selectVariantTrack(t),t.mimeType.startsWith("video/")&&this._onAdaptation()}}},{key:"closedCaptionsTracks",get:function(){var t=0;return(this.textTracks||[]).filter((function(t){return"subtitle"===t.kind})).map((function(e){return{id:t++,name:e.label||e.language,track:e}}))}},{key:"closedCaptionsTrackId",get:function(){return l(y(c.prototype),"closedCaptionsTrackId",this)},set:function(t){if(this._player){var e,i=this.closedCaptionsTracks;if(-1!==t){if(!(e=i.find((function(e){return e.id===t}))))return void a.Log.warn('Track id "'.concat(t,'" not found'));if(this._shakaTTVisible&&!0===e.track.active)return void a.Log.info('Track id "'.concat(t,'" already showing'))}e?(this._player.selectTextTrack(e.track),this._player.setTextTrackVisibility(!0),this._enableShakaTextTrack(!0)):(this._player.setTextTrackVisibility(!1),this._enableShakaTextTrack(!1)),this._ccTrackId=t,this.trigger(a.Events.PLAYBACK_SUBTITLE_CHANGED,{id:t})}}},{key:"_enableShakaTextTrack",value:function(t){this.el.textTracks&&(this._shakaTTVisible=t,Array.from(this.el.textTracks).filter((function(t){return"subtitles"===t.kind})).forEach((function(e){return e.mode=!0===t?"showing":"hidden"})))}},{key:"_checkForClosedCaptions",value:function(){if(!this._ccIsSetup){if(this.hasClosedCaptionsTracks){this.trigger(a.Events.PLAYBACK_SUBTITLE_AVAILABLE);var t=this.closedCaptionsTrackId;this.closedCaptionsTrackId=t}this._ccIsSetup=!0}}},{key:"destroy",value:function(){var t=this;this._stopTimeUpdateTimer(),clearInterval(this.sendStatsId),this._player?this._player.destroy().then((function(){return t._destroy()})).catch((function(){t._destroy(),a.Log.error("shaka could not be destroyed")})):this._destroy(),l(y(c.prototype),"destroy",this).call(this)}},{key:"_setup",value:function(){var t=this;this._isShakaReadyState=!1,this._ccIsSetup=!1;var e=function(){t._player=t._createPlayer(),t._setInitialConfig(),t._loadSource()};this._player?this._player.destroy().then((function(){return e()})):e()}},{key:"_createPlayer",value:function(){var t=new s.default.Player(this.el);return t.addEventListener("error",this._onError.bind(this)),t.addEventListener("adaptation",this._onAdaptation.bind(this)),t.addEventListener("buffering",this._handleShakaBufferingEvents.bind(this)),t}},{key:"_setInitialConfig",value:function(){this._options.shakaConfiguration&&this._player.configure(this._options.shakaConfiguration),this._options.shakaOnBeforeLoad&&this._options.shakaOnBeforeLoad(this._player)}},{key:"_loadSource",value:function(){var t=this;this._player.load(this._options.src).then((function(){return t._loaded()})).catch((function(e){return t._setupError(e)}))}},{key:"_onTimeUpdate",value:function(){if(this.shakaPlayerInstance){var t={current:this.getCurrentTime(),total:this.getDuration(),firstFragDateTime:this.getProgramDateTime()};this._lastTimeUpdate&&t.current===this._lastTimeUpdate.current&&t.total===this._lastTimeUpdate.total||(this._lastTimeUpdate=t,this.trigger(a.Events.PLAYBACK_TIMEUPDATE,t,this.name))}}},{key:"_handleBufferingEvents",value:function(){}},{key:"_handleShakaBufferingEvents",value:function(t){this._stopped||(this._isBuffering=t.buffering,this._isBuffering?this._onBuffering():this._onBufferfull())}},{key:"_onBuffering",value:function(){this.trigger(a.Events.PLAYBACK_BUFFERING)}},{key:"_onBufferfull",value:function(){this.trigger(a.Events.PLAYBACK_BUFFERFULL),this._isSeeking&&this._onSeeked(),this.isPlaying()&&this._onPlaying()}},{key:"_loaded",value:function(){this._onShakaReady(),this._startToSendStats(),this._fillLevels(),this._checkForClosedCaptions()}},{key:"_fillLevels",value:function(){0===this._levels.length&&(this._levels=this.videoTracks.map((function(t){return{id:t.id,label:"".concat(t.height,"p")}})).reverse(),this.trigger(a.Events.PLAYBACK_LEVELS_AVAILABLE,this.levels))}},{key:"_startToSendStats",value:function(){var t=this,e=this._options.shakaSendStatsInterval||3e4;this.sendStatsId=setInterval((function(){return t._sendStats()}),e)}},{key:"_sendStats",value:function(){this.trigger(a.Events.PLAYBACK_STATS_ADD,this._player.getStats())}},{key:"_setupError",value:function(t){this._onError(t)}},{key:"_onError",value:function(t){var e={shakaError:t,videoError:this.el.error},i=e.shakaError.detail||e.shakaError,r=i.category,n=i.code,o=i.severity;if(e.videoError||!n&&!r)return l(y(c.prototype),"_onError",this).call(this);var u=o===s.default.util.Error.Severity.CRITICAL,h={code:"".concat(r,"_").concat(n),description:"Category: ".concat(r,", code: ").concat(n,", severity: ").concat(o),level:u?a.PlayerError.Levels.FATAL:a.PlayerError.Levels.WARN,raw:t},f=this.createError(h);a.Log.error("Shaka error event:",f),this.trigger(a.Events.PLAYBACK_ERROR,f)}},{key:"_onAdaptation",value:function(){var t=this.videoTracks.filter((function(t){return!0===t.active}))[0];this._fillLevels(),this._sendStats(),this._pendingAdaptationEvent&&(this.trigger(a.Events.PLAYBACK_LEVEL_SWITCH_END),this._pendingAdaptationEvent=!1),a.Log.debug("an adaptation has happened:",t),this.highDefinition=t.height>=720,this.trigger(a.Events.PLAYBACK_HIGHDEFINITIONUPDATE,this.highDefinition),this.trigger(a.Events.PLAYBACK_BITRATE,{bandwidth:t.bandwidth,width:t.width,height:t.height,level:t.id,bitrate:t.videoBandwidth})}},{key:"_updateSettings",value:function(){"vod"===this.getPlaybackType()?this.settings.left=["playpause","position","duration"]:this.dvrEnabled?this.settings.left=["playpause"]:this.settings.left=["playstop"],this.settings.seekEnabled=this.isSeekEnabled(),this.trigger(a.Events.PLAYBACK_SETTINGSUPDATE)}},{key:"_destroy",value:function(){this._isShakaReadyState=!1,a.Log.debug("shaka was destroyed")}}])&&u(e.prototype,i),r&&u(e,r),Object.defineProperty(e,"prototype",{writable:!1}),c}(a.HTML5Video);e.default=p,t.exports=e.default},function(e,i){e.exports=t},function(t,i){t.exports=e}])})); | ||
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e(require("clappr"),require("shaka")):"function"==typeof define&&define.amd?define(["clappr","shaka"],e):"object"==typeof exports?exports.DashShakaPlayback=e(require("clappr"),require("shaka")):t.DashShakaPlayback=e(t.Clappr,t.shaka)}(window,(function(t,e){return function(t){var e={};function i(n){if(e[n])return e[n].exports;var r=e[n]={i:n,l:!1,exports:{}};return t[n].call(r.exports,r,r.exports,i),r.l=!0,r.exports}return i.m=t,i.c=e,i.d=function(t,e,n){i.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:n})},i.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},i.t=function(t,e){if(1&e&&(t=i(t)),8&e)return t;if(4&e&&"object"==typeof t&&t&&t.__esModule)return t;var n=Object.create(null);if(i.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var r in t)i.d(n,r,function(e){return t[e]}.bind(null,r));return n},i.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return i.d(e,"a",e),e},i.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},i.p="dist/",i(i.s=0)}([function(t,e,i){"use strict";function n(t){return(n="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}Object.defineProperty(e,"__esModule",{value:!0}),e.default=void 0;var r,a=i(1),s=(r=i(2))&&r.__esModule?r:{default:r};function o(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function u(t,e,i){return(u="undefined"!=typeof Reflect&&Reflect.get?Reflect.get:function(t,e,i){var n=function(t,e){for(;!Object.prototype.hasOwnProperty.call(t,e)&&null!==(t=y(t)););return t}(t,e);if(n){var r=Object.getOwnPropertyDescriptor(n,e);return r.get?r.get.call(i):r.value}})(t,e,i||t)}function l(t,e){for(var i=0;i<e.length;i++){var n=e[i];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,n.key,n)}}function c(t,e,i){return e&&l(t.prototype,e),i&&l(t,i),t}function h(t,e){return(h=Object.setPrototypeOf||function(t,e){return t.__proto__=e,t})(t,e)}function f(t){var e=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Date.prototype.toString.call(Reflect.construct(Date,[],(function(){}))),!0}catch(t){return!1}}();return function(){var i,n=y(t);if(e){var r=y(this).constructor;i=Reflect.construct(n,arguments,r)}else i=n.apply(this,arguments);return d(this,i)}}function d(t,e){return!e||"object"!==n(e)&&"function"!=typeof e?function(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}(t):e}function y(t){return(y=Object.setPrototypeOf?Object.getPrototypeOf:function(t){return t.__proto__||Object.getPrototypeOf(t)})(t)}var p=function(t){!function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),e&&h(t,e)}(i,t);var e=f(i);function i(){var t;o(this,i);for(var n=arguments.length,r=new Array(n),a=0;a<n;a++)r[a]=arguments[a];return(t=e.call.apply(e,[this].concat(r)))._levels=[],t._pendingAdaptationEvent=!1,t._isShakaReadyState=!1,t._minDvrSize=void 0===t.options.shakaMinimumDvrSize?60:t.options.shakaMinimumDvrSize,t}return c(i,[{key:"getDuration",value:function(){return this._duration}},{key:"getCurrentTime",value:function(){if(!this.shakaPlayerInstance)return 0;var t=this.shakaPlayerInstance.getMediaElement();return t?t.currentTime-this.seekRange.start:0}},{key:"name",get:function(){return"dash_shaka_playback"}},{key:"shakaVersion",get:function(){return s.default.player.Player.version}},{key:"shakaPlayerInstance",get:function(){return this._player}},{key:"levels",get:function(){return this._levels}},{key:"seekRange",get:function(){return this.shakaPlayerInstance?this.shakaPlayerInstance.seekRange():{start:0,end:0}}},{key:"currentLevel",set:function(t){var e=this;this._currentLevelId=t;var i=-1===this._currentLevelId;this.trigger(a.Events.PLAYBACK_LEVEL_SWITCH_START),i?(this._player.configure({abr:{enabled:!0}}),this.trigger(a.Events.PLAYBACK_LEVEL_SWITCH_END)):(this._player.configure({abr:{enabled:!1}}),this._pendingAdaptationEvent=!0,this.selectTrack(this.videoTracks.filter((function(t){return t.id===e._currentLevelId}))[0]))},get:function(){return this._currentLevelId||-1}},{key:"dvrEnabled",get:function(){return this._duration>=this._minDvrSize&&"live"===this.getPlaybackType()}},{key:"latency",get:function(){return this.shakaPlayerInstance?this.shakaPlayerInstance.getStats().liveLatency:0}},{key:"currentProgramDateTime",get:function(){return this.shakaPlayerInstance?this.shakaPlayerInstance.getPlayheadTimeAsDate():null}},{key:"_duration",get:function(){return this.shakaPlayerInstance?this.seekRange.end-this.seekRange.start:0}},{key:"_startTime",get:function(){return this.seekRange.start}},{key:"presentationStartTimeAsDate",get:function(){return this.shakaPlayerInstance&&this.shakaPlayerInstance.getPresentationStartTimeAsDate()?new Date(this.shakaPlayerInstance.getPresentationStartTimeAsDate().getTime()+1e3*this.seekRange.start):0}},{key:"bandwidthEstimate",get:function(){return this.shakaPlayerInstance?this.shakaPlayerInstance.getStats().estimatedBandwidth:null}},{key:"sourceMedia",get:function(){return this._options.src}}],[{key:"canPlay",value:function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"";s.default.polyfill.installAll();var i=s.default.Player.isBrowserSupported(),n=t.split("?")[0].match(/.*\.(.*)$/)||[];return i&&("mpd"===n[1]||e.indexOf("application/dash+xml")>-1)}},{key:"Events",get:function(){return{SHAKA_READY:"shaka:ready"}}},{key:"shakaPlayer",get:function(){return s.default}}]),c(i,[{key:"getProgramDateTime",value:function(){return this.presentationStartTimeAsDate}},{key:"_updateDvr",value:function(t){this.trigger(a.Events.PLAYBACK_DVR,t),this.trigger(a.Events.PLAYBACK_STATS_ADD,{dvr:t})}},{key:"seek",value:function(t){t<0&&(a.Log.warn("Attempt to seek to a negative time. Resetting to live point. Use seekToLivePoint() to seek to the live point."),t=this._duration),this.dvrEnabled&&this._updateDvr(t<this._duration-3),t+=this._startTime,this.el.currentTime=t}},{key:"pause",value:function(){this.el.pause(),this.dvrEnabled&&this._updateDvr(!0)}},{key:"play",value:function(){this._player||this.load(),this.isReady?(u(y(i.prototype),"play",this).call(this),this._startTimeUpdateTimer(),this._stopped=!1,this._src=this.el.src):this.once(i.Events.SHAKA_READY,this.play)}},{key:"load",value:function(t){t&&(this._options.src=t),this._setup()}},{key:"_onPlaying",value:function(){if(!this._isBuffering)return u(y(i.prototype),"_onPlaying",this).call(this)}},{key:"_onSeeking",value:function(){return this._isSeeking=!0,u(y(i.prototype),"_onSeeking",this).call(this)}},{key:"_onSeeked",value:function(){if(!this._isBuffering)return this._isSeeking=!1,u(y(i.prototype),"_onSeeked",this).call(this)}},{key:"_startTimeUpdateTimer",value:function(){var t=this;this._stopTimeUpdateTimer(),this._timeUpdateTimer=setInterval((function(){t._onTimeUpdate()}),100)}},{key:"_stopTimeUpdateTimer",value:function(){this._timeUpdateTimer&&clearInterval(this._timeUpdateTimer)}},{key:"_setupSrc",value:function(){}},{key:"_ready",value:function(){}},{key:"_onShakaReady",value:function(){this._isShakaReadyState=!0,this.trigger(i.Events.SHAKA_READY),this.trigger(a.Events.PLAYBACK_READY,this.name)}},{key:"error",value:function(t){a.Log.error("an error was raised by the video tag",t,this.el.error)}},{key:"isHighDefinitionInUse",value:function(){return!!this.highDefinition}},{key:"stop",value:function(){var t=this;this._stopTimeUpdateTimer(),clearInterval(this.sendStatsId),this._stopped=!0,this._player?(this._sendStats(),this._player.unload().then((function(){u(y(i.prototype),"stop",t).call(t),t._player=null,t._isShakaReadyState=!1})).catch((function(){a.Log.error("shaka could not be unloaded")}))):u(y(i.prototype),"stop",this).call(this)}},{key:"getPlaybackType",value:function(){return(this.isReady&&this._player.isLive()?"live":"vod")||""}},{key:"selectTrack",value:function(t){if("text"===t.type)this._player.selectTextTrack(t);else{if("variant"!==t.type)throw new Error("Unhandled track type:",t.type);this._player.selectVariantTrack(t),t.mimeType.startsWith("video/")&&this._onAdaptation()}}},{key:"_enableShakaTextTrack",value:function(t){this.el.textTracks&&(this._shakaTTVisible=t,Array.from(this.el.textTracks).filter((function(t){return"subtitles"===t.kind})).forEach((function(e){return e.mode=!0===t?"showing":"hidden"})))}},{key:"_checkForClosedCaptions",value:function(){if(!this._ccIsSetup){if(this.hasClosedCaptionsTracks){this.trigger(a.Events.PLAYBACK_SUBTITLE_AVAILABLE);var t=this.closedCaptionsTrackId;this.closedCaptionsTrackId=t}this._ccIsSetup=!0}}},{key:"destroy",value:function(){var t=this;this._stopTimeUpdateTimer(),clearInterval(this.sendStatsId),this._player?this._player.destroy().then((function(){return t._destroy()})).catch((function(){t._destroy(),a.Log.error("shaka could not be destroyed")})):this._destroy(),u(y(i.prototype),"destroy",this).call(this)}},{key:"_setup",value:function(){var t=this;this._isShakaReadyState=!1,this._ccIsSetup=!1;var e=function(){t._player=t._createPlayer(),t._setInitialConfig(),t._loadSource()};this._player?this._player.destroy().then((function(){return e()})):e()}},{key:"_createPlayer",value:function(){var t=new s.default.Player(this.el);return t.addEventListener("error",this._onError.bind(this)),t.addEventListener("adaptation",this._onAdaptation.bind(this)),t.addEventListener("buffering",this._handleShakaBufferingEvents.bind(this)),t}},{key:"_setInitialConfig",value:function(){this._options.shakaConfiguration&&this._player.configure(this._options.shakaConfiguration),this._options.shakaOnBeforeLoad&&this._options.shakaOnBeforeLoad(this._player)}},{key:"_loadSource",value:function(){var t=this;this._player.load(this._options.src).then((function(){return t._loaded()})).catch((function(e){return t._setupError(e)}))}},{key:"_onTimeUpdate",value:function(){if(this.shakaPlayerInstance){var t={current:this.getCurrentTime(),total:this.getDuration(),firstFragDateTime:this.getProgramDateTime()};this._lastTimeUpdate&&t.current===this._lastTimeUpdate.current&&t.total===this._lastTimeUpdate.total||(this._lastTimeUpdate=t,this.trigger(a.Events.PLAYBACK_TIMEUPDATE,t,this.name))}}},{key:"_handleBufferingEvents",value:function(){}},{key:"_handleShakaBufferingEvents",value:function(t){this._stopped||(this._isBuffering=t.buffering,this._isBuffering?this._onBuffering():this._onBufferfull())}},{key:"_onBuffering",value:function(){this.trigger(a.Events.PLAYBACK_BUFFERING)}},{key:"_onBufferfull",value:function(){this.trigger(a.Events.PLAYBACK_BUFFERFULL),this._isSeeking&&this._onSeeked(),this.isPlaying()&&this._onPlaying()}},{key:"_loaded",value:function(){this._onShakaReady(),this._startToSendStats(),this._fillLevels(),this._checkForClosedCaptions()}},{key:"_fillLevels",value:function(){0===this._levels.length&&(this._levels=this.videoTracks.map((function(t){return{id:t.id,label:"".concat(t.height,"p")}})).reverse(),this.trigger(a.Events.PLAYBACK_LEVELS_AVAILABLE,this.levels))}},{key:"_startToSendStats",value:function(){var t=this,e=this._options.shakaSendStatsInterval||3e4;this.sendStatsId=setInterval((function(){return t._sendStats()}),e)}},{key:"_sendStats",value:function(){this.trigger(a.Events.PLAYBACK_STATS_ADD,this._player.getStats())}},{key:"_setupError",value:function(t){this._onError(t)}},{key:"_onError",value:function(t){var e={shakaError:t,videoError:this.el.error},n=e.shakaError.detail||e.shakaError,r=n.category,o=n.code,l=n.severity;if(e.videoError||!o&&!r)return u(y(i.prototype),"_onError",this).call(this);var c=l===s.default.util.Error.Severity.CRITICAL,h={code:"".concat(r,"_").concat(o),description:"Category: ".concat(r,", code: ").concat(o,", severity: ").concat(l),level:c?a.PlayerError.Levels.FATAL:a.PlayerError.Levels.WARN,raw:t},f=this.createError(h);a.Log.error("Shaka error event:",f),this.trigger(a.Events.PLAYBACK_ERROR,f)}},{key:"_onAdaptation",value:function(){var t=this.videoTracks.filter((function(t){return!0===t.active}))[0];this._fillLevels(),this._sendStats(),this._pendingAdaptationEvent&&(this.trigger(a.Events.PLAYBACK_LEVEL_SWITCH_END),this._pendingAdaptationEvent=!1),a.Log.debug("an adaptation has happened:",t),this.highDefinition=t.height>=720,this.trigger(a.Events.PLAYBACK_HIGHDEFINITIONUPDATE,this.highDefinition),this.trigger(a.Events.PLAYBACK_BITRATE,{bandwidth:t.bandwidth,width:t.width,height:t.height,level:t.id,bitrate:t.videoBandwidth})}},{key:"_updateSettings",value:function(){"vod"===this.getPlaybackType()?this.settings.left=["playpause","position","duration"]:this.dvrEnabled?this.settings.left=["playpause"]:this.settings.left=["playstop"],this.settings.seekEnabled=this.isSeekEnabled(),this.trigger(a.Events.PLAYBACK_SETTINGSUPDATE)}},{key:"_destroy",value:function(){this._isShakaReadyState=!1,a.Log.debug("shaka was destroyed")}},{key:"isReady",get:function(){return this._isShakaReadyState}},{key:"textTracks",get:function(){return this.isReady&&this._player.getTextTracks()}},{key:"audioTracks",get:function(){return this.isReady&&this._player.getVariantTracks().filter((function(t){return t.mimeType.startsWith("audio/")}))}},{key:"videoTracks",get:function(){return this.isReady&&this._player.getVariantTracks().filter((function(t){return t.mimeType.startsWith("video/")}))}},{key:"closedCaptionsTracks",get:function(){var t=0;return(this.textTracks||[]).filter((function(t){return"subtitle"===t.kind})).map((function(e){return{id:t++,name:e.label||e.language,track:e}}))}},{key:"closedCaptionsTrackId",get:function(){return u(y(i.prototype),"closedCaptionsTrackId",this)},set:function(t){if(this._player){var e,i=this.closedCaptionsTracks;if(-1!==t){if(!(e=i.find((function(e){return e.id===t}))))return void a.Log.warn('Track id "'.concat(t,'" not found'));if(this._shakaTTVisible&&!0===e.track.active)return void a.Log.info('Track id "'.concat(t,'" already showing'))}e?(this._player.selectTextTrack(e.track),this._player.setTextTrackVisibility(!0),this._enableShakaTextTrack(!0)):(this._player.setTextTrackVisibility(!1),this._enableShakaTextTrack(!1)),this._ccTrackId=t,this.trigger(a.Events.PLAYBACK_SUBTITLE_CHANGED,{id:t})}}}]),i}(a.HTML5Video);e.default=p,t.exports=e.default},function(e,i){e.exports=t},function(t,i){t.exports=e}])})); | ||
//# sourceMappingURL=dash-shaka-playback.external.min.js.map |
{ | ||
"name": "dash-shaka-playback", | ||
"version": "3.1.0", | ||
"version": "3.2.0", | ||
"description": "clappr dash playback based on shaka player", | ||
@@ -16,3 +16,3 @@ "main": "./dist/dash-shaka-playback.js", | ||
"lint": "eslint src/", | ||
"prepublishOnly": "yarn release" | ||
"prepublishOnly": "yarn dist" | ||
}, | ||
@@ -19,0 +19,0 @@ "files": [ |
@@ -69,2 +69,12 @@ import {HTML5Video, Log, Events, PlayerError} from 'clappr' | ||
get latency() { | ||
if (!this.shakaPlayerInstance) return 0 | ||
return this.shakaPlayerInstance.getStats().liveLatency | ||
} | ||
get currentProgramDateTime() { | ||
if (!this.shakaPlayerInstance) return null | ||
return this.shakaPlayerInstance.getPlayheadTimeAsDate() | ||
} | ||
getDuration() { | ||
@@ -71,0 +81,0 @@ return this._duration |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
2126809
4976