@clappr/clappr-html5-tvs-playback
Advanced tools
Comparing version 0.1.0 to 0.2.0
@@ -402,3 +402,6 @@ import _classCallCheck from '@babel/runtime/helpers/classCallCheck'; | ||
value: function _appendSourceElement() { | ||
this.config && this.config.drm && !this._drmConfigured ? DRMHandler.sendLicenseRequest.call(this, this.config.drm, this._onDrmConfigured, this._onDrmError) : this.el.appendChild(this.$sourceElement); | ||
var shouldConfigureDRM = this.config && this.config.drm && !this._drmConfigured; | ||
if (shouldConfigureDRM) return DRMHandler.sendLicenseRequest.call(this, this.config.drm, this._onDrmConfigured, this._onDrmError); | ||
this.el.appendChild(this.$sourceElement); | ||
this.el.load(); | ||
} | ||
@@ -681,2 +684,5 @@ }, { | ||
var audioTracks = this.el.audioTracks; | ||
audioTracks === null || audioTracks === void 0 ? void 0 : audioTracks.removeEventListener('addtrack', this._onAudioTracksUpdated); | ||
audioTracks === null || audioTracks === void 0 ? void 0 : audioTracks.removeEventListener('removetrack', this._onAudioTracksUpdated); | ||
this._src = null; | ||
@@ -692,9 +698,9 @@ } | ||
this.$sourceElement.removeEventListener('error', this._sourceElementErrorHandler); | ||
this.$sourceElement.removeAttribute('src'); // The src attribute will be added again in play(). | ||
this.$sourceElement.src = ''; // The src attribute will be added again in play(). | ||
this.el.load(); // Loads with no src attribute to stop the loading of the previous source and avoid leaks. | ||
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. | ||
} | ||
@@ -701,0 +707,0 @@ /** |
@@ -527,3 +527,6 @@ (function (global, factory) { | ||
value: function _appendSourceElement() { | ||
this.config && this.config.drm && !this._drmConfigured ? DRMHandler.sendLicenseRequest.call(this, this.config.drm, this._onDrmConfigured, this._onDrmError) : this.el.appendChild(this.$sourceElement); | ||
var shouldConfigureDRM = this.config && this.config.drm && !this._drmConfigured; | ||
if (shouldConfigureDRM) return DRMHandler.sendLicenseRequest.call(this, this.config.drm, this._onDrmConfigured, this._onDrmError); | ||
this.el.appendChild(this.$sourceElement); | ||
this.el.load(); | ||
} | ||
@@ -806,2 +809,5 @@ }, { | ||
var audioTracks = this.el.audioTracks; | ||
audioTracks === null || audioTracks === void 0 ? void 0 : audioTracks.removeEventListener('addtrack', this._onAudioTracksUpdated); | ||
audioTracks === null || audioTracks === void 0 ? void 0 : audioTracks.removeEventListener('removetrack', this._onAudioTracksUpdated); | ||
this._src = null; | ||
@@ -817,9 +823,9 @@ } | ||
this.$sourceElement.removeEventListener('error', this._sourceElementErrorHandler); | ||
this.$sourceElement.removeAttribute('src'); // The src attribute will be added again in play(). | ||
this.$sourceElement.src = ''; // The src attribute will be added again in play(). | ||
this.el.load(); // Loads with no src attribute to stop the loading of the previous source and avoid leaks. | ||
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. | ||
} | ||
@@ -826,0 +832,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(){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)})); | ||
!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,v={MP4:"video/mp4",VND_APPLE_MPEGURL:"application/vnd.apple.mpegurl",VND_MS_SSTR:"application/vnd.ms-sstr+xml",DASH:"application/dash+xml"},y={m3u8:v.VND_APPLE_MPEGURL,m3u:v.VND_APPLE_MPEGURL,mp4:v.MP4,ism:v.VND_MS_SSTR,mpd:v.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(v).find((function(e){return t===e})),i=_(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%",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=y[_(e)],this.$sourceElement.src=e,this.$sourceElement.addEventListener("error",this._sourceElementErrorHandler),this._src=this.$sourceElement.src,this._appendSourceElement())}},{key:"_appendSourceElement",value:function(){if(this.config&&this.config.drm&&!this._drmConfigured)return f.sendLicenseRequest.call(this,this.config.drm,this._onDrmConfigured,this._onDrmError);this.el.appendChild(this.$sourceElement),this.el.load()}},{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();var e=this.el.audioTracks;null==e||e.removeEventListener("addtrack",this._onAudioTracksUpdated),null==e||e.removeEventListener("removetrack",this._onAudioTracksUpdated),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.src="",this.el.load(),this.$sourceElement.parentNode&&this.$sourceElement.parentNode.removeChild(this.$sourceElement),this.$sourceElement=null)}},{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.1.0", | ||
"version": "0.2.0", | ||
"description": "A Clappr HTML5 playback for smart TVs based on HbbTV 2.0.1 specs.", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
@@ -159,5 +159,7 @@ import { Events, Log, Playback, PlayerError, version } from '@clappr/core' | ||
_appendSourceElement() { | ||
this.config && this.config.drm && !this._drmConfigured | ||
? DRMHandler.sendLicenseRequest.call(this, this.config.drm, this._onDrmConfigured, this._onDrmError) | ||
: this.el.appendChild(this.$sourceElement) | ||
const shouldConfigureDRM = this.config && this.config.drm && !this._drmConfigured | ||
if (shouldConfigureDRM) return DRMHandler.sendLicenseRequest.call(this, this.config.drm, this._onDrmConfigured, this._onDrmError) | ||
this.el.appendChild(this.$sourceElement) | ||
this.el.load() | ||
} | ||
@@ -380,2 +382,5 @@ | ||
this._wipeUpMedia() | ||
const { audioTracks } = this.el | ||
audioTracks?.removeEventListener('addtrack', this._onAudioTracksUpdated) | ||
audioTracks?.removeEventListener('removetrack', this._onAudioTracksUpdated) | ||
this._src = null | ||
@@ -389,7 +394,7 @@ } | ||
this.$sourceElement.removeEventListener('error', this._sourceElementErrorHandler) | ||
this.$sourceElement.removeAttribute('src') // The src attribute will be added again in play(). | ||
this.$sourceElement.src = '' // The src attribute will be added again in play(). | ||
this.el.load() // Loads with no src attribute to stop the loading of the previous source and avoid leaks. | ||
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. | ||
} | ||
@@ -396,0 +401,0 @@ |
@@ -37,2 +37,3 @@ /** | ||
addEventListener: { value: jest.fn() }, | ||
removeEventListener: { value: jest.fn() }, | ||
getTrackById: { value: id => tracks[id] }, | ||
@@ -721,2 +722,9 @@ 0: { | ||
}) | ||
test('calls load on playback.el after setting up source', () => { | ||
jest.spyOn(this.playback.el, 'load') | ||
this.playback._setupSource(URL_VIDEO_MP4_EXAMPLE) | ||
expect(this.playback.el.load).toHaveBeenCalledTimes(1) | ||
}) | ||
}) | ||
@@ -1001,3 +1009,4 @@ | ||
test('logs video.play promise problems', () => { | ||
window.HTMLMediaElement.prototype.play = () => new Promise(() => { throw new Error('Uh-oh!') }) | ||
const error = new Error('Uh-oh!') | ||
window.HTMLMediaElement.prototype.play = () => new Promise(() => { throw error }) | ||
@@ -1008,3 +1017,4 @@ this.playback.play() | ||
LOG_WARN_STYLE, | ||
'The play promise throws one error: Uh-oh!', | ||
'The play promise throws one error: ', | ||
error, | ||
)) | ||
@@ -1137,2 +1147,11 @@ }) | ||
}) | ||
test('removes event listeners from audio tracks', () => { | ||
this.playback._src = URL_VIDEO_MP4_EXAMPLE | ||
this.playback.destroy() | ||
expect(this.playback.el.audioTracks.removeEventListener).toHaveBeenCalledTimes(2) | ||
expect(this.playback.el.audioTracks.removeEventListener).toHaveBeenCalledWith('addtrack', this.playback._onAudioTracksUpdated) | ||
expect(this.playback.el.audioTracks.removeEventListener).toHaveBeenCalledWith('removetrack', this.playback._onAudioTracksUpdated) | ||
}) | ||
}) | ||
@@ -1139,0 +1158,0 @@ |
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
157702
3300