7 lines
No EOL
18 KiB
JavaScript
Executable file
7 lines
No EOL
18 KiB
JavaScript
Executable file
/**
|
|
* videojs-chromecast
|
|
* @version 2.0.8
|
|
* @copyright 2017 Benjipott, Inc.
|
|
* @license Apache-2.0
|
|
*/
|
|
!function(e){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{var t;t="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:this,(t.video||(t.video={})).jsChromecast=e()}}(function(){return function e(t,i,o){function n(r,s){if(!i[r]){if(!t[r]){var c="function"==typeof require&&require;if(!s&&c)return c(r,!0);if(a)return a(r,!0);var u=new Error("Cannot find module '"+r+"'");throw u.code="MODULE_NOT_FOUND",u}var d=i[r]={exports:{}};t[r][0].call(d.exports,function(e){var i=t[r][1][e];return n(i?i:e)},d,d.exports,e,t,i,o)}return i[r].exports}for(var a="function"==typeof require&&require,r=0;r<o.length;r++)n(o[r]);return n}({1:[function(e,t,i){(function(e){"use strict";function o(e){return e&&e.__esModule?e:{"default":e}}function n(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function a(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}Object.defineProperty(i,"__esModule",{value:!0});var r=function(){function e(e,t){for(var i=0;i<t.length;i++){var o=t[i];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(e,o.key,o)}}return function(t,i,o){return i&&e(t.prototype,i),o&&e(t,o),t}}(),s=function(e,t,i){for(var o=!0;o;){var n=e,a=t,r=i;o=!1,null===n&&(n=Function.prototype);var s=Object.getOwnPropertyDescriptor(n,a);if(void 0!==s){if("value"in s)return s.value;var c=s.get;if(void 0===c)return;return c.call(r)}var u=Object.getPrototypeOf(n);if(null===u)return;e=u,t=a,i=r,o=!0,s=u=void 0}},c="undefined"!=typeof window?window.videojs:"undefined"!=typeof e?e.videojs:null,u=o(c),d=u["default"].getComponent("Component"),l=u["default"].getComponent("ControlBar"),p=u["default"].getComponent("Button"),h=function(e){function t(e,i){var o=this;n(this,t),s(Object.getPrototypeOf(t.prototype),"constructor",this).call(this,e,i),this.hide(),this.initializeApi(),i.appId=e.options_.chromecast.appId,e.chromecast=this,this.on(e,"loadstart",function(){o.casting&&o.apiInitialized&&o.onSessionSuccess(o.apiSession)})}return a(t,e),r(t,[{key:"initializeApi",value:function(){var e=void 0,t=void 0,i=void 0;return u["default"].browser.IS_CHROME&&!u["default"].browser.IS_EDGE?chrome.cast&&chrome.cast.isAvailable?(u["default"].log("Cast APIs are available"),t=this.options_.appId||chrome.cast.media.DEFAULT_MEDIA_RECEIVER_APP_ID,i=new chrome.cast.SessionRequest(t),e=new chrome.cast.ApiConfig(i,this.sessionJoinedListener.bind(this),this.receiverListener.bind(this)),chrome.cast.initialize(e,this.onInitSuccess.bind(this),this.castError.bind(this))):(u["default"].log("Cast APIs not available"),this.tryingReconnect<10&&(this.setTimeout(this.initializeApi,1e3),++this.tryingReconnect),void u["default"].log("Cast APIs not available. Max reconnect attempt")):void 0}},{key:"castError",value:function(e){var t={code:e.code,message:e.description};switch(e.code){case chrome.cast.ErrorCode.API_NOT_INITIALIZED:case chrome.cast.ErrorCode.EXTENSION_MISSING:case chrome.cast.ErrorCode.EXTENSION_NOT_COMPATIBLE:case chrome.cast.ErrorCode.INVALID_PARAMETER:case chrome.cast.ErrorCode.LOAD_MEDIA_FAILED:case chrome.cast.ErrorCode.RECEIVER_UNAVAILABLE:case chrome.cast.ErrorCode.SESSION_ERROR:case chrome.cast.ErrorCode.CHANNEL_ERROR:case chrome.cast.ErrorCode.TIMEOUT:this.addClass("error");break;case chrome.cast.ErrorCode.CANCEL:break;default:this.player_.error(t)}return u["default"].log("Cast Error: "+JSON.stringify(e))}},{key:"onInitSuccess",value:function(){return this.apiInitialized=!0}},{key:"sessionJoinedListener",value:function(e){return e.media.length&&(this.apiSession=e,this.onMediaDiscovered(e.media[0])),console.log("Session joined")}},{key:"receiverListener",value:function(e){return"available"===e?this.show():void 0}},{key:"doLaunch",value:function(){return u["default"].log("Cast video: "+this.player_.cache_.src),this.apiInitialized?chrome.cast.requestSession(this.onSessionSuccess.bind(this),this.castError.bind(this)):u["default"].log("Session not initialized")}},{key:"onSessionSuccess",value:function(e){var t=void 0,i=void 0,o=void 0,n=void 0,a=void 0,r=void 0;this.apiSession=e;var s=this.player_.cache_.src,c=this.player_.currentType();if(u["default"].log("Session initialized: "+e.sessionId+" source : "+s+" type : "+c),n=new chrome.cast.media.MediaInfo(s,c),n.metadata=new chrome.cast.media.GenericMediaMetadata,this.options_.metadata){a=this.options_.metadata;for(i in a)r=a[i],n.metadata[i]=r}var d=this.player().poster();d&&(t=new chrome.cast.Image(d),n.metadata.images=[t]);var l=this.player().textTracks(),p=this.player().remoteTextTrackEls(),h=[],f=0,v=void 0,y=void 0,m=0,g=void 0;if(l){for(f=0;f<l.length;f++)y=l.tracks_[f],v=p&&p.trackElements_&&p.trackElements_[f],m++,g=new chrome.cast.media.Track(m,chrome.cast.media.TrackType.TEXT),g.trackContentId=v?v.src:"caption_"+y.language,g.subtype=chrome.cast.media.TextTrackType.CAPTIONS,g.name=y.label,g.language=y.language,g.customData=null,h.push(g);n.textTrackStyle=new chrome.cast.media.TextTrackStyle,n.textTrackStyle.foregroundColor="#FFFFFF",n.textTrackStyle.backgroundColor="#00000060",n.textTrackStyle.edgeType=chrome.cast.media.TextTrackEdgeType.DROP_SHADOW,n.textTrackStyle.windowType=chrome.cast.media.TextTrackWindowType.ROUNDED_CORNERS}try{if(l=this.player().audioTracks())for(f=0;f<l.length;f++)y=l.tracks_[f],m++,g=new chrome.cast.media.Track(m,chrome.cast.media.TrackType.AUDIO),g.subtype=null,g.name=y.label,g.language=y.language,g.customData=null,h.push(g)}catch(b){u["default"].log("get player audioTracks fail"+b)}h.length&&(n.tracks=h),o=new chrome.cast.media.LoadRequest(n),o.autoplay=!0,o.currentTime=this.player_.currentTime(),this.apiSession.loadMedia(o,this.onMediaDiscovered.bind(this),this.castError.bind(this)),this.apiSession.addUpdateListener(this.onSessionUpdate.bind(this))}},{key:"onMediaDiscovered",value:function(e){this.player_.loadTech_("Chromecast",{type:"cast",apiMedia:e,apiSession:this.apiSession}),this.casting=!0,this.inactivityTimeout=this.player_.options_.inactivityTimeout,this.player_.options_.inactivityTimeout=0,this.player_.userActive(!0),this.addClass("connected"),this.removeClass("error")}},{key:"onSessionUpdate",value:function(e){return this.player_.apiMedia?e?void 0:this.onStopAppSuccess():void 0}},{key:"stopCasting",value:function(){return this.apiSession.stop(this.onStopAppSuccess.bind(this),this.castError.bind(this))}},{key:"onStopAppSuccess",value:function(){this.casting=!1;var e=this.player_.currentTime();return this.removeClass("connected"),this.player_.src(this.player_.options_.sources),this.player_.paused()||this.player_.one("seeked",function(){return this.player_.play()}),this.player_.currentTime(e),this.player_.options_.inactivityTimeout=this.inactivityTimeout,this.apiSession=null}},{key:"buildCSSClass",value:function(){return"vjs-chromecast-button "+s(Object.getPrototypeOf(t.prototype),"buildCSSClass",this).call(this)}},{key:"handleClick",value:function(){return s(Object.getPrototypeOf(t.prototype),"handleClick",this).call(this),this.casting?this.stopCasting():this.doLaunch()}}]),t}(p);h.prototype.tryingReconnect=0,h.prototype.inactivityTimeout=2e3,h.prototype.controlText_="Chromecast",l.prototype.options_.children.splice(l.prototype.options_.children.length-1,0,"chromeCastButton"),d.registerComponent("ChromeCastButton",h),i["default"]=h,t.exports=i["default"]}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{}],2:[function(e,t,i){(function(e){"use strict";function o(e){return e&&e.__esModule?e:{"default":e}}function n(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function a(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}Object.defineProperty(i,"__esModule",{value:!0});var r=function(){function e(e,t){for(var i=0;i<t.length;i++){var o=t[i];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(e,o.key,o)}}return function(t,i,o){return i&&e(t.prototype,i),o&&e(t,o),t}}(),s=function(e,t,i){for(var o=!0;o;){var n=e,a=t,r=i;o=!1,null===n&&(n=Function.prototype);var s=Object.getOwnPropertyDescriptor(n,a);if(void 0!==s){if("value"in s)return s.value;var c=s.get;if(void 0===c)return;return c.call(r)}var u=Object.getPrototypeOf(n);if(null===u)return;e=u,t=a,i=r,o=!0,s=u=void 0}},c="undefined"!=typeof window?window.videojs:"undefined"!=typeof e?e.videojs:null,u=o(c),d=u["default"].getComponent("Component"),l=u["default"].getComponent("Tech"),p=function(e){function t(e,i){var o=this;n(this,t),s(Object.getPrototypeOf(t.prototype),"constructor",this).call(this,e,i),this.apiMedia=this.options_.source.apiMedia,this.apiSession=this.options_.source.apiSession,this.receiver=this.apiSession.receiver.friendlyName;var a=this.onMediaStatusUpdate.bind(this),r=this.onSessionUpdate.bind(this);this.apiMedia.addUpdateListener(a),this.apiSession.addUpdateListener(r),this.on("dispose",function(){o.apiMedia.removeUpdateListener(a),o.apiSession.removeUpdateListener(r),o.onMediaStatusUpdate(),o.onSessionUpdate(!1)});var c=this.textTracks();c&&!function(){var e=o.handleTextTracksChange.bind(o);c.addEventListener("change",e),o.on("dispose",function(){c.removeEventListener("change",e)}),o.handleTextTracksChange()}();try{c=this.audioTracks(),c&&!function(){var e=o.handleAudioTracksChange.bind(o);c.addEventListener("change",e),o.on("dispose",function(){c.removeEventListener("change",e)})}()}catch(d){u["default"].log("get player audioTracks fail"+d)}try{c=this.videoTracks(),c&&!function(){var e=o.handleVideoTracksChange.bind(o);c.addEventListener("change",e),o.on("dispose",function(){c.removeEventListener("change",e)})}()}catch(d){u["default"].log("get player videoTracks fail"+d)}this.update(),this.triggerReady()}return a(t,e),r(t,[{key:"createEl",value:function(){var e=u["default"].createEl("div",{id:this.options_.techId,className:"vjs-tech vjs-tech-chromecast"});return e}},{key:"update",value:function(){this.el_.innerHTML='<div class="casting-image" style="background-image: url(\''+this.options_.poster+'\')"></div><div class="casting-overlay"><div class="casting-information"><div class="casting-icon"></div><div class="casting-description"><small>'+this.localize("CASTING TO")+"</small><br>"+this.receiver+"</div></div></div>"}},{key:"onSessionUpdate",value:function(e){return this.apiMedia?e?void 0:this.onStopAppSuccess():void 0}},{key:"onStopAppSuccess",value:function(){this.stopTrackingCurrentTime(),this.apiMedia=null}},{key:"onMediaStatusUpdate",value:function(){if(this.apiMedia)switch(this.apiMedia.playerState){case chrome.cast.media.PlayerState.BUFFERING:this.trigger("waiting");break;case chrome.cast.media.PlayerState.IDLE:this.trigger("timeupdate"),this.trigger("ended");break;case chrome.cast.media.PlayerState.PAUSED:this.trigger("pause"),this.paused_=!0;break;case chrome.cast.media.PlayerState.PLAYING:this.trigger("playing"),this.trigger("play"),this.paused_=!1}}},{key:"src",value:function(e){}},{key:"currentSrc",value:function(){return this.apiMedia?this.apiMedia.media.contentId:void 0}},{key:"handleAudioTracksChange",value:function(){var e=[],t=this.textTracks(),i=this.audioTracks();if(i){for(var o=0;o<i.length;o++){var n=i[o];n.enabled&&e.push(o+1+t.length)}return this.apiMedia&&e.length?(this.tracksInfoRequest=new chrome.cast.media.EditTracksInfoRequest(e),this.apiMedia.editTracksInfo(this.tracksInfoRequest,this.onTrackSuccess.bind(this),this.onTrackError.bind(this))):void 0}}},{key:"handleVideoTracksChange",value:function(){}},{key:"handleTextTracksChange",value:function(){var e=[],t=this.textTracks();if(t){for(var i=0;i<t.length;i++){var o=t[i];"showing"===o.mode&&e.push(i+1)}return this.apiMedia&&e.length?(this.tracksInfoRequest=new chrome.cast.media.EditTracksInfoRequest(e),this.apiMedia.editTracksInfo(this.tracksInfoRequest,this.onTrackSuccess.bind(this),this.onTrackError.bind(this))):void 0}}},{key:"onTrackSuccess",value:function(){return u["default"].log("track added")}},{key:"onTrackError",value:function(e){return u["default"].log("Cast track Error: "+JSON.stringify(e))}},{key:"castError",value:function(e){return u["default"].log("Cast Error: "+JSON.stringify(e))}},{key:"play",value:function(){return this.apiMedia?(this.paused_&&this.apiMedia.play(null,this.mediaCommandSuccessCallback.bind(this,"Playing: "+this.apiMedia.sessionId),this.castError.bind(this)),this.paused_=!1):void 0}},{key:"pause",value:function(){return this.apiMedia?this.paused_?void 0:(this.apiMedia.pause(null,this.mediaCommandSuccessCallback.bind(this,"Paused: "+this.apiMedia.sessionId),this.castError.bind(this)),this.paused_=!0):void 0}},{key:"paused",value:function(){return this.paused_}},{key:"ended",value:function(){return"FINISHED"===chrome.cast.media.IdleReason}},{key:"currentTime",value:function(){return this.apiMedia?this.apiMedia.getEstimatedTime():0}},{key:"setCurrentTime",value:function(e){if(!this.apiMedia)return 0;var t=void 0;return t=new chrome.cast.media.SeekRequest,t.currentTime=e,this.apiMedia.seek(t,this.onSeekSuccess.bind(this,e),this.castError.bind(this))}},{key:"onSeekSuccess",value:function(e){u["default"].log("seek success"+e)}},{key:"volume",value:function(){return this.volume_}},{key:"duration",value:function(){return this.apiMedia?this.apiMedia.media.duration||1/0:0}},{key:"controls",value:function(){return!1}},{key:"setVolume",value:function(e){var t=arguments.length<=1||void 0===arguments[1]?!1:arguments[1],i=void 0,o=void 0;return this.apiMedia?(o=new chrome.cast.Volume,o.level=e,o.muted=t,this.volume_=o.level,this.muted_=t,i=new chrome.cast.media.VolumeRequest,i.volume=o,this.apiMedia.setVolume(i,this.mediaCommandSuccessCallback.bind(this,"Volume changed"),this.castError.bind(this)),this.trigger("volumechange")):void 0}},{key:"mediaCommandSuccessCallback",value:function(e){u["default"].log(e)}},{key:"muted",value:function(){return this.muted_}},{key:"setMuted",value:function(e){return this.setVolume(this.volume_,e)}},{key:"supportsFullScreen",value:function(){return!1}},{key:"resetSrc_",value:function(e){e()}},{key:"dispose",value:function(){this.resetSrc_(Function.prototype),s(Object.getPrototypeOf(t.prototype),"dispose",this).call(this,this)}}]),t}(l);p.prototype.paused_=!1,p.prototype.options_={},p.prototype.timerStep=1e3,p.isSupported=function(){return!0},l.withSourceHandlers(p),p.nativeSourceHandler={},p.nativeSourceHandler.canPlayType=function(e){var t=/^application\/(?:dash\+xml|(x-|vnd\.apple\.)mpegurl)/i,i=/^video\/(mpd|mp4|webm|m3u8)/i;return t.test(e)?"probably":i.test(e)?"maybe":""},p.nativeSourceHandler.canHandleSource=function(e){return e.type?p.nativeSourceHandler.canPlayType(e.type):e.src?p.nativeSourceHandler.canPlayType(e.src):""},p.nativeSourceHandler.handleSource=function(e,t){t.src(e.src)},p.nativeSourceHandler.dispose=function(){},p.registerSourceHandler(p.nativeSourceHandler),p.prototype.featuresVolumeControl=!0,p.prototype.featuresPlaybackRate=!1,p.prototype.movingMediaElementInDOM=!1,p.prototype.featuresFullscreenResize=!1,p.prototype.featuresTimeupdateEvents=!1,p.prototype.featuresProgressEvents=!1,p.prototype.featuresNativeTextTracks=!0,p.prototype.featuresNativeAudioTracks=!0,p.prototype.featuresNativeVideoTracks=!1,u["default"].options.chromecast={},d.registerComponent("Chromecast",p),l.registerTech("Chromecast",p),i["default"]=p,t.exports=i["default"]}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{}],3:[function(e,t,i){(function(o){"use strict";function n(e){return e&&e.__esModule?e:{"default":e}}function a(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function r(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}Object.defineProperty(i,"__esModule",{value:!0});var s=function(e,t,i){for(var o=!0;o;){var n=e,a=t,r=i;o=!1,null===n&&(n=Function.prototype);var s=Object.getOwnPropertyDescriptor(n,a);if(void 0!==s){if("value"in s)return s.value;var c=s.get;if(void 0===c)return;return c.call(r)}var u=Object.getPrototypeOf(n);if(null===u)return;e=u,t=a,i=r,o=!0,s=u=void 0}},c="undefined"!=typeof window?window.videojs:"undefined"!=typeof o?o.videojs:null,u=n(c),d=e("./component/control-bar/chromecast-button"),l=(n(d),e("./tech/chromecast")),p=(n(l),u["default"].getComponent("Component")),h=function(e){function t(e,i){a(this,t),s(Object.getPrototypeOf(t.prototype),"constructor",this).call(this,e,i)}return r(t,e),t}(p);h.prototype.options_={},u["default"].options.children.push("chromecast"),u["default"].addLanguage("en",{"CASTING TO":"WIEDERGABE AUF"}),u["default"].addLanguage("de",{"CASTING TO":"WIEDERGABE AUF"}),u["default"].addLanguage("it",{"CASTING TO":"PLAYBACK SU"}),u["default"].addLanguage("fr",{"CASTING TO":"CAST EN COURS SUR"});var f=window.navigator.userAgent;u["default"].browser.IS_EDGE=/Edge/i.test(f),p.registerComponent("Chromecast",h),i["default"]=h,t.exports=i["default"]}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{"./component/control-bar/chromecast-button":1,"./tech/chromecast":2}],4:[function(e,t,i){(function(o){"use strict";function n(e){return e&&e.__esModule?e:{"default":e}}Object.defineProperty(i,"__esModule",{value:!0});var a="undefined"!=typeof window?window.videojs:"undefined"!=typeof o?o.videojs:null,r=n(a),s=e("./videojs-chromecast"),c=(n(s),function(e){var t=this;t.addChild("Chromecast",e)});r["default"].plugin("chromecast",c),i["default"]=c,t.exports=i["default"]}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{"./videojs-chromecast":3}]},{},[4])(4)}); |