@videojs/vhs-utils
Advanced tools
Comparing version 3.0.1 to 3.0.2
@@ -0,1 +1,8 @@ | ||
<a name="3.0.2"></a> | ||
## [3.0.2](https://github.com/videojs/vhs-utils/compare/v3.0.1...v3.0.2) (2021-05-20) | ||
### Bug Fixes | ||
* properly handle data URIs ([#27](https://github.com/videojs/vhs-utils/issues/27)) ([9b10245](https://github.com/videojs/vhs-utils/commit/9b10245)), closes [videojs/video.js#7240](https://github.com/videojs/video.js/issues/7240) | ||
<a name="3.0.1"></a> | ||
@@ -2,0 +9,0 @@ ## [3.0.1](https://github.com/videojs/vhs-utils/compare/v3.0.0...v3.0.1) (2021-04-29) |
@@ -20,2 +20,7 @@ "use strict"; | ||
return relativeUrl; | ||
} // if baseUrl is a data URI, ignore it and resolve everything relative to window.location | ||
if (/^data:/.test(baseUrl)) { | ||
baseUrl = _window.default.location && _window.default.location.href || ''; | ||
} // IE11 supports URL but not the URL constructor | ||
@@ -22,0 +27,0 @@ // feature detect the behavior we want |
@@ -1,2 +0,2 @@ | ||
/*! @name @videojs/vhs-utils @version 3.0.1 @license MIT */ | ||
/*! @name @videojs/vhs-utils @version 3.0.2 @license MIT */ | ||
(function (global, factory) { | ||
@@ -1406,2 +1406,7 @@ typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory(require('global/window')) : | ||
return relativeUrl; | ||
} // if baseUrl is a data URI, ignore it and resolve everything relative to window.location | ||
if (/^data:/.test(baseUrl)) { | ||
baseUrl = window__default['default'].location && window__default['default'].location.href || ''; | ||
} // IE11 supports URL but not the URL constructor | ||
@@ -1408,0 +1413,0 @@ // feature detect the behavior we want |
@@ -1,2 +0,2 @@ | ||
/*! @name @videojs/vhs-utils @version 3.0.1 @license MIT */ | ||
!function(e,r){"object"==typeof exports&&"undefined"!=typeof module?module.exports=r(require("global/window")):"function"==typeof define&&define.amd?define(["global/window"],r):(e="undefined"!=typeof globalThis?globalThis:e||self).vhsUtils=r(e.window)}(this,(function(e){"use strict";function r(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var t,n,o=r(e),a={mp4:/^(av0?1|avc0?[1234]|vp0?9|flac|opus|mp3|mp4a|mp4v|stpp.ttml.im1t)/,webm:/^(vp0?[89]|av0?1|opus|vorbis)/,ogg:/^(vp0?[89]|theora|flac|opus|vorbis)/,video:/^(av0?1|avc0?[1234]|vp0?[89]|hvc1|hev1|theora|mp4v)/,audio:/^(mp4a|flac|vorbis|opus|ac-[34]|ec-3|alac|mp3|speex|aac)/,text:/^(stpp.ttml.im1t)/,muxerVideo:/^(avc0?1)/,muxerAudio:/^(mp4a)/,muxerText:/a^/},i=["video","audio","text"],u=["Video","Audio","Text"],f=function(e){return e?e.replace(/avc1\.(\d+)\.(\d+)/i,(function(e,r,t){return"avc1."+("00"+Number(r).toString(16)).slice(-2)+"00"+("00"+Number(t).toString(16)).slice(-2)})):e},c=function(e){return e.map(f)},s=function(e){void 0===e&&(e="");var r=e.split(","),t=[];return r.forEach((function(e){var r;e=e.trim(),i.forEach((function(n){var o=a[n].exec(e.toLowerCase());if(o&&!(o.length<=1)){r=n;var i=e.substring(0,o[1].length),u=e.replace(i,"");t.push({type:i,details:u,mediaType:n})}})),r||t.push({type:e,details:"",mediaType:"unknown"})})),t},l=function(e){return void 0===e&&(e=""),a.audio.test(e.trim().toLowerCase())},p=function(e){return void 0===e&&(e=""),a.text.test(e.trim().toLowerCase())},h=function(e){if(e&&"string"==typeof e){var r=e.toLowerCase().split(",").map((function(e){return f(e.trim())})),t="video";1===r.length&&l(r[0])?t="audio":1===r.length&&p(r[0])&&(t="application");var n="mp4";return r.every((function(e){return a.mp4.test(e)}))?n="mp4":r.every((function(e){return a.webm.test(e)}))?n="webm":r.every((function(e){return a.ogg.test(e)}))&&(n="ogg"),t+"/"+n+';codecs="'+e+'"'}},v=Object.freeze({__proto__:null,translateLegacyCodec:f,translateLegacyCodecs:c,mapLegacyAvcCodecs:function(e){return e.replace(/avc1\.(\d+)\.(\d+)/i,(function(e){return c([e])[0]}))},parseCodecs:s,codecsFromDefault:function(e,r){if(!e.mediaGroups.AUDIO||!r)return null;var t=e.mediaGroups.AUDIO[r];if(!t)return null;for(var n in t){var o=t[n];if(o.default&&o.playlists)return s(o.playlists[0].attributes.CODECS)}return null},isVideoCodec:function(e){return void 0===e&&(e=""),a.video.test(e.trim().toLowerCase())},isAudioCodec:l,isTextCodec:p,getMimeForCodec:h,browserSupportsCodec:function(e){return void 0===e&&(e=""),o.default.MediaSource&&o.default.MediaSource.isTypeSupported&&o.default.MediaSource.isTypeSupported(h(e))||!1},muxerSupportsCodec:function(e){return void 0===e&&(e=""),e.toLowerCase().split(",").every((function(e){e=e.trim();for(var r=0;r<u.length;r++){if(a["muxer"+u[r]].test(e))return!0}return!1}))},DEFAULT_AUDIO_CODEC:"mp4a.40.2",DEFAULT_VIDEO_CODEC:"avc1.4d400d"}),y=function(e){return e.toString(2).length},g=function(e){return Math.ceil(y(e)/8)},d=function(e,r,t){return void 0===t&&(t=" "),(function(e,r){for(var t="";r--;)t+=e;return t}(t,r)+e.toString()).slice(-r)},m=function(e){return ArrayBuffer.isView(e)},b=function(e){return e instanceof Uint8Array?e:(Array.isArray(e)||m(e)||e instanceof ArrayBuffer||(e="number"!=typeof e||"number"==typeof e&&e!=e?0:[e]),new Uint8Array(e&&e.buffer||e,e&&e.byteOffset||0,e&&e.byteLength||0))},A=o.default.BigInt||Number,w=[A("0x1"),A("0x100"),A("0x10000"),A("0x1000000"),A("0x100000000"),A("0x10000000000"),A("0x1000000000000"),A("0x100000000000000"),A("0x10000000000000000")],L=(t=new Uint16Array([65484]),255===(n=new Uint8Array(t.buffer,t.byteOffset,t.byteLength))[0]?"big":204===n[0]?"little":"unknown"),U="big"===L,x="little"===L,T=function(e,r){var t=void 0===r?{}:r,n=t.signed,o=void 0!==n&&n,a=t.le,i=void 0!==a&&a;e=b(e);var u=i?"reduce":"reduceRight",f=(e[u]?e[u]:Array.prototype[u]).call(e,(function(r,t,n){var o=i?n:Math.abs(n+1-e.length);return r+A(t)*w[o]}),A(0));if(o){var c=w[e.length]/A(2)-A(1);(f=A(f))>c&&(f-=c,f-=c,f-=A(2))}return Number(f)},C=function(e,r){var t=(void 0===r?{}:r).le,n=void 0!==t&&t;("bigint"!=typeof e&&"number"!=typeof e||"number"==typeof e&&e!=e)&&(e=0),e=A(e);for(var o=g(e),a=new Uint8Array(new ArrayBuffer(o)),i=0;i<o;i++){var u=n?i:Math.abs(i+1-a.length);a[u]=Number(e/w[i]&A(255)),e<0&&(a[u]=Math.abs(~a[u]),a[u]-=0===i?1:2)}return a},S=function(e,r){if("string"!=typeof e&&e&&"function"==typeof e.toString&&(e=e.toString()),"string"!=typeof e)return new Uint8Array;r||(e=unescape(encodeURIComponent(e)));for(var t=new Uint8Array(e.length),n=0;n<e.length;n++)t[n]=e.charCodeAt(n);return t},E=function(e,r,t){var n=void 0===t?{}:t,o=n.offset,a=void 0===o?0:o,i=n.mask,u=void 0===i?[]:i;e=b(e);var f=(r=b(r)).every?r.every:Array.prototype.every;return r.length&&e.length-a>=r.length&&f.call(r,(function(r,t){return r===(u[t]?u[t]&e[a+t]:e[a+t])}))},k=Object.freeze({__proto__:null,countBits:y,countBytes:g,padStart:d,isTypedArray:m,toUint8:b,toHexString:function(e){e=b(e);for(var r="",t=0;t<e.length;t++)r+=d(e[t].toString(16),2,"0");return r},toBinaryString:function(e){e=b(e);for(var r="",t=0;t<e.length;t++)r+=d(e[t].toString(2),8,"0");return r},ENDIANNESS:L,IS_BIG_ENDIAN:U,IS_LITTLE_ENDIAN:x,bytesToNumber:T,numberToBytes:C,bytesToString:function(e){if(!e)return"";e=Array.prototype.slice.call(e);var r=String.fromCharCode.apply(null,b(e));try{return decodeURIComponent(escape(r))}catch(e){}return r},stringToBytes:S,concatTypedArrays:function(){for(var e=arguments.length,r=new Array(e),t=0;t<e;t++)r[t]=arguments[t];if((r=r.filter((function(e){return e&&(e.byteLength||e.length)&&"string"!=typeof e}))).length<=1)return b(r[0]);var n=r.reduce((function(e,r,t){return e+(r.byteLength||r.length)}),0),o=new Uint8Array(n),a=0;return r.forEach((function(e){e=b(e),o.set(e,a),a+=e.byteLength})),o},bytesMatch:E,sliceBytes:function(e,r,t){return Uint8Array.prototype.slice?Uint8Array.prototype.slice.call(e,r,t):new Uint8Array(Array.prototype.slice.call(e,r,t))},reverseBytes:function(e){return e.reverse?e.reverse():Array.prototype.reverse.call(e)}}),_=function(e){return"string"==typeof e?S(e):e},B=function e(r,t,n){void 0===n&&(n=!1),t=function(e){return Array.isArray(e)?e.map((function(e){return _(e)})):[_(e)]}(t),r=b(r);var o=[];if(!t.length)return o;for(var a=0;a<r.length;){var i=(r[a]<<24|r[a+1]<<16|r[a+2]<<8|r[a+3])>>>0,u=r.subarray(a+4,a+8);if(0===i)break;var f=a+i;if(f>r.length){if(n)break;f=r.length}var c=r.subarray(a+8,f);E(u,t[0])&&(1===t.length?o.push(c):o.push.apply(o,e(c,t.slice(1),n))),a=f}return o},D={EBML:b([26,69,223,163]),DocType:b([66,130]),Segment:b([24,83,128,103]),SegmentInfo:b([21,73,169,102]),Tracks:b([22,84,174,107]),Track:b([174]),TrackNumber:b([215]),DefaultDuration:b([35,227,131]),TrackEntry:b([174]),TrackType:b([131]),FlagDefault:b([136]),CodecID:b([134]),CodecPrivate:b([99,162]),VideoTrack:b([224]),AudioTrack:b([225]),Cluster:b([31,67,182,117]),Timestamp:b([231]),TimestampScale:b([42,215,177]),BlockGroup:b([160]),BlockDuration:b([155]),Block:b([161]),SimpleBlock:b([163])},R=[128,64,32,16,8,4,2,1],I=function(e,r,t,n){void 0===t&&(t=!0),void 0===n&&(n=!1);var o=function(e){for(var r=1,t=0;t<R.length&&!(e&R[t]);t++)r++;return r}(e[r]),a=e.subarray(r,r+o);return t&&((a=Array.prototype.slice.call(e,r,r+o))[0]^=R[o-1]),{length:o,value:T(a,{signed:n}),bytes:a}},N=function e(r){return"string"==typeof r?r.match(/.{1,2}/g).map((function(r){return e(r)})):"number"==typeof r?C(r):r},O=function e(r,t,n){if(n>=t.length)return t.length;var o=I(t,n,!1);if(E(r.bytes,o.bytes))return n;var a=I(t,n+o.length);return e(r,t,n+a.length+a.value+o.length)},z=function e(r,t){t=function(e){return Array.isArray(e)?e.map((function(e){return N(e)})):[N(e)]}(t),r=b(r);var n=[];if(!t.length)return n;for(var o=0;o<r.length;){var a=I(r,o,!1),i=I(r,o+a.length),u=o+a.length+i.length;127===i.value&&(i.value=O(a,r,u),i.value!==r.length&&(i.value-=u));var f=u+i.value>r.length?r.length:u+i.value,c=r.subarray(u,f);E(t[0],a.bytes)&&(1===t.length?n.push(c):n=n.concat(e(c,t.slice(1)))),o+=a.length+i.length+c.length}return n},M=b([73,68,51]),F=function e(r,t){return void 0===t&&(t=0),(r=b(r)).length-t<10||!E(r,M,{offset:t})?t:(t+=function(e,r){void 0===r&&(r=0);var t=(e=b(e))[r+5],n=e[r+6]<<21|e[r+7]<<14|e[r+8]<<7|e[r+9];return(16&t)>>4?n+20:n+10}(r,t),e(r,t))},j=b([0,0,0,1]),q=b([0,0,1]),P=b([0,0,3]),G=function(e){for(var r=[],t=1;t<e.length-2;)E(e.subarray(t,t+3),P)&&(r.push(t+2),t++),t++;if(0===r.length)return e;var n=e.length-r.length,o=new Uint8Array(n),a=0;for(t=0;t<n;a++,t++)a===r[0]&&(a++,r.shift()),o[t]=e[a];return o},V=function(e,r,t,n){void 0===n&&(n=1/0),e=b(e),t=[].concat(t);for(var o,a=0,i=0;a<e.length&&(i<n||o);){var u=void 0;if(E(e.subarray(a),j)?u=4:E(e.subarray(a),q)&&(u=3),u){if(i++,o)return G(e.subarray(o,a));var f=void 0;"h264"===r?f=31&e[a+u]:"h265"===r&&(f=e[a+u]>>1&63),-1!==t.indexOf(f)&&(o=a+u),a+=u+("h264"===r?1:2)}else a++}return e.subarray(0,0)},H={webm:b([119,101,98,109]),matroska:b([109,97,116,114,111,115,107,97]),flac:b([102,76,97,67]),ogg:b([79,103,103,83]),ac3:b([11,119]),riff:b([82,73,70,70]),avi:b([65,86,73]),wav:b([87,65,86,69]),"3gp":b([102,116,121,112,51,103]),mp4:b([102,116,121,112]),fmp4:b([115,116,121,112]),mov:b([102,116,121,112,113,116])},$={aac:function(e){var r=F(e);return E(e,[255,16],{offset:r,mask:[255,22]})},mp3:function(e){var r=F(e);return E(e,[255,2],{offset:r,mask:[255,6]})},webm:function(e){var r=z(e,[D.EBML,D.DocType])[0];return E(r,H.webm)},mkv:function(e){var r=z(e,[D.EBML,D.DocType])[0];return E(r,H.matroska)},mp4:function(e){return!$["3gp"](e)&&!$.mov(e)&&(E(e,H.mp4,{offset:4})||E(e,H.fmp4,{offset:4}))},mov:function(e){return E(e,H.mov,{offset:4})},"3gp":function(e){return E(e,H["3gp"],{offset:4})},ac3:function(e){var r=F(e);return E(e,H.ac3,{offset:r})},ts:function(e){if(e.length<189&&e.length>=1)return 71===e[0];for(var r=0;r+188<e.length&&r<188;){if(71===e[r]&&71===e[r+188])return!0;r+=1}return!1},flac:function(e){var r=F(e);return E(e,H.flac,{offset:r})},ogg:function(e){return E(e,H.ogg)},avi:function(e){return E(e,H.riff)&&E(e,H.avi,{offset:8})},wav:function(e){return E(e,H.riff)&&E(e,H.wav,{offset:8})},h264:function(e){return function(e,r,t){return V(e,"h264",r,t)}(e,7,3).length},h265:function(e){return function(e,r,t){return V(e,"h265",r,t)}(e,[32,33],3).length}},Z=Object.keys($).filter((function(e){return"ts"!==e&&"h264"!==e&&"h265"!==e})).concat(["ts","h264","h265"]);Z.forEach((function(e){var r=$[e];$[e]=function(e){return r(b(e))}}));var J=$,K=Object.freeze({__proto__:null,isLikely:J,detectContainerForBytes:function(e){e=b(e);for(var r=0;r<Z.length;r++){var t=Z[r];if(J[t](e))return t}return""},isLikelyFmp4MediaSegment:function(e){return B(e,["moof"]).length>0}});var Q=Object.freeze({__proto__:null,forEachMediaGroup:function(e,r,t){r.forEach((function(r){for(var n in e.mediaGroups[r])for(var o in e.mediaGroups[r][n]){var a=e.mediaGroups[r][n][o];t(a,r,n,o)}}))}});var W=function(e,r,t){return e(t={path:r,exports:{},require:function(e,r){return function(){throw new Error("Dynamic requires are not currently supported by @rollup/plugin-commonjs")}(null==r&&t.path)}},t.exports),t.exports}((function(e,r){var t,n,o,a,i;t=/^((?:[a-zA-Z0-9+\-.]+:)?)(\/\/[^\/?#]*)?((?:[^\/?#]*\/)*[^;?#]*)?(;[^?#]*)?(\?[^#]*)?(#.*)?$/,n=/^([^\/?#]*)(.*)$/,o=/(?:\/|^)\.(?=\/)/g,a=/(?:\/|^)\.\.\/(?!\.\.\/)[^\/]*(?=\/)/g,i={buildAbsoluteURL:function(e,r,t){if(t=t||{},e=e.trim(),!(r=r.trim())){if(!t.alwaysNormalize)return e;var o=i.parseURL(e);if(!o)throw new Error("Error trying to parse base URL.");return o.path=i.normalizePath(o.path),i.buildURLFromParts(o)}var a=i.parseURL(r);if(!a)throw new Error("Error trying to parse relative URL.");if(a.scheme)return t.alwaysNormalize?(a.path=i.normalizePath(a.path),i.buildURLFromParts(a)):r;var u=i.parseURL(e);if(!u)throw new Error("Error trying to parse base URL.");if(!u.netLoc&&u.path&&"/"!==u.path[0]){var f=n.exec(u.path);u.netLoc=f[1],u.path=f[2]}u.netLoc&&!u.path&&(u.path="/");var c={scheme:u.scheme,netLoc:a.netLoc,path:null,params:a.params,query:a.query,fragment:a.fragment};if(!a.netLoc&&(c.netLoc=u.netLoc,"/"!==a.path[0]))if(a.path){var s=u.path,l=s.substring(0,s.lastIndexOf("/")+1)+a.path;c.path=i.normalizePath(l)}else c.path=u.path,a.params||(c.params=u.params,a.query||(c.query=u.query));return null===c.path&&(c.path=t.alwaysNormalize?i.normalizePath(a.path):a.path),i.buildURLFromParts(c)},parseURL:function(e){var r=t.exec(e);return r?{scheme:r[1]||"",netLoc:r[2]||"",path:r[3]||"",params:r[4]||"",query:r[5]||"",fragment:r[6]||""}:null},normalizePath:function(e){for(e=e.split("").reverse().join("").replace(o,"");e.length!==(e=e.replace(a,"")).length;);return e.split("").reverse().join("")},buildURLFromParts:function(e){return e.scheme+e.netLoc+e.path+e.params+e.query+e.fragment}},e.exports=i})),X="http://example.com";return{codecs:v,byteHelpers:k,containers:K,decodeB64ToUint8Array:function(e){for(var r,t=(r=e,o.default.atob?o.default.atob(r):Buffer.from(r,"base64").toString("binary")),n=new Uint8Array(t.length),a=0;a<t.length;a++)n[a]=t.charCodeAt(a);return n},mediaGroups:Q,resolveUrl:function(e,r){if(/^[a-z]+:/i.test(r))return r;var t="function"==typeof o.default.URL,n=/^\/\//.test(e),a=!o.default.location&&!/\/\//i.test(e);if(t?e=new o.default.URL(e,o.default.location||X):/\/\//i.test(e)||(e=W.buildAbsoluteURL(o.default.location&&o.default.location.href||"",e)),t){var i=new URL(r,e);return a?i.href.slice(X.length):n?i.href.slice(i.protocol.length):i.href}return W.buildAbsoluteURL(e,r)},Stream:function(){function e(){this.listeners={}}var r=e.prototype;return r.on=function(e,r){this.listeners[e]||(this.listeners[e]=[]),this.listeners[e].push(r)},r.off=function(e,r){if(!this.listeners[e])return!1;var t=this.listeners[e].indexOf(r);return this.listeners[e]=this.listeners[e].slice(0),this.listeners[e].splice(t,1),t>-1},r.trigger=function(e){var r=this.listeners[e];if(r)if(2===arguments.length)for(var t=r.length,n=0;n<t;++n)r[n].call(this,arguments[1]);else for(var o=Array.prototype.slice.call(arguments,1),a=r.length,i=0;i<a;++i)r[i].apply(this,o)},r.dispose=function(){this.listeners={}},r.pipe=function(e){this.on("data",(function(r){e.push(r)}))},e}()}})); | ||
/*! @name @videojs/vhs-utils @version 3.0.2 @license MIT */ | ||
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e(require("global/window")):"function"==typeof define&&define.amd?define(["global/window"],e):(t="undefined"!=typeof globalThis?globalThis:t||self).vhsUtils=e(t.window)}(this,(function(t){"use strict";function e(t){return t&&"object"==typeof t&&"default"in t?t:{default:t}}var r,n,o=e(t),a={mp4:/^(av0?1|avc0?[1234]|vp0?9|flac|opus|mp3|mp4a|mp4v|stpp.ttml.im1t)/,webm:/^(vp0?[89]|av0?1|opus|vorbis)/,ogg:/^(vp0?[89]|theora|flac|opus|vorbis)/,video:/^(av0?1|avc0?[1234]|vp0?[89]|hvc1|hev1|theora|mp4v)/,audio:/^(mp4a|flac|vorbis|opus|ac-[34]|ec-3|alac|mp3|speex|aac)/,text:/^(stpp.ttml.im1t)/,muxerVideo:/^(avc0?1)/,muxerAudio:/^(mp4a)/,muxerText:/a^/},i=["video","audio","text"],u=["Video","Audio","Text"],f=function(t){return t?t.replace(/avc1\.(\d+)\.(\d+)/i,(function(t,e,r){return"avc1."+("00"+Number(e).toString(16)).slice(-2)+"00"+("00"+Number(r).toString(16)).slice(-2)})):t},c=function(t){return t.map(f)},s=function(t){void 0===t&&(t="");var e=t.split(","),r=[];return e.forEach((function(t){var e;t=t.trim(),i.forEach((function(n){var o=a[n].exec(t.toLowerCase());if(o&&!(o.length<=1)){e=n;var i=t.substring(0,o[1].length),u=t.replace(i,"");r.push({type:i,details:u,mediaType:n})}})),e||r.push({type:t,details:"",mediaType:"unknown"})})),r},l=function(t){return void 0===t&&(t=""),a.audio.test(t.trim().toLowerCase())},p=function(t){return void 0===t&&(t=""),a.text.test(t.trim().toLowerCase())},h=function(t){if(t&&"string"==typeof t){var e=t.toLowerCase().split(",").map((function(t){return f(t.trim())})),r="video";1===e.length&&l(e[0])?r="audio":1===e.length&&p(e[0])&&(r="application");var n="mp4";return e.every((function(t){return a.mp4.test(t)}))?n="mp4":e.every((function(t){return a.webm.test(t)}))?n="webm":e.every((function(t){return a.ogg.test(t)}))&&(n="ogg"),r+"/"+n+';codecs="'+t+'"'}},v=Object.freeze({__proto__:null,translateLegacyCodec:f,translateLegacyCodecs:c,mapLegacyAvcCodecs:function(t){return t.replace(/avc1\.(\d+)\.(\d+)/i,(function(t){return c([t])[0]}))},parseCodecs:s,codecsFromDefault:function(t,e){if(!t.mediaGroups.AUDIO||!e)return null;var r=t.mediaGroups.AUDIO[e];if(!r)return null;for(var n in r){var o=r[n];if(o.default&&o.playlists)return s(o.playlists[0].attributes.CODECS)}return null},isVideoCodec:function(t){return void 0===t&&(t=""),a.video.test(t.trim().toLowerCase())},isAudioCodec:l,isTextCodec:p,getMimeForCodec:h,browserSupportsCodec:function(t){return void 0===t&&(t=""),o.default.MediaSource&&o.default.MediaSource.isTypeSupported&&o.default.MediaSource.isTypeSupported(h(t))||!1},muxerSupportsCodec:function(t){return void 0===t&&(t=""),t.toLowerCase().split(",").every((function(t){t=t.trim();for(var e=0;e<u.length;e++){if(a["muxer"+u[e]].test(t))return!0}return!1}))},DEFAULT_AUDIO_CODEC:"mp4a.40.2",DEFAULT_VIDEO_CODEC:"avc1.4d400d"}),y=function(t){return t.toString(2).length},g=function(t){return Math.ceil(y(t)/8)},d=function(t,e,r){return void 0===r&&(r=" "),(function(t,e){for(var r="";e--;)r+=t;return r}(r,e)+t.toString()).slice(-e)},m=function(t){return ArrayBuffer.isView(t)},b=function(t){return t instanceof Uint8Array?t:(Array.isArray(t)||m(t)||t instanceof ArrayBuffer||(t="number"!=typeof t||"number"==typeof t&&t!=t?0:[t]),new Uint8Array(t&&t.buffer||t,t&&t.byteOffset||0,t&&t.byteLength||0))},A=o.default.BigInt||Number,w=[A("0x1"),A("0x100"),A("0x10000"),A("0x1000000"),A("0x100000000"),A("0x10000000000"),A("0x1000000000000"),A("0x100000000000000"),A("0x10000000000000000")],L=(r=new Uint16Array([65484]),255===(n=new Uint8Array(r.buffer,r.byteOffset,r.byteLength))[0]?"big":204===n[0]?"little":"unknown"),U="big"===L,x="little"===L,T=function(t,e){var r=void 0===e?{}:e,n=r.signed,o=void 0!==n&&n,a=r.le,i=void 0!==a&&a;t=b(t);var u=i?"reduce":"reduceRight",f=(t[u]?t[u]:Array.prototype[u]).call(t,(function(e,r,n){var o=i?n:Math.abs(n+1-t.length);return e+A(r)*w[o]}),A(0));if(o){var c=w[t.length]/A(2)-A(1);(f=A(f))>c&&(f-=c,f-=c,f-=A(2))}return Number(f)},C=function(t,e){var r=(void 0===e?{}:e).le,n=void 0!==r&&r;("bigint"!=typeof t&&"number"!=typeof t||"number"==typeof t&&t!=t)&&(t=0),t=A(t);for(var o=g(t),a=new Uint8Array(new ArrayBuffer(o)),i=0;i<o;i++){var u=n?i:Math.abs(i+1-a.length);a[u]=Number(t/w[i]&A(255)),t<0&&(a[u]=Math.abs(~a[u]),a[u]-=0===i?1:2)}return a},S=function(t,e){if("string"!=typeof t&&t&&"function"==typeof t.toString&&(t=t.toString()),"string"!=typeof t)return new Uint8Array;e||(t=unescape(encodeURIComponent(t)));for(var r=new Uint8Array(t.length),n=0;n<t.length;n++)r[n]=t.charCodeAt(n);return r},E=function(t,e,r){var n=void 0===r?{}:r,o=n.offset,a=void 0===o?0:o,i=n.mask,u=void 0===i?[]:i;t=b(t);var f=(e=b(e)).every?e.every:Array.prototype.every;return e.length&&t.length-a>=e.length&&f.call(e,(function(e,r){return e===(u[r]?u[r]&t[a+r]:t[a+r])}))},k=Object.freeze({__proto__:null,countBits:y,countBytes:g,padStart:d,isTypedArray:m,toUint8:b,toHexString:function(t){t=b(t);for(var e="",r=0;r<t.length;r++)e+=d(t[r].toString(16),2,"0");return e},toBinaryString:function(t){t=b(t);for(var e="",r=0;r<t.length;r++)e+=d(t[r].toString(2),8,"0");return e},ENDIANNESS:L,IS_BIG_ENDIAN:U,IS_LITTLE_ENDIAN:x,bytesToNumber:T,numberToBytes:C,bytesToString:function(t){if(!t)return"";t=Array.prototype.slice.call(t);var e=String.fromCharCode.apply(null,b(t));try{return decodeURIComponent(escape(e))}catch(t){}return e},stringToBytes:S,concatTypedArrays:function(){for(var t=arguments.length,e=new Array(t),r=0;r<t;r++)e[r]=arguments[r];if((e=e.filter((function(t){return t&&(t.byteLength||t.length)&&"string"!=typeof t}))).length<=1)return b(e[0]);var n=e.reduce((function(t,e,r){return t+(e.byteLength||e.length)}),0),o=new Uint8Array(n),a=0;return e.forEach((function(t){t=b(t),o.set(t,a),a+=t.byteLength})),o},bytesMatch:E,sliceBytes:function(t,e,r){return Uint8Array.prototype.slice?Uint8Array.prototype.slice.call(t,e,r):new Uint8Array(Array.prototype.slice.call(t,e,r))},reverseBytes:function(t){return t.reverse?t.reverse():Array.prototype.reverse.call(t)}}),_=function(t){return"string"==typeof t?S(t):t},B=function t(e,r,n){void 0===n&&(n=!1),r=function(t){return Array.isArray(t)?t.map((function(t){return _(t)})):[_(t)]}(r),e=b(e);var o=[];if(!r.length)return o;for(var a=0;a<e.length;){var i=(e[a]<<24|e[a+1]<<16|e[a+2]<<8|e[a+3])>>>0,u=e.subarray(a+4,a+8);if(0===i)break;var f=a+i;if(f>e.length){if(n)break;f=e.length}var c=e.subarray(a+8,f);E(u,r[0])&&(1===r.length?o.push(c):o.push.apply(o,t(c,r.slice(1),n))),a=f}return o},D={EBML:b([26,69,223,163]),DocType:b([66,130]),Segment:b([24,83,128,103]),SegmentInfo:b([21,73,169,102]),Tracks:b([22,84,174,107]),Track:b([174]),TrackNumber:b([215]),DefaultDuration:b([35,227,131]),TrackEntry:b([174]),TrackType:b([131]),FlagDefault:b([136]),CodecID:b([134]),CodecPrivate:b([99,162]),VideoTrack:b([224]),AudioTrack:b([225]),Cluster:b([31,67,182,117]),Timestamp:b([231]),TimestampScale:b([42,215,177]),BlockGroup:b([160]),BlockDuration:b([155]),Block:b([161]),SimpleBlock:b([163])},R=[128,64,32,16,8,4,2,1],I=function(t,e,r,n){void 0===r&&(r=!0),void 0===n&&(n=!1);var o=function(t){for(var e=1,r=0;r<R.length&&!(t&R[r]);r++)e++;return e}(t[e]),a=t.subarray(e,e+o);return r&&((a=Array.prototype.slice.call(t,e,e+o))[0]^=R[o-1]),{length:o,value:T(a,{signed:n}),bytes:a}},N=function t(e){return"string"==typeof e?e.match(/.{1,2}/g).map((function(e){return t(e)})):"number"==typeof e?C(e):e},O=function t(e,r,n){if(n>=r.length)return r.length;var o=I(r,n,!1);if(E(e.bytes,o.bytes))return n;var a=I(r,n+o.length);return t(e,r,n+a.length+a.value+o.length)},z=function t(e,r){r=function(t){return Array.isArray(t)?t.map((function(t){return N(t)})):[N(t)]}(r),e=b(e);var n=[];if(!r.length)return n;for(var o=0;o<e.length;){var a=I(e,o,!1),i=I(e,o+a.length),u=o+a.length+i.length;127===i.value&&(i.value=O(a,e,u),i.value!==e.length&&(i.value-=u));var f=u+i.value>e.length?e.length:u+i.value,c=e.subarray(u,f);E(r[0],a.bytes)&&(1===r.length?n.push(c):n=n.concat(t(c,r.slice(1)))),o+=a.length+i.length+c.length}return n},M=b([73,68,51]),F=function t(e,r){return void 0===r&&(r=0),(e=b(e)).length-r<10||!E(e,M,{offset:r})?r:(r+=function(t,e){void 0===e&&(e=0);var r=(t=b(t))[e+5],n=t[e+6]<<21|t[e+7]<<14|t[e+8]<<7|t[e+9];return(16&r)>>4?n+20:n+10}(e,r),t(e,r))},j=b([0,0,0,1]),q=b([0,0,1]),P=b([0,0,3]),G=function(t){for(var e=[],r=1;r<t.length-2;)E(t.subarray(r,r+3),P)&&(e.push(r+2),r++),r++;if(0===e.length)return t;var n=t.length-e.length,o=new Uint8Array(n),a=0;for(r=0;r<n;a++,r++)a===e[0]&&(a++,e.shift()),o[r]=t[a];return o},V=function(t,e,r,n){void 0===n&&(n=1/0),t=b(t),r=[].concat(r);for(var o,a=0,i=0;a<t.length&&(i<n||o);){var u=void 0;if(E(t.subarray(a),j)?u=4:E(t.subarray(a),q)&&(u=3),u){if(i++,o)return G(t.subarray(o,a));var f=void 0;"h264"===e?f=31&t[a+u]:"h265"===e&&(f=t[a+u]>>1&63),-1!==r.indexOf(f)&&(o=a+u),a+=u+("h264"===e?1:2)}else a++}return t.subarray(0,0)},H={webm:b([119,101,98,109]),matroska:b([109,97,116,114,111,115,107,97]),flac:b([102,76,97,67]),ogg:b([79,103,103,83]),ac3:b([11,119]),riff:b([82,73,70,70]),avi:b([65,86,73]),wav:b([87,65,86,69]),"3gp":b([102,116,121,112,51,103]),mp4:b([102,116,121,112]),fmp4:b([115,116,121,112]),mov:b([102,116,121,112,113,116])},$={aac:function(t){var e=F(t);return E(t,[255,16],{offset:e,mask:[255,22]})},mp3:function(t){var e=F(t);return E(t,[255,2],{offset:e,mask:[255,6]})},webm:function(t){var e=z(t,[D.EBML,D.DocType])[0];return E(e,H.webm)},mkv:function(t){var e=z(t,[D.EBML,D.DocType])[0];return E(e,H.matroska)},mp4:function(t){return!$["3gp"](t)&&!$.mov(t)&&(E(t,H.mp4,{offset:4})||E(t,H.fmp4,{offset:4}))},mov:function(t){return E(t,H.mov,{offset:4})},"3gp":function(t){return E(t,H["3gp"],{offset:4})},ac3:function(t){var e=F(t);return E(t,H.ac3,{offset:e})},ts:function(t){if(t.length<189&&t.length>=1)return 71===t[0];for(var e=0;e+188<t.length&&e<188;){if(71===t[e]&&71===t[e+188])return!0;e+=1}return!1},flac:function(t){var e=F(t);return E(t,H.flac,{offset:e})},ogg:function(t){return E(t,H.ogg)},avi:function(t){return E(t,H.riff)&&E(t,H.avi,{offset:8})},wav:function(t){return E(t,H.riff)&&E(t,H.wav,{offset:8})},h264:function(t){return function(t,e,r){return V(t,"h264",e,r)}(t,7,3).length},h265:function(t){return function(t,e,r){return V(t,"h265",e,r)}(t,[32,33],3).length}},Z=Object.keys($).filter((function(t){return"ts"!==t&&"h264"!==t&&"h265"!==t})).concat(["ts","h264","h265"]);Z.forEach((function(t){var e=$[t];$[t]=function(t){return e(b(t))}}));var J=$,K=Object.freeze({__proto__:null,isLikely:J,detectContainerForBytes:function(t){t=b(t);for(var e=0;e<Z.length;e++){var r=Z[e];if(J[r](t))return r}return""},isLikelyFmp4MediaSegment:function(t){return B(t,["moof"]).length>0}});var Q=Object.freeze({__proto__:null,forEachMediaGroup:function(t,e,r){e.forEach((function(e){for(var n in t.mediaGroups[e])for(var o in t.mediaGroups[e][n]){var a=t.mediaGroups[e][n][o];r(a,e,n,o)}}))}});var W=function(t,e,r){return t(r={path:e,exports:{},require:function(t,e){return function(){throw new Error("Dynamic requires are not currently supported by @rollup/plugin-commonjs")}(null==e&&r.path)}},r.exports),r.exports}((function(t,e){var r,n,o,a,i;r=/^((?:[a-zA-Z0-9+\-.]+:)?)(\/\/[^\/?#]*)?((?:[^\/?#]*\/)*[^;?#]*)?(;[^?#]*)?(\?[^#]*)?(#.*)?$/,n=/^([^\/?#]*)(.*)$/,o=/(?:\/|^)\.(?=\/)/g,a=/(?:\/|^)\.\.\/(?!\.\.\/)[^\/]*(?=\/)/g,i={buildAbsoluteURL:function(t,e,r){if(r=r||{},t=t.trim(),!(e=e.trim())){if(!r.alwaysNormalize)return t;var o=i.parseURL(t);if(!o)throw new Error("Error trying to parse base URL.");return o.path=i.normalizePath(o.path),i.buildURLFromParts(o)}var a=i.parseURL(e);if(!a)throw new Error("Error trying to parse relative URL.");if(a.scheme)return r.alwaysNormalize?(a.path=i.normalizePath(a.path),i.buildURLFromParts(a)):e;var u=i.parseURL(t);if(!u)throw new Error("Error trying to parse base URL.");if(!u.netLoc&&u.path&&"/"!==u.path[0]){var f=n.exec(u.path);u.netLoc=f[1],u.path=f[2]}u.netLoc&&!u.path&&(u.path="/");var c={scheme:u.scheme,netLoc:a.netLoc,path:null,params:a.params,query:a.query,fragment:a.fragment};if(!a.netLoc&&(c.netLoc=u.netLoc,"/"!==a.path[0]))if(a.path){var s=u.path,l=s.substring(0,s.lastIndexOf("/")+1)+a.path;c.path=i.normalizePath(l)}else c.path=u.path,a.params||(c.params=u.params,a.query||(c.query=u.query));return null===c.path&&(c.path=r.alwaysNormalize?i.normalizePath(a.path):a.path),i.buildURLFromParts(c)},parseURL:function(t){var e=r.exec(t);return e?{scheme:e[1]||"",netLoc:e[2]||"",path:e[3]||"",params:e[4]||"",query:e[5]||"",fragment:e[6]||""}:null},normalizePath:function(t){for(t=t.split("").reverse().join("").replace(o,"");t.length!==(t=t.replace(a,"")).length;);return t.split("").reverse().join("")},buildURLFromParts:function(t){return t.scheme+t.netLoc+t.path+t.params+t.query+t.fragment}},t.exports=i})),X="http://example.com";return{codecs:v,byteHelpers:k,containers:K,decodeB64ToUint8Array:function(t){for(var e,r=(e=t,o.default.atob?o.default.atob(e):Buffer.from(e,"base64").toString("binary")),n=new Uint8Array(r.length),a=0;a<r.length;a++)n[a]=r.charCodeAt(a);return n},mediaGroups:Q,resolveUrl:function(t,e){if(/^[a-z]+:/i.test(e))return e;/^data:/.test(t)&&(t=o.default.location&&o.default.location.href||"");var r="function"==typeof o.default.URL,n=/^\/\//.test(t),a=!o.default.location&&!/\/\//i.test(t);if(r?t=new o.default.URL(t,o.default.location||X):/\/\//i.test(t)||(t=W.buildAbsoluteURL(o.default.location&&o.default.location.href||"",t)),r){var i=new URL(e,t);return a?i.href.slice(X.length):n?i.href.slice(i.protocol.length):i.href}return W.buildAbsoluteURL(t,e)},Stream:function(){function t(){this.listeners={}}var e=t.prototype;return e.on=function(t,e){this.listeners[t]||(this.listeners[t]=[]),this.listeners[t].push(e)},e.off=function(t,e){if(!this.listeners[t])return!1;var r=this.listeners[t].indexOf(e);return this.listeners[t]=this.listeners[t].slice(0),this.listeners[t].splice(r,1),r>-1},e.trigger=function(t){var e=this.listeners[t];if(e)if(2===arguments.length)for(var r=e.length,n=0;n<r;++n)e[n].call(this,arguments[1]);else for(var o=Array.prototype.slice.call(arguments,1),a=e.length,i=0;i<a;++i)e[i].apply(this,o)},e.dispose=function(){this.listeners={}},e.pipe=function(t){this.on("data",(function(e){t.push(e)}))},t}()}})); |
@@ -9,2 +9,7 @@ import URLToolkit from 'url-toolkit'; | ||
return relativeUrl; | ||
} // if baseUrl is a data URI, ignore it and resolve everything relative to window.location | ||
if (/^data:/.test(baseUrl)) { | ||
baseUrl = window.location && window.location.href || ''; | ||
} // IE11 supports URL but not the URL constructor | ||
@@ -11,0 +16,0 @@ // feature detect the behavior we want |
{ | ||
"name": "@videojs/vhs-utils", | ||
"version": "3.0.1", | ||
"version": "3.0.2", | ||
"description": "Objects and functions shared throughtout @videojs/http-streaming code", | ||
@@ -5,0 +5,0 @@ "repository": { |
@@ -12,2 +12,7 @@ import URLToolkit from 'url-toolkit'; | ||
// if baseUrl is a data URI, ignore it and resolve everything relative to window.location | ||
if ((/^data:/).test(baseUrl)) { | ||
baseUrl = window.location && window.location.href || ''; | ||
} | ||
// IE11 supports URL but not the URL constructor | ||
@@ -14,0 +19,0 @@ // feature detect the behavior we want |
@@ -11,5 +11,7 @@ import QUnit from 'qunit'; | ||
let currentLocation = ''; | ||
let currentPath = ''; | ||
if (window.location && window.location.protocol) { | ||
currentLocation = window.location.protocol + '//' + window.location.host; | ||
currentPath = window.location.pathname.split('/').slice(0, -1).join('/'); | ||
} | ||
@@ -29,2 +31,21 @@ | ||
assert.equal(resolveUrl('/a/b/cd/e.m3u8', '../../../z.ts'), currentLocation + '/z.ts'); | ||
assert.equal( | ||
resolveUrl('data:application/dash+xml;charset=utf-8,http%3A%2F%2Fexample.com', 'hello.m3u8'), | ||
// we need to add the currentPath because we're actually working relative to window.location | ||
currentLocation + currentPath + '/hello.m3u8', | ||
'resolves urls relative to window when given a data base url' | ||
); | ||
assert.equal( | ||
resolveUrl('data:application/dash+xml;charset=utf-8,http%3A%2F%2Fexample.com', 'http://example.com/hello.m3u8'), | ||
'http://example.com/hello.m3u8', | ||
'absolute urls should still be absolute even with a data uri' | ||
); | ||
assert.equal( | ||
resolveUrl('http://example.com', 'data:application/dash+xml;charset=utf-8,http%3A%2F%2Fexample.com'), | ||
'data:application/dash+xml;charset=utf-8,http%3A%2F%2Fexample.com', | ||
'data uri is treated as an absolute url' | ||
); | ||
}); |
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
4487896
10585