@100mslive/hls-stats 0.2.9 → 0.2.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs.js CHANGED
@@ -1,2 +1,2 @@
1
- var u=Object.create;var r=Object.defineProperty,E=Object.defineProperties,b=Object.getOwnPropertyDescriptor,g=Object.getOwnPropertyDescriptors,I=Object.getOwnPropertyNames,p=Object.getOwnPropertySymbols,L=Object.getPrototypeOf,S=Object.prototype.hasOwnProperty,y=Object.prototype.propertyIsEnumerable;var v=(e,t,s)=>t in e?r(e,t,{enumerable:!0,configurable:!0,writable:!0,value:s}):e[t]=s,l=(e,t)=>{for(var s in t||(t={}))S.call(t,s)&&v(e,s,t[s]);if(p)for(var s of p(t))y.call(t,s)&&v(e,s,t[s]);return e},o=(e,t)=>E(e,g(t)),f=e=>r(e,"__esModule",{value:!0});var A=(e,t)=>{f(e);for(var s in t)r(e,s,{get:t[s],enumerable:!0})},G=(e,t,s)=>{if(t&&typeof t=="object"||typeof t=="function")for(let a of I(t))!S.call(e,a)&&a!=="default"&&r(e,a,{get:()=>t[a],enumerable:!(s=b(t,a))||s.enumerable});return e},F=e=>G(f(r(e!=null?u(L(e)):{},"default",e&&e.__esModule&&"default"in e?{get:()=>e.default,enumerable:!0}:{value:e,enumerable:!0})),e);A(exports,{HlsStats:()=>m});var n=F(require("hls.js"));var h=class{constructor(t,s){this.hlsStatsState={};this.hlsInstance=t,this.videoEl=s}getState(){return this.hlsStatsState}};var c=class extends h{constructor(){super(...arguments);this.timeUpdateHandler=()=>{let t=this.videoEl.buffered.length>0?this.videoEl.buffered.end(0)-this.videoEl.buffered.start(0):0,s=(this.hlsInstance.liveSyncPosition?this.hlsInstance.liveSyncPosition-this.videoEl.currentTime:0)*1e3,i=this.videoEl.getVideoPlaybackQuality().droppedVideoFrames;this.hlsStatsState=o(l({},this.hlsStatsState),{distanceFromLive:s>0?s:0,bufferedDuration:t,droppedFrames:i})};this.levelLoadedHandler=(t,{level:s})=>{let a=this.hlsInstance.levels[s],{bitrate:i,height:d,width:H}=a;this.hlsStatsState=o(l({},this.hlsStatsState),{bitrate:i,videoSize:{height:d,width:H}})};this.fragChangedHandler=(t,{frag:s})=>{let{stats:a,baseurl:i}=s,{bwEstimate:d}=a;this.hlsStatsState=o(l({},this.hlsStatsState),{bandwidthEstimate:d,url:i})}}startGatheringStats(){this.hlsInstance.on(n.default.Events.FRAG_CHANGED,this.fragChangedHandler),this.hlsInstance.on(n.default.Events.LEVEL_LOADED,this.levelLoadedHandler),this.videoEl.addEventListener("timeupdate",this.timeUpdateHandler)}finishGatheringStats(){this.videoEl.removeEventListener("timeupdate",this.timeUpdateHandler),this.hlsInstance.off(n.default.Events.FRAG_CHANGED,this.fragChangedHandler),this.hlsInstance.off(n.default.Events.LEVEL_LOADED,this.levelLoadedHandler)}};var m=class{constructor(t,s){this.intervalFunctionId=-1;this.subscribe=(t,s=2e3)=>(this.adapter.startGatheringStats(),this.intervalFunctionId=setInterval(()=>{t(this.getState())},s),this.unsubscribe);this.unsubscribe=()=>{clearInterval(this.intervalFunctionId),this.adapter.finishGatheringStats()};this.getState=()=>this.adapter.getState();let a=new c(t,s);this.adapter=a}};
1
+ "use strict";var H=Object.create;var n=Object.defineProperty,b=Object.defineProperties,g=Object.getOwnPropertyDescriptor,I=Object.getOwnPropertyDescriptors,L=Object.getOwnPropertyNames,v=Object.getOwnPropertySymbols,y=Object.getPrototypeOf,f=Object.prototype.hasOwnProperty,G=Object.prototype.propertyIsEnumerable;var p=(s,t,e)=>t in s?n(s,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):s[t]=e,o=(s,t)=>{for(var e in t||(t={}))f.call(t,e)&&p(s,e,t[e]);if(v)for(var e of v(t))G.call(t,e)&&p(s,e,t[e]);return s},d=(s,t)=>b(s,I(t));var A=(s,t)=>{for(var e in t)n(s,e,{get:t[e],enumerable:!0})},u=(s,t,e,a)=>{if(t&&typeof t=="object"||typeof t=="function")for(let i of L(t))!f.call(s,i)&&i!==e&&n(s,i,{get:()=>t[i],enumerable:!(a=g(t,i))||a.enumerable});return s};var F=(s,t,e)=>(e=s!=null?H(y(s)):{},u(t||!s||!s.__esModule?n(e,"default",{value:s,enumerable:!0}):e,s)),x=s=>u(n({},"__esModule",{value:!0}),s);var P={};A(P,{HlsStats:()=>m});module.exports=x(P);var l=F(require("hls.js"));var h=class{constructor(t,e){this.hlsStatsState={};this.hlsInstance=t,this.videoEl=e}getState(){return this.hlsStatsState}};var c=class extends h{constructor(){super(...arguments);this.timeUpdateHandler=()=>{let e=this.videoEl.buffered.length>0?this.videoEl.buffered.end(0)-this.videoEl.buffered.start(0):0,a=(this.hlsInstance.liveSyncPosition?this.hlsInstance.liveSyncPosition-this.videoEl.currentTime:0)*1e3,r=this.videoEl.getVideoPlaybackQuality().droppedVideoFrames;this.hlsStatsState=d(o({},this.hlsStatsState),{distanceFromLive:a>0?a:0,bufferedDuration:e,droppedFrames:r})};this.levelLoadedHandler=(e,{level:a})=>{let i=this.hlsInstance.levels[a],{bitrate:r,height:S,width:E}=i;this.hlsStatsState=d(o({},this.hlsStatsState),{bitrate:r,videoSize:{height:S,width:E}})};this.fragChangedHandler=(e,{frag:a})=>{let{stats:i,baseurl:r}=a,{bwEstimate:S}=i;this.hlsStatsState=d(o({},this.hlsStatsState),{bandwidthEstimate:S,url:r})}}startGatheringStats(){this.hlsInstance.on(l.default.Events.FRAG_CHANGED,this.fragChangedHandler),this.hlsInstance.on(l.default.Events.LEVEL_LOADED,this.levelLoadedHandler),this.videoEl.addEventListener("timeupdate",this.timeUpdateHandler)}finishGatheringStats(){this.videoEl.removeEventListener("timeupdate",this.timeUpdateHandler),this.hlsInstance.off(l.default.Events.FRAG_CHANGED,this.fragChangedHandler),this.hlsInstance.off(l.default.Events.LEVEL_LOADED,this.levelLoadedHandler)}};var m=class{constructor(t,e){this.intervalFunctionId=-1;this.subscribe=(t,e=2e3)=>(this.adapter.startGatheringStats(),this.intervalFunctionId=setInterval(()=>{t(this.getState())},e),this.unsubscribe);this.unsubscribe=()=>{clearInterval(this.intervalFunctionId),this.adapter.finishGatheringStats()};this.getState=()=>this.adapter.getState();let a=new c(t,e);this.adapter=a}};
2
2
  //# sourceMappingURL=index.cjs.js.map
