@clappr/clappr-html5-tvs-playback
Advanced tools
Comparing version 0.0.9 to 0.0.10
@@ -36,4 +36,4 @@ import _classCallCheck from '@babel/runtime/helpers/classCallCheck'; | ||
}; | ||
/* eslint-disable-next-line func-style */ | ||
/* eslint-disable-next-line func-style */ | ||
function sendLicenseRequest() { | ||
@@ -46,2 +46,3 @@ var config = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; | ||
var oipfdrmagent = document.getElementById('oipfdrmagent'); | ||
if (!oipfdrmagent) { | ||
@@ -51,3 +52,5 @@ oipfdrmagent = createDrmAgent(); | ||
} | ||
var xmlLicenceAcquisition = config.xmlLicenceAcquisition ? getFullChallengeMessageTemplate(config.xmlLicenceAcquisition) : getLicenseOverrideMessageTemplate(config.licenseServerURL); | ||
var drmRightsErrorHandler = function drmRightsErrorHandler(resultCode) { | ||
@@ -59,2 +62,3 @@ var errorMessage = { | ||
}; | ||
if (resultCode < 2) { | ||
@@ -65,2 +69,3 @@ Log.error('DRMHandler', 'Error at onDRMRightsError call', errorMessage[resultCode]); | ||
}; | ||
var drmMessageResultHandler = function drmMessageResultHandler(messageID, resultMessage, resultCode) { | ||
@@ -77,2 +82,3 @@ Log.info('DRMHandler', 'onDRMMessageResult messageID', messageID); | ||
}; | ||
if (resultCode !== 0) { | ||
@@ -82,4 +88,6 @@ Log.error('DRMHandler', 'Error at onDRMMessageResult call', errorMessage[resultCode]); | ||
} | ||
return successCallback(); | ||
}; | ||
try { | ||
@@ -94,4 +102,4 @@ oipfdrmagent.onDRMRightsError = drmRightsErrorHandler; | ||
} | ||
/* eslint-disable-next-line func-style */ | ||
/* eslint-disable-next-line func-style */ | ||
function clearLicenseRequest() { | ||
@@ -103,2 +111,3 @@ var onSuccess = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : function () {}; | ||
var oipfdrmagent = document.getElementById('oipfdrmagent'); | ||
if (!oipfdrmagent) { | ||
@@ -108,5 +117,8 @@ Log.warn('DRMHandler', 'No one DRM license has been configured before. It\'s not necessary to clear any license server.'); | ||
} | ||
var xmlLicenceAcquisition = getClearMessageTemplate(); | ||
try { | ||
oipfdrmagent.onDRMRightsError = successCallback; | ||
oipfdrmagent.onDRMMessageResult = function () { | ||
@@ -116,2 +128,3 @@ oipfdrmagent.remove(); | ||
}; | ||
oipfdrmagent.sendDRMMessage(MESSAGE_TYPE, xmlLicenceAcquisition, DRM_SYSTEM_ID); | ||
@@ -137,3 +150,2 @@ } catch (error) { | ||
}; | ||
/** Enum of possible HTMLMediaElement.readyState values. | ||
@@ -143,2 +155,3 @@ * @enum {number} | ||
*/ | ||
var READY_STATE_STAGES = { | ||
@@ -151,3 +164,2 @@ HAVE_NOTHING: 0, | ||
}; | ||
/** Enum of supported mime types. | ||
@@ -157,2 +169,3 @@ * @enum {string} | ||
*/ | ||
var MIME_TYPES = { | ||
@@ -177,2 +190,3 @@ MP4: 'video/mp4', | ||
var urlWithoutParameters = url.split('?')[0]; //eslint-disable-line | ||
var match = urlWithoutParameters.match(/(\.[A-Z0-9]+)/gi); | ||
@@ -184,4 +198,4 @@ var extension = match ? match.pop().replace('.', '') : ''; | ||
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 _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; } } | ||
/** | ||
@@ -191,10 +205,16 @@ * HTML5 playback implementation for HbbTV 2.0.1 capable devices. | ||
*/ | ||
var HTML5TVsPlayback = /*#__PURE__*/function (_Playback) { | ||
_inherits(HTML5TVsPlayback, _Playback); | ||
var _super = _createSuper(HTML5TVsPlayback); | ||
function HTML5TVsPlayback(options, i18n, playerError) { | ||
var _this; | ||
_classCallCheck(this, HTML5TVsPlayback); | ||
_this = _super.call(this, options, i18n, playerError); | ||
_this._onAudioTracksUpdated = _this._onAudioTracksUpdated.bind(_assertThisInitialized(_this)); | ||
_this._sourceElementErrorHandler = _this._onError.bind(_assertThisInitialized(_this)); | ||
_this._playbackType = _this.mediaType; | ||
@@ -206,6 +226,10 @@ _this._drmConfigured = false; | ||
_this._isDestroyed = false; | ||
_this._setAudioTrackListeners(); | ||
_this._setupSource(_this.options.src); | ||
return _this; | ||
} | ||
_createClass(HTML5TVsPlayback, [{ | ||
@@ -244,3 +268,3 @@ key: "name", | ||
get: function get() { | ||
return this.el.readyState >= READY_STATE_STAGES.HAVE_CURRENT_DATA; | ||
return this.el.readyState >= READY_STATE_STAGES.HAVE_FUTURE_DATA; | ||
} | ||
@@ -279,3 +303,7 @@ }, { | ||
var audioTracksFormatted = []; | ||
for (var i = 0; i < audioTracks.length; i++) audioTracksFormatted.push(this._formatAudioTrack(audioTracks[i])); | ||
for (var i = 0; i < audioTracks.length; i++) { | ||
audioTracksFormatted.push(this._formatAudioTrack(audioTracks[i])); | ||
} | ||
return audioTracksFormatted; | ||
@@ -289,6 +317,10 @@ } | ||
var audioTracks = this.el.audioTracks; | ||
for (var i = 0; i < audioTracks.length; i++) if (audioTracks[i].enabled) { | ||
currentTrack = audioTracks[i]; | ||
break; | ||
for (var i = 0; i < audioTracks.length; i++) { | ||
if (audioTracks[i].enabled) { | ||
currentTrack = audioTracks[i]; | ||
break; | ||
} | ||
} | ||
return currentTrack && this._formatAudioTrack(currentTrack); | ||
@@ -371,3 +403,5 @@ } | ||
this.$sourceElement.src = sourceURL; | ||
this.$sourceElement.addEventListener('error', this._sourceElementErrorHandler); | ||
this._src = this.$sourceElement.src; | ||
this._appendSourceElement(); | ||
@@ -384,2 +418,3 @@ } | ||
this._drmConfigured = true; | ||
this._appendSourceElement(); | ||
@@ -438,2 +473,4 @@ } | ||
Log.info(this.name, 'The HTMLMediaElement canplay event is triggered: ', e); | ||
!this._isReady && this._signalizeReadyState(); | ||
if (this._isBuffering) { | ||
@@ -467,3 +504,2 @@ this._isBuffering = false; | ||
Log.info(this.name, 'The HTMLMediaElement loadeddata event is triggered: ', e); | ||
!this._isReady && this._signalizeReadyState(); | ||
} | ||
@@ -536,2 +572,3 @@ }, { | ||
Log.debug(this.name, 'The HTMLMediaElement timeupdate event is triggered: ', e); // Preferring to debug level because of the high frequency of calls. | ||
this.trigger(Events.PLAYBACK_TIMEUPDATE, { | ||
@@ -561,4 +598,6 @@ current: this.el.currentTime, | ||
Log.info(this.name, 'The HTMLMediaElement ended event is triggered: ', e); | ||
this._wipeUpMedia(); | ||
this.trigger(Events.PLAYBACK_ENDED, this.name); | ||
this._wipeUpMedia(); | ||
} | ||
@@ -568,7 +607,10 @@ }, { | ||
value: function _onError(e) { | ||
Log.info(this.name, 'The HTMLMediaElement error event is triggered: ', e); | ||
var _ref = this.el.error || UNKNOWN_ERROR, | ||
code = _ref.code, | ||
message = _ref.message; | ||
var isUnknownError = code === UNKNOWN_ERROR.code; | ||
var _this$$sourceElement; | ||
Log.warn(this.name, 'The HTMLMediaElement error event is triggered: ', e); | ||
var _ref = ((_this$$sourceElement = this.$sourceElement) === null || _this$$sourceElement === void 0 ? void 0 : _this$$sourceElement.error) || this.el.error || UNKNOWN_ERROR, | ||
code = _ref.code, | ||
message = _ref.message; | ||
var formattedError = this.createError({ | ||
@@ -578,5 +620,5 @@ code: code, | ||
raw: this.el.error, | ||
level: isUnknownError ? PlayerError.Levels.WARN : PlayerError.Levels.FATAL | ||
level: PlayerError.Levels.FATAL | ||
}); | ||
isUnknownError ? Log.warn(this.name, 'HTML5 unknown error: ', formattedError) : this.trigger(Events.PLAYBACK_ERROR, formattedError); | ||
this.trigger(Events.PLAYBACK_ERROR, formattedError); | ||
} | ||
@@ -587,2 +629,3 @@ }, { | ||
this._wipeUpMedia(); | ||
this._setupSource(sourceURL); | ||
@@ -594,4 +637,7 @@ } | ||
var _this2 = this; | ||
this._isStopped = false; | ||
this._setupSource(this._src); | ||
var promise = this.el.play(); | ||
@@ -612,5 +658,4 @@ promise && promise.catch && promise.catch(function (error) { | ||
if (time < 0) return Log.warn(this.name, 'Attempting to seek to a negative time. Ignoring this operation.'); | ||
var timeToSeek = time; | ||
var timeToSeek = time; // Assumes that is a live state if the time is within the LIVE_STATE_THRESHOLD of the end of the stream. | ||
// Assumes that is a live state if the time is within the LIVE_STATE_THRESHOLD of the end of the stream. | ||
var dvrStatus = timeToSeek < this.duration - LIVE_STATE_THRESHOLD; | ||
@@ -625,6 +670,11 @@ this.dvrEnabled && this._updateDvr(dvrStatus); | ||
var _this$el$audioTracks; | ||
var track = (_this$el$audioTracks = this.el.audioTracks) === null || _this$el$audioTracks === void 0 ? void 0 : _this$el$audioTracks.getTrackById(id); | ||
if (!track || track.enabled) return; | ||
var audioTracks = this.el.audioTracks; | ||
for (var i = 0; i < audioTracks.length; i++) audioTracks[i].enabled = audioTracks[i].id === id; | ||
for (var i = 0; i < audioTracks.length; i++) { | ||
audioTracks[i].enabled = audioTracks[i].id === id; | ||
} | ||
this.trigger(Events.PLAYBACK_AUDIO_CHANGED, this._formatAudioTrack(track)); | ||
@@ -637,3 +687,5 @@ } | ||
this._isStopped = true; | ||
this._wipeUpMedia(); | ||
this.trigger(Events.PLAYBACK_STOP); | ||
@@ -645,4 +697,7 @@ } | ||
this._isDestroyed = true; | ||
_get(_getPrototypeOf(HTML5TVsPlayback.prototype), "destroy", this).call(this); | ||
this._wipeUpMedia(); | ||
this._src = null; | ||
@@ -655,8 +710,13 @@ } | ||
this._drmConfigured && DRMHandler.clearLicenseRequest.call(this, this._onDrmCleared, this._onDrmError); | ||
this.$sourceElement && this.$sourceElement.removeAttribute('src'); // The src attribute will be added again in play(). | ||
this.$sourceElement && this.$sourceElement.parentNode && this.$sourceElement.parentNode.removeChild(this.$sourceElement); | ||
this.$sourceElement = null; | ||
if (this.$sourceElement) { | ||
this.$sourceElement.removeEventListener('error', this._sourceElementErrorHandler); | ||
this.$sourceElement.removeAttribute('src'); // The src attribute will be added again in play(). | ||
this.$sourceElement.parentNode && this.$sourceElement.parentNode.removeChild(this.$sourceElement); | ||
this.$sourceElement = null; | ||
} | ||
this.el.load(); // Loads with no src attribute to stop the loading of the previous source and avoid leaks. | ||
} | ||
/** | ||
@@ -670,2 +730,3 @@ * Triggers the Clappr playback ready event if the isReady getter returns a true value. | ||
*/ | ||
}, { | ||
@@ -675,2 +736,3 @@ key: "_signalizeReadyState", | ||
var _this3 = this; | ||
var backOff = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 100; | ||
@@ -680,6 +742,5 @@ if (!this.isReady) return setTimeout(function () { | ||
}, backOff); | ||
this._isReady = true; | ||
this.trigger(Events.PLAYBACK_READY, this.name); | ||
this._isReady = true; | ||
} | ||
/** | ||
@@ -690,2 +751,3 @@ * @deprecated | ||
*/ | ||
}, { | ||
@@ -696,3 +758,2 @@ key: "getCurrentTime", | ||
} | ||
/** | ||
@@ -703,2 +764,3 @@ * @deprecated | ||
*/ | ||
}, { | ||
@@ -709,3 +771,2 @@ key: "getDuration", | ||
} | ||
/** | ||
@@ -716,2 +777,3 @@ * @deprecated | ||
*/ | ||
}, { | ||
@@ -722,3 +784,2 @@ key: "isPlaying", | ||
} | ||
/** | ||
@@ -729,2 +790,3 @@ * @deprecated | ||
*/ | ||
}, { | ||
@@ -743,8 +805,9 @@ key: "getPlaybackType", | ||
var isSourceExtensionSupported = MIME_TYPES_BY_EXTENSION[sourceExtension]; | ||
return isSupportedMimetype || isSourceExtensionSupported; | ||
return !!(isSupportedMimetype || isSourceExtensionSupported); | ||
} | ||
}]); | ||
return HTML5TVsPlayback; | ||
}(Playback); | ||
export { HTML5TVsPlayback as default }; | ||
export default HTML5TVsPlayback; |
@@ -5,3 +5,3 @@ (function (global, factory) { | ||
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.HTML5TVsPlayback = factory(global.Clappr)); | ||
})(this, (function (core) { 'use strict'; | ||
}(this, (function (core) { 'use strict'; | ||
@@ -13,2 +13,3 @@ function _classCallCheck(instance, Constructor) { | ||
} | ||
function _defineProperties(target, props) { | ||
@@ -20,13 +21,12 @@ for (var i = 0; i < props.length; i++) { | ||
if ("value" in descriptor) descriptor.writable = true; | ||
Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); | ||
Object.defineProperty(target, 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 _inherits(subClass, superClass) { | ||
@@ -36,2 +36,3 @@ if (typeof superClass !== "function" && superClass !== null) { | ||
} | ||
subClass.prototype = Object.create(superClass && superClass.prototype, { | ||
@@ -44,9 +45,7 @@ constructor: { | ||
}); | ||
Object.defineProperty(subClass, "prototype", { | ||
writable: false | ||
}); | ||
if (superClass) _setPrototypeOf(subClass, superClass); | ||
} | ||
function _getPrototypeOf(o) { | ||
_getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { | ||
_getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { | ||
return o.__proto__ || Object.getPrototypeOf(o); | ||
@@ -56,9 +55,12 @@ }; | ||
} | ||
function _setPrototypeOf(o, p) { | ||
_setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { | ||
_setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { | ||
o.__proto__ = p; | ||
return o; | ||
}; | ||
return _setPrototypeOf(o, p); | ||
} | ||
function _isNativeReflectConstruct() { | ||
@@ -68,2 +70,3 @@ if (typeof Reflect === "undefined" || !Reflect.construct) return false; | ||
if (typeof Proxy === "function") return true; | ||
try { | ||
@@ -76,2 +79,3 @@ Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); | ||
} | ||
function _assertThisInitialized(self) { | ||
@@ -81,19 +85,24 @@ if (self === void 0) { | ||
} | ||
return self; | ||
} | ||
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 _createSuper(Derived) { | ||
var hasNativeReflectConstruct = _isNativeReflectConstruct(); | ||
return function _createSuperInternal() { | ||
var Super = _getPrototypeOf(Derived), | ||
result; | ||
result; | ||
if (hasNativeReflectConstruct) { | ||
var NewTarget = _getPrototypeOf(this).constructor; | ||
result = Reflect.construct(Super, arguments, NewTarget); | ||
@@ -103,5 +112,7 @@ } else { | ||
} | ||
return _possibleConstructorReturn(this, result); | ||
}; | ||
} | ||
function _superPropBase(object, property) { | ||
@@ -112,34 +123,26 @@ while (!Object.prototype.hasOwnProperty.call(object, property)) { | ||
} | ||
return object; | ||
} | ||
function _get() { | ||
function _get(target, property, receiver) { | ||
if (typeof Reflect !== "undefined" && Reflect.get) { | ||
_get = Reflect.get.bind(); | ||
_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(arguments.length < 3 ? target : receiver); | ||
return desc.get.call(receiver); | ||
} | ||
return desc.value; | ||
}; | ||
} | ||
return _get.apply(this, arguments); | ||
return _get(target, property, receiver || target); | ||
} | ||
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 _toPropertyKey(arg) { | ||
var key = _toPrimitive(arg, "string"); | ||
return typeof key === "symbol" ? key : String(key); | ||
} | ||
@@ -172,4 +175,4 @@ var MESSAGE_TYPE = 'application/vnd.ms-playready.initiator+xml'; | ||
}; | ||
/* eslint-disable-next-line func-style */ | ||
/* eslint-disable-next-line func-style */ | ||
function sendLicenseRequest() { | ||
@@ -182,2 +185,3 @@ var config = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; | ||
var oipfdrmagent = document.getElementById('oipfdrmagent'); | ||
if (!oipfdrmagent) { | ||
@@ -187,3 +191,5 @@ oipfdrmagent = createDrmAgent(); | ||
} | ||
var xmlLicenceAcquisition = config.xmlLicenceAcquisition ? getFullChallengeMessageTemplate(config.xmlLicenceAcquisition) : getLicenseOverrideMessageTemplate(config.licenseServerURL); | ||
var drmRightsErrorHandler = function drmRightsErrorHandler(resultCode) { | ||
@@ -195,2 +201,3 @@ var errorMessage = { | ||
}; | ||
if (resultCode < 2) { | ||
@@ -201,2 +208,3 @@ core.Log.error('DRMHandler', 'Error at onDRMRightsError call', errorMessage[resultCode]); | ||
}; | ||
var drmMessageResultHandler = function drmMessageResultHandler(messageID, resultMessage, resultCode) { | ||
@@ -213,2 +221,3 @@ core.Log.info('DRMHandler', 'onDRMMessageResult messageID', messageID); | ||
}; | ||
if (resultCode !== 0) { | ||
@@ -218,4 +227,6 @@ core.Log.error('DRMHandler', 'Error at onDRMMessageResult call', errorMessage[resultCode]); | ||
} | ||
return successCallback(); | ||
}; | ||
try { | ||
@@ -230,4 +241,4 @@ oipfdrmagent.onDRMRightsError = drmRightsErrorHandler; | ||
} | ||
/* eslint-disable-next-line func-style */ | ||
/* eslint-disable-next-line func-style */ | ||
function clearLicenseRequest() { | ||
@@ -239,2 +250,3 @@ var onSuccess = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : function () {}; | ||
var oipfdrmagent = document.getElementById('oipfdrmagent'); | ||
if (!oipfdrmagent) { | ||
@@ -244,5 +256,8 @@ core.Log.warn('DRMHandler', 'No one DRM license has been configured before. It\'s not necessary to clear any license server.'); | ||
} | ||
var xmlLicenceAcquisition = getClearMessageTemplate(); | ||
try { | ||
oipfdrmagent.onDRMRightsError = successCallback; | ||
oipfdrmagent.onDRMMessageResult = function () { | ||
@@ -252,2 +267,3 @@ oipfdrmagent.remove(); | ||
}; | ||
oipfdrmagent.sendDRMMessage(MESSAGE_TYPE, xmlLicenceAcquisition, DRM_SYSTEM_ID); | ||
@@ -273,3 +289,2 @@ } catch (error) { | ||
}; | ||
/** Enum of possible HTMLMediaElement.readyState values. | ||
@@ -279,2 +294,3 @@ * @enum {number} | ||
*/ | ||
var READY_STATE_STAGES = { | ||
@@ -287,3 +303,2 @@ HAVE_NOTHING: 0, | ||
}; | ||
/** Enum of supported mime types. | ||
@@ -293,2 +308,3 @@ * @enum {string} | ||
*/ | ||
var MIME_TYPES = { | ||
@@ -313,2 +329,3 @@ MP4: 'video/mp4', | ||
var urlWithoutParameters = url.split('?')[0]; //eslint-disable-line | ||
var match = urlWithoutParameters.match(/(\.[A-Z0-9]+)/gi); | ||
@@ -323,10 +340,16 @@ var extension = match ? match.pop().replace('.', '') : ''; | ||
*/ | ||
var HTML5TVsPlayback = /*#__PURE__*/function (_Playback) { | ||
_inherits(HTML5TVsPlayback, _Playback); | ||
var _super = _createSuper(HTML5TVsPlayback); | ||
function HTML5TVsPlayback(options, i18n, playerError) { | ||
var _this; | ||
_classCallCheck(this, HTML5TVsPlayback); | ||
_this = _super.call(this, options, i18n, playerError); | ||
_this._onAudioTracksUpdated = _this._onAudioTracksUpdated.bind(_assertThisInitialized(_this)); | ||
_this._sourceElementErrorHandler = _this._onError.bind(_assertThisInitialized(_this)); | ||
_this._playbackType = _this.mediaType; | ||
@@ -338,6 +361,10 @@ _this._drmConfigured = false; | ||
_this._isDestroyed = false; | ||
_this._setAudioTrackListeners(); | ||
_this._setupSource(_this.options.src); | ||
return _this; | ||
} | ||
_createClass(HTML5TVsPlayback, [{ | ||
@@ -376,3 +403,3 @@ key: "name", | ||
get: function get() { | ||
return this.el.readyState >= READY_STATE_STAGES.HAVE_CURRENT_DATA; | ||
return this.el.readyState >= READY_STATE_STAGES.HAVE_FUTURE_DATA; | ||
} | ||
@@ -411,3 +438,7 @@ }, { | ||
var audioTracksFormatted = []; | ||
for (var i = 0; i < audioTracks.length; i++) audioTracksFormatted.push(this._formatAudioTrack(audioTracks[i])); | ||
for (var i = 0; i < audioTracks.length; i++) { | ||
audioTracksFormatted.push(this._formatAudioTrack(audioTracks[i])); | ||
} | ||
return audioTracksFormatted; | ||
@@ -421,6 +452,10 @@ } | ||
var audioTracks = this.el.audioTracks; | ||
for (var i = 0; i < audioTracks.length; i++) if (audioTracks[i].enabled) { | ||
currentTrack = audioTracks[i]; | ||
break; | ||
for (var i = 0; i < audioTracks.length; i++) { | ||
if (audioTracks[i].enabled) { | ||
currentTrack = audioTracks[i]; | ||
break; | ||
} | ||
} | ||
return currentTrack && this._formatAudioTrack(currentTrack); | ||
@@ -503,3 +538,5 @@ } | ||
this.$sourceElement.src = sourceURL; | ||
this.$sourceElement.addEventListener('error', this._sourceElementErrorHandler); | ||
this._src = this.$sourceElement.src; | ||
this._appendSourceElement(); | ||
@@ -516,2 +553,3 @@ } | ||
this._drmConfigured = true; | ||
this._appendSourceElement(); | ||
@@ -570,2 +608,4 @@ } | ||
core.Log.info(this.name, 'The HTMLMediaElement canplay event is triggered: ', e); | ||
!this._isReady && this._signalizeReadyState(); | ||
if (this._isBuffering) { | ||
@@ -599,3 +639,2 @@ this._isBuffering = false; | ||
core.Log.info(this.name, 'The HTMLMediaElement loadeddata event is triggered: ', e); | ||
!this._isReady && this._signalizeReadyState(); | ||
} | ||
@@ -668,2 +707,3 @@ }, { | ||
core.Log.debug(this.name, 'The HTMLMediaElement timeupdate event is triggered: ', e); // Preferring to debug level because of the high frequency of calls. | ||
this.trigger(core.Events.PLAYBACK_TIMEUPDATE, { | ||
@@ -693,4 +733,6 @@ current: this.el.currentTime, | ||
core.Log.info(this.name, 'The HTMLMediaElement ended event is triggered: ', e); | ||
this._wipeUpMedia(); | ||
this.trigger(core.Events.PLAYBACK_ENDED, this.name); | ||
this._wipeUpMedia(); | ||
} | ||
@@ -700,7 +742,10 @@ }, { | ||
value: function _onError(e) { | ||
core.Log.info(this.name, 'The HTMLMediaElement error event is triggered: ', e); | ||
var _ref = this.el.error || UNKNOWN_ERROR, | ||
code = _ref.code, | ||
message = _ref.message; | ||
var isUnknownError = code === UNKNOWN_ERROR.code; | ||
var _this$$sourceElement; | ||
core.Log.warn(this.name, 'The HTMLMediaElement error event is triggered: ', e); | ||
var _ref = ((_this$$sourceElement = this.$sourceElement) === null || _this$$sourceElement === void 0 ? void 0 : _this$$sourceElement.error) || this.el.error || UNKNOWN_ERROR, | ||
code = _ref.code, | ||
message = _ref.message; | ||
var formattedError = this.createError({ | ||
@@ -710,5 +755,5 @@ code: code, | ||
raw: this.el.error, | ||
level: isUnknownError ? core.PlayerError.Levels.WARN : core.PlayerError.Levels.FATAL | ||
level: core.PlayerError.Levels.FATAL | ||
}); | ||
isUnknownError ? core.Log.warn(this.name, 'HTML5 unknown error: ', formattedError) : this.trigger(core.Events.PLAYBACK_ERROR, formattedError); | ||
this.trigger(core.Events.PLAYBACK_ERROR, formattedError); | ||
} | ||
@@ -719,2 +764,3 @@ }, { | ||
this._wipeUpMedia(); | ||
this._setupSource(sourceURL); | ||
@@ -726,4 +772,7 @@ } | ||
var _this2 = this; | ||
this._isStopped = false; | ||
this._setupSource(this._src); | ||
var promise = this.el.play(); | ||
@@ -744,5 +793,4 @@ promise && promise.catch && promise.catch(function (error) { | ||
if (time < 0) return core.Log.warn(this.name, 'Attempting to seek to a negative time. Ignoring this operation.'); | ||
var timeToSeek = time; | ||
var timeToSeek = time; // Assumes that is a live state if the time is within the LIVE_STATE_THRESHOLD of the end of the stream. | ||
// Assumes that is a live state if the time is within the LIVE_STATE_THRESHOLD of the end of the stream. | ||
var dvrStatus = timeToSeek < this.duration - LIVE_STATE_THRESHOLD; | ||
@@ -757,6 +805,11 @@ this.dvrEnabled && this._updateDvr(dvrStatus); | ||
var _this$el$audioTracks; | ||
var track = (_this$el$audioTracks = this.el.audioTracks) === null || _this$el$audioTracks === void 0 ? void 0 : _this$el$audioTracks.getTrackById(id); | ||
if (!track || track.enabled) return; | ||
var audioTracks = this.el.audioTracks; | ||
for (var i = 0; i < audioTracks.length; i++) audioTracks[i].enabled = audioTracks[i].id === id; | ||
for (var i = 0; i < audioTracks.length; i++) { | ||
audioTracks[i].enabled = audioTracks[i].id === id; | ||
} | ||
this.trigger(core.Events.PLAYBACK_AUDIO_CHANGED, this._formatAudioTrack(track)); | ||
@@ -769,3 +822,5 @@ } | ||
this._isStopped = true; | ||
this._wipeUpMedia(); | ||
this.trigger(core.Events.PLAYBACK_STOP); | ||
@@ -777,4 +832,7 @@ } | ||
this._isDestroyed = true; | ||
_get(_getPrototypeOf(HTML5TVsPlayback.prototype), "destroy", this).call(this); | ||
this._wipeUpMedia(); | ||
this._src = null; | ||
@@ -787,8 +845,13 @@ } | ||
this._drmConfigured && DRMHandler.clearLicenseRequest.call(this, this._onDrmCleared, this._onDrmError); | ||
this.$sourceElement && this.$sourceElement.removeAttribute('src'); // The src attribute will be added again in play(). | ||
this.$sourceElement && this.$sourceElement.parentNode && this.$sourceElement.parentNode.removeChild(this.$sourceElement); | ||
this.$sourceElement = null; | ||
if (this.$sourceElement) { | ||
this.$sourceElement.removeEventListener('error', this._sourceElementErrorHandler); | ||
this.$sourceElement.removeAttribute('src'); // The src attribute will be added again in play(). | ||
this.$sourceElement.parentNode && this.$sourceElement.parentNode.removeChild(this.$sourceElement); | ||
this.$sourceElement = null; | ||
} | ||
this.el.load(); // Loads with no src attribute to stop the loading of the previous source and avoid leaks. | ||
} | ||
/** | ||
@@ -802,2 +865,3 @@ * Triggers the Clappr playback ready event if the isReady getter returns a true value. | ||
*/ | ||
}, { | ||
@@ -807,2 +871,3 @@ key: "_signalizeReadyState", | ||
var _this3 = this; | ||
var backOff = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 100; | ||
@@ -812,6 +877,5 @@ if (!this.isReady) return setTimeout(function () { | ||
}, backOff); | ||
this._isReady = true; | ||
this.trigger(core.Events.PLAYBACK_READY, this.name); | ||
this._isReady = true; | ||
} | ||
/** | ||
@@ -822,2 +886,3 @@ * @deprecated | ||
*/ | ||
}, { | ||
@@ -828,3 +893,2 @@ key: "getCurrentTime", | ||
} | ||
/** | ||
@@ -835,2 +899,3 @@ * @deprecated | ||
*/ | ||
}, { | ||
@@ -841,3 +906,2 @@ key: "getDuration", | ||
} | ||
/** | ||
@@ -848,2 +912,3 @@ * @deprecated | ||
*/ | ||
}, { | ||
@@ -854,3 +919,2 @@ key: "isPlaying", | ||
} | ||
/** | ||
@@ -861,2 +925,3 @@ * @deprecated | ||
*/ | ||
}, { | ||
@@ -875,5 +940,6 @@ key: "getPlaybackType", | ||
var isSourceExtensionSupported = MIME_TYPES_BY_EXTENSION[sourceExtension]; | ||
return isSupportedMimetype || isSourceExtensionSupported; | ||
return !!(isSupportedMimetype || isSourceExtensionSupported); | ||
} | ||
}]); | ||
return HTML5TVsPlayback; | ||
@@ -884,2 +950,2 @@ }(core.Playback); | ||
})); | ||
}))); |
@@ -1,1 +0,1 @@ | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t(require("@clappr/core")):"function"==typeof define&&define.amd?define(["@clappr/core"],t):(e="undefined"!=typeof globalThis?globalThis:e||self).HTML5TVsPlayback=t(e.Clappr)}(this,(function(e){"use strict";function t(e,t){for(var n=0;n<t.length;n++){var i=t[n];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(e,(r=i.key,o=void 0,"symbol"==typeof(o=function(e,t){if("object"!=typeof e||null===e)return e;var n=e[Symbol.toPrimitive];if(void 0!==n){var i=n.call(e,t||"default");if("object"!=typeof i)return i;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}(r,"string"))?o:String(o)),i)}var r,o}function n(e){return n=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(e){return e.__proto__||Object.getPrototypeOf(e)},n(e)}function i(e,t){return i=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(e,t){return e.__proto__=t,e},i(e,t)}function r(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function o(e){var t=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(e){return!1}}();return function(){var i,o=n(e);if(t){var a=n(this).constructor;i=Reflect.construct(o,arguments,a)}else i=o.apply(this,arguments);return function(e,t){if(t&&("object"==typeof t||"function"==typeof t))return t;if(void 0!==t)throw new TypeError("Derived constructors may only return object or undefined");return r(e)}(this,i)}}function a(){return a="undefined"!=typeof Reflect&&Reflect.get?Reflect.get.bind():function(e,t,i){var r=function(e,t){for(;!Object.prototype.hasOwnProperty.call(e,t)&&null!==(e=n(e)););return e}(e,t);if(r){var o=Object.getOwnPropertyDescriptor(r,t);return o.get?o.get.call(arguments.length<3?e:i):o.value}},a.apply(this,arguments)}var s="application/vnd.ms-playready.initiator+xml",u="urn:dvb:casystemid:19219";var l={sendLicenseRequest:function(){var t,n=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:function(){},r=(arguments.length>1&&void 0!==arguments[1]?arguments[1]:function(){}).bind(this),o=i.bind(this),a=document.getElementById("oipfdrmagent");a||((t=document.createElement("object")).id="oipfdrmagent",t.type="application/oipfdrmagent",t.style.visibility="hidden",t.style.position="absolute",t.style.top="0",t.style.left="0",t.style.width="0",t.style.height="0",a=t,this&&this.el?this.el.appendChild(a):document.body.appendChild(a));var l,d,c=n.xmlLicenceAcquisition?(d=n.xmlLicenceAcquisition,'<?xml version="1.0" encoding="utf-8"?><PlayReadyInitiator xmlns="http://schemas.microsoft.com/DRM/2007/03/protocols/"><LicenseAcquisition><Header>'+"".concat(d)+"</Header></LicenseAcquisition></PlayReadyInitiator>"):(l=n.licenseServerURL,'<?xml version="1.0" encoding="utf-8"?><PlayReadyInitiator xmlns="http://schemas.microsoft.com/DRM/2007/03/protocols/"><LicenseServerUriOverride>'+"<LA_URL>".concat(l,"</LA_URL>")+"</LicenseServerUriOverride></PlayReadyInitiator>");try{a.onDRMRightsError=function(t){var n={0:"DRM: No license error",1:"DRM: Invalid license error",2:"DRM: License valid"};if(t<2)return e.Log.error("DRMHandler","Error at onDRMRightsError call",n[t]),o(n[t])},a.onDRMMessageResult=function(t,n,i){e.Log.info("DRMHandler","onDRMMessageResult messageID",t),e.Log.info("DRMHandler","onDRMMessageResult resultMessage",n),e.Log.info("DRMHandler","onDRMMessageResult resultCode",i);var a={1:"DRM: Unspecified error",2:"DRM: Cannot process request",3:"DRM: Wrong format",4:"DRM: User Consent Needed",5:"DRM: Unknown DRM system"};return 0!==i?(e.Log.error("DRMHandler","Error at onDRMMessageResult call",a[i]),o(a[i])):r()},a.sendDRMMessage(s,c,u)}catch(t){return e.Log.error("DRMHandler","Error at sendDRMMessage call",t.message),o(t.message)}},clearLicenseRequest:function(){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:function(){},n=(arguments.length>0&&void 0!==arguments[0]?arguments[0]:function(){}).bind(this),i=t.bind(this),r=document.getElementById("oipfdrmagent");if(r){try{r.onDRMRightsError=n,r.onDRMMessageResult=function(){r.remove(),n()},r.sendDRMMessage(s,'<?xml version="1.0" encoding="utf-8"?><PlayReadyInitiator xmlns="http://schemas.microsoft.com/DRM/2007/03/protocols/"></PlayReadyInitiator>',u)}catch(t){e.Log.error("DRMHandler","Error at sendDRMMessage call",t.message),i(t.message)}}else e.Log.warn("DRMHandler","No one DRM license has been configured before. It's not necessary to clear any license server.")}},d={code:"unknown",message:"unknown"},c=2,h={MP4:"video/mp4",VND_APPLE_MPEGURL:"application/vnd.apple.mpegurl",VND_MS_SSTR:"application/vnd.ms-sstr+xml",DASH:"application/dash+xml"},g={m3u8:h.VND_APPLE_MPEGURL,m3u:h.VND_APPLE_MPEGURL,mp4:h.MP4,ism:h.VND_MS_SSTR,mpd:h.DASH},f=function(e){var t=e.split("?")[0].match(/(\.[A-Z0-9]+)/gi);return t?t.pop().replace(".",""):""},y=function(s){!function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),Object.defineProperty(e,"prototype",{writable:!1}),t&&i(e,t)}(v,s);var u,y,m,p=o(v);function v(e,t,n){var i;return function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,v),(i=p.call(this,e,t,n))._onAudioTracksUpdated=i._onAudioTracksUpdated.bind(r(i)),i._playbackType=i.mediaType,i._drmConfigured=!1,i._isReady=!1,i._isBuffering=!1,i._isStopped=!1,i._isDestroyed=!1,i._setAudioTrackListeners(),i._setupSource(i.options.src),i}return u=v,y=[{key:"name",get:function(){return"html5_tvs_playback"}},{key:"supportedVersion",get:function(){return{min:e.version}}},{key:"tagName",get:function(){return"video"}},{key:"attributes",get:function(){return{width:"100%",height:"100%"}}},{key:"mediaType",get:function(){return this.el.duration===1/0?e.Playback.LIVE:e.Playback.VOD}},{key:"isReady",get:function(){return this.el.readyState>=c}},{key:"playing",get:function(){return!this.el.paused&&!this.el.ended}},{key:"currentTime",get:function(){return this.el.currentTime}},{key:"duration",get:function(){return this.isLive?this.el.seekable.end(this.el.seekable.length-1)-this.el.seekable.start(0):this.el.duration}},{key:"ended",get:function(){return this.el.ended}},{key:"buffering",get:function(){return this._isBuffering}},{key:"audioTracks",get:function(){if(!this.el.audioTracks)return[];for(var e=this.el.audioTracks,t=[],n=0;n<e.length;n++)t.push(this._formatAudioTrack(e[n]));return t}},{key:"currentAudioTrack",get:function(){if(!this.el.audioTracks)return null;for(var e=null,t=this.el.audioTracks,n=0;n<t.length;n++)if(t[n].enabled){e=t[n];break}return e&&this._formatAudioTrack(e)}},{key:"isLive",get:function(){return this.mediaType===e.Playback.LIVE}},{key:"minimumDvrSizeConfig",get:function(){var e=this.options.playback&&this.options.playback.minimumDvrSize;return void 0!==e&&"number"==typeof e&&e}},{key:"dvrSize",get:function(){return this.minimumDvrSizeConfig?this.minimumDvrSizeConfig:60}},{key:"dvrEnabled",get:function(){return this.duration>=this.dvrSize&&this.isLive}},{key:"config",get:function(){return this.options.html5TvsPlayback}},{key:"events",get:function(){return{canplay:this._onCanPlay,canplaythrough:this._onCanPlayThrough,loadstart:this._onLoadStart,loadedmetadata:this._onLoadedMetadata,loadeddata:this._onLoadedData,waiting:this._onWaiting,stalled:this._onStalled,emptied:this._onEmptied,play:this._onPlay,playing:this._onPlaying,pause:this._onPause,ratechange:this._onRateChange,volumechange:this._onVolumeChange,seeking:this._onSeeking,seeked:this._onSeeked,progress:this._onProgress,timeupdate:this._onTimeUpdate,durationchange:this._onDurationChange,abort:this._onAbort,suspend:this._onSuspend,ended:this._onEnded,error:this._onError}}},{key:"playbackType",get:function(){return this._playbackType},set:function(e){this._playbackType=e}},{key:"sourceMedia",get:function(){return this._src}},{key:"_setupSource",value:function(e){e!==(this.$sourceElement&&this.$sourceElement.src)&&(this.$sourceElement=document.createElement("source"),this.$sourceElement.type=g[f(e)],this.$sourceElement.src=e,this._src=this.$sourceElement.src,this._appendSourceElement())}},{key:"_appendSourceElement",value:function(){this.config&&this.config.drm&&!this._drmConfigured?l.sendLicenseRequest.call(this,this.config.drm,this._onDrmConfigured,this._onDrmError):this.el.appendChild(this.$sourceElement)}},{key:"_onDrmConfigured",value:function(){this._drmConfigured=!0,this._appendSourceElement()}},{key:"_onDrmCleared",value:function(){this._drmConfigured=!1}},{key:"_onDrmError",value:function(t){this._drmConfigured=!1;var n=this.createError({code:"DRM",description:t,level:e.PlayerError.Levels.FATAL});this.trigger(e.Events.PLAYBACK_ERROR,n)}},{key:"_setAudioTrackListeners",value:function(){var e=this.el.audioTracks;e&&(e.addEventListener("addtrack",this._onAudioTracksUpdated),e.addEventListener("removetrack",this._onAudioTracksUpdated))}},{key:"_onAudioTracksUpdated",value:function(){this.trigger(e.Events.PLAYBACK_AUDIO_AVAILABLE,this.audioTracks)}},{key:"_formatAudioTrack",value:function(e){return{id:e.id,language:e.language,label:e.label,kind:e.kind}}},{key:"_updateDvr",value:function(t){this.trigger(e.Events.PLAYBACK_DVR,t),this.trigger(e.Events.PLAYBACK_STATS_ADD,{dvr:t})}},{key:"_onCanPlay",value:function(t){e.Log.info(this.name,"The HTMLMediaElement canplay event is triggered: ",t),this._isBuffering&&(this._isBuffering=!1,this.trigger(e.Events.PLAYBACK_BUFFERFULL,this.name))}},{key:"_onCanPlayThrough",value:function(t){e.Log.info(this.name,"The HTMLMediaElement canplaythrough event is triggered: ",t)}},{key:"_onLoadStart",value:function(t){e.Log.info(this.name,"The HTMLMediaElement loadstart event is triggered: ",t)}},{key:"_onLoadedMetadata",value:function(t){e.Log.info(this.name,"The HTMLMediaElement loadedmetadata event is triggered: ",t),this.trigger(e.Events.PLAYBACK_LOADEDMETADATA,{duration:t.target.duration,data:t})}},{key:"_onLoadedData",value:function(t){e.Log.info(this.name,"The HTMLMediaElement loadeddata event is triggered: ",t),!this._isReady&&this._signalizeReadyState()}},{key:"_onWaiting",value:function(t){this._isBuffering=!0,e.Log.info(this.name,"The HTMLMediaElement waiting event is triggered: ",t),this.trigger(e.Events.PLAYBACK_BUFFERING,this.name)}},{key:"_onStalled",value:function(t){e.Log.info(this.name,"The HTMLMediaElement stalled event is triggered: ",t)}},{key:"_onEmptied",value:function(t){e.Log.info(this.name,"The HTMLMediaElement emptied event is triggered: ",t)}},{key:"_onPlay",value:function(t){e.Log.info(this.name,"The HTMLMediaElement play event is triggered: ",t),this.trigger(e.Events.PLAYBACK_PLAY_INTENT)}},{key:"_onPlaying",value:function(t){e.Log.info(this.name,"The HTMLMediaElement playing event is triggered: ",t),this.trigger(e.Events.PLAYBACK_PLAY)}},{key:"_onPause",value:function(t){e.Log.info(this.name,"The HTMLMediaElement pause event is triggered: ",t),this.trigger(e.Events.PLAYBACK_PAUSE)}},{key:"_onRateChange",value:function(t){e.Log.info(this.name,"The HTMLMediaElement ratechange event is triggered: ",t)}},{key:"_onVolumeChange",value:function(t){e.Log.info(this.name,"The HTMLMediaElement volumechange event is triggered: ",t)}},{key:"_onSeeking",value:function(t){e.Log.info(this.name,"The HTMLMediaElement seeking event is triggered: ",t),this.trigger(e.Events.PLAYBACK_SEEK)}},{key:"_onSeeked",value:function(t){e.Log.info(this.name,"The HTMLMediaElement seeked event is triggered: ",t),this.trigger(e.Events.PLAYBACK_SEEKED)}},{key:"_onProgress",value:function(t){e.Log.debug(this.name,"The HTMLMediaElement progress event is triggered: ",t)}},{key:"_onTimeUpdate",value:function(t){e.Log.debug(this.name,"The HTMLMediaElement timeupdate event is triggered: ",t),this.trigger(e.Events.PLAYBACK_TIMEUPDATE,{current:this.el.currentTime,total:this.duration},this.name)}},{key:"_onDurationChange",value:function(t){e.Log.info(this.name,"The HTMLMediaElement durationchange event is triggered: ",t)}},{key:"_onAbort",value:function(t){e.Log.info(this.name,"The HTMLMediaElement abort event is triggered: ",t)}},{key:"_onSuspend",value:function(t){e.Log.info(this.name,"The HTMLMediaElement suspend event is triggered: ",t)}},{key:"_onEnded",value:function(t){e.Log.info(this.name,"The HTMLMediaElement ended event is triggered: ",t),this.trigger(e.Events.PLAYBACK_ENDED,this.name),this._wipeUpMedia()}},{key:"_onError",value:function(t){e.Log.info(this.name,"The HTMLMediaElement error event is triggered: ",t);var n=this.el.error||d,i=n.code,r=n.message,o=i===d.code,a=this.createError({code:i,description:r,raw:this.el.error,level:o?e.PlayerError.Levels.WARN:e.PlayerError.Levels.FATAL});o?e.Log.warn(this.name,"HTML5 unknown error: ",a):this.trigger(e.Events.PLAYBACK_ERROR,a)}},{key:"load",value:function(e){this._wipeUpMedia(),this._setupSource(e)}},{key:"play",value:function(){var t=this;this._isStopped=!1,this._setupSource(this._src);var n=this.el.play();n&&n.catch&&n.catch((function(n){return e.Log.warn(t.name,"The play promise throws one error: ",n)}))}},{key:"pause",value:function(){this.el.pause(),this.dvrEnabled&&this._updateDvr(!0)}},{key:"seek",value:function(t){if(t<0)return e.Log.warn(this.name,"Attempting to seek to a negative time. Ignoring this operation.");var n=t,i=n<this.duration-3;this.dvrEnabled&&this._updateDvr(i),this.el.seekable&&this.el.seekable.start&&(n+=this.el.seekable.start(0)),this.el.currentTime=n}},{key:"switchAudioTrack",value:function(t){var n,i=null===(n=this.el.audioTracks)||void 0===n?void 0:n.getTrackById(t);if(i&&!i.enabled){for(var r=this.el.audioTracks,o=0;o<r.length;o++)r[o].enabled=r[o].id===t;this.trigger(e.Events.PLAYBACK_AUDIO_CHANGED,this._formatAudioTrack(i))}}},{key:"stop",value:function(){this.pause(),this._isStopped=!0,this._wipeUpMedia(),this.trigger(e.Events.PLAYBACK_STOP)}},{key:"destroy",value:function(){this._isDestroyed=!0,a(n(v.prototype),"destroy",this).call(this),this._wipeUpMedia(),this._src=null}},{key:"_wipeUpMedia",value:function(){this._isReady=!1,this._drmConfigured&&l.clearLicenseRequest.call(this,this._onDrmCleared,this._onDrmError),this.$sourceElement&&this.$sourceElement.removeAttribute("src"),this.$sourceElement&&this.$sourceElement.parentNode&&this.$sourceElement.parentNode.removeChild(this.$sourceElement),this.$sourceElement=null,this.el.load()}},{key:"_signalizeReadyState",value:function(){var t=this,n=arguments.length>0&&void 0!==arguments[0]?arguments[0]:100;if(!this.isReady)return setTimeout((function(){t._signalizeReadyState(2*n)}),n);this.trigger(e.Events.PLAYBACK_READY,this.name),this._isReady=!0}},{key:"getCurrentTime",value:function(){return this.currentTime}},{key:"getDuration",value:function(){return this.duration}},{key:"isPlaying",value:function(){return this.playing}},{key:"getPlaybackType",value:function(){return this.mediaType}}],m=[{key:"canPlay",value:function(e,t){var n=Object.values(h).find((function(e){return t===e})),i=f(e);return n||g[i]}}],y&&t(u.prototype,y),m&&t(u,m),Object.defineProperty(u,"prototype",{writable:!1}),v}(e.Playback);return y})); | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t(require("@clappr/core")):"function"==typeof define&&define.amd?define(["@clappr/core"],t):(e="undefined"!=typeof globalThis?globalThis:e||self).HTML5TVsPlayback=t(e.Clappr)}(this,(function(e){"use strict";function t(e,t){for(var n=0;n<t.length;n++){var i=t[n];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(e,i.key,i)}}function n(e){return(n=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)})(e)}function i(e,t){return(i=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e})(e,t)}function r(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function o(e,t){return!t||"object"!=typeof t&&"function"!=typeof t?r(e):t}function a(e){var t=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(e){return!1}}();return function(){var i,r=n(e);if(t){var a=n(this).constructor;i=Reflect.construct(r,arguments,a)}else i=r.apply(this,arguments);return o(this,i)}}function s(e,t,i){return(s="undefined"!=typeof Reflect&&Reflect.get?Reflect.get:function(e,t,i){var r=function(e,t){for(;!Object.prototype.hasOwnProperty.call(e,t)&&null!==(e=n(e)););return e}(e,t);if(r){var o=Object.getOwnPropertyDescriptor(r,t);return o.get?o.get.call(i):o.value}})(e,t,i||e)}var u="application/vnd.ms-playready.initiator+xml",l="urn:dvb:casystemid:19219",d=function(e){return'<?xml version="1.0" encoding="utf-8"?><PlayReadyInitiator xmlns="http://schemas.microsoft.com/DRM/2007/03/protocols/"><LicenseAcquisition><Header>'+"".concat(e)+"</Header></LicenseAcquisition></PlayReadyInitiator>"},c=function(e){return'<?xml version="1.0" encoding="utf-8"?><PlayReadyInitiator xmlns="http://schemas.microsoft.com/DRM/2007/03/protocols/"><LicenseServerUriOverride>'+"<LA_URL>".concat(e,"</LA_URL>")+"</LicenseServerUriOverride></PlayReadyInitiator>"},h=function(){var e=document.createElement("object");return e.id="oipfdrmagent",e.type="application/oipfdrmagent",e.style.visibility="hidden",e.style.position="absolute",e.style.top="0",e.style.left="0",e.style.width="0",e.style.height="0",e};var g={sendLicenseRequest:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:function(){},i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:function(){},r=n.bind(this),o=i.bind(this),a=document.getElementById("oipfdrmagent");a||(a=h(),this&&this.el?this.el.appendChild(a):document.body.appendChild(a));var s=t.xmlLicenceAcquisition?d(t.xmlLicenceAcquisition):c(t.licenseServerURL),g=function(t){var n={0:"DRM: No license error",1:"DRM: Invalid license error",2:"DRM: License valid"};if(t<2)return e.Log.error("DRMHandler","Error at onDRMRightsError call",n[t]),o(n[t])},f=function(t,n,i){e.Log.info("DRMHandler","onDRMMessageResult messageID",t),e.Log.info("DRMHandler","onDRMMessageResult resultMessage",n),e.Log.info("DRMHandler","onDRMMessageResult resultCode",i);var a={1:"DRM: Unspecified error",2:"DRM: Cannot process request",3:"DRM: Wrong format",4:"DRM: User Consent Needed",5:"DRM: Unknown DRM system"};return 0!==i?(e.Log.error("DRMHandler","Error at onDRMMessageResult call",a[i]),o(a[i])):r()};try{a.onDRMRightsError=g,a.onDRMMessageResult=f,a.sendDRMMessage(u,s,l)}catch(t){return e.Log.error("DRMHandler","Error at sendDRMMessage call",t.message),o(t.message)}},clearLicenseRequest:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:function(){},n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:function(){},i=t.bind(this),r=n.bind(this),o=document.getElementById("oipfdrmagent");if(o){var a='<?xml version="1.0" encoding="utf-8"?><PlayReadyInitiator xmlns="http://schemas.microsoft.com/DRM/2007/03/protocols/"></PlayReadyInitiator>';try{o.onDRMRightsError=i,o.onDRMMessageResult=function(){o.remove(),i()},o.sendDRMMessage(u,a,l)}catch(t){e.Log.error("DRMHandler","Error at sendDRMMessage call",t.message),r(t.message)}}else e.Log.warn("DRMHandler","No one DRM license has been configured before. It's not necessary to clear any license server.")}},f={code:"unknown",message:"unknown"},m=3,y={MP4:"video/mp4",VND_APPLE_MPEGURL:"application/vnd.apple.mpegurl",VND_MS_SSTR:"application/vnd.ms-sstr+xml",DASH:"application/dash+xml"},p={m3u8:y.VND_APPLE_MPEGURL,m3u:y.VND_APPLE_MPEGURL,mp4:y.MP4,ism:y.VND_MS_SSTR,mpd:y.DASH},v=function(e){var t=e.split("?")[0].match(/(\.[A-Z0-9]+)/gi);return t?t.pop().replace(".",""):""};return function(o){!function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),t&&i(e,t)}(h,o);var u,l,d,c=a(h);function h(e,t,n){var i;return function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,h),(i=c.call(this,e,t,n))._onAudioTracksUpdated=i._onAudioTracksUpdated.bind(r(i)),i._sourceElementErrorHandler=i._onError.bind(r(i)),i._playbackType=i.mediaType,i._drmConfigured=!1,i._isReady=!1,i._isBuffering=!1,i._isStopped=!1,i._isDestroyed=!1,i._setAudioTrackListeners(),i._setupSource(i.options.src),i}return u=h,d=[{key:"canPlay",value:function(e,t){var n=Object.values(y).find((function(e){return t===e})),i=v(e);return!(!n&&!p[i])}}],(l=[{key:"name",get:function(){return"html5_tvs_playback"}},{key:"supportedVersion",get:function(){return{min:e.version}}},{key:"tagName",get:function(){return"video"}},{key:"attributes",get:function(){return{width:"100%",height:"100%"}}},{key:"mediaType",get:function(){return this.el.duration===1/0?e.Playback.LIVE:e.Playback.VOD}},{key:"isReady",get:function(){return this.el.readyState>=m}},{key:"playing",get:function(){return!this.el.paused&&!this.el.ended}},{key:"currentTime",get:function(){return this.el.currentTime}},{key:"duration",get:function(){return this.isLive?this.el.seekable.end(this.el.seekable.length-1)-this.el.seekable.start(0):this.el.duration}},{key:"ended",get:function(){return this.el.ended}},{key:"buffering",get:function(){return this._isBuffering}},{key:"audioTracks",get:function(){if(!this.el.audioTracks)return[];for(var e=this.el.audioTracks,t=[],n=0;n<e.length;n++)t.push(this._formatAudioTrack(e[n]));return t}},{key:"currentAudioTrack",get:function(){if(!this.el.audioTracks)return null;for(var e=null,t=this.el.audioTracks,n=0;n<t.length;n++)if(t[n].enabled){e=t[n];break}return e&&this._formatAudioTrack(e)}},{key:"isLive",get:function(){return this.mediaType===e.Playback.LIVE}},{key:"minimumDvrSizeConfig",get:function(){var e=this.options.playback&&this.options.playback.minimumDvrSize;return void 0!==e&&"number"==typeof e&&e}},{key:"dvrSize",get:function(){return this.minimumDvrSizeConfig?this.minimumDvrSizeConfig:60}},{key:"dvrEnabled",get:function(){return this.duration>=this.dvrSize&&this.isLive}},{key:"config",get:function(){return this.options.html5TvsPlayback}},{key:"events",get:function(){return{canplay:this._onCanPlay,canplaythrough:this._onCanPlayThrough,loadstart:this._onLoadStart,loadedmetadata:this._onLoadedMetadata,loadeddata:this._onLoadedData,waiting:this._onWaiting,stalled:this._onStalled,emptied:this._onEmptied,play:this._onPlay,playing:this._onPlaying,pause:this._onPause,ratechange:this._onRateChange,volumechange:this._onVolumeChange,seeking:this._onSeeking,seeked:this._onSeeked,progress:this._onProgress,timeupdate:this._onTimeUpdate,durationchange:this._onDurationChange,abort:this._onAbort,suspend:this._onSuspend,ended:this._onEnded,error:this._onError}}},{key:"playbackType",get:function(){return this._playbackType},set:function(e){this._playbackType=e}},{key:"sourceMedia",get:function(){return this._src}},{key:"_setupSource",value:function(e){e!==(this.$sourceElement&&this.$sourceElement.src)&&(this.$sourceElement=document.createElement("source"),this.$sourceElement.type=p[v(e)],this.$sourceElement.src=e,this.$sourceElement.addEventListener("error",this._sourceElementErrorHandler),this._src=this.$sourceElement.src,this._appendSourceElement())}},{key:"_appendSourceElement",value:function(){this.config&&this.config.drm&&!this._drmConfigured?g.sendLicenseRequest.call(this,this.config.drm,this._onDrmConfigured,this._onDrmError):this.el.appendChild(this.$sourceElement)}},{key:"_onDrmConfigured",value:function(){this._drmConfigured=!0,this._appendSourceElement()}},{key:"_onDrmCleared",value:function(){this._drmConfigured=!1}},{key:"_onDrmError",value:function(t){this._drmConfigured=!1;var n=this.createError({code:"DRM",description:t,level:e.PlayerError.Levels.FATAL});this.trigger(e.Events.PLAYBACK_ERROR,n)}},{key:"_setAudioTrackListeners",value:function(){var e=this.el.audioTracks;e&&(e.addEventListener("addtrack",this._onAudioTracksUpdated),e.addEventListener("removetrack",this._onAudioTracksUpdated))}},{key:"_onAudioTracksUpdated",value:function(){this.trigger(e.Events.PLAYBACK_AUDIO_AVAILABLE,this.audioTracks)}},{key:"_formatAudioTrack",value:function(e){return{id:e.id,language:e.language,label:e.label,kind:e.kind}}},{key:"_updateDvr",value:function(t){this.trigger(e.Events.PLAYBACK_DVR,t),this.trigger(e.Events.PLAYBACK_STATS_ADD,{dvr:t})}},{key:"_onCanPlay",value:function(t){e.Log.info(this.name,"The HTMLMediaElement canplay event is triggered: ",t),!this._isReady&&this._signalizeReadyState(),this._isBuffering&&(this._isBuffering=!1,this.trigger(e.Events.PLAYBACK_BUFFERFULL,this.name))}},{key:"_onCanPlayThrough",value:function(t){e.Log.info(this.name,"The HTMLMediaElement canplaythrough event is triggered: ",t)}},{key:"_onLoadStart",value:function(t){e.Log.info(this.name,"The HTMLMediaElement loadstart event is triggered: ",t)}},{key:"_onLoadedMetadata",value:function(t){e.Log.info(this.name,"The HTMLMediaElement loadedmetadata event is triggered: ",t),this.trigger(e.Events.PLAYBACK_LOADEDMETADATA,{duration:t.target.duration,data:t})}},{key:"_onLoadedData",value:function(t){e.Log.info(this.name,"The HTMLMediaElement loadeddata event is triggered: ",t)}},{key:"_onWaiting",value:function(t){this._isBuffering=!0,e.Log.info(this.name,"The HTMLMediaElement waiting event is triggered: ",t),this.trigger(e.Events.PLAYBACK_BUFFERING,this.name)}},{key:"_onStalled",value:function(t){e.Log.info(this.name,"The HTMLMediaElement stalled event is triggered: ",t)}},{key:"_onEmptied",value:function(t){e.Log.info(this.name,"The HTMLMediaElement emptied event is triggered: ",t)}},{key:"_onPlay",value:function(t){e.Log.info(this.name,"The HTMLMediaElement play event is triggered: ",t),this.trigger(e.Events.PLAYBACK_PLAY_INTENT)}},{key:"_onPlaying",value:function(t){e.Log.info(this.name,"The HTMLMediaElement playing event is triggered: ",t),this.trigger(e.Events.PLAYBACK_PLAY)}},{key:"_onPause",value:function(t){e.Log.info(this.name,"The HTMLMediaElement pause event is triggered: ",t),this.trigger(e.Events.PLAYBACK_PAUSE)}},{key:"_onRateChange",value:function(t){e.Log.info(this.name,"The HTMLMediaElement ratechange event is triggered: ",t)}},{key:"_onVolumeChange",value:function(t){e.Log.info(this.name,"The HTMLMediaElement volumechange event is triggered: ",t)}},{key:"_onSeeking",value:function(t){e.Log.info(this.name,"The HTMLMediaElement seeking event is triggered: ",t),this.trigger(e.Events.PLAYBACK_SEEK)}},{key:"_onSeeked",value:function(t){e.Log.info(this.name,"The HTMLMediaElement seeked event is triggered: ",t),this.trigger(e.Events.PLAYBACK_SEEKED)}},{key:"_onProgress",value:function(t){e.Log.debug(this.name,"The HTMLMediaElement progress event is triggered: ",t)}},{key:"_onTimeUpdate",value:function(t){e.Log.debug(this.name,"The HTMLMediaElement timeupdate event is triggered: ",t),this.trigger(e.Events.PLAYBACK_TIMEUPDATE,{current:this.el.currentTime,total:this.duration},this.name)}},{key:"_onDurationChange",value:function(t){e.Log.info(this.name,"The HTMLMediaElement durationchange event is triggered: ",t)}},{key:"_onAbort",value:function(t){e.Log.info(this.name,"The HTMLMediaElement abort event is triggered: ",t)}},{key:"_onSuspend",value:function(t){e.Log.info(this.name,"The HTMLMediaElement suspend event is triggered: ",t)}},{key:"_onEnded",value:function(t){e.Log.info(this.name,"The HTMLMediaElement ended event is triggered: ",t),this._wipeUpMedia(),this.trigger(e.Events.PLAYBACK_ENDED,this.name)}},{key:"_onError",value:function(t){var n;e.Log.warn(this.name,"The HTMLMediaElement error event is triggered: ",t);var i=(null===(n=this.$sourceElement)||void 0===n?void 0:n.error)||this.el.error||f,r=i.code,o=i.message,a=this.createError({code:r,description:o,raw:this.el.error,level:e.PlayerError.Levels.FATAL});this.trigger(e.Events.PLAYBACK_ERROR,a)}},{key:"load",value:function(e){this._wipeUpMedia(),this._setupSource(e)}},{key:"play",value:function(){var t=this;this._isStopped=!1,this._setupSource(this._src);var n=this.el.play();n&&n.catch&&n.catch((function(n){return e.Log.warn(t.name,"The play promise throws one error: ",n)}))}},{key:"pause",value:function(){this.el.pause(),this.dvrEnabled&&this._updateDvr(!0)}},{key:"seek",value:function(t){if(t<0)return e.Log.warn(this.name,"Attempting to seek to a negative time. Ignoring this operation.");var n=t,i=n<this.duration-3;this.dvrEnabled&&this._updateDvr(i),this.el.seekable&&this.el.seekable.start&&(n+=this.el.seekable.start(0)),this.el.currentTime=n}},{key:"switchAudioTrack",value:function(t){var n,i=null===(n=this.el.audioTracks)||void 0===n?void 0:n.getTrackById(t);if(i&&!i.enabled){for(var r=this.el.audioTracks,o=0;o<r.length;o++)r[o].enabled=r[o].id===t;this.trigger(e.Events.PLAYBACK_AUDIO_CHANGED,this._formatAudioTrack(i))}}},{key:"stop",value:function(){this.pause(),this._isStopped=!0,this._wipeUpMedia(),this.trigger(e.Events.PLAYBACK_STOP)}},{key:"destroy",value:function(){this._isDestroyed=!0,s(n(h.prototype),"destroy",this).call(this),this._wipeUpMedia(),this._src=null}},{key:"_wipeUpMedia",value:function(){this._isReady=!1,this._drmConfigured&&g.clearLicenseRequest.call(this,this._onDrmCleared,this._onDrmError),this.$sourceElement&&(this.$sourceElement.removeEventListener("error",this._sourceElementErrorHandler),this.$sourceElement.removeAttribute("src"),this.$sourceElement.parentNode&&this.$sourceElement.parentNode.removeChild(this.$sourceElement),this.$sourceElement=null),this.el.load()}},{key:"_signalizeReadyState",value:function(){var t=this,n=arguments.length>0&&void 0!==arguments[0]?arguments[0]:100;if(!this.isReady)return setTimeout((function(){t._signalizeReadyState(2*n)}),n);this._isReady=!0,this.trigger(e.Events.PLAYBACK_READY,this.name)}},{key:"getCurrentTime",value:function(){return this.currentTime}},{key:"getDuration",value:function(){return this.duration}},{key:"isPlaying",value:function(){return this.playing}},{key:"getPlaybackType",value:function(){return this.mediaType}}])&&t(u.prototype,l),d&&t(u,d),h}(e.Playback)})); |
{ | ||
"name": "@clappr/clappr-html5-tvs-playback", | ||
"version": "0.0.9", | ||
"version": "0.0.10", | ||
"description": "A Clappr HTML5 playback for smart TVs based on HbbTV 2.0.1 specs.", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
@@ -23,3 +23,3 @@ import { Events, Log, Playback, PlayerError, version } from '@clappr/core' | ||
return isSupportedMimetype || isSourceExtensionSupported | ||
return !!(isSupportedMimetype || isSourceExtensionSupported) | ||
} | ||
@@ -37,3 +37,3 @@ | ||
get isReady() { return this.el.readyState >= READY_STATE_STAGES.HAVE_CURRENT_DATA } | ||
get isReady() { return this.el.readyState >= READY_STATE_STAGES.HAVE_FUTURE_DATA } | ||
@@ -135,2 +135,3 @@ get playing() { return !this.el.paused && !this.el.ended } | ||
this._onAudioTracksUpdated = this._onAudioTracksUpdated.bind(this) | ||
this._sourceElementErrorHandler = this._onError.bind(this) | ||
this._playbackType = this.mediaType | ||
@@ -155,2 +156,3 @@ | ||
this.$sourceElement.src = sourceURL | ||
this.$sourceElement.addEventListener('error', this._sourceElementErrorHandler) | ||
this._src = this.$sourceElement.src | ||
@@ -215,2 +217,3 @@ this._appendSourceElement() | ||
Log.info(this.name, 'The HTMLMediaElement canplay event is triggered: ', e) | ||
!this._isReady && this._signalizeReadyState() | ||
if (this._isBuffering) { | ||
@@ -237,3 +240,2 @@ this._isBuffering = false | ||
Log.info(this.name, 'The HTMLMediaElement loadeddata event is triggered: ', e) | ||
!this._isReady && this._signalizeReadyState() | ||
} | ||
@@ -311,10 +313,9 @@ | ||
Log.info(this.name, 'The HTMLMediaElement ended event is triggered: ', e) | ||
this._wipeUpMedia() | ||
this.trigger(Events.PLAYBACK_ENDED, this.name) | ||
this._wipeUpMedia() | ||
} | ||
_onError(e) { | ||
Log.info(this.name, 'The HTMLMediaElement error event is triggered: ', e) | ||
const { code, message } = this.el.error || UNKNOWN_ERROR | ||
const isUnknownError = code === UNKNOWN_ERROR.code | ||
Log.warn(this.name, 'The HTMLMediaElement error event is triggered: ', e) | ||
const { code, message } = this.$sourceElement?.error || this.el.error || UNKNOWN_ERROR | ||
@@ -325,8 +326,6 @@ const formattedError = this.createError({ | ||
raw: this.el.error, | ||
level: isUnknownError ? PlayerError.Levels.WARN : PlayerError.Levels.FATAL, | ||
level: PlayerError.Levels.FATAL, | ||
}) | ||
isUnknownError | ||
? Log.warn(this.name, 'HTML5 unknown error: ', formattedError) | ||
: this.trigger(Events.PLAYBACK_ERROR, formattedError) | ||
this.trigger(Events.PLAYBACK_ERROR, formattedError) | ||
} | ||
@@ -394,5 +393,8 @@ | ||
this._drmConfigured && DRMHandler.clearLicenseRequest.call(this, this._onDrmCleared, this._onDrmError) | ||
this.$sourceElement && this.$sourceElement.removeAttribute('src') // The src attribute will be added again in play(). | ||
this.$sourceElement && this.$sourceElement.parentNode && this.$sourceElement.parentNode.removeChild(this.$sourceElement) | ||
this.$sourceElement = null | ||
if (this.$sourceElement) { | ||
this.$sourceElement.removeEventListener('error', this._sourceElementErrorHandler) | ||
this.$sourceElement.removeAttribute('src') // The src attribute will be added again in play(). | ||
this.$sourceElement.parentNode && this.$sourceElement.parentNode.removeChild(this.$sourceElement) | ||
this.$sourceElement = null | ||
} | ||
this.el.load() // Loads with no src attribute to stop the loading of the previous source and avoid leaks. | ||
@@ -412,4 +414,4 @@ } | ||
this._isReady = true | ||
this.trigger(Events.PLAYBACK_READY, this.name) | ||
this._isReady = true | ||
} | ||
@@ -416,0 +418,0 @@ |
@@ -91,11 +91,11 @@ /** | ||
test('checks if one video URL has supported format', () => { | ||
expect(HTML5TVsPlayback.canPlay(URL_VIDEO_MP4_EXAMPLE)).toBeTruthy() | ||
expect(HTML5TVsPlayback.canPlay(URL_VIDEO_M3U8_EXAMPLE)).toBeTruthy() | ||
expect(HTML5TVsPlayback.canPlay(URL_VIDEO_UNSUPPORTED_FORMAT_EXAMPLE)).toBeFalsy() | ||
expect(HTML5TVsPlayback.canPlay(URL_VIDEO_MP4_EXAMPLE)).toBe(true) | ||
expect(HTML5TVsPlayback.canPlay(URL_VIDEO_M3U8_EXAMPLE)).toBe(true) | ||
expect(HTML5TVsPlayback.canPlay(URL_VIDEO_UNSUPPORTED_FORMAT_EXAMPLE)).toBe(false) | ||
}) | ||
test('checks if one video is supported via mime type', () => { | ||
expect(HTML5TVsPlayback.canPlay(URL_VIDEO_EXAMPLE, 'video/mp4')).toBeTruthy() | ||
expect(HTML5TVsPlayback.canPlay(URL_VIDEO_EXAMPLE, 'application/vnd.apple.mpegurl')).toBeTruthy() | ||
expect(HTML5TVsPlayback.canPlay(URL_VIDEO_EXAMPLE, 'mock/xpto')).toBeFalsy() | ||
expect(HTML5TVsPlayback.canPlay(URL_VIDEO_EXAMPLE, 'video/mp4')).toBe(true) | ||
expect(HTML5TVsPlayback.canPlay(URL_VIDEO_EXAMPLE, 'application/vnd.apple.mpegurl')).toBe(true) | ||
expect(HTML5TVsPlayback.canPlay(URL_VIDEO_EXAMPLE, 'mock/xpto')).toBe(false) | ||
}) | ||
@@ -140,3 +140,3 @@ }) | ||
test('isReady getter returns the check if video.readyState is greater than or equal HAVE_CURRENT_DATA value', () => { | ||
test('isReady getter returns the check if video.readyState is greater than or equal HAVE_FUTURE_DATA value', () => { | ||
jest.spyOn(this.playback.el, 'readyState', 'get').mockReturnValueOnce(READY_STATE_STAGES.HAVE_NOTHING) | ||
@@ -146,3 +146,3 @@ | ||
jest.spyOn(this.playback.el, 'readyState', 'get').mockReturnValueOnce(READY_STATE_STAGES.HAVE_CURRENT_DATA) | ||
jest.spyOn(this.playback.el, 'readyState', 'get').mockReturnValueOnce(READY_STATE_STAGES.HAVE_FUTURE_DATA) | ||
@@ -612,4 +612,4 @@ expect(this.playback.isReady).toBeTruthy() | ||
1, | ||
LOG_INFO_HEAD_MESSAGE, | ||
LOG_INFO_STYLE, | ||
LOG_WARN_HEAD_MESSAGE, | ||
LOG_WARN_STYLE, | ||
'The HTMLMediaElement error event is triggered: ', | ||
@@ -619,2 +619,16 @@ errorEvent, | ||
}) | ||
test('maps _onError method as error event callback on source element', () => { | ||
this.playback._setupSource(URL_VIDEO_MP4_EXAMPLE) | ||
const errorEvent = new Event('error') | ||
this.playback.$sourceElement.dispatchEvent(errorEvent) | ||
expect(console.log).toHaveBeenNthCalledWith( | ||
1, | ||
LOG_WARN_HEAD_MESSAGE, | ||
LOG_WARN_STYLE, | ||
'The HTMLMediaElement error event is triggered: ', | ||
errorEvent, | ||
) | ||
}) | ||
}) | ||
@@ -814,9 +828,9 @@ | ||
describe('_onLoadedData callback', () => { | ||
describe('_onCanPlay callback', () => { | ||
test('calls _signalizeReadyState method if _isReady flag has a falsy value', () => { | ||
jest.spyOn(this.playback, '_signalizeReadyState') | ||
this.playback._isReady = true | ||
this.playback._onLoadedData() | ||
this.playback._onCanPlay() | ||
this.playback._isReady = false | ||
this.playback._onLoadedData() | ||
this.playback._onCanPlay() | ||
@@ -913,2 +927,11 @@ expect(this.playback._signalizeReadyState).toHaveBeenCalledTimes(1) | ||
test('calls _wipeUpMedia method before notifying PLAYBACK_ENDED event', done => { | ||
jest.spyOn(this.playback, '_wipeUpMedia') | ||
this.playback.listenToOnce(this.playback, Events.PLAYBACK_ENDED, () => { | ||
expect(this.playback._wipeUpMedia).toHaveBeenCalledTimes(1) | ||
done() | ||
}) | ||
this.playback._onEnded() | ||
}) | ||
test('calls _wipeUpMedia method', () => { | ||
@@ -923,21 +946,2 @@ jest.spyOn(this.playback, '_wipeUpMedia') | ||
describe('_onError callback', () => { | ||
test('logs warn message if is an unknown error', () => { | ||
this.playback._onError() | ||
expect(console.log).toHaveBeenNthCalledWith( | ||
3, | ||
LOG_WARN_HEAD_MESSAGE, | ||
LOG_WARN_STYLE, | ||
'HTML5 unknown error: ', | ||
{ | ||
code: 'html5_tvs_playback:unknown', | ||
description: 'unknown', | ||
level: 'WARN', | ||
origin: 'html5_tvs_playback', | ||
raw: undefined, | ||
scope: 'playback', | ||
}, | ||
) | ||
}) | ||
test('triggers PLAYBACK_ERROR event with formatted error object', () => { | ||
@@ -1200,2 +1204,13 @@ const cb = jest.fn() | ||
test('sets _isReady flag with true value before triggering PLAYBACK_READY', done => { | ||
jest.spyOn(this.playback, 'isReady', 'get').mockReturnValueOnce(true) | ||
this.playback._isReady = false | ||
this.playback.listenToOnce(this.playback, Events.PLAYBACK_READY, () => { | ||
expect(this.playback._isReady).toBeTruthy() | ||
done() | ||
}) | ||
this.playback._signalizeReadyState() | ||
}) | ||
test('sets _isReady flag with true value', () => { | ||
@@ -1202,0 +1217,0 @@ jest.spyOn(this.playback, 'isReady', 'get').mockReturnValueOnce(true) |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
153382
3235
0