New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

dash-shaka-playback

Package Overview
Dependencies
Maintainers
0
Versions
69
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

dash-shaka-playback - npm Package Compare versions

Comparing version 3.2.0 to 3.3.0

457

dist/dash-shaka-playback.external.js

@@ -109,4 +109,3 @@ (function webpackUniversalModuleDefinition(root, factory) {

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); }
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
Object.defineProperty(exports, "__esModule", {

@@ -116,54 +115,44 @@ 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 _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 _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(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
function _callSuper(t, o, e) { return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e)); }
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 _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
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 _superPropBase(object, property) { while (!Object.prototype.hasOwnProperty.call(object, property)) { object = _getPrototypeOf(object); if (object === null) break; } return object; }
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; } 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 { 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); }
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
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); }
var SEND_STATS_INTERVAL_MS = 30 * 1e3;
var DEFAULT_LEVEL_AUTO = -1;
var DashShakaPlayback = /*#__PURE__*/function (_HTML5Video) {
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 = _callSuper(this, DashShakaPlayback, [].concat(args));
_this._levels = [];
_this._pendingAdaptationEvent = false;
_this._isShakaReadyState = false;
_this._lastTimeUpdate = {
current: 0,
total: 0,
firstFragDateTime: 0
};
_this._timeUpdateFiringRate = 0.2;
_this._durationChangeMinOffset = 0.5;
_this._minDvrSize = typeof _this.options.shakaMinimumDvrSize === 'undefined' ? 60 : _this.options.shakaMinimumDvrSize;
return _this;
}
_inherits(DashShakaPlayback, _HTML5Video);
var _super = _createSuper(DashShakaPlayback);
_createClass(DashShakaPlayback, [{
key: "getDuration",
value: function getDuration() {
return this._duration;
}
}, {
key: "getCurrentTime",
value: function getCurrentTime() {
if (!this.shakaPlayerInstance) return 0;
var shakaMediaElement = this.shakaPlayerInstance.getMediaElement();
return shakaMediaElement ? shakaMediaElement.currentTime - this.seekRange.start : 0;
}
}, {
return _createClass(DashShakaPlayback, [{
key: "name",

@@ -199,9 +188,10 @@ 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) {

@@ -213,3 +203,2 @@ this._player.configure({

});
this._pendingAdaptationEvent = true;

@@ -225,8 +214,4 @@ this.selectTrack(this.videoTracks.filter(function (t) {

});
this.trigger(_clappr.Events.PLAYBACK_LEVEL_SWITCH_END);
}
},
get: function get() {
return this._currentLevelId || DEFAULT_LEVEL_AUTO;
}

@@ -251,2 +236,7 @@ }, {

}, {
key: "getDuration",
value: function getDuration() {
return this._duration;
}
}, {
key: "_duration",

@@ -258,2 +248,9 @@ 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",

@@ -280,46 +277,3 @@ 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",

@@ -330,10 +284,2 @@ value: function getProgramDateTime() {

}, {
key: "_updateDvr",
value: function _updateDvr(status) {
this.trigger(_clappr.Events.PLAYBACK_DVR, status);
this.trigger(_clappr.Events.PLAYBACK_STATS_ADD, {
'dvr': status
});
}
}, {
key: "seek",

@@ -343,8 +289,4 @@ value: function seek(time) {

_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
this.dvrEnabled && this._updateDvr(time < this._duration - 3);
}
time += this._startTime;

@@ -357,3 +299,2 @@ this.el.currentTime = time;

this.el.pause();
this.dvrEnabled && this._updateDvr(true);
}

@@ -364,3 +305,2 @@ }, {

if (!this._player) this.load();
if (!this.isReady) {

@@ -370,7 +310,4 @@ this.once(DashShakaPlayback.Events.SHAKA_READY, this.play);

}
_get(_getPrototypeOf(DashShakaPlayback.prototype), "play", this).call(this);
this._startTimeUpdateTimer();
this._stopped = false;

@@ -383,3 +320,2 @@ this._src = this.el.src;

if (source) this._options.src = source;
this._setup();

@@ -418,5 +354,3 @@ }

var _this3 = this;
this._stopTimeUpdateTimer();
this._timeUpdateTimer = setInterval(function () {

@@ -430,11 +364,14 @@ _this3._onTimeUpdate();

this._timeUpdateTimer && clearInterval(this._timeUpdateTimer);
} // skipping HTML5Video `_setupSrc` (on tag video)
}
// skipping HTML5Video `_setupSrc` (on tag video)
}, {
key: "_setupSrc",
value: function _setupSrc() {} // skipping ready event on video tag in favor of ready on shaka
value: function _setupSrc() {}
// 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
}

@@ -449,4 +386,10 @@ }, {

}, {
key: "isReady",
get: function get() {
return this._isShakaReadyState;
}
// skipping error handling on video tag in favor of error on shaka
}, {
key: "error",
// skipping error handling on video tag in favor of error on shaka
value: function error(event) {

@@ -464,14 +407,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._stopToSendStats();
this._stopped = true;
if (this._player) {
this._sendStats();
this._lastTimeUpdate = {
current: 0,
total: 0,
firstFragDateTime: 0
};
this._player.unload().then(function () {
_get(_getPrototypeOf(DashShakaPlayback.prototype), "stop", _this4).call(_this4);
_this4._player = null;

@@ -487,2 +430,21 @@ _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",

@@ -499,3 +461,2 @@ value: function getPlaybackType() {

this._player.selectVariantTrack(track);
if (track.mimeType.startsWith('video/')) {

@@ -510,7 +471,72 @@ // 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",

@@ -523,3 +549,2 @@ value: function _enableShakaTextTrack(isEnable) {

}
this._shakaTTVisible = isEnable;

@@ -538,3 +563,2 @@ Array.from(this.el.textTracks).filter(function (track) {

}
if (this.hasClosedCaptionsTracks) {

@@ -545,3 +569,2 @@ this.trigger(_clappr.Events.PLAYBACK_SUBTITLE_AVAILABLE);

}
this._ccIsSetup = true;

@@ -553,7 +576,4 @@ }

var _this5 = this;
this._stopTimeUpdateTimer();
clearInterval(this.sendStatsId);
this._stopToSendStats();
if (this._player) {

@@ -564,3 +584,2 @@ this._player.destroy().then(function () {

_this5._destroy();
_clappr.Log.error('shaka could not be destroyed');

@@ -571,3 +590,2 @@ });

}
_get(_getPrototypeOf(DashShakaPlayback.prototype), "destroy", this).call(this);

@@ -579,14 +597,10 @@ }

var _this6 = this;
this._isShakaReadyState = false;
this._ccIsSetup = false;
this._stopToSendStats();
var runAllSteps = function runAllSteps() {
_this6._player = _this6._createPlayer();
_this6._setInitialConfig();
_this6._loadSource();
};
this._player ? this._player.destroy().then(function () {

@@ -615,3 +629,2 @@ return runAllSteps();

var _this7 = this;
this._player.load(this._options.src).then(function () {

@@ -632,8 +645,12 @@ return _this7._loaded();

};
var isSame = this._lastTimeUpdate && update.current === this._lastTimeUpdate.current && update.total === this._lastTimeUpdate.total;
var isSameTime = Math.abs(update.current - this._lastTimeUpdate.current) < this._timeUpdateFiringRate;
var isSameDuration = Math.abs(update.total - this._lastTimeUpdate.total) < this._durationChangeMinOffset;
var isSameFirstFragDateTime = update.firstFragDateTime === this._lastTimeUpdate.firstFragDateTime;
var isSame = isSameTime && isSameDuration && isSameFirstFragDateTime;
if (isSame) return;
this._lastTimeUpdate = update;
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
}, {

@@ -665,7 +682,4 @@ key: "_handleBufferingEvents",

this._onShakaReady();
this._startToSendStats();
this._fillLevels();
this._checkForClosedCaptions();

@@ -690,3 +704,3 @@ }

var _this8 = this;
this._stopToSendStats();
var intervalMs = this._options.shakaSendStatsInterval || SEND_STATS_INTERVAL_MS;

@@ -698,2 +712,8 @@ this.sendStatsId = setInterval(function () {

}, {
key: "_stopToSendStats",
value: function _stopToSendStats() {
this.sendStatsId && clearInterval(this.sendStatsId);
this.sendStatsId = null;
}
}, {
key: "_sendStats",

@@ -715,13 +735,18 @@ value: function _sendStats() {

};
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,
data = _ref.data;
if (error.videoError || !code && !category) return _get(_getPrototypeOf(DashShakaPlayback.prototype), "_onError", this).call(this);
var shakaErrorData = '';
try {
shakaErrorData = JSON.stringify(data);
} catch (error) {
_clappr.Log.warn('Fail to parse shaka error data', error);
}
var isCritical = severity === _shakaPlayer["default"].util.Error.Severity.CRITICAL;
var errorData = {
code: "".concat(category, "_").concat(code),
description: "Category: ".concat(category, ", code: ").concat(code, ", severity: ").concat(severity),
description: "Category: ".concat(category, ", code: ").concat(code, ", severity: ").concat(severity, ", data: ").concat(shakaErrorData),
level: isCritical ? _clappr.PlayerError.Levels.FATAL : _clappr.PlayerError.Levels.WARN,

@@ -731,5 +756,3 @@ raw: err

var formattedError = this.createError(errorData);
_clappr.Log.error('Shaka error event:', formattedError);
this.trigger(_clappr.Events.PLAYBACK_ERROR, formattedError);

@@ -743,9 +766,7 @@ }

})[0];
this._fillLevels();
this._fillLevels(); // update stats that may have changed before we trigger event
// 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) {

@@ -755,5 +776,3 @@ this.trigger(_clappr.Events.PLAYBACK_LEVEL_SWITCH_END);

}
_clappr.Log.debug('an adaptation has happened:', activeVideo);
this.highDefinition = activeVideo.height >= 720;

@@ -780,112 +799,28 @@ this.trigger(_clappr.Events.PLAYBACK_HIGHDEFINITIONUPDATE, this.highDefinition);

this._isShakaReadyState = false;
_clappr.Log.debug('shaka was destroyed');
}
}, {
key: "isReady",
}], [{
key: "Events",
get: function get() {
return this._isShakaReadyState;
return {
SHAKA_READY: 'shaka:ready'
};
}
}, {
key: "textTracks",
key: "shakaPlayer",
get: function get() {
return this.isReady && this._player.getTextTracks();
return _shakaPlayer["default"];
}
}, {
key: "audioTracks",
get: function get() {
return this.isReady && this._player.getVariantTracks().filter(function (t) {
return t.mimeType.startsWith('audio/');
});
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: "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;
exports["default"] = _default;
var _default = exports["default"] = DashShakaPlayback;
module.exports = exports.default;

@@ -892,0 +827,0 @@

@@ -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(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}])}));
!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){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,l(n.key),n)}}function l(t){var e=function(t,e){if("object"!=n(t)||!t)return t;var i=t[Symbol.toPrimitive];if(void 0!==i){var r=i.call(t,e||"default");if("object"!=n(r))return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===e?String:Number)(t)}(t,"string");return"symbol"==n(e)?e:e+""}function c(t,e,i){return e=d(e),function(t,e){if(e&&("object"===n(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)}(t,function(){try{var t=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){})))}catch(t){}return function(){return!!t}()}()?Reflect.construct(e,i||[],d(t).constructor):e.apply(t,i))}function h(){return(h="undefined"!=typeof Reflect&&Reflect.get?Reflect.get.bind():function(t,e,i){var n=f(t,e);if(n){var r=Object.getOwnPropertyDescriptor(n,e);return r.get?r.get.call(arguments.length<3?t:i):r.value}}).apply(this,arguments)}function f(t,e){for(;!Object.prototype.hasOwnProperty.call(t,e)&&null!==(t=d(t)););return t}function d(t){return(d=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(t){return t.__proto__||Object.getPrototypeOf(t)})(t)}function y(t,e){return(y=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t})(t,e)}var p=function(t){function e(){var t;o(this,e);for(var i=arguments.length,n=new Array(i),r=0;r<i;r++)n[r]=arguments[r];return(t=c(this,e,[].concat(n)))._levels=[],t._pendingAdaptationEvent=!1,t._isShakaReadyState=!1,t._lastTimeUpdate={current:0,total:0,firstFragDateTime:0},t._timeUpdateFiringRate=.2,t._durationChangeMinOffset=.5,t._minDvrSize=void 0===t.options.shakaMinimumDvrSize?60:t.options.shakaMinimumDvrSize,t}return 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&&y(t,e)}(e,t),i=e,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(),n=t.split("?")[0].match(/.*\.(.*)$/)||[];return i&&("mpd"===n[1]||e.indexOf("application/dash+xml")>-1)}}],(n=[{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:"latency",get:function(){return this.shakaPlayerInstance?this.shakaPlayerInstance.getStats().liveLatency:0}},{key:"currentProgramDateTime",get:function(){return this.shakaPlayerInstance?this.shakaPlayerInstance.getPlayheadTimeAsDate():null}},{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:"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),t+=this._startTime,this.el.currentTime=t}},{key:"pause",value:function(){this.el.pause()}},{key:"play",value:function(){this._player||this.load(),this.isReady?(h(d(e.prototype),"play",this).call(this),this._startTimeUpdateTimer(),this._stopped=!1,this._src=this.el.src):this.once(e.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 h(d(e.prototype),"_onPlaying",this).call(this)}},{key:"_onSeeking",value:function(){return this._isSeeking=!0,h(d(e.prototype),"_onSeeking",this).call(this)}},{key:"_onSeeked",value:function(){if(!this._isBuffering)return this._isSeeking=!1,h(d(e.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(e.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(),this._stopToSendStats(),this._stopped=!0,this._player?(this._sendStats(),this._lastTimeUpdate={current:0,total:0,firstFragDateTime:0},this._player.unload().then((function(){h(d(e.prototype),"stop",t).call(t),t._player=null,t._isShakaReadyState=!1})).catch((function(){a.Log.error("shaka could not be unloaded")}))):h(d(e.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 h(d(e.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(),this._stopToSendStats(),this._player?this._player.destroy().then((function(){return t._destroy()})).catch((function(){t._destroy(),a.Log.error("shaka could not be destroyed")})):this._destroy(),h(d(e.prototype),"destroy",this).call(this)}},{key:"_setup",value:function(){var t=this;this._isShakaReadyState=!1,this._ccIsSetup=!1,this._stopToSendStats();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()},e=Math.abs(t.current-this._lastTimeUpdate.current)<this._timeUpdateFiringRate,i=Math.abs(t.total-this._lastTimeUpdate.total)<this._durationChangeMinOffset,n=t.firstFragDateTime===this._lastTimeUpdate.firstFragDateTime;e&&i&&n||(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;this._stopToSendStats();var e=this._options.shakaSendStatsInterval||3e4;this.sendStatsId=setInterval((function(){return t._sendStats()}),e)}},{key:"_stopToSendStats",value:function(){this.sendStatsId&&clearInterval(this.sendStatsId),this.sendStatsId=null}},{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 i={shakaError:t,videoError:this.el.error},n=i.shakaError.detail||i.shakaError,r=n.category,o=n.code,u=n.severity,l=n.data;if(i.videoError||!o&&!r)return h(d(e.prototype),"_onError",this).call(this);var c="";try{c=JSON.stringify(l)}catch(i){a.Log.warn("Fail to parse shaka error data",i)}var f=u===s.default.util.Error.Severity.CRITICAL,y={code:"".concat(r,"_").concat(o),description:"Category: ".concat(r,", code: ").concat(o,", severity: ").concat(u,", data: ").concat(c),level:f?a.PlayerError.Levels.FATAL:a.PlayerError.Levels.WARN,raw:t},p=this.createError(y);a.Log.error("Shaka error event:",p),this.trigger(a.Events.PLAYBACK_ERROR,p)}},{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(i.prototype,n),r&&u(i,r),Object.defineProperty(i,"prototype",{writable:!1}),i;var i,n,r}(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.2.0",
"version": "3.3.0",
"description": "clappr dash playback based on shaka player",

@@ -15,4 +15,3 @@ "main": "./dist/dash-shaka-playback.js",

"release": "webpack",
"lint": "eslint src/",
"prepublishOnly": "yarn dist"
"lint": "eslint src/"
},

@@ -26,3 +25,3 @@ "files": [

"peerDependencies": {
"@clappr/core": "^0.4.17"
"@clappr/core": "*"
},

@@ -29,0 +28,0 @@ "devDependencies": {

@@ -119,2 +119,5 @@ import {HTML5Video, Log, Events, PlayerError} from 'clappr'

this._isShakaReadyState = false
this._lastTimeUpdate = { current: 0, total: 0, firstFragDateTime: 0 }
this._timeUpdateFiringRate = 0.2
this._durationChangeMinOffset = 0.5

@@ -128,7 +131,2 @@ this._minDvrSize = typeof (this.options.shakaMinimumDvrSize) === 'undefined' ? 60 : this.options.shakaMinimumDvrSize

_updateDvr(status) {
this.trigger(Events.PLAYBACK_DVR, status)
this.trigger(Events.PLAYBACK_STATS_ADD, { 'dvr': status })
}
seek(time) {

@@ -139,4 +137,2 @@ if (time < 0) {

}
// assume live if time within 3 seconds of end of stream
this.dvrEnabled && this._updateDvr(time < this._duration-3)
time += this._startTime

@@ -148,3 +144,2 @@ this.el.currentTime = time

this.el.pause()
this.dvrEnabled && this._updateDvr(true)
}

@@ -234,3 +229,3 @@

this._stopTimeUpdateTimer()
clearInterval(this.sendStatsId)
this._stopToSendStats()
this._stopped = true

@@ -241,2 +236,3 @@

this._lastTimeUpdate = { current: 0, total: 0, firstFragDateTime: 0 }
this._player.unload().then(() => {

@@ -373,3 +369,3 @@ super.stop()

this._stopTimeUpdateTimer()
clearInterval(this.sendStatsId)
this._stopToSendStats()

@@ -393,2 +389,3 @@ if (this._player) {

this._ccIsSetup = false
this._stopToSendStats()

@@ -428,13 +425,8 @@ let runAllSteps = () => {

let update = {
current: this.getCurrentTime(),
total: this.getDuration(),
firstFragDateTime: this.getProgramDateTime()
}
let isSame = this._lastTimeUpdate && (
update.current === this._lastTimeUpdate.current &&
update.total === this._lastTimeUpdate.total)
if (isSame)
return
const update = { current: this.getCurrentTime(), total: this.getDuration(), firstFragDateTime: this.getProgramDateTime() }
const isSameTime = Math.abs(update.current - this._lastTimeUpdate.current) < this._timeUpdateFiringRate
const isSameDuration = Math.abs(update.total - this._lastTimeUpdate.total) < this._durationChangeMinOffset
const isSameFirstFragDateTime = update.firstFragDateTime === this._lastTimeUpdate.firstFragDateTime
const isSame = isSameTime && isSameDuration && isSameFirstFragDateTime
if (isSame) return
this._lastTimeUpdate = update

@@ -479,2 +471,3 @@ this.trigger(Events.PLAYBACK_TIMEUPDATE, update, this.name)

_startToSendStats () {
this._stopToSendStats()
const intervalMs = this._options.shakaSendStatsInterval || SEND_STATS_INTERVAL_MS

@@ -484,2 +477,7 @@ this.sendStatsId = setInterval(() => this._sendStats(), intervalMs)

_stopToSendStats() {
this.sendStatsId && clearInterval(this.sendStatsId)
this.sendStatsId = null
}
_sendStats () {

@@ -499,10 +497,16 @@ this.trigger(Events.PLAYBACK_STATS_ADD, this._player.getStats())

let { category, code, severity } = error.shakaError.detail || error.shakaError
let { category, code, severity, data } = error.shakaError.detail || error.shakaError
if (error.videoError || !code && !category) return super._onError()
let shakaErrorData = ''
try {
shakaErrorData = JSON.stringify(data)
} catch (error) {
Log.warn('Fail to parse shaka error data', error)
}
const isCritical = severity === shaka.util.Error.Severity.CRITICAL
const errorData = {
code: `${category}_${code}`,
description: `Category: ${category}, code: ${code}, severity: ${severity}`,
description: `Category: ${category}, code: ${code}, severity: ${severity}, data: ${shakaErrorData}`,
level: isCritical ? PlayerError.Levels.FATAL : PlayerError.Levels.WARN,

@@ -509,0 +513,0 @@ raw: err

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc