Vulture/VApp/node_modules/@videojs/http-streaming/dist/videojs-http-streaming.min.js

6 lines
365 KiB
JavaScript
Raw Normal View History

/*! @name @videojs/http-streaming @version 3.17.0 @license Apache-2.0 */
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("video.js"),require("@xmldom/xmldom")):"function"==typeof define&&define.amd?define(["exports","video.js","@xmldom/xmldom"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).httpStreaming={},e.videojs,e.window)}(this,(function(e,t,i){"use strict";function n(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var s=n(t);function a(){return a=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var i=arguments[t];for(var n in i)Object.prototype.hasOwnProperty.call(i,n)&&(e[n]=i[n])}return e},a.apply(this,arguments)}var r="https://example.com",o=function(e,t){if(/^[a-z]+:/i.test(t))return t;/^data:/.test(e)&&(e=window.location&&window.location.href||"");var i=/^\/\//.test(e),n=!window.location&&!/\/\//i.test(e);e=new window.URL(e,window.location||r);var s=new URL(t,e);return n?s.href.slice(r.length):i?s.href.slice(s.protocol.length):s.href};const d=o,u=(e,t)=>t&&t.responseURL&&e!==t.responseURL?t.responseURL:e,l=e=>s.default.log.debug?s.default.log.debug.bind(s.default,"VHS:",`${e} >`):function(){};var h=function(){function e(){this.listeners={}}var t=e.prototype;return t.on=function(e,t){this.listeners[e]||(this.listeners[e]=[]),this.listeners[e].push(t)},t.off=function(e,t){if(!this.listeners[e])return!1;var i=this.listeners[e].indexOf(t);return this.listeners[e]=this.listeners[e].slice(0),this.listeners[e].splice(i,1),i>-1},t.trigger=function(e){var t=this.listeners[e];if(t)if(2===arguments.length)for(var i=t.length,n=0;n<i;++n)t[n].call(this,arguments[1]);else for(var s=Array.prototype.slice.call(arguments,1),a=t.length,r=0;r<a;++r)t[r].apply(this,s)},t.dispose=function(){this.listeners={}},t.pipe=function(e){this.on("data",(function(t){e.push(t)}))},e}();function c(e){for(var t,i=(t=e,window.atob?window.atob(t):Buffer.from(t,"base64").toString("binary")),n=new Uint8Array(i.length),s=0;s<i.length;s++)n[s]=i.charCodeAt(s);return n}
/*! @name m3u8-parser @version 7.2.0 @license Apache-2.0 */class p extends h{constructor(){super(),this.buffer=""}push(e){let t;for(this.buffer+=e,t=this.buffer.indexOf("\n");t>-1;t=this.buffer.indexOf("\n"))this.trigger("data",this.buffer.substring(0,t)),this.buffer=this.buffer.substring(t+1)}}const m=String.fromCharCode(9),g=function(e){const t=/([0-9.]*)?@?([0-9.]*)?/.exec(e||""),i={};return t[1]&&(i.length=parseInt(t[1],10)),t[2]&&(i.offset=parseInt(t[2],10)),i},f=function(e){const t={};if(!e)return t;const i=e.split(new RegExp('(?:^|,)((?:[^=]*)=(?:"[^"]*"|[^,]*))'));let n,s=i.length;for(;s--;)""!==i[s]&&(n=/([^=]*)=(.*)/.exec(i[s]).slice(1),n[0]=n[0].replace(/^\s+|\s+$/g,""),n[1]=n[1].replace(/^\s+|\s+$/g,""),n[1]=n[1].replace(/^['"](.*)['"]$/g,"$1"),t[n[0]]=n[1]);return t},y=e=>{const t=e.split("x"),i={};return t[0]&&(i.width=parseInt(t[0],10)),t[1]&&(i.height=parseInt(t[1],10)),i};class _ extends h{constructor(){super(),this.customParsers=[],this.tagMappers=[]}push(e){let t,i;0!==(e=e.trim()).length&&("#"===e[0]?this.tagMappers.reduce(((t,i)=>{const n=i(e);return n===e?t:t.concat([n])}),[e]).forEach((e=>{for(let t=0;t<this.customParsers.length;t++)if(this.customParsers[t].call(this,e))return;if(0===e.indexOf("#EXT"))if(e=e.replace("\r",""),t=/^#EXTM3U/.exec(e),t)this.trigger("data",{type:"tag",tagType:"m3u"});else{if(t=/^#EXTINF:([0-9\.]*)?,?(.*)?$/.exec(e),t)return i={type:"tag",tagType:"inf"},t[1]&&(i.duration=parseFloat(t[1])),t[2]&&(i.title=t[2]),void this.trigger("data",i);if(t=/^#EXT-X-TARGETDURATION:([0-9.]*)?/.exec(e),t)return i={type:"tag",tagType:"targetduration"},t[1]&&(i.duration=parseInt(t[1],10)),void this.trigger("data",i);if(t=/^#EXT-X-VERSION:([0-9.]*)?/.exec(e),t)return i={type:"tag",tagType:"version"},t[1]&&(i.version=parseInt(t[1],10)),void this.trigger("data",i);if(t=/^#EXT-X-MEDIA-SEQUENCE:(\-?[0-9.]*)?/.exec(e),t)return i={type:"tag",tagType:"media-sequence"},t[1]&&(i.number=parseInt(t[1],10)),void this.trigger("data",i);if(t=/^#EXT-X-DISCONTINUITY-SEQUENCE:(\-?[0-9.]*)?/.exec(e),t)return i={type:"tag",tagType:"discontinuity-sequence"},t[1]&&(i.number=parseInt(t[1],10)),void this.trigger("data",i);if(t=/^#EXT-X-PLAYLIST-TYPE:(.*)?$/.exec(e),t)return i={type:"tag",tagType:"playlist-type"},t[1]&&(i.playlistType=t[1]),void this.trigger("data",i);if(t=/^#EXT-X-BYTERANGE:(.*)?$/.exec(e),t)return i=a(g(t[1]),{type:"tag",tagType:"byterange"}),void this.trigger("data",i);if(t=/^#EXT-X-ALLOW-CACHE:(YES|NO)?/.exec(e),t)return i={type:"tag",tagType:"allow-cache"},t[1]&&(i.allowed=!/NO/.test(t[1])),void this.trigger("data",i);if(t=/^#EXT-X-MAP:(.*)$/.exec(e),t){if(i={type:"tag",tagType:"map"},t[1]){const e=f(t[1]);e.URI&&(i.uri=e.URI),e.BYTERANGE&&(i.byterange=g(e.BYTERANGE))}this.trigger("data",i)}else{if(t=/^#EXT-X-STREAM-INF:(.*)$/.exec(e),t)return i={type:"tag",tagType:"stream-inf"},t[1]&&(i.attributes=f(t[1]),i.attributes.RESOLUTION&&(i.attributes.RESOLUTION=y(i.attributes.RESOLUTION)),i.attributes.BANDWIDTH&&(i.attributes.BANDWIDTH=parseInt(i.attributes.BANDWIDTH,10)),i.attributes["FRAME-RATE"]&&(i.attributes["FRAME-RATE"]=parseFloat(i.attributes["FRAME-RATE"])),i.attributes["PROGRAM-ID"]&&(i.attributes["PROGRAM-ID"]=parseInt(i.attributes["PROGRAM-ID"],10))),void this.trigger("data",i);if(t=/^#EXT-X-MEDIA:(.*)$/.exec(e),t)return i={type:"tag",tagType:"media"},t[1]&&(i.attributes=f(t[1])),void this.trigger("data",i);if(t=/^#EXT-X-ENDLIST/.exec(e),t)this.trigger("data",{type:"tag",tagType:"endlist"});else if(t=/^#EXT-X-DISCONTINUITY/.exec(e),t)this.trigger("data",{type:"tag",tagType:"discontinuity"});else{if(t=/^#EXT-X-PROGRAM-DATE-TIME:(.*)$/.exec(e),t)return i={type:"tag",tagType:"program-date-time"},t[1]&&(i.dateTimeString=t[1],i.dateTimeObject=new Date(t[1])),void this.trigger("data",i);if(t=/^#EXT-X-KEY:(.*)$/.exec(e),t)return i={type:"tag",tagType:"key"},t[1]&&(i.attributes=f(t[1]),i.attributes.IV&&("0x"===i.attributes.IV.substring(0,2).toLowerCase()&&(i.attributes.IV=i.attributes.IV.substring(2)),i.attributes.IV=i.attributes.IV.match(/.{8}/g),i.attributes.IV[0]=parseInt(i.attributes.IV[0],1
/*! @name pkcs7 @version 1.0.4 @license Apache-2.0 */let t=null;class i{constructor(e){let i,n,s;t||(t=function(){const e=[[[],[],[],[],[]],[[],[],[],[],[]]],t=e[0],i=e[1],n=t[4],s=i[4];let a,r,o;const d=[],u=[];let l,h,c,p,m,g;for(a=0;a<256;a++)u[(d[a]=a<<1^283*(a>>7))^a]=a;for(r=o=0;!n[r];r^=l||1,o=u[o]||1)for(p=o^o<<1^o<<2^o<<3^o<<4,p=p>>8^255&p^99,n[r]=p,s[p]=r,c=d[h=d[l=d[r]]],g=16843009*c^65537*h^257*l^16843008*r,m=257*d[p]^16843008*p,a=0;a<4;a++)t[a][r]=m=m<<24^m>>>8,i[a][p]=g=g<<24^g>>>8;for(a=0;a<5;a++)t[a]=t[a].slice(0),i[a]=i[a].slice(0);return e}()),this._tables=[[t[0][0].slice(),t[0][1].slice(),t[0][2].slice(),t[0][3].slice(),t[0][4].slice()],[t[1][0].slice(),t[1][1].slice(),t[1][2].slice(),t[1][3].slice(),t[1][4].slice()]];const a=this._tables[0][4],r=this._tables[1],o=e.length;let d=1;if(4!==o&&6!==o&&8!==o)throw new Error("Invalid aes key size");const u=e.slice(0),l=[];for(this._key=[u,l],i=o;i<4*o+28;i++)s=u[i-1],(i%o==0||8===o&&i%o==4)&&(s=a[s>>>24]<<24^a[s>>16&255]<<16^a[s>>8&255]<<8^a[255&s],i%o==0&&(s=s<<8^s>>>24^d<<24,d=d<<1^283*(d>>7))),u[i]=u[i-o]^s;for(n=0;i;n++,i--)s=u[3&n?i:i-4],l[n]=i<=4||n<4?s:r[0][a[s>>>24]]^r[1][a[s>>16&255]]^r[2][a[s>>8&255]]^r[3][a[255&s]]}decrypt(e,t,i,n,s,a){const r=this._key[1];let o,d,u,l=e^r[0],h=n^r[1],c=i^r[2],p=t^r[3];const m=r.length/4-2;let g,f=4;const y=this._tables[1],_=y[0],T=y[1],b=y[2],S=y[3],v=y[4];for(g=0;g<m;g++)o=_[l>>>24]^T[h>>16&255]^b[c>>8&255]^S[255&p]^r[f],d=_[h>>>24]^T[c>>16&255]^b[p>>8&255]^S[255&l]^r[f+1],u=_[c>>>24]^T[p>>16&255]^b[l>>8&255]^S[255&h]^r[f+2],p=_[p>>>24]^T[l>>16&255]^b[h>>8&255]^S[255&c]^r[f+3],f+=4,l=o,h=d,c=u;for(g=0;g<4;g++)s[(3&-g)+a]=v[l>>>24]<<24^v[h>>16&255]<<16^v[c>>8&255]<<8^v[255&p]^r[f++],o=l,l=h,h=c,c=p,p=o}}class n extends e{constructor(){super(e),this.jobs=[],this.delay=1,this.timeout_=null}processJob_(){this.jobs.shift()(),this.jobs.length?this.timeout_=setTimeout(this.processJob_.bind(this),this.delay):this.timeout_=null}push(e){this.jobs.push(e),this.timeout_||(this.timeout_=setTimeout(this.processJob_.bind(this),this.delay))}}const s=function(e){return e<<24|(65280&e)<<8|(16711680&e)>>8|e>>>24};class a{constructor(e,t,i,r){const o=a.STEP,d=new Int32Array(e.buffer),u=new Uint8Array(e.byteLength);let l=0;for(this.asyncStream_=new n,this.asyncStream_.push(this.decryptChunk_(d.subarray(l,l+o),t,i,u)),l=o;l<d.length;l+=o)i=new Uint32Array([s(d[l-4]),s(d[l-3]),s(d[l-2]),s(d[l-1])]),this.asyncStream_.push(this.decryptChunk_(d.subarray(l,l+o),t,i,u));this.asyncStream_.push((function(){var e;
/*! @name aes-decrypter @version 4.0.2 @license Apache-2.0 */r(null,(e=u).subarray(0,e.byteLength-e[e.byteLength-1]))}))}static get STEP(){return 32e3}decryptChunk_(e,t,n,a){return function(){const r=function(e,t,n){const a=new Int32Array(e.buffer,e.byteOffset,e.byteLength>>2),r=new i(Array.prototype.slice.call(t)),o=new Uint8Array(e.byteLength),d=new Int32Array(o.buffer);let u,l,h,c,p,m,g,f,y;for(u=n[0],l=n[1],h=n[2],c=n[3],y=0;y<a.length;y+=4)p=s(a[y]),m=s(a[y+1]),g=s(a[y+2]),f=s(a[y+3]),r.decrypt(p,m,g,f,d,y),d[y]=s(d[y]^u),d[y+1]=s(d[y+1]^l),d[y+2]=s(d[y+2]^h),d[y+3]=s(d[y+3]^c),u=p,l=m,h=g,c=f;return o}(e,t,n);a.set(r,e.byteOffset)}}}var r="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{},o=("undefined"!=typeof window?window:void 0!==r?r:"undefined"!=typeof self?self:{}).BigInt||Number;o("0x1"),o("0x100"),o("0x10000"),o("0x1000000"),o("0x100000000"),o("0x10000000000"),o("0x1000000000000"),o("0x100000000000000"),o("0x10000000000000000"),function(){var e=new Uint16Array([65484]),t=new Uint8Array(e.buffer,e.byteOffset,e.byteLength);255===t[0]||t[0]}();self.onmessage=function(e){const t=e.data,i=new Uint8Array(t.encrypted.bytes,t.encrypted.byteOffset,t.encrypted.byteLength),n=new Uint32Array(t.key.bytes,t.key.byteOffset,t.key.byteLength/4),s=new Uint32Array(t.iv.bytes,t.iv.byteOffset,t.iv.byteLength/4);new a(i,n,s,(function(e,i){self.postMessage(function(e){const t={};return Object.keys(e).forEach((i=>{const n=e[i];var s;s=n,("function"===ArrayBuffer.isView?ArrayBuffer.isView(s):s&&s.buffer instanceof ArrayBuffer)?t[i]={bytes:n.buffer,byteOffset:n.byteOffset,byteLength:n.byteLength}:t[i]=n})),t}({source:t.source,decrypted:i}),[i.buffer])}))}})));var Wn=Si(Gn);const Hn=e=>{let t=e.default?"main":"alternative";return e.characteristics&&e.characteristics.indexOf("public.accessibility.describes-video")>=0&&(t="main-desc"),t},Xn=(e,t)=>{e.abort(),e.pause(),t&&t.activePlaylistLoader&&(t.activePlaylistLoader.pause(),t.activePlaylistLoader=null)},jn=(e,t)=>{t.activePlaylistLoader=e,e.load()},zn={AUDIO:(e,t)=>()=>{const{mediaTypes:{[e]:i},excludePlaylist:n}=t,a=i.activeTrack(),r=i.activeGroup(),o=(r.filter((e=>e.default))[0]||r[0]).id,d=i.tracks[o];if(a!==d){s.default.log.warn("Problem encountered loading the alternate audio track.Switching back to default.");for(const e in i.tracks)i.tracks[e].enabled=i.tracks[e]===d;i.onTrackChanged()}else n({error:{message:"Problem encountered loading the default audio track."}})},SUBTITLES:(e,t)=>()=>{const{mediaTypes:{[e]:i}}=t;s.default.log.warn("Problem encountered loading the subtitle track.Disabling subtitle track.");const n=i.activeTrack();n&&(n.mode="disabled"),i.onTrackChanged()}},Yn={AUDIO:(e,t,i)=>{if(!t)return;const{tech:n,requestOptions:s,segmentLoaders:{[e]:a}}=i;t.on("loadedmetadata",(()=>{const e=t.media();a.playlist(e,s),(!n.paused()||e.endList&&"none"!==n.preload())&&a.load()})),t.on("loadedplaylist",(()=>{a.playlist(t.media(),s),n.paused()||a.load()})),t.on("error",zn[e](e,i))},SUBTITLES:(e,t,i)=>{const{tech:n,requestOptions:s,segmentLoaders:{[e]:a},mediaTypes:{[e]:r}}=i;t.on("loadedmetadata",(()=>{const e=t.media();a.playlist(e,s),a.track(r.activeTrack()),(!n.paused()||e.endList&&"none"!==n.preload())&&a.load()})),t.on("loadedplaylist",(()=>{a.playlist(t.media(),s),n.paused()||a.load()})),t.on("error",zn[e](e,i))}},Qn={AUDIO:(e,t)=>{const{vhs:i,sourceType:n,segmentLoaders:{[e]:a},requestOptions:r,main:{mediaGroups:o},mediaTypes:{[e]:{groups:d,tracks:u,logger_:l}},mainPlaylistLoader:h}=t,c=ae(h.main);o[e]&&0!==Object.keys(o[e]).length||(o[e]={main:{default:{default:!0}}},c&&(o[e].main.default.playlists=h.main.playlists));for(const a in o[e]){d[a]||(d[a]=[]);for(const p in o[e][a]){let m,g=o[e][a][p];if(c?(l(`AUDIO group '${a}' label '${p}' is a main playlist`),g.isMainPlaylist=!0,m=null):m="vhs-json"===n&&g.playlists?new Ue(g.playlists[0],i,r):g.resolvedUri?new Ue(g.resolvedUri,i,r):g.playlists&&"dash"===n?new _i(g.playlists[0],i,r,h):null,g=C({id:p,playlistLoader:m},g),Yn[e](e,g.p