@dolbyio/webrtc-stats
Version:
Dolby OptiView WebRTC Statistics
3 lines (2 loc) • 13.9 kB
JavaScript
(()=>{var U=Object.create;var E=Object.defineProperty;var G=Object.getOwnPropertyDescriptor;var J=Object.getOwnPropertyNames;var $=Object.getPrototypeOf,z=Object.prototype.hasOwnProperty;var w=(i,e)=>()=>{try{return e||i((e={exports:{}}).exports,e),e.exports}catch(n){throw e=0,n}};var X=(i,e,n,t)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of J(e))!z.call(i,r)&&r!==n&&E(i,r,{get:()=>e[r],enumerable:!(t=G(e,r))||t.enumerable});return i};var C=(i,e,n)=>(n=i!=null?U($(i)):{},X(e||!i||!i.__esModule?E(n,"default",{value:i,enumerable:!0}):n,i));var T=w((y,g)=>{(function(i){"use strict";var e={};e.VERSION="1.6.1";var n,t={},r=function(s,d){return function(){return d.apply(s,arguments)}},a=function(){var s=arguments,d=s[0],l,p;for(p=1;p<s.length;p++)for(l in s[p])!(l in d)&&s[p].hasOwnProperty(l)&&(d[l]=s[p][l]);return d},o=function(s,d){return{value:s,name:d}};e.TRACE=o(1,"TRACE"),e.DEBUG=o(2,"DEBUG"),e.INFO=o(3,"INFO"),e.TIME=o(4,"TIME"),e.WARN=o(5,"WARN"),e.ERROR=o(8,"ERROR"),e.OFF=o(99,"OFF");var c=function(s){this.context=s,this.setLevel(s.filterLevel),this.log=this.info};c.prototype={setLevel:function(s){s&&"value"in s&&(this.context.filterLevel=s)},getLevel:function(){return this.context.filterLevel},enabledFor:function(s){var d=this.context.filterLevel;return s.value>=d.value},trace:function(){this.invoke(e.TRACE,arguments)},debug:function(){this.invoke(e.DEBUG,arguments)},info:function(){this.invoke(e.INFO,arguments)},warn:function(){this.invoke(e.WARN,arguments)},error:function(){this.invoke(e.ERROR,arguments)},time:function(s){typeof s=="string"&&s.length>0&&this.invoke(e.TIME,[s,"start"])},timeEnd:function(s){typeof s=="string"&&s.length>0&&this.invoke(e.TIME,[s,"end"])},invoke:function(s,d){n&&this.enabledFor(s)&&n(d,a({level:s},this.context))}};var u=new c({filterLevel:e.OFF});(function(){var s=e;s.enabledFor=r(u,u.enabledFor),s.trace=r(u,u.trace),s.debug=r(u,u.debug),s.time=r(u,u.time),s.timeEnd=r(u,u.timeEnd),s.info=r(u,u.info),s.warn=r(u,u.warn),s.error=r(u,u.error),s.log=s.info})(),e.setHandler=function(s){n=s},e.setLevel=function(s){u.setLevel(s);for(var d in t)t.hasOwnProperty(d)&&t[d].setLevel(s)},e.getLevel=function(){return u.getLevel()},e.get=function(s){return t[s]||(t[s]=new c(a({name:s},u.context)))},e.createDefaultHandler=function(s){s=s||{},s.formatter=s.formatter||function(m,v){v.name&&m.unshift("["+v.name+"]")};var d={},l=function(p,m){Function.prototype.apply.call(p,console,m)};return typeof console>"u"?function(){}:function(p,m){p=Array.prototype.slice.call(p);var v=console.log,h;m.level===e.TIME?(h=(m.name?"["+m.name+"] ":"")+p[0],p[1]==="start"?console.time?console.time(h):d[h]=new Date().getTime():console.timeEnd?console.timeEnd(h):l(v,[h+": "+(new Date().getTime()-d[h])+"ms"])):(m.level===e.WARN&&console.warn?v=console.warn:m.level===e.ERROR&&console.error?v=console.error:m.level===e.INFO&&console.info?v=console.info:m.level===e.DEBUG&&console.debug?v=console.debug:m.level===e.TRACE&&console.trace&&(v=console.trace),s.formatter(p,m),l(v,p))}},e.useDefaults=function(s){e.setLevel(s&&s.defaultLevel||e.DEBUG),e.setHandler(e.createDefaultHandler(s))},e.setDefaults=e.useDefaults,typeof define=="function"&&define.amd?define(e):typeof g<"u"&&g.exports?g.exports=e:(e._prevLogger=i.Logger,e.noConflict=function(){return i.Logger=e._prevLogger,e},i.Logger=e)})(y)});var F=w((se,O)=>{"use strict";var R=typeof Reflect=="object"?Reflect:null,I=R&&typeof R.apply=="function"?R.apply:function(e,n,t){return Function.prototype.apply.call(e,n,t)},S;R&&typeof R.ownKeys=="function"?S=R.ownKeys:Object.getOwnPropertySymbols?S=function(e){return Object.getOwnPropertyNames(e).concat(Object.getOwnPropertySymbols(e))}:S=function(e){return Object.getOwnPropertyNames(e)};function Y(i){console&&console.warn&&console.warn(i)}var A=Number.isNaN||function(e){return e!==e};function f(){f.init.call(this)}O.exports=f;O.exports.once=te;f.EventEmitter=f;f.prototype._events=void 0;f.prototype._eventsCount=0;f.prototype._maxListeners=void 0;var B=10;function L(i){if(typeof i!="function")throw new TypeError('The "listener" argument must be of type Function. Received type '+typeof i)}Object.defineProperty(f,"defaultMaxListeners",{enumerable:!0,get:function(){return B},set:function(i){if(typeof i!="number"||i<0||A(i))throw new RangeError('The value of "defaultMaxListeners" is out of range. It must be a non-negative number. Received '+i+".");B=i}});f.init=function(){(this._events===void 0||this._events===Object.getPrototypeOf(this)._events)&&(this._events=Object.create(null),this._eventsCount=0),this._maxListeners=this._maxListeners||void 0};f.prototype.setMaxListeners=function(e){if(typeof e!="number"||e<0||A(e))throw new RangeError('The value of "n" is out of range. It must be a non-negative number. Received '+e+".");return this._maxListeners=e,this};function P(i){return i._maxListeners===void 0?f.defaultMaxListeners:i._maxListeners}f.prototype.getMaxListeners=function(){return P(this)};f.prototype.emit=function(e){for(var n=[],t=1;t<arguments.length;t++)n.push(arguments[t]);var r=e==="error",a=this._events;if(a!==void 0)r=r&&a.error===void 0;else if(!r)return!1;if(r){var o;if(n.length>0&&(o=n[0]),o instanceof Error)throw o;var c=new Error("Unhandled error."+(o?" ("+o.message+")":""));throw c.context=o,c}var u=a[e];if(u===void 0)return!1;if(typeof u=="function")I(u,this,n);else for(var s=u.length,d=W(u,s),t=0;t<s;++t)I(d[t],this,n);return!0};function x(i,e,n,t){var r,a,o;if(L(n),a=i._events,a===void 0?(a=i._events=Object.create(null),i._eventsCount=0):(a.newListener!==void 0&&(i.emit("newListener",e,n.listener?n.listener:n),a=i._events),o=a[e]),o===void 0)o=a[e]=n,++i._eventsCount;else if(typeof o=="function"?o=a[e]=t?[n,o]:[o,n]:t?o.unshift(n):o.push(n),r=P(i),r>0&&o.length>r&&!o.warned){o.warned=!0;var c=new Error("Possible EventEmitter memory leak detected. "+o.length+" "+String(e)+" listeners added. Use emitter.setMaxListeners() to increase limit");c.name="MaxListenersExceededWarning",c.emitter=i,c.type=e,c.count=o.length,Y(c)}return i}f.prototype.addListener=function(e,n){return x(this,e,n,!1)};f.prototype.on=f.prototype.addListener;f.prototype.prependListener=function(e,n){return x(this,e,n,!0)};function Z(){if(!this.fired)return this.target.removeListener(this.type,this.wrapFn),this.fired=!0,arguments.length===0?this.listener.call(this.target):this.listener.apply(this.target,arguments)}function D(i,e,n){var t={fired:!1,wrapFn:void 0,target:i,type:e,listener:n},r=Z.bind(t);return r.listener=n,t.wrapFn=r,r}f.prototype.once=function(e,n){return L(n),this.on(e,D(this,e,n)),this};f.prototype.prependOnceListener=function(e,n){return L(n),this.prependListener(e,D(this,e,n)),this};f.prototype.removeListener=function(e,n){var t,r,a,o,c;if(L(n),r=this._events,r===void 0)return this;if(t=r[e],t===void 0)return this;if(t===n||t.listener===n)--this._eventsCount===0?this._events=Object.create(null):(delete r[e],r.removeListener&&this.emit("removeListener",e,t.listener||n));else if(typeof t!="function"){for(a=-1,o=t.length-1;o>=0;o--)if(t[o]===n||t[o].listener===n){c=t[o].listener,a=o;break}if(a<0)return this;a===0?t.shift():Q(t,a),t.length===1&&(r[e]=t[0]),r.removeListener!==void 0&&this.emit("removeListener",e,c||n)}return this};f.prototype.off=f.prototype.removeListener;f.prototype.removeAllListeners=function(e){var n,t,r;if(t=this._events,t===void 0)return this;if(t.removeListener===void 0)return arguments.length===0?(this._events=Object.create(null),this._eventsCount=0):t[e]!==void 0&&(--this._eventsCount===0?this._events=Object.create(null):delete t[e]),this;if(arguments.length===0){var a=Object.keys(t),o;for(r=0;r<a.length;++r)o=a[r],o!=="removeListener"&&this.removeAllListeners(o);return this.removeAllListeners("removeListener"),this._events=Object.create(null),this._eventsCount=0,this}if(n=t[e],typeof n=="function")this.removeListener(e,n);else if(n!==void 0)for(r=n.length-1;r>=0;r--)this.removeListener(e,n[r]);return this};function _(i,e,n){var t=i._events;if(t===void 0)return[];var r=t[e];return r===void 0?[]:typeof r=="function"?n?[r.listener||r]:[r]:n?ee(r):W(r,r.length)}f.prototype.listeners=function(e){return _(this,e,!0)};f.prototype.rawListeners=function(e){return _(this,e,!1)};f.listenerCount=function(i,e){return typeof i.listenerCount=="function"?i.listenerCount(e):N.call(i,e)};f.prototype.listenerCount=N;function N(i){var e=this._events;if(e!==void 0){var n=e[i];if(typeof n=="function")return 1;if(n!==void 0)return n.length}return 0}f.prototype.eventNames=function(){return this._eventsCount>0?S(this._events):[]};function W(i,e){for(var n=new Array(e),t=0;t<e;++t)n[t]=i[t];return n}function Q(i,e){for(;e+1<i.length;e++)i[e]=i[e+1];i.pop()}function ee(i){for(var e=new Array(i.length),n=0;n<e.length;++n)e[n]=i[n].listener||i[n];return e}function te(i,e){return new Promise(function(n,t){function r(o){i.removeListener(e,a),t(o)}function a(){typeof i.removeListener=="function"&&i.removeListener("error",r),n([].slice.call(arguments))}j(i,e,a,{once:!0}),e!=="error"&&ne(i,r,{once:!0})})}function ne(i,e,n){typeof i.on=="function"&&j(i,"error",e,n)}function j(i,e,n,t){if(typeof i.on=="function")t.once?i.once(e,n):i.on(e,n);else if(typeof i.addEventListener=="function")i.addEventListener(e,function r(a){t.once&&i.removeEventListener(e,r),n(a)});else throw new TypeError('The "emitter" argument must be of type EventEmitter. Received type '+typeof i)}});var ie=C(T());var K=C(F()),q=C(T());var M=(r=>(r[r.none=0]="none",r[r.cpu=1]="cpu",r[r.bandwidth=2]="bandwidth",r[r.other=3]="other",r))(M||{});var k=i=>{let e=i.kind||i.mediaType;return!["audio","video"].includes(e??"")&&i.type==="inbound-rtp"&&(i.id.toLocaleLowerCase().includes("video")?e="video":e="audio"),e},b=(i,e,n,t)=>n&&t?(e-t)/((i-n)/1e3):0,V=(i,e,n,t)=>{let r=i-(n??0),a=e-(t??0),o=r+a;return o===0?0:r/o};var H=class extends K.EventEmitter{constructor(n){super();this.#n=null;this.#e=null;this.start=()=>{this.#t.info("WebRTC statistics collection is starting..."),this.#e=null,this.#n=setInterval(this.#c,this.#r)};this.stop=()=>{this.#n&&(clearInterval(this.#n),this.#n=null,this.#t.info("WebRTC statistics collection has stopped."))};this.#c=async()=>{let n,t;try{this.#t.trace("Requesting WebRTC statistics..."),n=await this.#i(),t=new Date().toISOString()}catch(o){this.#t.error("Problem collecting the WebRTC statistics.",o),this.emit("error",`Problem collecting the WebRTC statistics - ${o}`);return}let r=Array.from(n.values()),a={timestamp:t,input:{audio:[],video:[]},output:{audio:[],video:[]}};this.#s&&(a.rawStats=n);for(let o=0;o<Object.keys(r).length;o++){let c=r[o];switch(c.type){case"outbound-rtp":let u=c,s=k(u);s==="audio"?await this.#f(n,u,a):s==="video"&&await this.#d(n,u,a);break;case"inbound-rtp":let d=c,l=k(d);l==="audio"?await this.#p(n,d,a):l==="video"&&await this.#m(n,d,a);break;case"candidate-pair":let p=c;p.nominated&&this.#l(p,a);break;default:break}}this.#e=a,this.emit("stats",a)};this.#t=q.default.get("WebRTCStats"),this.#i=n.getStats,this.#r=n.getStatsInterval||1e3,this.#s=!!n.includeRawStats}#i;#r;#s;#n;#t;#e;#c;#o(n,t){if(t){let r=n.get(t);if(r)return{mimeType:r.mimeType}}return{}}async#a(n,t,r){let a=b(t.timestamp,t.bytesSent,r?.timestamp,r?.totalBytesSent),o=b(t.timestamp,t.packetsSent,r?.timestamp,r?.totalPacketsSent),c=this.#o(n,t.codecId);return{id:t.id,timestamp:t.timestamp,mid:t.mid,totalBytesSent:t.bytesSent,bytesSentDelta:t.bytesSent-(r?.totalBytesSent??0),totalPacketsSent:t.packetsSent,packetsSentDelta:t.packetsSent-(r?.totalPacketsSent??0),bitrate:a,packetRate:o,targetBitrate:t.targetBitrate,retransmittedPacketsSent:t.retransmittedPacketsSent,retransmittedPacketsSentDelta:t.retransmittedPacketsSent-(r?.retransmittedPacketsSent??0),retransmittedBytesSent:t.retransmittedBytesSent,retransmittedBytesSentDelta:t.retransmittedBytesSent-(r?.retransmittedBytesSent??0),...c}}async#f(n,t,r){let a=this.#e?.output.audio.find(u=>u.id===t.id);if(a&&t.timestamp-a.timestamp<=0)return;let c={...await this.#a(n,t,a)};r.output.audio.push(c)}async#d(n,t,r){let a=this.#e?.output.video.find(s=>s.id===t.id);if(a&&t.timestamp-a.timestamp<=0)return;let o=await this.#a(n,t,a),c=0;t.qualityLimitationReason&&(c=t.qualityLimitationReason);let u={...o,frameWidth:t.frameWidth,frameHeight:t.frameHeight,framesPerSecond:t.framesPerSecond,framesSent:t.framesSent,qualityLimitationReason:c,qualityLimitationDurations:t.qualityLimitationDurations};r.output.video.push(u)}async#u(n,t,r){let a=b(t.timestamp,t.bytesReceived,r?.timestamp,r?.totalBytesReceived),o=b(t.timestamp,t.packetsReceived,r?.timestamp,r?.totalPacketsReceived),c=V(t.packetsLost,t.packetsReceived,r?.totalPacketsLost,r?.totalPacketsReceived),u=(t.packetsLost??0)-(r?.totalPacketsLost??0),s=this.#o(n,t.codecId);return{id:t.id,timestamp:t.timestamp,mid:t.mid,trackIdentifier:t.trackIdentifier,jitter:t.jitter,jitterBufferDelay:t.jitterBufferDelay,jitterBufferEmittedCount:t.jitterBufferEmittedCount,totalBytesReceived:t.bytesReceived,totalPacketsReceived:t.packetsReceived,totalPacketsLost:t.packetsLost,bitrate:a,packetRate:o,packetLossRatio:c,packetLossDelta:u,...s}}async#p(n,t,r){let a=this.#e?.input.audio.find(c=>c.id===t.id);if(a&&t.timestamp-a.timestamp<=0)return;let o=await this.#u(n,t,a);r.input.audio.push(o)}async#m(n,t,r){let a=this.#e?.input.video.find(u=>u.id===t.id);if(a&&t.timestamp-a.timestamp<=0)return;let c={...await this.#u(n,t,a),keyFramesDecoded:t.keyFramesDecoded,frameHeight:t.frameHeight,frameWidth:t.frameWidth,framesDecoded:t.framesDecoded,framesDropped:t.framesDropped,framesPerSecond:t.framesPerSecond,framesReceived:t.framesReceived};r.input.video.push(c)}#l(n,t){t.totalRoundTripTime=n.totalRoundTripTime,t.currentRoundTripTime=n.currentRoundTripTime,t.responsesReceived=n.responsesReceived,t.availableOutgoingBitrate=n.availableOutgoingBitrate,t.availableIncomingBitrate=n.availableIncomingBitrate}};})();
//# sourceMappingURL=webrtc-stats.js.map