@clappr/clappr-html5-tvs-playback
Advanced tools
Comparing version 0.0.4 to 0.0.5
@@ -199,2 +199,3 @@ import _classCallCheck from '@babel/runtime/helpers/classCallCheck'; | ||
_this._onAudioTracksUpdated = _this._onAudioTracksUpdated.bind(_assertThisInitialized(_this)); | ||
_this._playbackType = _this.mediaType; | ||
_this._drmConfigured = false; | ||
@@ -344,2 +345,15 @@ _this._isReady = false; | ||
}, { | ||
key: "playbackType", | ||
get: function get() { | ||
return this._playbackType; | ||
}, | ||
set: function set(newPlaybackType) { | ||
this._playbackType = newPlaybackType; | ||
} | ||
}, { | ||
key: "sourceMedia", | ||
get: function get() { | ||
return this._src; | ||
} | ||
}, { | ||
key: "_setupSource", | ||
@@ -346,0 +360,0 @@ value: function _setupSource(sourceURL) { |
@@ -324,2 +324,3 @@ (function (global, factory) { | ||
_this._onAudioTracksUpdated = _this._onAudioTracksUpdated.bind(_assertThisInitialized(_this)); | ||
_this._playbackType = _this.mediaType; | ||
_this._drmConfigured = false; | ||
@@ -469,2 +470,15 @@ _this._isReady = false; | ||
}, { | ||
key: "playbackType", | ||
get: function get() { | ||
return this._playbackType; | ||
}, | ||
set: function set(newPlaybackType) { | ||
this._playbackType = newPlaybackType; | ||
} | ||
}, { | ||
key: "sourceMedia", | ||
get: function get() { | ||
return this._src; | ||
} | ||
}, { | ||
key: "_setupSource", | ||
@@ -471,0 +485,0 @@ value: function _setupSource(sourceURL) { |
@@ -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=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%",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(){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 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:"_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&&(Object.values(this.el.audioTracks).forEach((function(e){e.enabled=e.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.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)})); | ||
!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,y={MP4:"video/mp4",VND_APPLE_MPEGURL:"application/vnd.apple.mpegurl",VND_MS_SSTR:"application/vnd.ms-sstr+xml"},v={m3u8:y.VND_APPLE_MPEGURL,m3u:y.VND_APPLE_MPEGURL,mp4:y.MP4,ism:y.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._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,c=[{key:"canPlay",value:function(e,t){var n=Object.values(y).find((function(e){return t===e})),i=p(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>=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 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[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&&(Object.values(this.el.audioTracks).forEach((function(e){e.enabled=e.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.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)})); |
{ | ||
"name": "@clappr/clappr-html5-tvs-playback", | ||
"version": "0.0.4", | ||
"version": "0.0.5", | ||
"description": "A Clappr HTML5 playback for smart TVs based on HbbTV 2.0.1 specs.", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
@@ -88,3 +88,9 @@ <!-- [![](https://data.jsdelivr.com/v1/package/npm/@joaopaulo.vieira/clappr-html5-tvs-playback//badge)](https://www.jsdelivr.com/package/npm/@joaopaulo.vieira/clappr-html5-tvs-playback/) --> | ||
| `playback.dvrEnabled` | Indicates whether the live media is on DVR state. | `{Boolean}` | | ||
| `playback.playbackType` | Returns if the type of media when this property was not change the value is `live` or `vod`. | `{String}` | | ||
| `playback.sourceMedia` | Returns a media url in use. | `{String}` | | ||
| setter | description | parameter | | ||
|--------|-------------|----------| | ||
| `playback.playbackType` | Set the new value of playback.playbackType property. | `{String}` | | ||
## Types | ||
@@ -91,0 +97,0 @@ #### `AudioTrack` |
@@ -107,5 +107,18 @@ import { Events, Log, Playback, PlayerError, version } from '@clappr/core' | ||
get playbackType() { | ||
return this._playbackType | ||
} | ||
set playbackType(newPlaybackType) { | ||
this._playbackType = newPlaybackType | ||
} | ||
get sourceMedia() { | ||
return this._src | ||
} | ||
constructor(options, i18n, playerError) { | ||
super(options, i18n, playerError) | ||
this._onAudioTracksUpdated = this._onAudioTracksUpdated.bind(this) | ||
this._playbackType = this.mediaType | ||
@@ -112,0 +125,0 @@ this._drmConfigured = false |
@@ -201,2 +201,18 @@ /** | ||
test('playbackType getter returns mediaType property when is not changed', () => { | ||
this.playback.el = { duration: 0 } | ||
expect(this.playback.playbackType).toEqual(this.playback.mediaType) | ||
}) | ||
test('playbackType setter updates playbackType with new value', () => { | ||
this.playback.playbackType = 'new value' | ||
expect(this.playback.playbackType).toEqual('new value') | ||
}) | ||
test('sourceMedia getter returns returns src property', () => { | ||
expect(this.playback.sourceMedia).toBe(this.playback._src) | ||
}) | ||
test('adds event listeners to the audioTrack object of the media element', () => { | ||
@@ -203,0 +219,0 @@ expect(this.playback.el.audioTracks.addEventListener).toHaveBeenCalledWith('addtrack', this.playback._onAudioTracksUpdated) |
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
149730
3156
133
1