@@ -2,6 +2,6 @@
2
2
  "version": 3,
3
3
  "sources": ["../src/index.ts", "../src/adapters/HlsJsAdapter.ts", "../src/adapters/BaseAdapter.ts", "../src/controllers/HlsStats.ts"],
4
4
  "sourcesContent": ["export { HlsStats } from './controllers/HlsStats';\nexport type { IHlsStats } from './interfaces/IHlsStats';\nexport type { HlsPlayerStats } from './interfaces/index';\n", "import Hls from 'hls.js';\nimport { BaseAdapter } from './BaseAdapter';\n\nexport class HlsJsAdapter extends BaseAdapter {\n timeUpdateHandler = () => {\n const bufferedDuration =\n this.videoEl.buffered.length > 0 ? this.videoEl.buffered.end(0) - this.videoEl.buffered.start(0) : 0;\n const distanceFromLive =\n (this.hlsInstance.liveSyncPosition ? this.hlsInstance.liveSyncPosition - this.videoEl.currentTime : 0) * 1000;\n const quality = this.videoEl.getVideoPlaybackQuality();\n const droppedFrames = quality.droppedVideoFrames;\n this.hlsStatsState = {\n ...this.hlsStatsState,\n distanceFromLive: distanceFromLive > 0 ? distanceFromLive : 0,\n bufferedDuration,\n droppedFrames,\n };\n };\n\n levelLoadedHandler = (_: any, { level }: { level: number }) => {\n const currentLevel = this.hlsInstance.levels[level];\n const { bitrate, height, width } = currentLevel;\n this.hlsStatsState = {\n ...this.hlsStatsState,\n bitrate,\n videoSize: {\n height,\n width,\n },\n };\n };\n\n fragChangedHandler = (_: any, { frag }: { frag: { stats: { bwEstimate: number }; baseurl: string } }) => {\n const { stats, baseurl } = frag;\n const { bwEstimate } = stats;\n this.hlsStatsState = {\n ...this.hlsStatsState,\n bandwidthEstimate: bwEstimate,\n url: baseurl,\n };\n };\n\n startGatheringStats(): void {\n this.hlsInstance.on(Hls.Events.FRAG_CHANGED, this.fragChangedHandler);\n this.hlsInstance.on(Hls.Events.LEVEL_LOADED, this.levelLoadedHandler);\n this.videoEl.addEventListener('timeupdate', this.timeUpdateHandler);\n }\n\n finishGatheringStats(): void {\n this.videoEl.removeEventListener('timeupdate', this.timeUpdateHandler);\n this.hlsInstance.off(Hls.Events.FRAG_CHANGED, this.fragChangedHandler);\n this.hlsInstance.off(Hls.Events.LEVEL_LOADED, this.levelLoadedHandler);\n }\n}\n", "import Hls from 'hls.js';\nimport { HlsPlayerStats } from '../interfaces';\nexport abstract class BaseAdapter {\n hlsInstance: Hls;\n videoEl: HTMLVideoElement;\n hlsStatsState: HlsPlayerStats = {};\n constructor(hlsInstance: Hls, videoEl: HTMLVideoElement) {\n this.hlsInstance = hlsInstance;\n this.videoEl = videoEl;\n }\n abstract startGatheringStats(): void;\n abstract finishGatheringStats(): void;\n getState() {\n return this.hlsStatsState;\n }\n}\n", "import Hls from 'hls.js';\nimport { BaseAdapter } from '../adapters/BaseAdapter';\nimport { HlsJsAdapter } from '../adapters/HlsJsAdapter';\nimport { HlsPlayerStats } from '../interfaces';\nimport { IHlsStats } from '../interfaces/IHlsStats';\n\nexport class HlsStats implements IHlsStats {\n adapter: BaseAdapter;\n intervalFunctionId = -1;\n constructor(hlsLibraryInstance: Hls, videoEl: HTMLVideoElement) {\n const hlsJsAdapter = new HlsJsAdapter(hlsLibraryInstance, videoEl);\n this.adapter = hlsJsAdapter;\n }\n\n subscribe = (callback: (state: HlsPlayerStats) => void, interval = 2000) => {\n this.adapter.startGatheringStats();\n //@ts-ignore\n this.intervalFunctionId = setInterval(() => {\n callback(this.getState());\n }, interval);\n return this.unsubscribe;\n };\n unsubscribe = () => {\n clearInterval(this.intervalFunctionId);\n this.adapter.finishGatheringStats();\n };\n\n getState = () => {\n return this.adapter.getState();\n };\n}\n"],
