@mux/playback-core
Advanced tools
Comparing version 0.8.1-canary.1-4980706 to 0.8.1-canary.10-030fdc6
@@ -1,2 +0,2 @@ | ||
var ae=Object.create;var k=Object.defineProperty;var se=Object.getOwnPropertyDescriptor;var ie=Object.getOwnPropertyNames;var ue=Object.getPrototypeOf,ce=Object.prototype.hasOwnProperty;var U=e=>k(e,"__esModule",{value:!0});var le=(e,t)=>{U(e);for(var r in t)k(e,r,{get:t[r],enumerable:!0})},pe=(e,t,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let n of ie(t))!ce.call(e,n)&&n!=="default"&&k(e,n,{get:()=>t[n],enumerable:!(r=se(t,n))||r.enumerable});return e},P=e=>pe(U(k(e!=null?ae(ue(e)):{},"default",e&&e.__esModule&&"default"in e?{get:()=>e.default,enumerable:!0}:{value:e,enumerable:!0})),e);var K=(e,t,r)=>{if(!t.has(e))throw TypeError("Cannot "+r)};var B=(e,t,r)=>(K(e,t,"read from private field"),r?r.call(e):t.get(e)),F=(e,t,r)=>{if(t.has(e))throw TypeError("Cannot add the same private member more than once");t instanceof WeakSet?t.add(e):t.set(e,r)},$=(e,t,r,n)=>(K(e,t,"write to private field"),n?n.call(e,r):t.set(e,r),r);le(exports,{ExtensionMimeTypeMap:()=>g,Hls:()=>T.default,MediaError:()=>c,MimeTypeShorthandMap:()=>R,StreamTypes:()=>b,allMediaTypes:()=>me,generatePlayerInitTime:()=>fe,getError:()=>ge,getStreamTypeConfig:()=>Z,getType:()=>V,inferMimeTypeFromURL:()=>Q,initialize:()=>Ee,isMuxVideoSrc:()=>te,loadMedia:()=>ne,mux:()=>D.default,setupAutoplay:()=>W,setupHls:()=>ee,setupMux:()=>re,shorthandKeys:()=>Te,teardown:()=>j,toMuxVideoURL:()=>Me,toPlaybackIdParts:()=>J});if(typeof DocumentFragment=="undefined"){class e{}globalThis.DocumentFragment=e}globalThis.customElements||(globalThis.customElements={get(e){},define(e,t,r){},upgrade(e){},whenDefined(e){return Promise.resolve(globalThis.HTMLElement)}});var h;if(!globalThis.CustomEvent){class e{constructor(r,n={}){F(this,h,void 0);$(this,h,n==null?void 0:n.detail)}get detail(){B(this,h)}initCustomEvent(r,n,o,a){}}h=new WeakMap,globalThis.CustomEvent=e}if(!globalThis.EventTarget){class e{addEventListener(){}removeEventListener(){}dispatchEvent(r){return!0}}globalThis.EventTarget=e}if(!globalThis.HTMLElement){class e extends EventTarget{}globalThis.HTMLElement=e}if(!globalThis.HTMLVideoElement){class e extends EventTarget{}globalThis.HTMLVideoElement=e}var Y,q;if(!((Y=globalThis.document)==null?void 0:Y.createElement)){let e=(q=globalThis.document)!=null?q:{};e.createElement=function(r,n){return new HTMLElement},globalThis.document=e}var D=P(require("mux-embed")),T=P(require("hls.js"));var w=P(require("hls.js")),I={ANY:"any",MUTED:"muted"},de=Object.values(I),z=e=>typeof e=="boolean"||typeof e=="string"&&de.includes(e),W=(e,t,r)=>{let n=!1,o=!1,a=z(t)?t:!!t,i=()=>{e.addEventListener("playing",()=>{n=!0},{once:!0})};if(i(),e.addEventListener("loadstart",()=>{n=!1,i(),C(e,a)},{once:!0}),e.addEventListener("loadedmetadata",()=>{r||(o=!Number.isFinite(e.duration)),C(e,a)},{once:!0}),r&&r.once(w.default.Events.LEVEL_LOADED,(u,l)=>{var p;o=(p=l.details.live)!=null?p:!1}),!a){let u=()=>{!o||((r==null?void 0:r.liveSyncPosition)?e.currentTime=r.liveSyncPosition:Number.isFinite(e.seekable.end(0))&&(e.currentTime=e.seekable.end(0)))};e.addEventListener("play",()=>{r&&e.preload==="metadata"?r.once(w.default.Events.LEVEL_UPDATED,u):r&&u()},{once:!0})}return u=>{n||(a=z(u)?u:!!u,C(e,a))}},C=(e,t)=>{if(!t)return;let r=e.muted,n=()=>e.muted=r;switch(t){case I.ANY:e.play().catch(o=>{e.muted=!0,e.play().catch(n)});break;case I.MUTED:e.muted=!0,e.play().catch(n);break;default:e.play().catch(()=>{});break}};var E=class extends Error{constructor(t,r=E.MEDIA_ERR_CUSTOM,n){super(t);var o;this.name="MediaError",this.code=r,this.fatal=n!=null?n:r>=E.MEDIA_ERR_NETWORK&&r<=E.MEDIA_ERR_ENCRYPTED,this.message||(this.message=(o=E.defaultMessages[this.code])!=null?o:"")}},c=E;c.MEDIA_ERR_ABORTED=1,c.MEDIA_ERR_NETWORK=2,c.MEDIA_ERR_DECODE=3,c.MEDIA_ERR_SRC_NOT_SUPPORTED=4,c.MEDIA_ERR_ENCRYPTED=5,c.MEDIA_ERR_CUSTOM=100,c.defaultMessages={1:"You aborted the media playback",2:"A network error caused the media download to fail.",3:"A media error caused playback to be aborted. The media could be corrupt or your browser does not support this format.",4:"An unsupported error occurred. The server or network failed, or your browser does not support this format.",5:"The media is encrypted and there are no keys to decrypt it."};var x=P(require("hls.js"));function X(e,t){t.on(x.default.Events.NON_NATIVE_TEXT_TRACKS_FOUND,(o,{tracks:a})=>{a.forEach(i=>{var l;let s=(l=i.subtitleTrack)!=null?l:i.closedCaptions,u=t.subtitleTracks.findIndex(({lang:p,name:y,type:f})=>p==(s==null?void 0:s.lang)&&y===i.label&&f.toLowerCase()===i.kind);ye(e,i.kind,i.label,s==null?void 0:s.lang,`${i.kind}${u}`)})});let r=()=>{var i;if(!t.subtitleTracks.length)return;let o=Array.from(e.textTracks).find(s=>s.id&&s.mode==="showing"&&["subtitles","captions"].includes(s.kind)),a=`${(i=t.subtitleTracks[t.subtitleTrack])==null?void 0:i.type.toLowerCase()}${t.subtitleTrack}`;if(o&&(t.subtitleTrack<0||(o==null?void 0:o.id)!==a)){let s=t.subtitleTracks.findIndex(({lang:u,name:l,type:p})=>u==o.language&&l===o.label&&p.toLowerCase()===o.kind);t.subtitleTrack=s}o&&(o==null?void 0:o.id)===a&&o.cues&&Array.from(o.cues).forEach(s=>{o.addCue(s)})};e.textTracks.addEventListener("change",r),t.on(x.default.Events.CUES_PARSED,(o,{track:a,type:i,cues:s})=>{let u=e.textTracks.getTrackById(a);if(!u)return;let l=u.mode==="disabled";l&&(u.mode="hidden"),s.forEach(p=>{var y;((y=u.cues)==null?void 0:y.getCueById(p.id))||u.addCue(p)}),l&&(u.mode="disabled")}),t.on(x.default.Events.DESTROYING,()=>{e.textTracks.removeEventListener("change",r),e.querySelectorAll("track").forEach(a=>{!(a.id&&["subtitles","captions"].includes(a.kind))||!t.subtitleTracks.some(({type:i},s)=>a.id===`${i.toLowerCase()}${s}`)||e.removeChild(a)})});let n=()=>{Array.from(e.textTracks).forEach(o=>{var a,i;if(!["subtitles","caption"].includes(o.kind)&&o.label==="thumbnails"){if(!((a=o.cues)==null?void 0:a.length)){let s=e.querySelector('track[label="thumbnails"]'),u=(i=s==null?void 0:s.getAttribute("src"))!=null?i:"";s==null||s.removeAttribute("src"),setTimeout(()=>{s==null||s.setAttribute("src",u)},0)}o.mode!=="hidden"&&(o.mode="hidden")}})};t.once(x.default.Events.MANIFEST_LOADED,n),t.once(x.default.Events.MEDIA_ATTACHED,n)}function ye(e,t,r,n,o){let a=document.createElement("track");return a.kind=t,a.label=r,n&&(a.srclang=n),o&&(a.id=o),a.track.mode="disabled",e.appendChild(a),a.track}var O=(e,t)=>e in t;var G="mux.com",fe=()=>D.default.utils.now(),b={VOD:"on-demand",ON_DEMAND:"on-demand",LIVE:"live",LL_LIVE:"ll-live",DVR:"live:dvr",LL_DVR:"ll-live:dvr"},g={M3U8:"application/vnd.apple.mpegurl",MP4:"video/mp4"},R={HLS:g.M3U8},Te=Object.keys(R),me=[...Object.values(g),"hls","HLS"],J=e=>{let t=e.indexOf("?");if(t<0)return[e];let r=e.slice(0,t),n=e.slice(t);return[r,n]},Me=(e,{domain:t=G}={})=>{if(!e)return;let[r,n=""]=J(e);return`https://stream.${t}/${r}.m3u8${n}`},Q=e=>{let t="";try{t=new URL(e).pathname}catch{console.error("invalid url")}let r=t.lastIndexOf(".");if(r<0)return"";let o=t.slice(r+1).toUpperCase();return O(o,g)?g[o]:""},V=e=>{let t=e.type;if(t){let n=t.toUpperCase();return O(n,R)?R[n]:t}let{src:r}=e;return r?Q(r):""},Z=e=>{if([b.LIVE,b.LL_LIVE].includes(e)){let t={backBufferLength:12};return e===b.LL_LIVE?{...t,maxFragLookUpTolerance:.001}:t}return{}},S=new WeakMap,ge=e=>{var t;return(t=S.get(e))==null?void 0:t.error},j=(e,t)=>{t&&(t.detachMedia(),t.destroy()),(e==null?void 0:e.mux)&&!e.mux.deleted&&(e.mux.destroy(),e.mux),e&&(e.removeEventListener("error",oe),e.removeEventListener("error",N),S.delete(e))},ee=(e,t)=>{var L,v,_;let{debug:r,preferMse:n,streamType:o,startTime:a=-1}=e,i=V(e),s=i===g.M3U8,u=!i||((L=t==null?void 0:t.canPlayType(i))!=null?L:!0),l=T.default.isSupported(),f=((_=(v=window==null?void 0:window.navigator)==null?void 0:v.userAgent)!=null?_:"").toLowerCase().indexOf("android")!==-1&&o===b.LL_LIVE;if(s&&!(!s||u&&!((n||f)&&l))&&l){let M={backBufferLength:30,renderTextTracksNatively:!1,liveDurationInfinity:!0},d=Z(o);return new T.default({debug:r,startPosition:a,...M,...d})}},te=({playbackId:e,src:t,customDomain:r})=>{if(e)return!0;if(typeof t!="string")return!1;let n=new URL(t).hostname.toLocaleLowerCase();return n.includes(G)||!!r&&n.includes(r.toLocaleLowerCase())},re=(e,t,r)=>{let{envKey:n}=e,o=te(e);if((n||o)&&t){let{playerInitTime:a,playerSoftwareName:i,playerSoftwareVersion:s,beaconCollectionDomain:u,metadata:l,debug:p}=e,y=f=>typeof f.player_error_code=="string"?!1:typeof e.errorTranslator=="function"?e.errorTranslator(f):f;D.default.monitor(t,{debug:p,beaconCollectionDomain:u,hlsjs:r,Hls:r?T.default:void 0,automaticErrorTracking:!1,errorTranslator:y,data:{...n?{env_key:n}:{},player_software_name:i,player_software_version:s,player_init_time:a,...l}})}},ne=(e,t,r)=>{var L,v,_;if(!t){console.warn("attempting to load media before mediaEl exists");return}let{preferMse:n,streamType:o}=e,a=V(e),i=a===g.M3U8,s=!a||((L=t==null?void 0:t.canPlayType(a))!=null?L:!0),u=T.default.isSupported(),y=((_=(v=window==null?void 0:window.navigator)==null?void 0:v.userAgent)!=null?_:"").toLowerCase().indexOf("android")!==-1&&o===b.LL_LIVE,f=!i||s&&!((n||y)&&u),{src:m}=e;if(t&&s&&f){if(typeof m=="string"){let{startTime:M}=e;if(t.setAttribute("src",m),M){let d=({target:A})=>{A.currentTime=M,A.removeEventListener("loadedmetadata",d)};t.addEventListener("loadedmetadata",d)}}else t.removeAttribute("src");t.addEventListener("error",oe),t.addEventListener("error",N)}else if(r&&m){switch(r.on(T.default.Events.ERROR,(M,d)=>{let A={[T.default.ErrorTypes.NETWORK_ERROR]:c.MEDIA_ERR_NETWORK,[T.default.ErrorTypes.MEDIA_ERROR]:c.MEDIA_ERR_DECODE},H=new c("",A[d.type]);H.fatal=d.fatal,H.data=d,t.dispatchEvent(new CustomEvent("error",{detail:H}))}),t.addEventListener("error",N),X(t,r),t.preload){case"none":t.addEventListener("play",()=>r.loadSource(m),{once:!0});break;case"metadata":let M=r.config.maxBufferLength,d=r.config.maxBufferSize;r.config.maxBufferLength=1,r.config.maxBufferSize=1,t.addEventListener("play",()=>{r.config.maxBufferLength=M,r.config.maxBufferSize=d},{once:!0}),r.loadSource(m);break;default:r.loadSource(m)}r.attachMedia(t)}else console.error("It looks like the video you're trying to play will not work on this system! If possible, try upgrading to the newest versions of your browser or software.")};async function oe(e){if(!e.isTrusted)return;e.stopImmediatePropagation();let t=e.target;if(!(t==null?void 0:t.error))return;let{message:r,code:n}=t.error,o=new c(r,n);if(t.src&&(n!==c.MEDIA_ERR_DECODE||n!==void 0)){let{status:a}=await fetch(t.src);o.data={response:{code:a}}}t.dispatchEvent(new CustomEvent("error",{detail:o}))}function N(e){var o;if(!(e instanceof CustomEvent)||!(e.detail instanceof c))return;let t=e.target,r=e.detail;if(!r||!r.fatal)return;let n=S.get(t);n&&(n.error=r),(o=t.mux)==null||o.emit("error",{player_error_code:r.code,player_error_message:r.message})}var Ee=(e,t,r)=>{j(t,r),S.set(t,{});let n=ee(e,t);return re(e,t,n),ne(e,t,n),n}; | ||
var ie=Object.create;var h=Object.defineProperty;var ce=Object.getOwnPropertyDescriptor;var ue=Object.getOwnPropertyNames;var le=Object.getPrototypeOf,de=Object.prototype.hasOwnProperty;var K=e=>h(e,"__esModule",{value:!0});var pe=(e,t)=>{K(e);for(var r in t)h(e,r,{get:t[r],enumerable:!0})},ye=(e,t,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let n of ue(t))!de.call(e,n)&&n!=="default"&&h(e,n,{get:()=>t[n],enumerable:!(r=ce(t,n))||r.enumerable});return e},P=e=>ye(K(h(e!=null?ie(le(e)):{},"default",e&&e.__esModule&&"default"in e?{get:()=>e.default,enumerable:!0}:{value:e,enumerable:!0})),e);var B=(e,t,r)=>{if(!t.has(e))throw TypeError("Cannot "+r)};var F=(e,t,r)=>(B(e,t,"read from private field"),r?r.call(e):t.get(e)),q=(e,t,r)=>{if(t.has(e))throw TypeError("Cannot add the same private member more than once");t instanceof WeakSet?t.add(e):t.set(e,r)},Y=(e,t,r,n)=>(B(e,t,"write to private field"),n?n.call(e,r):t.set(e,r),r);pe(exports,{ExtensionMimeTypeMap:()=>g,Hls:()=>T.default,MediaError:()=>u,MimeTypeShorthandMap:()=>R,StreamTypes:()=>L,addTextTrack:()=>C,allMediaTypes:()=>Me,generatePlayerInitTime:()=>Te,getError:()=>Ee,getStreamTypeConfig:()=>ee,getType:()=>N,inferMimeTypeFromURL:()=>j,initialize:()=>xe,isMuxVideoSrc:()=>ne,loadMedia:()=>ae,mux:()=>D.default,removeTextTrack:()=>J,setupAutoplay:()=>X,setupHls:()=>re,setupMux:()=>oe,shorthandKeys:()=>me,teardown:()=>te,toMuxVideoURL:()=>ge,toPlaybackIdParts:()=>Z});if(typeof DocumentFragment=="undefined"){class e{}globalThis.DocumentFragment=e}globalThis.customElements||(globalThis.customElements={get(e){},define(e,t,r){},upgrade(e){},whenDefined(e){return Promise.resolve(globalThis.HTMLElement)}});var k;if(!globalThis.CustomEvent){class e{constructor(r,n={}){q(this,k,void 0);Y(this,k,n==null?void 0:n.detail)}get detail(){F(this,k)}initCustomEvent(r,n,o,a){}}k=new WeakMap,globalThis.CustomEvent=e}if(!globalThis.EventTarget){class e{addEventListener(){}removeEventListener(){}dispatchEvent(r){return!0}}globalThis.EventTarget=e}if(!globalThis.HTMLElement){class e extends EventTarget{}globalThis.HTMLElement=e}if(!globalThis.HTMLVideoElement){class e extends EventTarget{}globalThis.HTMLVideoElement=e}var $,z;if(!(($=globalThis.document)==null?void 0:$.createElement)){let e=(z=globalThis.document)!=null?z:{};e.createElement=function(r,n){return new HTMLElement},globalThis.document=e}var D=P(require("mux-embed")),T=P(require("hls.js"));var w=P(require("hls.js")),I={ANY:"any",MUTED:"muted"},fe=Object.values(I),W=e=>typeof e=="boolean"||typeof e=="string"&&fe.includes(e),X=(e,t,r)=>{let n=!1,o=!1,a=W(t)?t:!!t,c=()=>{e.addEventListener("playing",()=>{n=!0},{once:!0})};if(c(),e.addEventListener("loadstart",()=>{n=!1,c(),O(e,a)},{once:!0}),e.addEventListener("loadedmetadata",()=>{r||(o=!Number.isFinite(e.duration)),O(e,a)},{once:!0}),r&&r.once(w.default.Events.LEVEL_LOADED,(i,l)=>{var d;o=(d=l.details.live)!=null?d:!1}),!a){let i=()=>{!o||((r==null?void 0:r.liveSyncPosition)?e.currentTime=r.liveSyncPosition:Number.isFinite(e.seekable.end(0))&&(e.currentTime=e.seekable.end(0)))};e.addEventListener("play",()=>{r&&e.preload==="metadata"?r.once(w.default.Events.LEVEL_UPDATED,i):r&&i()},{once:!0})}return i=>{n||(a=W(i)?i:!!i,O(e,a))}},O=(e,t)=>{if(!t)return;let r=e.muted,n=()=>e.muted=r;switch(t){case I.ANY:e.play().catch(o=>{e.muted=!0,e.play().catch(n)});break;case I.MUTED:e.muted=!0,e.play().catch(n);break;default:e.play().catch(()=>{});break}};var E=class extends Error{constructor(t,r=E.MEDIA_ERR_CUSTOM,n){super(t);var o;this.name="MediaError",this.code=r,this.fatal=n!=null?n:r>=E.MEDIA_ERR_NETWORK&&r<=E.MEDIA_ERR_ENCRYPTED,this.message||(this.message=(o=E.defaultMessages[this.code])!=null?o:"")}},u=E;u.MEDIA_ERR_ABORTED=1,u.MEDIA_ERR_NETWORK=2,u.MEDIA_ERR_DECODE=3,u.MEDIA_ERR_SRC_NOT_SUPPORTED=4,u.MEDIA_ERR_ENCRYPTED=5,u.MEDIA_ERR_CUSTOM=100,u.defaultMessages={1:"You aborted the media playback",2:"A network error caused the media download to fail.",3:"A media error caused playback to be aborted. The media could be corrupt or your browser does not support this format.",4:"An unsupported error occurred. The server or network failed, or your browser does not support this format.",5:"The media is encrypted and there are no keys to decrypt it."};var x=P(require("hls.js"));function G(e,t){t.on(x.default.Events.NON_NATIVE_TEXT_TRACKS_FOUND,(o,{tracks:a})=>{a.forEach(c=>{var l;let s=(l=c.subtitleTrack)!=null?l:c.closedCaptions,i=t.subtitleTracks.findIndex(({lang:d,name:y,type:f})=>d==(s==null?void 0:s.lang)&&y===c.label&&f.toLowerCase()===c.kind);C(e,c.kind,c.label,s==null?void 0:s.lang,`${c.kind}${i}`)})});let r=()=>{var c;if(!t.subtitleTracks.length)return;let o=Array.from(e.textTracks).find(s=>s.id&&s.mode==="showing"&&["subtitles","captions"].includes(s.kind)),a=`${(c=t.subtitleTracks[t.subtitleTrack])==null?void 0:c.type.toLowerCase()}${t.subtitleTrack}`;if(o&&(t.subtitleTrack<0||(o==null?void 0:o.id)!==a)){let s=t.subtitleTracks.findIndex(({lang:i,name:l,type:d})=>i==o.language&&l===o.label&&d.toLowerCase()===o.kind);t.subtitleTrack=s}o&&(o==null?void 0:o.id)===a&&o.cues&&Array.from(o.cues).forEach(s=>{o.addCue(s)})};e.textTracks.addEventListener("change",r),t.on(x.default.Events.CUES_PARSED,(o,{track:a,type:c,cues:s})=>{let i=e.textTracks.getTrackById(a);if(!i)return;let l=i.mode==="disabled";l&&(i.mode="hidden"),s.forEach(d=>{var y;((y=i.cues)==null?void 0:y.getCueById(d.id))||i.addCue(d)}),l&&(i.mode="disabled")}),t.on(x.default.Events.DESTROYING,()=>{e.textTracks.removeEventListener("change",r),e.querySelectorAll("track[data-removeondestroy]").forEach(a=>{a.remove()})});let n=()=>{Array.from(e.textTracks).forEach(o=>{var a,c;if(!["subtitles","caption"].includes(o.kind)&&o.label==="thumbnails"){if(!((a=o.cues)==null?void 0:a.length)){let s=e.querySelector('track[label="thumbnails"]'),i=(c=s==null?void 0:s.getAttribute("src"))!=null?c:"";s==null||s.removeAttribute("src"),setTimeout(()=>{s==null||s.setAttribute("src",i)},0)}o.mode!=="hidden"&&(o.mode="hidden")}})};t.once(x.default.Events.MANIFEST_LOADED,n),t.once(x.default.Events.MEDIA_ATTACHED,n)}function C(e,t,r,n,o){let a=document.createElement("track");return a.kind=t,a.label=r,n&&(a.srclang=n),o&&(a.id=o),a.track.mode="disabled",a.setAttribute("data-removeondestroy",""),e.append(a),a.track}function J(e,t){let r=Array.prototype.find.call(e.querySelectorAll("track"),n=>n.track===t);r==null||r.remove()}var V=(e,t)=>e in t;var Q="mux.com",Te=()=>D.default.utils.now(),L={VOD:"on-demand",ON_DEMAND:"on-demand",LIVE:"live",LL_LIVE:"ll-live",DVR:"live:dvr",LL_DVR:"ll-live:dvr"},g={M3U8:"application/vnd.apple.mpegurl",MP4:"video/mp4"},R={HLS:g.M3U8},me=Object.keys(R),Me=[...Object.values(g),"hls","HLS"],Z=e=>{let t=e.indexOf("?");if(t<0)return[e];let r=e.slice(0,t),n=e.slice(t);return[r,n]},ge=(e,{domain:t=Q}={})=>{if(!e)return;let[r,n=""]=Z(e);return`https://stream.${t}/${r}.m3u8${n}`},j=e=>{let t="";try{t=new URL(e).pathname}catch{console.error("invalid url")}let r=t.lastIndexOf(".");if(r<0)return"";let o=t.slice(r+1).toUpperCase();return V(o,g)?g[o]:""},N=e=>{let t=e.type;if(t){let n=t.toUpperCase();return V(n,R)?R[n]:t}let{src:r}=e;return r?j(r):""},ee=e=>{if([L.LIVE,L.LL_LIVE].includes(e)){let t={backBufferLength:12};return e===L.LL_LIVE?{...t,maxFragLookUpTolerance:.001}:t}return{}},H=new WeakMap,Ee=e=>{var t;return(t=H.get(e))==null?void 0:t.error},te=(e,t)=>{t&&(t.detachMedia(),t.destroy()),(e==null?void 0:e.mux)&&!e.mux.deleted&&(e.mux.destroy(),e.mux),e&&(e.removeEventListener("error",se),e.removeEventListener("error",U),H.delete(e))},re=(e,t)=>{var b,v,A;let{debug:r,preferMse:n,streamType:o,startTime:a=-1}=e,c=N(e),s=c===g.M3U8,i=!c||((b=t==null?void 0:t.canPlayType(c))!=null?b:!0),l=T.default.isSupported(),f=((A=(v=window==null?void 0:window.navigator)==null?void 0:v.userAgent)!=null?A:"").toLowerCase().indexOf("android")!==-1&&o===L.LL_LIVE;if(s&&!(!s||i&&!((n||f)&&l))&&l){let M={backBufferLength:30,renderTextTracksNatively:!1,liveDurationInfinity:!0},p=ee(o);return new T.default({debug:r,startPosition:a,...M,...p})}},ne=({playbackId:e,src:t,customDomain:r})=>{if(e)return!0;if(typeof t!="string")return!1;let n=new URL(t).hostname.toLocaleLowerCase();return n.includes(Q)||!!r&&n.includes(r.toLocaleLowerCase())},oe=(e,t,r)=>{let{envKey:n}=e,o=ne(e);if((n||o)&&t){let{playerInitTime:a,playerSoftwareName:c,playerSoftwareVersion:s,beaconCollectionDomain:i,metadata:l,debug:d}=e,y=f=>typeof f.player_error_code=="string"?!1:typeof e.errorTranslator=="function"?e.errorTranslator(f):f;D.default.monitor(t,{debug:d,beaconCollectionDomain:i,hlsjs:r,Hls:r?T.default:void 0,automaticErrorTracking:!1,errorTranslator:y,data:{...n?{env_key:n}:{},player_software_name:c,player_software_version:s,player_init_time:a,...l}})}},ae=(e,t,r)=>{var b,v,A;if(!t){console.warn("attempting to load media before mediaEl exists");return}let{preferMse:n,streamType:o}=e,a=N(e),c=a===g.M3U8,s=!a||((b=t==null?void 0:t.canPlayType(a))!=null?b:!0),i=T.default.isSupported(),y=((A=(v=window==null?void 0:window.navigator)==null?void 0:v.userAgent)!=null?A:"").toLowerCase().indexOf("android")!==-1&&o===L.LL_LIVE,f=!c||s&&!((n||y)&&i),{src:m}=e;if(t&&s&&f){if(typeof m=="string"){let{startTime:M}=e;if(t.setAttribute("src",m),M){let p=({target:_})=>{_.currentTime=M,_.removeEventListener("loadedmetadata",p)};t.addEventListener("loadedmetadata",p)}}else t.removeAttribute("src");t.addEventListener("error",se),t.addEventListener("error",U)}else if(r&&m){switch(r.on(T.default.Events.ERROR,(M,p)=>{let _={[T.default.ErrorTypes.NETWORK_ERROR]:u.MEDIA_ERR_NETWORK,[T.default.ErrorTypes.MEDIA_ERROR]:u.MEDIA_ERR_DECODE},S=new u("",_[p.type]);S.fatal=p.fatal,S.data=p,t.dispatchEvent(new CustomEvent("error",{detail:S}))}),t.addEventListener("error",U),G(t,r),t.preload){case"none":t.addEventListener("play",()=>r.loadSource(m),{once:!0});break;case"metadata":let M=r.config.maxBufferLength,p=r.config.maxBufferSize;r.config.maxBufferLength=1,r.config.maxBufferSize=1,t.addEventListener("play",()=>{r.config.maxBufferLength=M,r.config.maxBufferSize=p},{once:!0}),r.loadSource(m);break;default:r.loadSource(m)}r.attachMedia(t)}else console.error("It looks like the video you're trying to play will not work on this system! If possible, try upgrading to the newest versions of your browser or software.")};async function se(e){if(!e.isTrusted)return;e.stopImmediatePropagation();let t=e.target;if(!(t==null?void 0:t.error))return;let{message:r,code:n}=t.error,o=new u(r,n);if(t.src&&(n!==u.MEDIA_ERR_DECODE||n!==void 0)){let{status:a}=await fetch(t.src);o.data={response:{code:a}}}t.dispatchEvent(new CustomEvent("error",{detail:o}))}function U(e){var o;if(!(e instanceof CustomEvent)||!(e.detail instanceof u))return;let t=e.target,r=e.detail;if(!r||!r.fatal)return;let n=H.get(t);n&&(n.error=r),(o=t.mux)==null||o.emit("error",{player_error_code:r.code,player_error_message:r.message})}var xe=(e,t,r)=>{te(t,r),H.set(t,{});let n=re(e,t);return oe(e,t,n),ae(e,t,n),n}; | ||
//# sourceMappingURL=index.cjs.js.map |
@@ -6,2 +6,3 @@ import '@mux/polyfills'; | ||
import { MediaError } from './errors'; | ||
import { addTextTrack, removeTextTrack } from './tracks'; | ||
import { Autoplay, UpdateAutoplay } from './autoplay'; | ||
@@ -11,3 +12,3 @@ export declare type ValueOf<T> = T[keyof T]; | ||
export declare type PlaybackEngine = Hls; | ||
export { mux, Hls, MediaError, Autoplay, UpdateAutoplay, setupAutoplay }; | ||
export { mux, Hls, MediaError, Autoplay, UpdateAutoplay, setupAutoplay, addTextTrack, removeTextTrack }; | ||
export declare const generatePlayerInitTime: () => any; | ||
@@ -14,0 +15,0 @@ export declare type StreamTypes = { |
import Hls from 'hls.js'; | ||
export declare function setupTracks(mediaEl: HTMLMediaElement, hls: Pick<Hls, 'on' | 'once' | 'subtitleTracks' | 'subtitleTrack'>): void; | ||
export declare function addTextTrack(mediaEl: HTMLMediaElement, kind: TextTrackKind, label: string, lang?: string, id?: string): TextTrack | undefined; | ||
export declare function removeTextTrack(mediaEl: HTMLMediaElement, track: TextTrack): void; |
@@ -6,2 +6,3 @@ import '@mux/polyfills'; | ||
import { MediaError } from './errors'; | ||
import { addTextTrack, removeTextTrack } from './tracks'; | ||
import type { Autoplay, UpdateAutoplay } from './autoplay'; | ||
@@ -11,3 +12,3 @@ export declare type ValueOf<T> = T[keyof T]; | ||
export declare type PlaybackEngine = Hls; | ||
export { mux, Hls, MediaError, Autoplay, UpdateAutoplay, setupAutoplay }; | ||
export { mux, Hls, MediaError, Autoplay, UpdateAutoplay, setupAutoplay, addTextTrack, removeTextTrack }; | ||
export declare const generatePlayerInitTime: () => any; | ||
@@ -14,0 +15,0 @@ export declare type StreamTypes = { |
import Hls from 'hls.js'; | ||
export declare function setupTracks(mediaEl: HTMLMediaElement, hls: Pick<Hls, 'on' | 'once' | 'subtitleTracks' | 'subtitleTrack'>): void; | ||
export declare function addTextTrack(mediaEl: HTMLMediaElement, kind: TextTrackKind, label: string, lang?: string, id?: string): TextTrack | undefined; | ||
export declare function removeTextTrack(mediaEl: HTMLMediaElement, track: TextTrack): void; |
{ | ||
"name": "@mux/playback-core", | ||
"version": "0.8.1-canary.1-4980706", | ||
"version": "0.8.1-canary.10-030fdc6", | ||
"description": "Core library for media playback in the browser shared by mux elements", | ||
@@ -5,0 +5,0 @@ "main": "./dist/index.cjs.js", |
@@ -7,3 +7,3 @@ import '@mux/polyfills'; | ||
import { MediaError } from './errors'; | ||
import { setupTracks } from './tracks'; | ||
import { setupTracks, addTextTrack, removeTextTrack } from './tracks'; | ||
import { isKeyOf } from './util'; | ||
@@ -15,3 +15,3 @@ import type { Autoplay, UpdateAutoplay } from './autoplay'; | ||
export type PlaybackEngine = Hls; | ||
export { mux, Hls, MediaError, Autoplay, UpdateAutoplay, setupAutoplay }; | ||
export { mux, Hls, MediaError, Autoplay, UpdateAutoplay, setupAutoplay, addTextTrack, removeTextTrack }; | ||
@@ -18,0 +18,0 @@ const MUX_VIDEO_DOMAIN = 'mux.com'; |
import Hls from 'hls.js'; | ||
import type { MediaPlaylist } from 'hls.js'; | ||
@@ -15,3 +14,3 @@ export function setupTracks( | ||
createTextTrack( | ||
addTextTrack( | ||
mediaEl, | ||
@@ -77,8 +76,6 @@ trackObj.kind as TextTrackKind, | ||
const trackEls = mediaEl.querySelectorAll('track'); | ||
// Use data attribute to identify tracks that should be removed when switching sources/destroying hls.js instance. | ||
const trackEls: NodeListOf<HTMLTrackElement> = mediaEl.querySelectorAll('track[data-removeondestroy]'); | ||
trackEls.forEach((trackEl) => { | ||
if (!(trackEl.id && ['subtitles', 'captions'].includes(trackEl.kind))) return; | ||
if (!hls.subtitleTracks.some(({ type }, idx) => trackEl.id === `${type.toLowerCase()}${idx}`)) return; | ||
mediaEl.removeChild(trackEl); | ||
trackEl.remove(); | ||
}); | ||
@@ -114,3 +111,3 @@ }); | ||
function createTextTrack( | ||
export function addTextTrack( | ||
mediaEl: HTMLMediaElement, | ||
@@ -133,4 +130,14 @@ kind: TextTrackKind, | ||
trackEl.track.mode = 'disabled'; | ||
mediaEl.appendChild(trackEl); | ||
// Add data attribute to identify tracks that should be removed when switching sources/destroying hls.js instance. | ||
trackEl.setAttribute('data-removeondestroy', ''); | ||
mediaEl.append(trackEl); | ||
return trackEl.track; | ||
} | ||
export function removeTextTrack(mediaEl: HTMLMediaElement, track: TextTrack) { | ||
const trackEl: HTMLTrackElement | undefined = Array.prototype.find.call( | ||
mediaEl.querySelectorAll('track'), | ||
(trackEl: HTMLTrackElement) => trackEl.track === track | ||
); | ||
trackEl?.remove(); | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
4102344
4731
28
3