@clappr/clappr-html5-tvs-playback
Advanced tools
Comparing version 0.0.1 to 0.0.2
@@ -199,5 +199,8 @@ import _classCallCheck from '@babel/runtime/helpers/classCallCheck'; | ||
_this._onAudioTracksUpdated = _this._onAudioTracksUpdated.bind(_assertThisInitialized(_this)); | ||
_this._drmConfigured = false; | ||
_this._isReady = false; | ||
_this._isBuffering = false; | ||
_this._isStopped = false; | ||
_this._isDestroyed = false; | ||
_this._setPrivateFlags(); | ||
_this._setAudioTrackListeners(); | ||
@@ -340,11 +343,2 @@ | ||
}, { | ||
key: "_setPrivateFlags", | ||
value: function _setPrivateFlags() { | ||
this._drmConfigured = false; | ||
this._isReady = false; | ||
this._isBuffering = false; | ||
this._isStopped = false; | ||
this._isDestroyed = false; | ||
} | ||
}, { | ||
key: "_setupSource", | ||
@@ -354,7 +348,2 @@ value: function _setupSource(sourceURL) { | ||
if (sourceURL === currentSource) return; | ||
this.config && this.config.drm && !this._drmConfigured ? DRMHandler.sendLicenseRequest.call(this, this.config.drm, this._onDrmConfigured, this._onDrmError) : this._setSourceOnVideoTag(sourceURL); | ||
} | ||
}, { | ||
key: "_setSourceOnVideoTag", | ||
value: function _setSourceOnVideoTag(sourceURL) { | ||
this.$sourceElement = document.createElement('source'); | ||
@@ -364,3 +353,3 @@ this.$sourceElement.type = MIME_TYPES_BY_EXTENSION[getExtension(sourceURL)]; | ||
this._src = this.$sourceElement.src; | ||
this.el.appendChild(this.$sourceElement); | ||
this.config && this.config.drm && !this._drmConfigured ? DRMHandler.sendLicenseRequest.call(this, this.config.drm, this._onDrmConfigured, this._onDrmError) : this.el.appendChild(this.$sourceElement); | ||
} | ||
@@ -371,4 +360,3 @@ }, { | ||
this._drmConfigured = true; | ||
this._setSourceOnVideoTag(this.options.src); | ||
this.el.appendChild(this.$sourceElement); | ||
} | ||
@@ -375,0 +363,0 @@ }, { |
@@ -324,5 +324,8 @@ (function (global, factory) { | ||
_this._onAudioTracksUpdated = _this._onAudioTracksUpdated.bind(_assertThisInitialized(_this)); | ||
_this._drmConfigured = false; | ||
_this._isReady = false; | ||
_this._isBuffering = false; | ||
_this._isStopped = false; | ||
_this._isDestroyed = false; | ||
_this._setPrivateFlags(); | ||
_this._setAudioTrackListeners(); | ||
@@ -465,11 +468,2 @@ | ||
}, { | ||
key: "_setPrivateFlags", | ||
value: function _setPrivateFlags() { | ||
this._drmConfigured = false; | ||
this._isReady = false; | ||
this._isBuffering = false; | ||
this._isStopped = false; | ||
this._isDestroyed = false; | ||
} | ||
}, { | ||
key: "_setupSource", | ||
@@ -479,7 +473,2 @@ value: function _setupSource(sourceURL) { | ||
if (sourceURL === currentSource) return; | ||
this.config && this.config.drm && !this._drmConfigured ? DRMHandler.sendLicenseRequest.call(this, this.config.drm, this._onDrmConfigured, this._onDrmError) : this._setSourceOnVideoTag(sourceURL); | ||
} | ||
}, { | ||
key: "_setSourceOnVideoTag", | ||
value: function _setSourceOnVideoTag(sourceURL) { | ||
this.$sourceElement = document.createElement('source'); | ||
@@ -489,3 +478,3 @@ this.$sourceElement.type = MIME_TYPES_BY_EXTENSION[getExtension(sourceURL)]; | ||
this._src = this.$sourceElement.src; | ||
this.el.appendChild(this.$sourceElement); | ||
this.config && this.config.drm && !this._drmConfigured ? DRMHandler.sendLicenseRequest.call(this, this.config.drm, this._onDrmConfigured, this._onDrmError) : this.el.appendChild(this.$sourceElement); | ||
} | ||
@@ -496,4 +485,3 @@ }, { | ||
this._drmConfigured = true; | ||
this._setSourceOnVideoTag(this.options.src); | ||
this.el.appendChild(this.$sourceElement); | ||
} | ||
@@ -500,0 +488,0 @@ }, { |
@@ -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,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",c=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>"},d=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?c(t.xmlLicenceAcquisition):d(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=2,v={MP4:"video/mp4",VND_APPLE_MPEGURL:"application/vnd.apple.mpegurl",VND_MS_SSTR:"application/vnd.ms-sstr+xml"},y={m3u8:v.VND_APPLE_MPEGURL,m3u:v.VND_APPLE_MPEGURL,mp4:v.MP4,ism:v.VND_MS_SSTR},p=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,c,d=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=d.call(this,e,t,n))._onAudioTracksUpdated=i._onAudioTracksUpdated.bind(r(i)),i._setPrivateFlags(),i._setAudioTrackListeners(),i._setupSource(i.options.src),i}return u=h,c=[{key:"canPlay",value:function(e,t){var n=Object.values(v).find((function(e){return t===e})),i=p(e);return n||y[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%"}}},{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(){return this.el.audioTracks?Object.values(this.el.audioTracks).map(this._formatAudioTrack):[]}},{key:"currentAudioTrack",get:function(){if(!this.el.audioTracks)return null;var e=Object.values(this.el.audioTracks).find((function(e){return e.enabled}));return 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:"_setPrivateFlags",value:function(){this._drmConfigured=!1,this._isReady=!1,this._isBuffering=!1,this._isStopped=!1,this._isDestroyed=!1}},{key:"_setupSource",value:function(e){e!==(this.$sourceElement&&this.$sourceElement.src)&&(this.config&&this.config.drm&&!this._drmConfigured?g.sendLicenseRequest.call(this,this.config.drm,this._onDrmConfigured,this._onDrmError):this._setSourceOnVideoTag(e))}},{key:"_setSourceOnVideoTag",value:function(e){this.$sourceElement=document.createElement("source"),this.$sourceElement.type=y[p(e)],this.$sourceElement.src=e,this._src=this.$sourceElement.src,this.el.appendChild(this.$sourceElement)}},{key:"_onDrmConfigured",value:function(){this._drmConfigured=!0,this._setSourceOnVideoTag(this.options.src)}},{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 timeupdate 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||f,i=n.code,r=n.message,o=i===f.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);i&&!i.enabled&&(i.enabled=!0,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.removeAttribute("src"),this.$sourceElement&&this.$sourceElement.remove(),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}}])&&t(u.prototype,l),c&&t(u,c),h}(e.Playback)})); | ||
!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=2,v={MP4:"video/mp4",VND_APPLE_MPEGURL:"application/vnd.apple.mpegurl",VND_MS_SSTR:"application/vnd.ms-sstr+xml"},y={m3u8:v.VND_APPLE_MPEGURL,m3u:v.VND_APPLE_MPEGURL,mp4:v.MP4,ism:v.VND_MS_SSTR},p=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._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(v).find((function(e){return t===e})),i=p(e);return n||y[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%"}}},{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(){return this.el.audioTracks?Object.values(this.el.audioTracks).map(this._formatAudioTrack):[]}},{key:"currentAudioTrack",get:function(){if(!this.el.audioTracks)return null;var e=Object.values(this.el.audioTracks).find((function(e){return e.enabled}));return 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:"_setupSource",value:function(e){e!==(this.$sourceElement&&this.$sourceElement.src)&&(this.$sourceElement=document.createElement("source"),this.$sourceElement.type=y[p(e)],this.$sourceElement.src=e,this._src=this.$sourceElement.src,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.el.appendChild(this.$sourceElement)}},{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 timeupdate 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||f,i=n.code,r=n.message,o=i===f.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);i&&!i.enabled&&(i.enabled=!0,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.removeAttribute("src"),this.$sourceElement&&this.$sourceElement.remove(),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}}])&&t(u.prototype,l),d&&t(u,d),h}(e.Playback)})); |
{ | ||
"name": "@clappr/clappr-html5-tvs-playback", | ||
"version": "0.0.1", | ||
"version": "0.0.2", | ||
"description": "A Clappr HTML5 playback for smart TVs based on HbbTV 2.0.1 specs.", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
@@ -110,8 +110,2 @@ import { Events, Log, Playback, PlayerError, version } from '@clappr/core' | ||
this._setPrivateFlags() | ||
this._setAudioTrackListeners() | ||
this._setupSource(this.options.src) | ||
} | ||
_setPrivateFlags() { | ||
this._drmConfigured = false | ||
@@ -122,2 +116,5 @@ this._isReady = false | ||
this._isDestroyed = false | ||
this._setAudioTrackListeners() | ||
this._setupSource(this.options.src) | ||
} | ||
@@ -129,15 +126,10 @@ | ||
this.config && this.config.drm && !this._drmConfigured | ||
? DRMHandler.sendLicenseRequest.call(this, this.config.drm, this._onDrmConfigured, this._onDrmError) | ||
: this._setSourceOnVideoTag(sourceURL) | ||
} | ||
_setSourceOnVideoTag(sourceURL) { | ||
this.$sourceElement = document.createElement('source') | ||
this.$sourceElement.type = MIME_TYPES_BY_EXTENSION[getExtension(sourceURL)] | ||
this.$sourceElement.src = sourceURL | ||
this._src = this.$sourceElement.src | ||
this.el.appendChild(this.$sourceElement) | ||
this.config && this.config.drm && !this._drmConfigured | ||
? DRMHandler.sendLicenseRequest.call(this, this.config.drm, this._onDrmConfigured, this._onDrmError) | ||
: this.el.appendChild(this.$sourceElement) | ||
} | ||
@@ -147,3 +139,3 @@ | ||
this._drmConfigured = true | ||
this._setSourceOnVideoTag(this.options.src) | ||
this.el.appendChild(this.$sourceElement) | ||
} | ||
@@ -150,0 +142,0 @@ |
@@ -134,6 +134,2 @@ /** | ||
test('have a getter called mediaType', () => { | ||
expect(Object.getOwnPropertyDescriptor(Object.getPrototypeOf(this.playback), 'mediaType').get).toBeTruthy() | ||
}) | ||
describe('mediaType getter', () => { | ||
@@ -153,6 +149,2 @@ test('returns Playback.LIVE if video.duration property is Infinity', () => { | ||
test('have a getter called isReady', () => { | ||
expect(Object.getOwnPropertyDescriptor(Object.getPrototypeOf(this.playback), 'isReady').get).toBeTruthy() | ||
}) | ||
test('isReady getter returns the check if video.readyState is greater than or equal HAVE_CURRENT_DATA value', () => { | ||
@@ -168,6 +160,2 @@ jest.spyOn(this.playback.el, 'readyState', 'get').mockReturnValueOnce(READY_STATE_STAGES.HAVE_NOTHING) | ||
test('have a getter called playing', () => { | ||
expect(Object.getOwnPropertyDescriptor(Object.getPrototypeOf(this.playback), 'playing').get).toBeTruthy() | ||
}) | ||
test('playing getter returns if video it\'s not paused and it\'s not ended', () => { | ||
@@ -190,6 +178,2 @@ jest.spyOn(this.playback.el, 'paused', 'get').mockReturnValueOnce(false) | ||
test('have a getter called currentTime', () => { | ||
expect(Object.getOwnPropertyDescriptor(Object.getPrototypeOf(this.playback), 'currentTime').get).toBeTruthy() | ||
}) | ||
test('currentTime getter returns video.currentTime property', () => { | ||
@@ -199,6 +183,2 @@ expect(this.playback.currentTime).toEqual(this.playback.el.currentTime) | ||
test('have a getter called duration', () => { | ||
expect(Object.getOwnPropertyDescriptor(Object.getPrototypeOf(this.playback), 'duration').get).toBeTruthy() | ||
}) | ||
describe('duration getter', () => { | ||
@@ -227,6 +207,2 @@ test('returns video.duration property for VoD content', () => { | ||
test('have a getter called ended', () => { | ||
expect(Object.getOwnPropertyDescriptor(Object.getPrototypeOf(this.playback), 'ended').get).toBeTruthy() | ||
}) | ||
test('ended getter returns video.ended property', () => { | ||
@@ -236,6 +212,2 @@ expect(this.playback.ended).toEqual(this.playback.el.ended) | ||
test('have a getter called buffering', () => { | ||
expect(Object.getOwnPropertyDescriptor(Object.getPrototypeOf(this.playback), 'buffering').get).toBeTruthy() | ||
}) | ||
test('buffering getter returns _isBuffering flag value', () => { | ||
@@ -336,6 +308,2 @@ expect(this.playback.buffering).toEqual(this.playback._isBuffering) | ||
test('have a getter called isLive', () => { | ||
expect(Object.getOwnPropertyDescriptor(Object.getPrototypeOf(this.playback), 'isLive').get).toBeTruthy() | ||
}) | ||
test('isLive getter returns the check if the mediaType getter returns the Playback.LIVE value', () => { | ||
@@ -351,6 +319,2 @@ jest.spyOn(this.playback, 'mediaType', 'get').mockReturnValueOnce(Playback.VOD) | ||
test('have a getter called minimumDvrSizeConfig', () => { | ||
expect(Object.getOwnPropertyDescriptor(Object.getPrototypeOf(this.playback), 'minimumDvrSizeConfig').get).toBeTruthy() | ||
}) | ||
test('minimumDvrSizeConfig getter returns the value of a valid options.playback.minimumDvrSize config', () => { | ||
@@ -370,6 +334,2 @@ this.playback.options.playback = { minimumDvrSize: 'invalid_config' } | ||
test('have a getter called dvrSize', () => { | ||
expect(Object.getOwnPropertyDescriptor(Object.getPrototypeOf(this.playback), 'dvrSize').get).toBeTruthy() | ||
}) | ||
describe('dvrSize getter', () => { | ||
@@ -389,6 +349,2 @@ test('returns the minimumDvrSizeConfig getter value if options.playback.minimumDvrSize is valid', () => { | ||
test('have a getter called dvrEnabled', () => { | ||
expect(Object.getOwnPropertyDescriptor(Object.getPrototypeOf(this.playback), 'dvrEnabled').get).toBeTruthy() | ||
}) | ||
test('dvrEnabled getter returns the check of the isLive is truthy and if the duration is greater or equal the dvrSize value', () => { | ||
@@ -414,6 +370,2 @@ jest.spyOn(this.playback, 'isLive', 'get').mockReturnValueOnce(false) | ||
test('have a getter called events', () => { | ||
expect(Object.getOwnPropertyDescriptor(Object.getPrototypeOf(this.playback), 'events').get).toBeTruthy() | ||
}) | ||
describe('events getter', () => { | ||
@@ -662,6 +614,2 @@ test('maps _onCanPlay method as canplay event callback', () => { | ||
test('have a getter called config', () => { | ||
expect(Object.getOwnPropertyDescriptor(Object.getPrototypeOf(this.playback), 'config').get).toBeTruthy() | ||
}) | ||
test('config getter returns the options.html5TvsPlayback value', () => { | ||
@@ -675,7 +623,16 @@ const { core, container } = setupTest({ src: URL_VIDEO_MP4_EXAMPLE }) | ||
describe('constructor', () => { | ||
test('calls _setPrivateFlags method', () => { | ||
jest.spyOn(HTML5TVsPlayback.prototype, '_setPrivateFlags') | ||
test('sets the initial state for internal flags', () => { | ||
expect(HTML5TVsPlayback.prototype._isReady).toBeUndefined() | ||
expect(HTML5TVsPlayback.prototype._drmConfigured).toBeUndefined() | ||
expect(HTML5TVsPlayback.prototype._isBuffering).toBeUndefined() | ||
expect(HTML5TVsPlayback.prototype._isStopped).toBeUndefined() | ||
expect(HTML5TVsPlayback.prototype._isDestroyed).toBeUndefined() | ||
setupTest() | ||
expect(HTML5TVsPlayback.prototype._setPrivateFlags).toHaveBeenCalledTimes(1) | ||
expect(this.playback._isReady).toBeFalsy() | ||
expect(this.playback._drmConfigured).toBeFalsy() | ||
expect(this.playback._isBuffering).toBeFalsy() | ||
expect(this.playback._isStopped).toBeFalsy() | ||
expect(this.playback._isDestroyed).toBeFalsy() | ||
}) | ||
@@ -691,33 +648,5 @@ | ||
describe('_setPrivateFlags method', () => { | ||
test('sets _isReady flag with false value', () => { | ||
expect(HTML5TVsPlayback.prototype._isReady).toBeUndefined() | ||
expect(this.playback._isReady).toBeFalsy() | ||
}) | ||
test('sets _drmConfigured flag with false value', () => { | ||
expect(HTML5TVsPlayback.prototype._drmConfigured).toBeUndefined() | ||
expect(this.playback._drmConfigured).toBeFalsy() | ||
}) | ||
test('sets _isBuffering flag with false value', () => { | ||
expect(HTML5TVsPlayback.prototype._isBuffering).toBeUndefined() | ||
expect(this.playback._isBuffering).toBeFalsy() | ||
}) | ||
test('sets _isStopped flag with false value', () => { | ||
expect(HTML5TVsPlayback.prototype._isStopped).toBeUndefined() | ||
expect(this.playback._isStopped).toBeFalsy() | ||
}) | ||
test('sets _isDestroyed flag with false value', () => { | ||
expect(HTML5TVsPlayback.prototype._isStopped).toBeUndefined() | ||
expect(this.playback._isDestroyed).toBeFalsy() | ||
}) | ||
}) | ||
describe('_setupSource method', () => { | ||
test('avoids unnecessary video.src updates', () => { | ||
jest.spyOn(DRMHandler, 'sendLicenseRequest') | ||
jest.spyOn(this.playback, '_setSourceOnVideoTag') | ||
@@ -730,32 +659,8 @@ this.playback.$sourceElement = document.createElement('source') | ||
expect(DRMHandler.sendLicenseRequest).not.toHaveBeenCalled() | ||
expect(this.playback._setSourceOnVideoTag).not.toHaveBeenCalled() | ||
}) | ||
test('sets license server if config.drm exists and _drmConfigured flag is false', () => { | ||
const { core, container } = setupTest({ src: URL_VIDEO_MP4_EXAMPLE, html5TvsPlayback: { drm: { licenseServerURL: 'http://fake-domain.com/license_server/playready' } } }) | ||
core.activeContainer = container | ||
jest.spyOn(DRMHandler, 'sendLicenseRequest') | ||
container.playback._setupSource(URL_VIDEO_MP4_EXAMPLE) | ||
expect(DRMHandler.sendLicenseRequest).toHaveBeenCalledWith( | ||
container.playback.config.drm, | ||
container.playback._onDrmConfigured, | ||
container.playback._onDrmError, | ||
) | ||
}) | ||
test('calls _setSourceOnVideoTag method if no one license server URL is configured or _drmConfigured flag is true', () => { | ||
jest.spyOn(this.playback, '_setSourceOnVideoTag') | ||
this.playback._setupSource(URL_VIDEO_MP4_EXAMPLE) | ||
expect(this.playback._setSourceOnVideoTag).toHaveBeenCalledWith(URL_VIDEO_MP4_EXAMPLE) | ||
}) | ||
}) | ||
describe('_setSourceOnVideoTag method', () => { | ||
test('creates the $sourceElement reference', () => { | ||
expect(this.playback.$sourceElement).toBeUndefined() | ||
this.playback._setSourceOnVideoTag(URL_VIDEO_MP4_EXAMPLE) | ||
this.playback._setupSource(URL_VIDEO_MP4_EXAMPLE) | ||
@@ -766,3 +671,3 @@ expect(this.playback.$sourceElement).toBeDefined() | ||
test('sets received source URL extension as $sourceElement.type attribute', () => { | ||
this.playback._setSourceOnVideoTag(URL_VIDEO_MP4_EXAMPLE) | ||
this.playback._setupSource(URL_VIDEO_MP4_EXAMPLE) | ||
@@ -773,3 +678,3 @@ expect(this.playback.$sourceElement.type).toEqual('video/mp4') | ||
test('sets received source URL as $sourceElement.src attribute', () => { | ||
this.playback._setSourceOnVideoTag(URL_VIDEO_MP4_EXAMPLE) | ||
this.playback._setupSource(URL_VIDEO_MP4_EXAMPLE) | ||
@@ -785,5 +690,19 @@ expect(this.playback.$sourceElement.src).toEqual(URL_VIDEO_MP4_EXAMPLE) | ||
test('appends $sourceElement into the playback.el', () => { | ||
this.playback._setSourceOnVideoTag(URL_VIDEO_MP4_EXAMPLE) | ||
test('sets license server if config.drm exists and _drmConfigured flag is false', () => { | ||
const { core, container } = setupTest({ src: URL_VIDEO_MP4_EXAMPLE, html5TvsPlayback: { drm: { licenseServerURL: 'http://fake-domain.com/license_server/playready' } } }) | ||
core.activeContainer = container | ||
jest.spyOn(DRMHandler, 'sendLicenseRequest') | ||
container.playback._setupSource(URL_VIDEO_MP4_EXAMPLE) | ||
expect(DRMHandler.sendLicenseRequest).toHaveBeenCalledWith( | ||
container.playback.config.drm, | ||
container.playback._onDrmConfigured, | ||
container.playback._onDrmError, | ||
) | ||
}) | ||
test('appends $sourceElement into the playback.el if no one license server URL is configured or _drmConfigured flag is true', () => { | ||
this.playback._setupSource(URL_VIDEO_MP4_EXAMPLE) | ||
expect(this.playback.el.firstChild).toEqual(this.playback.$sourceElement) | ||
@@ -804,10 +723,8 @@ }) | ||
test('calls _setSourceOnVideoTag method with options.src value', () => { | ||
test('appends $sourceElement into the playback.el', () => { | ||
const { core, container } = setupTest({ src: URL_VIDEO_MP4_EXAMPLE }) | ||
core.activeContainer = container | ||
jest.spyOn(container.playback, '_setSourceOnVideoTag') | ||
container.playback._onDrmConfigured() | ||
expect(container.playback._setSourceOnVideoTag).toHaveBeenCalledTimes(1) | ||
expect(container.playback._setSourceOnVideoTag).toHaveBeenCalledWith(container.playback.options.src) | ||
expect(container.playback.el.firstChild).toEqual(container.playback.$sourceElement) | ||
}) | ||
@@ -1221,3 +1138,3 @@ }) | ||
beforeEach(() => { | ||
this.playback._setSourceOnVideoTag(URL_VIDEO_MP4_EXAMPLE) | ||
this.playback._setupSource(URL_VIDEO_MP4_EXAMPLE) | ||
}) | ||
@@ -1224,0 +1141,0 @@ |
172038
3923