5
- "mappings": "s6BAAA,4BCAA,MAAgB,qBCET,WAA2B,CAIhC,YAAY,EAAkB,EAA2B,CADzD,mBAAgC,GAE9B,KAAK,YAAc,EACnB,KAAK,QAA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IF,EACrB,CAAE,WAAAG,CAAW,EAAIF,EACvB,KAAK,cAAgBT,EAAAC,EAAA,GAChB,KAAK,eADW,CAEnB,kBAAmBU,EACnB,IAAKD,CACP,EACF,EAEA,qBAA4B,CAC1B,KAAK,YAAY,GAAG,EAAAE,QAAI,OAAO,aAAc,KAAK,kBAAkB,EACpE,KAAK,YAAY,GAAG,EAAAA,QAAI,OAAO,aAAc,KAAK,kBAAkB,EACpE,KAAK,QAAQ,iBAAiB,aAAc,KAAK,iBAAiB,CACpE,CAEA,sBAA6B,CAC3B,KAAK,QAAQ,oBAAoB,aAAc,KAAK,iBAAiB,EACrE,KAAK,YAAY,IAAI,EAAAA,QAAI,OAAO,aAAc,KAAK,kBAAkB,EACrE,KAAK,YAAY,IAAI,EAAAA,QAAI,OAAO,aAAc,KAAK,kBAAkB,CACvE,CACF,EE/CO,IAAMC,EAAN,KAAoC,CAGzC,YAAYC,EAAyBC,EAA2B,CADhE,wBAAqB,GAMrB,eAAY,CAACC,EAA2CC,EAAW,OACjE,KAAK,QAAQ,oBAAoB,EAEjC,KAAK,mBAAqB,YAAY,IAAM,CAC1CD,EAAS,KAAK,SAAS,CAAC,CAC1B,EAAGC,CAAQ,EACJ,KAAK,aAEd,iBAAc,IAAM,CAClB,cAAc,KAAK,kBAAkB,EACrC,KAAK,QAAQ,qBAAqB,CACpC,EAEA,cAAW,IACF,KAAK,QAAQ,SAAS,EAlB7B,IAAMC,EAAe,IAAIC,EAAaL,EAAoBC,CAAO,EACjE,KAAK,QAAUG,CACjB,CAkBF",
6
+ "names": ["src_exports", "__export", "HlsStats", "__toCommonJS", "import_hls", "BaseAdapter", "hlsInstance", "videoEl", "HlsJsAdapter", "BaseAdapter", "bufferedDuration", "distanceFromLive", "droppedFrames", "__spreadProps", "__spreadValues", "_", "level", "currentLevel", "bitrate", "height", "width", "frag", "stats", "baseurl", "bwEstimate", "Hls", "HlsStats", "hlsLibraryInstance", "videoEl", "callback", "interval", "hlsJsAdapter", "HlsJsAdapter"]
7
7
  }
