mirror of
https://github.com/zhw2590582/ArtPlayer.git
synced 2026-10-08 10:56:15 -08:00
8 lines
8.4 KiB
JavaScript
8 lines
8.4 KiB
JavaScript
|
|
/*!
|
|
* artplayer-plugin-chromecast.js v1.0.1
|
|
* Github: https://github.com/zhw2590582/ArtPlayer
|
|
* (c) 2017-2026 Harvey Zhao
|
|
* Released under the MIT License.
|
|
*/
|
|
!function(e,t,n,r,o){var a="u">typeof globalThis?globalThis:"u">typeof self?self:"u">typeof window?window:"u">typeof global?global:{},c="function"==typeof a[r]&&a[r],i=c.i||{},s=c.cache||{},l="u">typeof module&&"function"==typeof module.require&&module.require.bind(module);function u(t,n){if(!s[t]){if(!e[t]){if(o[t])return o[t];var i="function"==typeof a[r]&&a[r];if(!n&&i)return i(t,!0);if(c)return c(t,!0);if(l&&"string"==typeof t)return l(t);var f=Error("Cannot find module '"+t+"'");throw f.code="MODULE_NOT_FOUND",f}p.resolve=function(n){var r=e[t][1][n];return null!=r?r:n},p.cache={};var d=s[t]=new u.Module(t);e[t][0].call(d.exports,p,d,d.exports,a)}return s[t].exports;function p(e){var t=p.resolve(e);if(!1===t)return{};if(Array.isArray(t)){var n={__esModule:!0};return t.forEach(function(e){var t=e[0],r=e[1],o=e[2]||e[0],a=u(r);"*"===t?Object.keys(a).forEach(function(e){"default"===e||"__esModule"===e||Object.prototype.hasOwnProperty.call(n,e)||Object.defineProperty(n,e,{enumerable:!0,get:function(){return a[e]}})}):"*"===o?Object.defineProperty(n,t,{enumerable:!0,value:a}):Object.defineProperty(n,t,{enumerable:!0,get:function(){return"default"===o?a.__esModule?a.default:a:a[o]}})}),n}return u(t)}}u.isParcelRequire=!0,u.Module=function(e){this.id=e,this.bundle=u,this.require=l,this.exports={}},u.modules=e,u.cache=s,u.parent=c,u.distDir=void 0,u.publicUrl=void 0,u.devServer=void 0,u.i=i,u.register=function(t,n){e[t]=[function(e,t){t.exports=n},{}]},Object.defineProperty(u,"root",{get:function(){return a[r]}}),a[r]=u;for(var f=0;f<t.length;f++)u(t[f]);if(n){var d=u(n);"object"==typeof exports&&"u">typeof module?module.exports=d:"function"==typeof define&&define.amd&&define(function(){return d})}}({"1xnGs":[function(e,t,n,r){var o=e("@parcel/transformer-js/src/esmodule-helpers.js");o.defineInteropFlag(n),o.export(n,"default",function(){return i});var a=e("@swc/helpers/cjs/_async_to_generator.cjs"),c=e("@swc/helpers/cjs/_ts_generator.cjs");function i(e){var t=!1,n=null,r=null,o=function(e){var t=document.querySelector(".art-icon-cast");if(t)switch(e){case"connected":t.style.color="red";break;case"connecting":case"disconnecting":t.style.color="orange";break;default:t.style.color="white"}},i=function(t,n){var r=e.url||t.option.url,o=new window.chrome.cast.media.MediaInfo(r,e.mimeType||({mp4:"video/mp4",webm:"video/webm",ogg:"video/ogg",ogv:"video/ogg",mp3:"audio/mp3",wav:"audio/wav",flv:"video/x-flv",mov:"video/quicktime",avi:"video/x-msvideo",wmv:"video/x-ms-wmv",mpd:"application/dash+xml",m3u8:"application/x-mpegURL"})[r.split("?")[0].split("#")[0].split(".").pop().toLowerCase()]||"application/octet-stream"),a=new window.chrome.cast.media.LoadRequest(o);n.loadMedia(a).then(function(){var n;t.notice.show="Casting started",null==(n=e.onCastStart)||n.call(e)}).catch(function(n){var r;throw t.notice.show="Error casting media",null==(r=e.onError)||r.call(e,n),n})};return function(s){return(0,a._)(function(){return(0,c._)(this,function(l){return s.controls.add({name:"chromecast",position:"right",tooltip:"Chromecast",html:'<i class="art-icon art-icon-cast">'.concat(e.icon||'<svg height="20" width="20" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 576 512"><path d="M512 96H64v99c-13-2-26.4-3-40-3H0V96C0 60.7 28.7 32 64 32H512c35.3 0 64 28.7 64 64V416c0 35.3-28.7 64-64 64H288V456c0-13.6-1-27-3-40H512V96zM24 224c128.1 0 232 103.9 232 232c0 13.3-10.7 24-24 24s-24-10.7-24-24c0-101.6-82.4-184-184-184c-13.3 0-24-10.7-24-24s10.7-24 24-24zm8 192a32 32 0 1 1 0 64 32 32 0 1 1 0-64zM0 344c0-13.3 10.7-24 24-24c75.1 0 136 60.9 136 136c0 13.3-10.7 24-24 24s-24-10.7-24-24c0-48.6-39.4-88-88-88c-13.3 0-24-10.7-24-24z"/></svg>',"</i>"),click:function(){return(0,a._)(function(){var a,l,u,f,d;return(0,c._)(this,function(c){switch(c.label){case 0:if(t)return[3,4];c.label=1;case 1:return c.trys.push([1,3,,4]),[4,new Promise(function(a,c){var i;window.__onGCastApiAvailable=function(i){if(i){var s=window.cast.framework.CastContext.getInstance();s.setOptions({receiverApplicationId:window.chrome.cast.media.DEFAULT_MEDIA_RECEIVER_APP_ID,autoJoinPolicy:window.chrome.cast.AutoJoinPolicy.ORIGIN_SCOPED}),s.addEventListener(window.cast.framework.CastContextEventType.SESSION_STATE_CHANGED,function(t){var a,c,i,s,l,u=window.cast.framework.SessionState;switch(r=t.sessionState,n=t.session,t.sessionState){case u.NO_SESSION:null==(a=e.onStateChange)||a.call(e,"disconnected"),o("disconnected");break;case u.SESSION_STARTING:null==(c=e.onStateChange)||c.call(e,"connecting"),o("connecting");break;case u.SESSION_STARTED:null==(i=e.onStateChange)||i.call(e,"connected"),o("connected");break;case u.SESSION_ENDING:null==(s=e.onStateChange)||s.call(e,"disconnecting"),o("disconnecting");break;case u.SESSION_RESUMED:null==(l=e.onStateChange)||l.call(e,"connected"),o("connected")}}),s.addEventListener(window.cast.framework.CastContextEventType.CAST_STATE_CHANGED,function(t){var n,r,o,a=window.cast.framework.CastState;switch(t.castState){case a.NO_DEVICES_AVAILABLE:null==(n=e.onCastAvailable)||n.call(e,!1);break;case a.NOT_CONNECTED:null==(r=e.onCastAvailable)||r.call(e,!0);break;case a.CONNECTING:case a.CONNECTED:null==(o=e.onCastAvailable)||o.call(e,!0)}}),t=!0,a()}else c(Error("Cast API is not available"))},window.chrome&&window.chrome.cast||(i=e.sdk||"https://www.gstatic.com/cv/js/sender/v1/cast_sender.js?loadCastFramework=1",new Promise(function(e,t){var n=document.createElement("script");n.src=i,n.onload=e,n.onerror=t,document.body.appendChild(n)})).catch(c)})];case 2:return c.sent(),[3,4];case 3:throw a=c.sent(),s.notice.show="Failed to initialize Cast API",null==(l=e.onError)||l.call(e,a),a;case 4:if(u=window.cast.framework.CastContext.getInstance(),!n)return[3,5];return i(s,n),[3,8];case 5:return c.trys.push([5,7,,8]),[4,u.requestSession()];case 6:return i(s,c.sent()),[3,8];case 7:throw f=c.sent(),s.notice.show="Error connecting to cast session",null==(d=e.onError)||d.call(e,f),f;case 8:return[2]}})})()}}),[2,{name:"artplayerPluginChromecast",getCastState:function(){return r},isCasting:function(){return null!==n}}]})})()}}"u">typeof window&&(window.artplayerPluginChromecast=i)},{"@swc/helpers/cjs/_async_to_generator.cjs":"cZn0e","@swc/helpers/cjs/_ts_generator.cjs":"eltGh","@parcel/transformer-js/src/esmodule-helpers.js":"qpMMf"}],cZn0e:[function(e,t,n,r){"use strict";function o(e,t,n,r,o,a,c){try{var i=e[a](c),s=i.value}catch(e){n(e);return}i.done?t(s):Promise.resolve(s).then(r,o)}n._=function(e){return function(){var t=this,n=arguments;return new Promise(function(r,a){var c=e.apply(t,n);function i(e){o(c,r,a,i,s,"next",e)}function s(e){o(c,r,a,i,s,"throw",e)}i(void 0)})}}},{}],eltGh:[function(e,t,n,r){"use strict";n._=function(e,t){var n,r,o,a={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]},c=Object.create(("function"==typeof Iterator?Iterator:Object).prototype),i=Object.defineProperty;return i(c,"next",{value:s(0)}),i(c,"throw",{value:s(1)}),i(c,"return",{value:s(2)}),"function"==typeof Symbol&&i(c,Symbol.iterator,{value:function(){return this}}),c;function s(i){return function(s){var l=[i,s];if(n)throw TypeError("Generator is already executing.");for(;c&&(c=0,l[0]&&(a=0)),a;)try{if(n=1,r&&(o=2&l[0]?r.return:l[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,l[1])).done)return o;switch(r=0,o&&(l=[2&l[0],o.value]),l[0]){case 0:case 1:o=l;break;case 4:return a.label++,{value:l[1],done:!1};case 5:a.label++,r=l[1],l=[0];continue;case 7:l=a.ops.pop(),a.trys.pop();continue;default:if(!(o=(o=a.trys).length>0&&o[o.length-1])&&(6===l[0]||2===l[0])){a=0;continue}if(3===l[0]&&(!o||l[1]>o[0]&&l[1]<o[3])){a.label=l[1];break}if(6===l[0]&&a.label<o[1]){a.label=o[1],o=l;break}if(o&&a.label<o[2]){a.label=o[2],a.ops.push(l);break}o[2]&&a.ops.pop(),a.trys.pop();continue}l=t.call(e,a)}catch(e){l=[6,e],r=0}finally{n=o=0}if(5&l[0])throw l[1];return{value:l[0]?l[1]:void 0,done:!0}}}}},{}],qpMMf:[function(e,t,n,r){n.interopDefault=function(e){return e&&e.__esModule?e:{default:e}},n.defineInteropFlag=function(e){Object.defineProperty(e,"__esModule",{value:!0})},n.exportAll=function(e,t){return Object.keys(e).forEach(function(n){"default"===n||"__esModule"===n||Object.prototype.hasOwnProperty.call(t,n)||Object.defineProperty(t,n,{enumerable:!0,get:function(){return e[n]}})}),t},n.export=function(e,t,n){Object.defineProperty(e,t,{enumerable:!0,get:n})}},{}]},["1xnGs"],"1xnGs","parcelRequire4dc0",{}); |