@clappr/clappr-html5-tvs-playback
Advanced tools
Comparing version 0.0.10 to 0.1.0
@@ -12,2 +12,3 @@ import _classCallCheck from '@babel/runtime/helpers/classCallCheck'; | ||
var DRM_SYSTEM_ID = 'urn:dvb:casystemid:19219'; | ||
var getFullChallengeMessageTemplate = function getFullChallengeMessageTemplate(header) { | ||
@@ -17,2 +18,3 @@ var template = '<?xml version="1.0" encoding="utf-8"?>' + '<PlayReadyInitiator xmlns="http://schemas.microsoft.com/DRM/2007/03/protocols/">' + '<LicenseAcquisition>' + '<Header>' + "".concat(header) + '</Header>' + '</LicenseAcquisition>' + '</PlayReadyInitiator>'; | ||
}; | ||
var getLicenseOverrideMessageTemplate = function getLicenseOverrideMessageTemplate(licenseServerURL) { | ||
@@ -22,2 +24,3 @@ var template = '<?xml version="1.0" encoding="utf-8"?>' + '<PlayReadyInitiator xmlns="http://schemas.microsoft.com/DRM/2007/03/protocols/">' + '<LicenseServerUriOverride>' + "<LA_URL>".concat(licenseServerURL, "</LA_URL>") + '</LicenseServerUriOverride>' + '</PlayReadyInitiator>'; | ||
}; | ||
var getClearMessageTemplate = function getClearMessageTemplate() { | ||
@@ -27,2 +30,3 @@ var template = '<?xml version="1.0" encoding="utf-8"?>' + '<PlayReadyInitiator xmlns="http://schemas.microsoft.com/DRM/2007/03/protocols/">' + '</PlayReadyInitiator>'; | ||
}; | ||
var createDrmAgent = function createDrmAgent() { | ||
@@ -40,2 +44,9 @@ var drmElement = document.createElement('object'); | ||
}; | ||
var DRMFunctions = { | ||
getFullChallengeMessageTemplate: getFullChallengeMessageTemplate, | ||
getLicenseOverrideMessageTemplate: getLicenseOverrideMessageTemplate, | ||
getClearMessageTemplate: getClearMessageTemplate, | ||
createDrmAgent: createDrmAgent | ||
}; | ||
/* eslint-disable-next-line func-style */ | ||
@@ -52,7 +63,7 @@ | ||
if (!oipfdrmagent) { | ||
oipfdrmagent = createDrmAgent(); | ||
oipfdrmagent = DRMFunctions.createDrmAgent(); | ||
this && this.el ? this.el.appendChild(oipfdrmagent) : document.body.appendChild(oipfdrmagent); | ||
} | ||
var xmlLicenceAcquisition = config.xmlLicenceAcquisition ? getFullChallengeMessageTemplate(config.xmlLicenceAcquisition) : getLicenseOverrideMessageTemplate(config.licenseServerURL); | ||
var xmlLicenceAcquisition = config.xmlLicenceAcquisition ? DRMFunctions.getFullChallengeMessageTemplate(config.xmlLicenceAcquisition) : DRMFunctions.getLicenseOverrideMessageTemplate(config.licenseServerURL); | ||
@@ -97,4 +108,6 @@ var drmRightsErrorHandler = function drmRightsErrorHandler(resultCode) { | ||
} catch (error) { | ||
Log.error('DRMHandler', 'Error at sendDRMMessage call', error.message); | ||
return errorCallback(error.message); | ||
Log.warn('DRMHandler', 'Error at sendDRMMessage call', error.message); // Some TVs handles the DRM license request automatically, so we can consider it as a success to allow the TV to setup the DRM license | ||
oipfdrmagent.parentNode && oipfdrmagent.parentNode.removeChild(oipfdrmagent); | ||
return successCallback(); | ||
} | ||
@@ -113,6 +126,6 @@ } | ||
Log.warn('DRMHandler', 'No one DRM license has been configured before. It\'s not necessary to clear any license server.'); | ||
return; | ||
return successCallback(); | ||
} | ||
var xmlLicenceAcquisition = getClearMessageTemplate(); | ||
var xmlLicenceAcquisition = DRMFunctions.getClearMessageTemplate(); | ||
@@ -123,3 +136,3 @@ try { | ||
oipfdrmagent.onDRMMessageResult = function () { | ||
oipfdrmagent.remove(); | ||
oipfdrmagent.parentNode && oipfdrmagent.parentNode.removeChild(oipfdrmagent); | ||
successCallback(); | ||
@@ -126,0 +139,0 @@ }; |
@@ -140,2 +140,3 @@ (function (global, factory) { | ||
var DRM_SYSTEM_ID = 'urn:dvb:casystemid:19219'; | ||
var getFullChallengeMessageTemplate = function getFullChallengeMessageTemplate(header) { | ||
@@ -145,2 +146,3 @@ var template = '<?xml version="1.0" encoding="utf-8"?>' + '<PlayReadyInitiator xmlns="http://schemas.microsoft.com/DRM/2007/03/protocols/">' + '<LicenseAcquisition>' + '<Header>' + "".concat(header) + '</Header>' + '</LicenseAcquisition>' + '</PlayReadyInitiator>'; | ||
}; | ||
var getLicenseOverrideMessageTemplate = function getLicenseOverrideMessageTemplate(licenseServerURL) { | ||
@@ -150,2 +152,3 @@ var template = '<?xml version="1.0" encoding="utf-8"?>' + '<PlayReadyInitiator xmlns="http://schemas.microsoft.com/DRM/2007/03/protocols/">' + '<LicenseServerUriOverride>' + "<LA_URL>".concat(licenseServerURL, "</LA_URL>") + '</LicenseServerUriOverride>' + '</PlayReadyInitiator>'; | ||
}; | ||
var getClearMessageTemplate = function getClearMessageTemplate() { | ||
@@ -155,2 +158,3 @@ var template = '<?xml version="1.0" encoding="utf-8"?>' + '<PlayReadyInitiator xmlns="http://schemas.microsoft.com/DRM/2007/03/protocols/">' + '</PlayReadyInitiator>'; | ||
}; | ||
var createDrmAgent = function createDrmAgent() { | ||
@@ -168,2 +172,9 @@ var drmElement = document.createElement('object'); | ||
}; | ||
var DRMFunctions = { | ||
getFullChallengeMessageTemplate: getFullChallengeMessageTemplate, | ||
getLicenseOverrideMessageTemplate: getLicenseOverrideMessageTemplate, | ||
getClearMessageTemplate: getClearMessageTemplate, | ||
createDrmAgent: createDrmAgent | ||
}; | ||
/* eslint-disable-next-line func-style */ | ||
@@ -180,7 +191,7 @@ | ||
if (!oipfdrmagent) { | ||
oipfdrmagent = createDrmAgent(); | ||
oipfdrmagent = DRMFunctions.createDrmAgent(); | ||
this && this.el ? this.el.appendChild(oipfdrmagent) : document.body.appendChild(oipfdrmagent); | ||
} | ||
var xmlLicenceAcquisition = config.xmlLicenceAcquisition ? getFullChallengeMessageTemplate(config.xmlLicenceAcquisition) : getLicenseOverrideMessageTemplate(config.licenseServerURL); | ||
var xmlLicenceAcquisition = config.xmlLicenceAcquisition ? DRMFunctions.getFullChallengeMessageTemplate(config.xmlLicenceAcquisition) : DRMFunctions.getLicenseOverrideMessageTemplate(config.licenseServerURL); | ||
@@ -225,4 +236,6 @@ var drmRightsErrorHandler = function drmRightsErrorHandler(resultCode) { | ||
} catch (error) { | ||
core.Log.error('DRMHandler', 'Error at sendDRMMessage call', error.message); | ||
return errorCallback(error.message); | ||
core.Log.warn('DRMHandler', 'Error at sendDRMMessage call', error.message); // Some TVs handles the DRM license request automatically, so we can consider it as a success to allow the TV to setup the DRM license | ||
oipfdrmagent.parentNode && oipfdrmagent.parentNode.removeChild(oipfdrmagent); | ||
return successCallback(); | ||
} | ||
@@ -241,6 +254,6 @@ } | ||
core.Log.warn('DRMHandler', 'No one DRM license has been configured before. It\'s not necessary to clear any license server.'); | ||
return; | ||
return successCallback(); | ||
} | ||
var xmlLicenceAcquisition = getClearMessageTemplate(); | ||
var xmlLicenceAcquisition = DRMFunctions.getClearMessageTemplate(); | ||
@@ -251,3 +264,3 @@ try { | ||
oipfdrmagent.onDRMMessageResult = function () { | ||
oipfdrmagent.remove(); | ||
oipfdrmagent.parentNode && oipfdrmagent.parentNode.removeChild(oipfdrmagent); | ||
successCallback(); | ||
@@ -254,0 +267,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",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)})); | ||
!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(){return'<?xml version="1.0" encoding="utf-8"?><PlayReadyInitiator xmlns="http://schemas.microsoft.com/DRM/2007/03/protocols/"></PlayReadyInitiator>'},g=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 f={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=g(),this&&this.el?this.el.appendChild(a):document.body.appendChild(a));var s=t.xmlLicenceAcquisition?d(t.xmlLicenceAcquisition):c(t.licenseServerURL),h=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=h,a.onDRMMessageResult=f,a.sendDRMMessage(u,s,l)}catch(t){return e.Log.warn("DRMHandler","Error at sendDRMMessage call",t.message),a.parentNode&&a.parentNode.removeChild(a),r()}},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)return e.Log.warn("DRMHandler","No one DRM license has been configured before. It's not necessary to clear any license server."),i();var a=h();try{o.onDRMRightsError=i,o.onDRMMessageResult=function(){o.parentNode&&o.parentNode.removeChild(o),i()},o.sendDRMMessage(u,a,l)}catch(t){e.Log.error("DRMHandler","Error at sendDRMMessage call",t.message),r(t.message)}}},m={code:"unknown",message:"unknown"},p=3,y={MP4:"video/mp4",VND_APPLE_MPEGURL:"application/vnd.apple.mpegurl",VND_MS_SSTR:"application/vnd.ms-sstr+xml",DASH:"application/dash+xml"},v={m3u8:y.VND_APPLE_MPEGURL,m3u:y.VND_APPLE_MPEGURL,mp4:y.MP4,ism:y.VND_MS_SSTR,mpd:y.DASH},_=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=_(e);return!(!n&&!v[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>=p}},{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=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?f.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||m,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&&f.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.10", | ||
"version": "0.1.0", | ||
"description": "A Clappr HTML5 playback for smart TVs based on HbbTV 2.0.1 specs.", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
@@ -6,3 +6,3 @@ import { Log } from '@clappr/core' | ||
export const getFullChallengeMessageTemplate = header => { | ||
const getFullChallengeMessageTemplate = header => { | ||
const template = '<?xml version="1.0" encoding="utf-8"?>' | ||
@@ -19,3 +19,3 @@ + '<PlayReadyInitiator xmlns="http://schemas.microsoft.com/DRM/2007/03/protocols/">' | ||
export const getLicenseOverrideMessageTemplate = licenseServerURL => { | ||
const getLicenseOverrideMessageTemplate = licenseServerURL => { | ||
const template = '<?xml version="1.0" encoding="utf-8"?>' | ||
@@ -30,3 +30,3 @@ + '<PlayReadyInitiator xmlns="http://schemas.microsoft.com/DRM/2007/03/protocols/">' | ||
export const getClearMessageTemplate = () => { | ||
const getClearMessageTemplate = () => { | ||
const template = '<?xml version="1.0" encoding="utf-8"?>' | ||
@@ -38,3 +38,3 @@ + '<PlayReadyInitiator xmlns="http://schemas.microsoft.com/DRM/2007/03/protocols/">' | ||
export const createDrmAgent = () => { | ||
const createDrmAgent = () => { | ||
const drmElement = document.createElement('object') | ||
@@ -54,2 +54,9 @@ | ||
const DRMFunctions = { | ||
getFullChallengeMessageTemplate, | ||
getLicenseOverrideMessageTemplate, | ||
getClearMessageTemplate, | ||
createDrmAgent, | ||
} | ||
/* eslint-disable-next-line func-style */ | ||
@@ -62,3 +69,3 @@ export function sendLicenseRequest(config = {}, onSuccess = () => {}, onFail = () => {}) { | ||
if (!oipfdrmagent) { | ||
oipfdrmagent = createDrmAgent() | ||
oipfdrmagent = DRMFunctions.createDrmAgent() | ||
this && this.el | ||
@@ -70,4 +77,4 @@ ? this.el.appendChild(oipfdrmagent) | ||
const xmlLicenceAcquisition = config.xmlLicenceAcquisition | ||
? getFullChallengeMessageTemplate(config.xmlLicenceAcquisition) | ||
: getLicenseOverrideMessageTemplate(config.licenseServerURL) | ||
? DRMFunctions.getFullChallengeMessageTemplate(config.xmlLicenceAcquisition) | ||
: DRMFunctions.getLicenseOverrideMessageTemplate(config.licenseServerURL) | ||
@@ -113,4 +120,6 @@ const drmRightsErrorHandler = resultCode => { | ||
} catch (error) { | ||
Log.error('DRMHandler', 'Error at sendDRMMessage call', error.message) | ||
return errorCallback(error.message) | ||
Log.warn('DRMHandler', 'Error at sendDRMMessage call', error.message) | ||
// Some TVs handles the DRM license request automatically, so we can consider it as a success to allow the TV to setup the DRM license | ||
oipfdrmagent.parentNode && oipfdrmagent.parentNode.removeChild(oipfdrmagent) | ||
return successCallback() | ||
} | ||
@@ -127,6 +136,6 @@ } | ||
Log.warn('DRMHandler', 'No one DRM license has been configured before. It\'s not necessary to clear any license server.') | ||
return | ||
return successCallback() | ||
} | ||
const xmlLicenceAcquisition = getClearMessageTemplate() | ||
const xmlLicenceAcquisition = DRMFunctions.getClearMessageTemplate() | ||
@@ -137,3 +146,3 @@ try { | ||
oipfdrmagent.onDRMMessageResult = () => { | ||
oipfdrmagent.remove() | ||
oipfdrmagent.parentNode && oipfdrmagent.parentNode.removeChild(oipfdrmagent) | ||
successCallback() | ||
@@ -154,2 +163,2 @@ } | ||
export default DRMHandler | ||
export { DRMFunctions, DRMHandler as default } |
import mockConsole from 'jest-mock-console' | ||
import DRMHandler, { | ||
import DRMHandler, { DRMFunctions } from './drm_handler' | ||
const { | ||
getFullChallengeMessageTemplate, | ||
@@ -8,6 +10,10 @@ getLicenseOverrideMessageTemplate, | ||
createDrmAgent, | ||
} = DRMFunctions | ||
const { | ||
sendLicenseRequest, | ||
clearLicenseRequest, | ||
} from './drm_handler' | ||
} = DRMHandler | ||
let oipfdrmagent | ||
const LOG_WARN_STYLE = 'color: #ff8000;font-weight: bold; font-size: 13px;' | ||
@@ -20,2 +26,6 @@ const LOG_WARN_HEAD_MESSAGE = '%c[warn][DRMHandler]' | ||
jest.clearAllMocks() | ||
oipfdrmagent = createDrmAgent() | ||
oipfdrmagent.sendDRMMessage = () => {} | ||
jest.spyOn(DRMFunctions, 'createDrmAgent').mockReturnValue(oipfdrmagent) | ||
}) | ||
@@ -75,3 +85,3 @@ afterEach(() => this.restoreConsole()) | ||
test('returns a DOM element with a specific type to handle with the DRM license request', () => { | ||
const drmElement = createDrmAgent() | ||
const drmElement = DRMFunctions.createDrmAgent() | ||
@@ -83,3 +93,3 @@ expect(drmElement.tagName).toEqual('OBJECT') | ||
test('returns a DOM element with properties that avoids showing it on the screen', () => { | ||
const drmElement = createDrmAgent() | ||
const drmElement = DRMFunctions.createDrmAgent() | ||
@@ -106,3 +116,3 @@ expect(drmElement.id).toEqual('oipfdrmagent') | ||
test('reuses drmAgent element if already exists', () => { | ||
document.body.appendChild(createDrmAgent()) | ||
document.body.appendChild(DRMFunctions.createDrmAgent()) | ||
sendLicenseRequest(this.config) | ||
@@ -128,5 +138,6 @@ | ||
test('calls the errorCallback if the sendDRMMessage call fails', () => { | ||
test('calls the successCallback if the sendDRMMessage is not available', () => { | ||
const successCb = jest.fn() | ||
const errorCb = jest.fn() | ||
oipfdrmagent.sendDRMMessage = undefined | ||
sendLicenseRequest(this.config, successCb, errorCb) | ||
@@ -136,4 +147,4 @@ | ||
expect(console.log).toHaveBeenCalledWith( | ||
'%c[error][DRMHandler]', | ||
'color: #ff0000;font-weight: bold; font-size: 13px;', | ||
'%c[warn][DRMHandler]', | ||
'color: #ff8000;font-weight: bold; font-size: 13px;', | ||
'Error at sendDRMMessage call', | ||
@@ -143,3 +154,3 @@ 'oipfdrmagent.sendDRMMessage is not a function', | ||
expect(errorCb).toHaveBeenCalledTimes(1) | ||
expect(successCb).toHaveBeenCalledTimes(1) | ||
}) | ||
@@ -149,5 +160,4 @@ | ||
test('don\'t calls the errorCallback if the received code number is greater o equal 2', () => { | ||
document.body.appendChild(createDrmAgent()) | ||
document.body.appendChild(DRMFunctions.createDrmAgent()) | ||
const drmAgentElement = document.getElementById('oipfdrmagent') | ||
drmAgentElement.sendDRMMessage = () => {} | ||
@@ -163,5 +173,4 @@ const successCb = jest.fn() | ||
test('returns one error if the received code number is below 2', () => { | ||
document.body.appendChild(createDrmAgent()) | ||
document.body.appendChild(DRMFunctions.createDrmAgent()) | ||
const drmAgentElement = document.getElementById('oipfdrmagent') | ||
drmAgentElement.sendDRMMessage = () => {} | ||
@@ -179,5 +188,4 @@ const successCb = jest.fn() | ||
test('calls the errorCallback if the received result code is nonzero', () => { | ||
document.body.appendChild(createDrmAgent()) | ||
document.body.appendChild(DRMFunctions.createDrmAgent()) | ||
const drmAgentElement = document.getElementById('oipfdrmagent') | ||
drmAgentElement.sendDRMMessage = () => {} | ||
@@ -194,5 +202,4 @@ const successCb = jest.fn() | ||
test('calls the successCallback if the received result code is 0', () => { | ||
document.body.appendChild(createDrmAgent()) | ||
document.body.appendChild(DRMFunctions.createDrmAgent()) | ||
const drmAgentElement = document.getElementById('oipfdrmagent') | ||
drmAgentElement.sendDRMMessage = () => {} | ||
@@ -225,6 +232,15 @@ const cb = jest.fn() | ||
test('calls successCallback if no drmAgent element exists', () => { | ||
const successCb = jest.fn() | ||
const errorCb = jest.fn() | ||
clearLicenseRequest(successCb, errorCb) | ||
expect(successCb).toHaveBeenCalledTimes(1) | ||
}) | ||
test('calls the errorCallback if the sendDRMMessage call fails', () => { | ||
const successCb = jest.fn() | ||
const errorCb = jest.fn() | ||
document.body.appendChild(createDrmAgent()) | ||
oipfdrmagent.sendDRMMessage = undefined | ||
document.body.appendChild(DRMFunctions.createDrmAgent()) | ||
clearLicenseRequest(successCb, errorCb) | ||
@@ -245,3 +261,3 @@ | ||
test('removes drmAgentElement from DOM', () => { | ||
document.body.appendChild(createDrmAgent()) | ||
document.body.appendChild(DRMFunctions.createDrmAgent()) | ||
const drmAgentElement = document.getElementById('oipfdrmagent') | ||
@@ -258,3 +274,3 @@ drmAgentElement.sendDRMMessage = () => {} | ||
test('calls the successCallback', () => { | ||
document.body.appendChild(createDrmAgent()) | ||
document.body.appendChild(DRMFunctions.createDrmAgent()) | ||
const drmAgentElement = document.getElementById('oipfdrmagent') | ||
@@ -261,0 +277,0 @@ drmAgentElement.sendDRMMessage = () => {} |
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
155637
3269