package/dist/index.js CHANGED
@@ -1,2 +1,2 @@
1
- var v=Object.defineProperty,f=Object.defineProperties;var H=Object.getOwnPropertyDescriptors;var c=Object.getOwnPropertySymbols;var u=Object.prototype.hasOwnProperty,E=Object.prototype.propertyIsEnumerable;var m=(s,e,t)=>e in s?v(s,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):s[e]=t,r=(s,e)=>{for(var t in e||(e={}))u.call(e,t)&&m(s,t,e[t]);if(c)for(var t of c(e))E.call(e,t)&&m(s,t,e[t]);return s},n=(s,e)=>f(s,H(e));import l from"hls.js";var d=class{constructor(e,t){this.hlsStatsState={};this.hlsInstance=e,this.videoEl=t}getState(){return this.hlsStatsState}};var h=class extends d{constructor(){super(...arguments);this.timeUpdateHandler=()=>{let e=this.videoEl.buffered.length>0?this.videoEl.buffered.end(0)-this.videoEl.buffered.start(0):0,t=(this.hlsInstance.liveSyncPosition?this.hlsInstance.liveSyncPosition-this.videoEl.currentTime:0)*1e3,i=this.videoEl.getVideoPlaybackQuality().droppedVideoFrames;this.hlsStatsState=n(r({},this.hlsStatsState),{distanceFromLive:t>0?t:0,bufferedDuration:e,droppedFrames:i})};this.levelLoadedHandler=(e,{level:t})=>{let a=this.hlsInstance.levels[t],{bitrate:i,height:o,width:S}=a;this.hlsStatsState=n(r({},this.hlsStatsState),{bitrate:i,videoSize:{height:o,width:S}})};this.fragChangedHandler=(e,{frag:t})=>{let{stats:a,baseurl:i}=t,{bwEstimate:o}=a;this.hlsStatsState=n(r({},this.hlsStatsState),{bandwidthEstimate:o,url:i})}}startGatheringStats(){this.hlsInstance.on(l.Events.FRAG_CHANGED,this.fragChangedHandler),this.hlsInstance.on(l.Events.LEVEL_LOADED,this.levelLoadedHandler),this.videoEl.addEventListener("timeupdate",this.timeUpdateHandler)}finishGatheringStats(){this.videoEl.removeEventListener("timeupdate",this.timeUpdateHandler),this.hlsInstance.off(l.Events.FRAG_CHANGED,this.fragChangedHandler),this.hlsInstance.off(l.Events.LEVEL_LOADED,this.levelLoadedHandler)}};var p=class{constructor(e,t){this.intervalFunctionId=-1;this.subscribe=(e,t=2e3)=>(this.adapter.startGatheringStats(),this.intervalFunctionId=setInterval(()=>{e(this.getState())},t),this.unsubscribe);this.unsubscribe=()=>{clearInterval(this.intervalFunctionId),this.adapter.finishGatheringStats()};this.getState=()=>this.adapter.getState();let a=new h(e,t);this.adapter=a}};export{p as HlsStats};
1
+ var f=Object.defineProperty,u=Object.defineProperties;var E=Object.getOwnPropertyDescriptors;var S=Object.getOwnPropertySymbols;var H=Object.prototype.hasOwnProperty,b=Object.prototype.propertyIsEnumerable;var v=(s,e,t)=>e in s?f(s,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):s[e]=t,n=(s,e)=>{for(var t in e||(e={}))H.call(e,t)&&v(s,t,e[t]);if(S)for(var t of S(e))b.call(e,t)&&v(s,t,e[t]);return s},l=(s,e)=>u(s,E(e));import d from"hls.js";var o=class{constructor(e,t){this.hlsStatsState={};this.hlsInstance=e,this.videoEl=t}getState(){return this.hlsStatsState}};var h=class extends o{constructor(){super(...arguments);this.timeUpdateHandler=()=>{let t=this.videoEl.buffered.length>0?this.videoEl.buffered.end(0)-this.videoEl.buffered.start(0):0,a=(this.hlsInstance.liveSyncPosition?this.hlsInstance.liveSyncPosition-this.videoEl.currentTime:0)*1e3,i=this.videoEl.getVideoPlaybackQuality().droppedVideoFrames;this.hlsStatsState=l(n({},this.hlsStatsState),{distanceFromLive:a>0?a:0,bufferedDuration:t,droppedFrames:i})};this.levelLoadedHandler=(t,{level:a})=>{let r=this.hlsInstance.levels[a],{bitrate:i,height:c,width:p}=r;this.hlsStatsState=l(n({},this.hlsStatsState),{bitrate:i,videoSize:{height:c,width:p}})};this.fragChangedHandler=(t,{frag:a})=>{let{stats:r,baseurl:i}=a,{bwEstimate:c}=r;this.hlsStatsState=l(n({},this.hlsStatsState),{bandwidthEstimate:c,url:i})}}startGatheringStats(){this.hlsInstance.on(d.Events.FRAG_CHANGED,this.fragChangedHandler),this.hlsInstance.on(d.Events.LEVEL_LOADED,this.levelLoadedHandler),this.videoEl.addEventListener("timeupdate",this.timeUpdateHandler)}finishGatheringStats(){this.videoEl.removeEventListener("timeupdate",this.timeUpdateHandler),this.hlsInstance.off(d.Events.FRAG_CHANGED,this.fragChangedHandler),this.hlsInstance.off(d.Events.LEVEL_LOADED,this.levelLoadedHandler)}};var m=class{constructor(e,t){this.intervalFunctionId=-1;this.subscribe=(e,t=2e3)=>(this.adapter.startGatheringStats(),this.intervalFunctionId=setInterval(()=>{e(this.getState())},t),this.unsubscribe);this.unsubscribe=()=>{clearInterval(this.intervalFunctionId),this.adapter.finishGatheringStats()};this.getState=()=>this.adapter.getState();let a=new h(e,t);this.adapter=a}};export{m as HlsStats};
2
2
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -2,6 +2,6 @@
2
2
  "version": 3,
3
3
  "sources": ["../src/adapters/HlsJsAdapter.ts", "../src/adapters/BaseAdapter.ts", "../src/controllers/HlsStats.ts"],
4
4
  "sourcesContent": ["import Hls from 'hls.js';\nimport { BaseAdapter } from './BaseAdapter';\n\nexport class HlsJsAdapter extends BaseAdapter {\n timeUpdateHandler = () => {\n const bufferedDuration =\n this.videoEl.buffered.length > 0 ? this.videoEl.buffered.end(0) - this.videoEl.buffered.start(0) : 0;\n const distanceFromLive =\n (this.hlsInstance.liveSyncPosition ? this.hlsInstance.liveSyncPosition - this.videoEl.currentTime : 0) * 1000;\n const quality = this.videoEl.getVideoPlaybackQuality();\n const droppedFrames = quality.droppedVideoFrames;\n this.hlsStatsState = {\n ...this.hlsStatsState,\n distanceFromLive: distanceFromLive > 0 ? distanceFromLive : 0,\n bufferedDuration,\n droppedFrames,\n };\n };\n\n levelLoadedHandler = (_: any, { level }: { level: number }) => {\n const currentLevel = this.hlsInstance.levels[level];\n const { bitrate, height, width } = currentLevel;\n this.hlsStatsState = {\n ...this.hlsStatsState,\n bitrate,\n videoSize: {\n height,\n width,\n },\n };\n };\n\n fragChangedHandler = (_: any, { frag }: { frag: { stats: { bwEstimate: number }; baseurl: string } }) => {\n const { stats, baseurl } = frag;\n const { bwEstimate } = stats;\n this.hlsStatsState = {\n ...this.hlsStatsState,\n bandwidthEstimate: bwEstimate,\n url: baseurl,\n };\n };\n\n startGatheringStats(): void {\n this.hlsInstance.on(Hls.Events.FRAG_CHANGED, this.fragChangedHandler);\n this.hlsInstance.on(Hls.Events.LEVEL_LOADED, this.levelLoadedHandler);\n this.videoEl.addEventListener('timeupdate', this.timeUpdateHandler);\n }\n\n finishGatheringStats(): void {\n this.videoEl.removeEventListener('timeupdate', this.timeUpdateHandler);\n this.hlsInstance.off(Hls.Events.FRAG_CHANGED, this.fragChangedHandler);\n this.hlsInstance.off(Hls.Events.LEVEL_LOADED, this.levelLoadedHandler);\n }\n}\n", "import Hls from 'hls.js';\nimport { HlsPlayerStats } from '../interfaces';\nexport abstract class BaseAdapter {\n hlsInstance: Hls;\n videoEl: HTMLVideoElement;\n hlsStatsState: HlsPlayerStats = {};\n constructor(hlsInstance: Hls, videoEl: HTMLVideoElement) {\n this.hlsInstance = hlsInstance;\n this.videoEl = videoEl;\n }\n abstract startGatheringStats(): void;\n abstract finishGatheringStats(): void;\n getState() {\n return this.hlsStatsState;\n }\n}\n", "import Hls from 'hls.js';\nimport { BaseAdapter } from '../adapters/BaseAdapter';\nimport { HlsJsAdapter } from '../adapters/HlsJsAdapter';\nimport { HlsPlayerStats } from '../interfaces';\nimport { IHlsStats } from '../interfaces/IHlsStats';\n\nexport class HlsStats implements IHlsStats {\n adapter: BaseAdapter;\n intervalFunctionId = -1;\n constructor(hlsLibraryInstance: Hls, videoEl: HTMLVideoElement) {\n const hlsJsAdapter = new HlsJsAdapter(hlsLibraryInstance, videoEl);\n this.adapter = hlsJsAdapter;\n }\n\n subscribe = (callback: (state: HlsPlayerStats) => void, interval = 2000) => {\n this.adapter.startGatheringStats();\n //@ts-ignore\n this.intervalFunctionId = setInterval(() => {\n callback(this.getState());\n }, interval);\n return this.unsubscribe;\n };\n unsubscribe = () => {\n clearInterval(this.intervalFunctionId);\n this.adapter.finishGatheringStats();\n };\n\n getState = () => {\n return this.adapter.getState();\n };\n}\n"],
5
- "mappings": "6aAAA,sBCEO,WAA2B,CAIhC,YAAY,EAAkB,EAA2B,CADzD,mBAAgC,GAE9B,KAAK,YAAc,EACnB,KAAK,QAAU,EAIjB,UAAW,CACT,MAAO,MAAK,gBDVT,mBAA2B,EAAY,CAAvC,aAHP,CAGO,oBACL,uBAAoB,IAAM,CACxB,GAAM,GACJ,KAAK,QAAQ,SAAS,OAAS,EAAI,KAAK,QAAQ,SAAS,IAAI,GAAK,KAAK,QAAQ,SAAS,MAAM,GAAK,EAC/F,EACH,MAAK,YAAY,iBAAmB,KAAK,YAAY,iBAAmB,KAAK,QAAQ,YAAc,GAAK,IAErG,EAAgB,AADN,KAAK,QAAQ,0BACC,mBAC9B,KAAK,cAAgB,OAChB,KAAK,eADW,CAEnB,iBAAkB,EAAmB,EAAI,EAAmB,EAC5D,mBACA,mBAIJ,wBAAqB,CAAC,EAAQ,CAAE,WAA+B,CAC7D,GAAM,GAAe,KAAK,YAAY,OAAO,GACvC,CAAE,UAAS,SAAQ,SAAU,EACnC,KAAK,cAAgB,OAChB,KAAK,eADW,CAEnB,UACA,UAAW,CACT,SACA,YAKN,wBAAqB,CAAC,EAAQ,CAAE,UAAyE,CACvG,GAAM,CAAE,QAAO,WAAY,EACrB,CAAE,cAAe,EACvB,KAAK,cAAgB,OAChB,KAAK,eADW,CAEnB,kBAAmB,EACnB,IAAK,KAIT,qBAA4B,CAC1B,KAAK,YAAY,GAAG,EAAI,OAAO,aAAc,KAAK,oBAClD,KAAK,YAAY,GAAG,EAAI,OAAO,aAAc,KAAK,oBAClD,KAAK,QAAQ,iBAAiB,aAAc,KAAK,mBAGnD,sBAA6B,CAC3B,KAAK,QAAQ,oBAAoB,aAAc,KAAK,mBACpD,KAAK,YAAY,IAAI,EAAI,OAAO,aA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eADW,CAEnB,QAAAI,EACA,UAAW,CACT,OAAAC,EACA,MAAAC,CACF,CACF,EACF,EAEA,wBAAqB,CAACL,EAAQ,CAAE,KAAAM,CAAK,IAAoE,CACvG,GAAM,CAAE,MAAAC,EAAO,QAAAC,CAAQ,EAAIF,EACrB,CAAE,WAAAG,CAAW,EAAIF,EACvB,KAAK,cAAgBT,EAAAC,EAAA,GAChB,KAAK,eADW,CAEnB,kBAAmBU,EACnB,IAAKD,CACP,EACF,EAEA,qBAA4B,CAC1B,KAAK,YAAY,GAAGE,EAAI,OAAO,aAAc,KAAK,kBAAkB,EACpE,KAAK,YAAY,GAAGA,EAAI,OAAO,aAAc,KAAK,kBAAkB,EACpE,KAAK,QAAQ,iBAAiB,aAAc,KAAK,iBAAiB,CACpE,CAEA,sBAA6B,CAC3B,KAAK,QAAQ,oBAAoB,aAAc,KAAK,iBAAiB,EACrE,KAAK,YAAY,IAAIA,EAAI,OAAO,aAAc,KAAK,kBAAkB,EACrE,KAAK,YAAY,IAAIA,EAAI,OAAO,aAAc,KAAK,kBAAkB,CACvE,CACF,EE/CO,IAAMC,EAAN,KAAoC,CAGzC,YAAYC,EAAyBC,EAA2B,CADhE,wBAAqB,GAMrB,eAAY,CAACC,EAA2CC,EAAW,OACjE,KAAK,QAAQ,oBAAoB,EAEjC,KAAK,mBAAqB,YAAY,IAAM,CAC1CD,EAAS,KAAK,SAAS,CAAC,CAC1B,EAAGC,CAAQ,EACJ,KAAK,aAEd,iBAAc,IAAM,CAClB,cAAc,KAAK,kBAAkB,EACrC,KAAK,QAAQ,qBAAqB,CACpC,EAEA,cAAW,IACF,KAAK,QAAQ,SAAS,EAlB7B,IAAMC,EAAe,IAAIC,EAAaL,EAAoBC,CAAO,EACjE,KAAK,QAAUG,CACjB,CAkBF",
6
+ "names": ["Hls", "BaseAdapter", "hlsInstance", "videoEl", "HlsJsAdapter", "BaseAdapter", "bufferedDuration", "distanceFromLive", "droppedFrames", "__spreadProps", "__spreadValues", "_", "level", "currentLevel", "bitrate", "height", "width", "frag", "stats", "baseurl", "bwEstimate", "Hls", "HlsStats", "hlsLibraryInstance", "videoEl", "callback", "interval", "hlsJsAdapter", "HlsJsAdapter"]
7
7
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@100mslive/hls-stats",
3
- "version": "0.2.9",
3
+ "version": "0.2.10",
4
4
  "description": "A simple library that provides stats for your hls stream",
5
5
  "main": "dist/index.cjs.js",
6
6
  "module": "dist/index.js",
@@ -36,5 +36,5 @@
36
36
  "peerDependencies": {
37
37
  "hls.js": "^1.3.0"
38
38
  },
39
- "gitHead": "15cb6d59a886be7d2ba20d442e58f724a790d424"
39
+ "gitHead": "fe8f6b9b3b39b210c46f19c021ccf37c654c32d4"
40
40
  }