dingrtc 3.6.1-108.1

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.js ADDED
@@ -0,0 +1,3 @@
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),require("webrtc-adapter");var e=require("@dingrtc/shared"),t=require("sdp-transform"),r=require("@dingrtc/channel");function n(e,t,r,n,i,o,a){try{var s=e[o](a),c=s.value}catch(e){return void r(e)}s.done?t(c):Promise.resolve(c).then(n,i)}function i(e){return function(){var t=this,r=arguments;return new Promise(function(i,o){var a=e.apply(t,r);function s(e){n(a,i,o,s,c,"next",e)}function c(e){n(a,i,o,s,c,"throw",e)}s(void 0)})}}function o(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function a(e){return a="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},a(e)}function s(e){var t=function(e,t){if("object"!=a(e)||!e)return e;var r=e[Symbol.toPrimitive];if(void 0!==r){var n=r.call(e,t);if("object"!=a(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return e+""}(e,"string");return"symbol"==a(t)?t:t+""}function c(e,t){for(var r=0;t.length>r;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,s(n.key),n)}}function u(e,t,r){return t&&c(e.prototype,t),r&&c(e,r),Object.defineProperty(e,"prototype",{writable:!1}),e}function d(e,t){if(t&&("object"==a(t)||"function"==typeof t))return t;if(void 0!==t)throw new TypeError("Derived constructors may only return object or undefined");return function(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}(e)}function l(e){return l=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(e){return e.__proto__||Object.getPrototypeOf(e)},l(e)}function p(e,t){return p=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(e,t){return e.__proto__=t,e},p(e,t)}function f(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),Object.defineProperty(e,"prototype",{writable:!1}),t&&p(e,t)}function v(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var m,h={exports:{}},y={exports:{}};(m=y).exports=function(e,t){this.v=e,this.k=t},m.exports.__esModule=!0,m.exports.default=m.exports;var g=y.exports,b={exports:{}},S={exports:{}};!function(e){function t(r,n,i,o){var a=Object.defineProperty;try{a({},"",{})}catch(r){a=0}e.exports=t=function(e,r,n,i){function o(r,n){t(e,r,function(e){return this._invoke(r,n,e)})}r?a?a(e,r,{value:n,enumerable:!i,configurable:!i,writable:!i}):e[r]=n:(o("next",0),o("throw",1),o("return",2))},e.exports.__esModule=!0,e.exports.default=e.exports,t(r,n,i,o)}e.exports=t,e.exports.__esModule=!0,e.exports.default=e.exports}(S);var k=S.exports;!function(e){var t=k;function r(){
2
+ /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/babel/babel/blob/main/packages/babel-helpers/LICENSE */
3
+ var n,i,o="function"==typeof Symbol?Symbol:{},a=o.iterator||"@@iterator",s=o.toStringTag||"@@toStringTag";function c(e,r,o,a){var s=Object.create((r&&r.prototype instanceof d?r:d).prototype);return t(s,"_invoke",function(e,t,r){var o,a,s,c=0,d=r||[],l=!1,p={p:0,n:0,v:n,a:f,f:f.bind(n,4),d:function(e,t){return o=e,a=0,s=n,p.n=t,u}};function f(e,t){for(a=e,s=t,i=0;!l&&c&&!r&&d.length>i;i++){var r,o=d[i],f=p.p,v=o[2];e>3?(r=v===t)&&(s=o[(a=o[4])?5:(a=3,3)],o[4]=o[5]=n):f>=o[0]&&((r=2>e&&o[1]>f)?(a=0,p.v=t,p.n=o[1]):v>f&&(r=3>e||o[0]>t||t>v)&&(o[4]=e,o[5]=t,p.n=v,a=0))}if(r||e>1)return u;throw l=!0,t}return function(r,d,v){if(c>1)throw TypeError("Generator is already running");for(l&&1===d&&f(d,v),a=d,s=v;(i=2>a?n:s)||!l;){o||(a?3>a?(a>1&&(p.n=-1),f(a,s)):p.n=s:p.v=s);try{if(c=2,o){if(a||(r="next"),i=o[r]){if(!(i=i.call(o,s)))throw TypeError("iterator result is not an object");if(!i.done)return i;s=i.value,2>a&&(a=0)}else 1===a&&(i=o.return)&&i.call(o),2>a&&(s=TypeError("The iterator does not provide a '"+r+"' method"),a=1);o=n}else if((i=(l=0>p.n)?s:e.call(t,p))!==u)break}catch(e){o=n,a=1,s=e}finally{c=1}}return{value:i,done:l}}}(e,o,a),!0),s}var u={};function d(){}function l(){}function p(){}i=Object.getPrototypeOf;var f=[][a]?i(i([][a]())):(t(i={},a,function(){return this}),i),v=p.prototype=d.prototype=Object.create(f);function m(e){return Object.setPrototypeOf?Object.setPrototypeOf(e,p):(e.__proto__=p,t(e,s,"GeneratorFunction")),e.prototype=Object.create(v),e}return l.prototype=p,t(v,"constructor",p),t(p,"constructor",l),l.displayName="GeneratorFunction",t(p,s,"GeneratorFunction"),t(v),t(v,s,"Generator"),t(v,a,function(){return this}),t(v,"toString",function(){return"[object Generator]"}),(e.exports=r=function(){return{w:c,m:m}},e.exports.__esModule=!0,e.exports.default=e.exports)()}e.exports=r,e.exports.__esModule=!0,e.exports.default=e.exports}(b);var P=b.exports,E={exports:{}},w={exports:{}},T={exports:{}};!function(e){var t=g,r=k;e.exports=function e(n,i){function o(e,r,a,s){try{var c=n[e](r),u=c.value;return u instanceof t?i.resolve(u.v).then(function(e){o("next",e,a,s)},function(e){o("throw",e,a,s)}):i.resolve(u).then(function(e){c.value=e,a(c)},function(e){return o("throw",e,a,s)})}catch(e){s(e)}}var a;this.next||(r(e.prototype),r(e.prototype,"function"==typeof Symbol&&Symbol.asyncIterator||"@asyncIterator",function(){return this})),r(this,"_invoke",function(e,t,r){function n(){return new i(function(t,n){o(e,r,t,n)})}return a=a?a.then(n,n):n()},!0)},e.exports.__esModule=!0,e.exports.default=e.exports}(T);var O=T.exports;!function(e){var t=P,r=O;e.exports=function(e,n,i,o,a){return new r(t().w(e,n,i,o),a||Promise)},e.exports.__esModule=!0,e.exports.default=e.exports}(w);var I=w.exports;!function(e){var t=I;e.exports=function(e,r,n,i,o){var a=t(e,r,n,i,o);return a.next().then(function(e){return e.done?e.value:a.next()})},e.exports.__esModule=!0,e.exports.default=e.exports}(E);var R=E.exports,A={exports:{}};!function(e){e.exports=function(e){var t=Object(e),r=[];for(var n in t)r.unshift(n);return function e(){for(;r.length;)if((n=r.pop())in t)return e.value=n,e.done=!1,e;return e.done=!0,e}},e.exports.__esModule=!0,e.exports.default=e.exports}(A);var C=A.exports,_={exports:{}},M={exports:{}};!function(e){function t(r){return e.exports=t="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},e.exports.__esModule=!0,e.exports.default=e.exports,t(r)}e.exports=t,e.exports.__esModule=!0,e.exports.default=e.exports}(M);var D=M.exports;!function(e){var t=D.default;e.exports=function(e){if(null!=e){var r=e["function"==typeof Symbol&&Symbol.iterator||"@@iterator"],n=0;if(r)return r.call(e);if("function"==typeof e.next)return e;if(!isNaN(e.length))return{next:function(){return e&&n>=e.length&&(e=void 0),{value:e&&e[n++],done:!e}}}}throw new TypeError(t(e)+" is not iterable")},e.exports.__esModule=!0,e.exports.default=e.exports}(_);var x=_.exports;!function(e){var t=g,r=P,n=R,i=I,o=O,a=C,s=x;function c(){var u=r(),d=u.m(c),l=(Object.getPrototypeOf?Object.getPrototypeOf(d):d.__proto__).constructor;function p(e){var t="function"==typeof e&&e.constructor;return!!t&&(t===l||"GeneratorFunction"===(t.displayName||t.name))}var f={throw:1,return:2,break:3,continue:3};function v(e){var t,r;return function(n){t||(t={stop:function(){return r(n.a,2)},catch:function(){return n.v},abrupt:function(e,t){return r(n.a,f[e],t)},delegateYield:function(e,i,o){return t.resultName=i,r(n.d,s(e),o)},finish:function(e){return r(n.f,e)}},r=function(e,r,i){n.p=t.prev,n.n=t.next;try{return e(r,i)}finally{t.next=n.n}}),t.resultName&&(t[t.resultName]=n.v,t.resultName=void 0),t.sent=n.v,t.next=n.n;try{return e.call(this,t)}finally{n.p=t.prev,n.n=t.next}}}return(e.exports=c=function(){return{wrap:function(e,t,r,n){return u.w(v(e),t,r,n&&n.reverse())},isGeneratorFunction:p,mark:u.m,awrap:function(e,r){return new t(e,r)},AsyncIterator:o,async:function(e,t,r,o,a){return(p(t)?i:n)(v(e),t,r,o,a)},keys:a,values:s}},e.exports.__esModule=!0,e.exports.default=e.exports)()}e.exports=c,e.exports.__esModule=!0,e.exports.default=e.exports}(h);var j=(0,h.exports)(),N=j;try{regeneratorRuntime=j}catch(e){"object"==typeof globalThis?globalThis.regeneratorRuntime=j:Function("r","regeneratorRuntime = r")(j)}var L,V,G,U,F,B,q,H,J,Y,W,Q,K,z,$=v(N);function X(e,t,r){return(t=s(t))in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}!function(e){e.PCMU="pcmu",e.PCMA="pcma",e.OPUS="opus",e.G722="g722",e.ISAC="iSAC",e.ILBC="iLBC",e.AAC="aac",e.AC3="ac3",e.NELLYMOSER="nellymoser"}(L||(L={})),function(e){e.VP8="vp8",e.VP9="vp9",e.H264="h264",e.H265="h265",e.AV1="av1",e.AV1X="av1x"}(V||(V={})),exports.AudioSourceInfo=void 0,(G=exports.AudioSourceInfo||(exports.AudioSourceInfo={})).MIC="mic",G.SCREENCAST="screen-cast",G.MIXED="mixed",exports.VideoSourceInfo=void 0,(U=exports.VideoSourceInfo||(exports.VideoSourceInfo={})).CAMERA="camera",U.SCREENCAST="screen-cast",U.MIXED="mixed",function(e){e.PUBLISH="publish",e.SUBSCRIBE="subscribe"}(F||(F={})),function(e){e[e.UNKNOWN=0]="UNKNOWN",e[e.GREAT=1]="GREAT",e[e.GOOD=2]="GOOD",e[e.NORMAL=3]="NORMAL",e[e.POOR=4]="POOR",e[e.BAD=5]="BAD",e[e.DISCONNECTED=6]="DISCONNECTED"}(B||(B={})),function(e){e[e.Native=1]="Native",e[e.Web=2]="Web",e[e.MiniProgram=3]="MiniProgram"}(q||(q={})),function(e){e[e.Windows=1]="Windows",e[e.Android=2]="Android",e[e.Mac=3]="Mac",e[e.iOS=4]="iOS",e[e.Linux=5]="Linux",e[e.Others=6]="Others"}(H||(H={})),function(e){e[e.UserKickOut=2011]="UserKickOut",e[e.UserReplaced=2012]="UserReplaced"}(J||(J={})),function(e){e[e.Idle=0]="Idle",e[e.Processing=1]="Processing",e[e.End=2]="End"}(Y||(Y={})),function(e){e[e.New=0]="New",e[e.Idle=1]="Idle",e[e.Processing=2]="Processing",e[e.Ended=3]="Ended"}(W||(W={})),function(e){e.QuotaLimit="task exceed limit",e.PCNotExisted="connection does NOT exist",e.RoomClosed="room_already_closed:30107",e.RoomNotExisted="room does not exist",e.RoomBusy="RoomBusy",e.RoomNotJoined="participant has not joined",e.FailOver="Session has been aborted"}(Q||(Q={})),function(e){e[e.MIC_OPEN=0]="MIC_OPEN",e[e.MIC_INTERRUPTED=1]="MIC_INTERRUPTED",e[e.CAMERA_OPEN=2]="CAMERA_OPEN",e[e.BACKGROUND_MODE=3]="BACKGROUND_MODE",e[e.DOWNLINK=4]="DOWNLINK",e[e.UPLINK=5]="UPLINK"}(K||(K={})),function(e){e[e.None=0]="None",e[e.LD=2]="LD",e[e.SD=4]="SD",e[e.HD=8]="HD",e[e.FHD=16]="FHD",e[e.QHD=32]="QHD",e[e.UHD=64]="UHD"}(z||(z={}));var Z,ee={VD_120x120:[120,120],VD_160x120:[160,120],VD_180x180:[180,180],VD_240x180:[240,180],VD_320x180:[320,180],VD_240x240:[240,240],VD_320x240:[320,240],VD_424x240:[424,240],VD_360x360:[360,360],VD_480x360:[480,360],VD_640x360:[640,360],VD_480x480:[480,480],VD_640x480:[640,480],VD_840x480:[840,480],VD_960x540:[960,540],VD_960x720:[960,720],VD_1280x720:[1280,720],VD_1920x1080:[1920,1080]};exports.AudioSourceState=void 0,(Z=exports.AudioSourceState||(exports.AudioSourceState={})).Playing="playing",Z.Paused="paused",Z.Stopped="stopped";var te="3.6.1",re=-999,ne="rtc-label";JSON.stringify({needPersonalityAudioStream:!0,outPeerConnectionNotReuse:!0});var ie="onertc_state_sync",oe="onertc_internal_track_event",ae=function(e){return{width:ee[e][0],height:ee[e][1]}},se=function(e){return"object"===a(e.video)&&e.video.source===exports.VideoSourceInfo.SCREENCAST},ce=function(t){var r,n=Object.create({}),i={};null!==(r=navigator)&&void 0!==r&&null!==(r=r.mediaDevices)&&void 0!==r&&r.getSupportedConstraints&&(i=navigator.mediaDevices.getSupportedConstraints());var o=t.AEC,a=t.AGC,s=t.ANS;return t.deviceId&&(n.deviceId=e.Environment.isSafari()?t.deviceId:{exact:t.deviceId}),i.autoGainControl&&(n.autoGainControl={ideal:null==a||a}),i.echoCancellation&&(n.echoCancellation={ideal:null==o||o}),i.noiseSuppression&&(n.noiseSuppression={ideal:null==s||s}),n},ue=function(t){if(!e.isObject(t)||!t.audio&&!t.video)return Promise.reject(new TypeError("Invalid constrains"));var r=t.audio,n=t.video;if(!se(t)&&"object"===a(r)&&r.source===exports.AudioSourceInfo.SCREENCAST)return Promise.reject(new TypeError("Cannot share screen without video."));if(se(t)&&"object"===a(r)&&r.source!==exports.AudioSourceInfo.SCREENCAST)return Promise.reject(new TypeError("Cannot capture video from screen cast while capture audio from other source."));if(!r&&!n)return Promise.reject(new TypeError("At least one of audio and video must be requested."));var i=Object.create({});if(i.audio="object"===a(r)&&r.source===exports.AudioSourceInfo.MIC||"object"===a(r)&&r.source===exports.AudioSourceInfo.SCREENCAST?ce(r):t.audio,"object"===a(n)){var o,s=n.frameRate,c=n.deviceId,u=n.source,d=n.facingMode,l=n.displaySurface,p=n.dimension;i.video=Object.create({}),e.isNumber(s)&&(i.video.frameRate=Math.min(n.frameRate,30)),p&&(o=ae(p)),o&&o.width&&o.height&&(u===exports.VideoSourceInfo.SCREENCAST?(i.video.width=o.width,i.video.height=o.height):(i.video.width={ideal:o.width,max:o.width},i.video.height={ideal:o.height,max:o.width})),e.isString(c)&&c&&(i.video.deviceId={exact:c}),u===exports.VideoSourceInfo.SCREENCAST&&(e.Environment.isFirefox()&&(i.video.mediaSource="screen"),l&&["browser","window","monitor"].includes(l)&&(i.video.displaySurface=l)),d&&["user","environment"].includes(d)&&(i.video.facingMode=d)}else i.video=n;return se(t)?navigator.mediaDevices.getDisplayMedia(i):navigator.mediaDevices.getUserMedia(i)};function de(){return de="undefined"!=typeof Reflect&&Reflect.get?Reflect.get.bind():function(e,t,r){var n=function(e,t){for(;!{}.hasOwnProperty.call(e,t)&&null!==(e=l(e)););return e}(e,t);if(n){var i=Object.getOwnPropertyDescriptor(n,t);return i.get?i.get.call(3>arguments.length?e:r):i.value}},de.apply(null,arguments)}function le(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=Array(t);t>r;r++)n[r]=e[r];return n}function pe(e,t){if(e){if("string"==typeof e)return le(e,t);var r={}.toString.call(e).slice(8,-1);return"Object"===r&&e.constructor&&(r=e.constructor.name),"Map"===r||"Set"===r?Array.from(e):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?le(e,t):void 0}}function fe(e){return function(e){if(Array.isArray(e))return le(e)}(e)||function(e){if("undefined"!=typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}(e)||pe(e)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}var ve,me,he=function(e){if(!e)return{};var t={id:e.id,active:e.active},r=e.getTracks().map(function(e){return function(e){var t={};return e?(t.kind=e.kind,t.label=e.label,t.id=e.id,t.contentHint=e.contentHint,t.enabled=e.enabled,t.muted=e.muted,t.readyState=e.readyState,t.settings=e.getSettings(),t.constraints=e.getConstraints(),t):t}(e)});return t.trackInfos=r,t},ye=function(e){if(!e)return!1;var t=e.getVideoTracks()[0];return t&&t.enabled&&!t.muted},ge=function(e,t){var r=(e.timestamp-((null==t?void 0:t.timestamp)||e.timestamp))/1e3;return r>0||(r=1),r},be=function(e,t){return null!=e?[2,4,6,0][e]:null!==t?[3,0,0,0,1,1,2][t]:void 0},Se=function(e,t){isNaN(e)&&(e=0),isNaN(t)&&(t=0);var r=e-t;return 0>r&&(r=e),r},ke=new Map,Pe=function(t){return new Promise(function(r){e.addTimer(r,1e3*t)})},Ee=e.getReporter().log,we="rtc-intersecting",Te="visible",Oe="invisible",Ie=["abort","canplay","canplaythrough","durationchange","emptied","ended","error","loadeddata","loadedmetadata","loadstart","pause","play","playing","ratechange","seeked","seeking","stalled","suspend","volumechange","waiting"],Re=function(e){return"".concat(null==e?void 0:e.getAttribute(ne),"-").concat(null==e?void 0:e.rtcPurpose)},Ae=function(){return u(function t(r,n){var i=this;o(this,t),Object.defineProperty(this,"mediaElementPool",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"mediaElementsInUse",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"allElements",{enumerable:!0,configurable:!0,writable:!0,value:new Set}),Object.defineProperty(this,"hasActivated",{enumerable:!0,configurable:!0,writable:!0,value:!1}),Object.defineProperty(this,"mediaKind",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"mediaPlaybackCheckInterval",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"debouncer",{enumerable:!0,configurable:!0,writable:!0,value:new e.Debouncer}),Object.defineProperty(this,"currentTimeOfLastCheckMap",{enumerable:!0,configurable:!0,writable:!0,value:new Map}),Object.defineProperty(this,"observer",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_activatedListener",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"destroy",{enumerable:!0,configurable:!0,writable:!0,value:function(){i.mediaElementPool.forEach(function(e){return i._resetMediaElement(e)}),i.mediaElementPool=[],i.allElements.clear(),i.mediaElementsInUse.forEach(function(e){return i._resetMediaElement(e)}),i.mediaElementsInUse=[],document.removeEventListener("click",i._onUserInteraction),document.removeEventListener("touchstart",i._onUserInteraction),document.removeEventListener("visibilitychange",i._tryReloadOnPauseAndErrorWhenVisibleTriggerByVisible),i.mediaPlaybackCheckInterval&&(e.removeTimer(i.mediaPlaybackCheckInterval,"interval"),i.mediaPlaybackCheckInterval=null),[].concat(fe(i.mediaElementPool),fe(i.mediaElementsInUse)).forEach(function(e){var t;return null===(t=i.observer)||void 0===t?void 0:t.unobserve(e)})}}),Object.defineProperty(this,"_tryReloadOnPauseAndErrorWhenVisible",{enumerable:!0,configurable:!0,writable:!0,value:function(e){i.mediaElementsInUse.forEach(function(t){if(t.srcObject){var r=t.srcObject;if(t.error){var n="".concat(e,": ").concat(Re(t)," has error, error=").concat(t.error,",doc.visibilityState=").concat(document.visibilityState,", mediaStream="),o=he(r);Ee.debug(n,o),"visible"===document.visibilityState&&ye(r)&&t.load()}if(t.paused){var a=!1;if(i.hasActivated&&"video"===i.mediaKind?function(e){return e&&e.getAttribute(we)===Te}(t)&&"visible"===document.visibilityState&&"visible"===getComputedStyle(t).visibility&&(a=!0):a=!0,a){var s="".concat(e,": ").concat(Re(t)," paused, doc.visibilityState=").concat(document.visibilityState,", intersecting=").concat(t.getAttribute(we),", mediaStream="),c=he(r);Ee.error(s,c),ye(r)&&t.load(),t.paused&&t.play().catch(function(e){console.error("inPoll",e)})}}}}),i.debouncer.debounce(i._tryReloadOnCurrentTimeFreeze.bind(i,e),1e3)}}),Object.defineProperty(this,"_tryReloadOnCurrentTimeFreeze",{enumerable:!0,configurable:!0,writable:!0,value:function(e){i.mediaElementsInUse.forEach(function(t){if(t.srcObject){var r=t.srcObject,n="video"===i.mediaKind?r.getVideoTracks()[0]:void 0;if(!t.paused&&i.currentTimeOfLastCheckMap.get(t)===t.currentTime&&!0!==(null==n?void 0:n.muted)){var o="".concat(e,": ").concat(Re(t)," currentTime stop, doc.visibilityState=").concat(document.visibilityState,", curTime=").concat(t.currentTime,", mediaStream="),a=he(r);return Ee.error(o,a),void("visible"===document.visibilityState&&ye(r)&&t.load())}i.currentTimeOfLastCheckMap.set(t,t.currentTime)}})}}),Object.defineProperty(this,"_tryReloadOnPauseAndErrorWhenVisibleTriggerByVisible",{enumerable:!0,configurable:!0,writable:!0,value:function(){i._tryReloadOnPauseAndErrorWhenVisible("visibilityChange")}}),Object.defineProperty(this,"_elementDefaultErrorHandler",{enumerable:!0,configurable:!0,writable:!0,value:function(e){var t=e.target,r="error event on ".concat(i.mediaKind," playback, mediaStream="),n=he(null==t?void 0:t.srcObject);Ee.error(r,n,null==t?void 0:t.error)}}),Object.defineProperty(this,"_elementDefaultPauseHandler",{enumerable:!0,configurable:!0,writable:!0,value:function(e){var t=e.target,r="pause event on ".concat(i.mediaKind," playback, mediaStream="),n=he(null==t?void 0:t.srcObject);Ee.error(r,n,null==t?void 0:t.error)}}),Object.defineProperty(this,"_elementDefaultPlayHandler",{enumerable:!0,configurable:!0,writable:!0,value:function(e){var t=e.target,r="play event on ".concat(i.mediaKind," playback, mediaStream="),n=he(null==t?void 0:t.srcObject);Ee.debug(r,n)}}),Object.defineProperty(this,"_onUserInteraction",{enumerable:!0,configurable:!0,writable:!0,value:function(){var t=[].concat(fe(i.mediaElementPool),fe(i.mediaElementsInUse));if(!i.hasActivated&&(i.hasActivated=!0,t.forEach(function(e){e.load()}),i._activatedListener))try{i._activatedListener()}catch(t){Ee.error("error occurred when exec activatedListener",e.tryJsonStringify(t))}i._tryReloadOnPauseAndErrorWhenVisible("userInteract")}}),this.mediaElementsInUse=[],this.mediaElementPool=[],this.mediaKind=r,window.IntersectionObserver&&(this.observer=new IntersectionObserver(function(e){e.forEach(function(e){var t,r;e.isIntersecting?null===(t=e.target)||void 0===t||t.setAttribute(we,Te):null===(r=e.target)||void 0===r||r.setAttribute(we,Oe)})}));for(var a=0;n>a;a++){var s,c=this._createElement();null===(s=this.observer)||void 0===s||s.observe(c),this.addAtttribute(c),c.setAttribute(ne,"".concat(r,"-").concat(a)),this.mediaElementPool.push(c),this.allElements.add(c)}document.addEventListener("click",this._onUserInteraction,!0),document.addEventListener("touchstart",this._onUserInteraction,!0),document.addEventListener("visibilitychange",this._tryReloadOnPauseAndErrorWhenVisibleTriggerByVisible,!0),this.mediaPlaybackCheckInterval=e.addTimer(function(){i.hasActivated&&i._tryReloadOnPauseAndErrorWhenVisible("intervalCheck")},4e3,"interval")},[{key:"addAtttribute",value:function(e){if(e.autoplay=!0,e.setAttribute(ne,"toReused"),e instanceof HTMLVideoElement)e.muted=!0,e.playsInline=!0,e.controls=!1,e.setAttribute("webkit-playsinline","true"),e.setAttribute("x5-video-player-type","h5"),e.setAttribute("x5-playsinline","true");else{var t,r=e;r.volume=1,null===(t=r.setSinkId)||void 0===t||t.call(r,"")}}},{key:"popElement",value:function(e){var t;return(t=this.mediaElementPool.shift())?(this._resetMediaElement(t),t.addEventListener("error",this._elementDefaultErrorHandler),t.addEventListener("pause",this._elementDefaultPauseHandler),t.addEventListener("play",this._elementDefaultPlayHandler),t.rtcPurpose=e||""):(t=document.createElement(this.mediaKind),this.addAtttribute(t)),t}},{key:"pushElement",value:function(e){if(this.allElements.has(e)){var t=this.mediaElementsInUse;this.mediaElementsInUse=this.mediaElementsInUse.filter(function(t){return t!==e}),t.length!==this.mediaElementsInUse.length&&(this.mediaElementPool.push(e),this._resetMediaElement(e))}}},{key:"isMediaElementActivated",value:function(){return this.hasActivated}},{key:"setActivateListener",value:function(e){this._activatedListener=e}},{key:"_createElement",value:function(){var e,t=document.createElement(this.mediaKind);return null===(e=this.observer)||void 0===e||e.observe(t),t}},{key:"_resetMediaElement",value:function(e){Ie.forEach(function(t){e["on".concat(t)]=null}),e.removeEventListener("error",this._elementDefaultErrorHandler),e.removeEventListener("pause",this._elementDefaultPauseHandler),e.removeEventListener("play",this._elementDefaultPlayHandler),e.style.cssText="",e.className="",this.addAtttribute(e),e.srcObject=null}}])}(),Ce=function(){return ve||De(),ve},_e=function(){return me||De(),me},Me=e.Environment.isIOS()||e.Environment.isAndroid()?9:25,De=function(){ve||(ve=new Ae("audio",2)),me||(me=new Ae("video",Me))},xe=new AudioContext,je=function(e){var t=e.getAudioTracks(),r=xe.createMediaStreamDestination();return t.forEach(function(e){xe.createMediaStreamSource(new MediaStream([e])).connect(r)}),r.stream.getAudioTracks()[0]},Ne=function(e,t,r){"running"!==e.state&&e.resume(),r.connect(t),t.fftSize=2048,t.smoothingTimeConstant=.4;var n=new Float32Array(t.fftSize);if(t.getFloatTimeDomainData)t.getFloatTimeDomainData(n);else{var i=new Uint8Array(t.fftSize);t.getByteTimeDomainData(i);for(var o=0;n.length>o;++o)n[o]=i[o]/128-1}for(var a=0,s=0;n.length>s;s++)a+=n[s]*n[s];return Math.max(10*Math.log10(a/n.length)+100,0)/100},Le=function(e){var t=document.createElement("canvas"),r=t.getContext("2d"),n=(null==e?void 0:e.srcObject).getTracks()[0];if(!n)return"";var i=n.getSettings(),o=i.width,a=i.height;return t.width=o,t.height=a,r.drawImage(e,0,0,o,a),t.toDataURL("image/png")};function Ve(){try{var e=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(e){}return(Ve=function(){return!!e})()}var Ge=e.getReporter(),Ue=Ge.log,Fe=Ge.trace,Be=new Map,qe=function(){function t(r,n){var i,a,s,c;return o(this,t),a=this,s=l(s=t),i=d(a,Ve()?Reflect.construct(s,[],l(a).constructor):s.apply(a,c)),Object.defineProperty(i,"trackMediaType",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(i,"isPlaying",{enumerable:!0,configurable:!0,writable:!0,value:!1}),Object.defineProperty(i,"source",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(i,"logger",{enumerable:!0,configurable:!0,writable:!0,value:Fe}),Object.defineProperty(i,"sourceNode",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(i,"element",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(i,"audioContext",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(i,"analyser",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(i,"trackSettings",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(i,"sfuStream",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(i,"mediaStreamTrack",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(i,"playerConfig",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(i,"wrapperDom",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(i,"trackId",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(i,"sourceMirror",{enumerable:!0,configurable:!0,writable:!0,value:!1}),i.trackId=e.createUuid(),r?(i.trackMediaType=r.kind,i.trackSettings=r.getSettings()):n&&(i.trackMediaType="audio"),"audio"===i.trackMediaType&&(i.audioContext=xe,i.analyser=i.audioContext.createAnalyser()),i.setMediaStreamTrack(r,n),i}return f(t,e.EventEmitter),u(t,[{key:"getTrackId",value:function(){return this.trackId}},{key:"setMediaStreamTrack",value:function(t,r){var n=this,i=this.mediaStreamTrack;if(i&&(i.onended=null),t||r){var o;if(i&&t&&(t.enabled=i.enabled),"audio"===this.trackMediaType)if(this.sourceNode&&(this.sourceNode.disconnect(),this.sourceNode=null),t)this.sourceNode=null===(o=this.audioContext)||void 0===o?void 0:o.createMediaStreamSource(new MediaStream([t]));else if(r){var a,s=je(r);this.sourceNode=null===(a=this.audioContext)||void 0===a?void 0:a.createMediaStreamSource(new MediaStream([s]))}t?(this.mediaStreamTrack=t,this.mediaStreamTrack.onended=function(){n.source===exports.VideoSourceInfo.SCREENCAST?n.logger.sendEvent("SCREEN_DEVICE_STOP"):n.source===exports.AudioSourceInfo.MIC?new e.DingRTCError(e.ErrorCode.MicInterrupt):n.source===exports.VideoSourceInfo.CAMERA&&new e.DingRTCError(e.ErrorCode.CameraInterrupt)}):r&&(this.sfuStream=r)}}},{key:"replaceTrack",value:function(e,t){Ue.info("replaceTrack",e,t),t&&this.isPlaying&&this.stop(),this.replaceTrackInner(e)}},{key:"replaceTrackInner",value:function(e,t){this.setMediaStreamTrack(e,t),this.emit(oe,"replace",this),this.isPlaying&&this.innnerPlay()}},{key:"setSource",value:function(e){e===exports.VideoSourceInfo.CAMERA?this.logger.sendEvent("VIDEO_DEVICE_START"):e===exports.VideoSourceInfo.SCREENCAST?this.logger.sendEvent("SCREEN_DEVICE_START"):e===exports.AudioSourceInfo.MIC&&this.logger.sendEvent("AUDIO_DEVICE_START"),this.source=e}},{key:"stop",value:function(){this.isPlaying=!1,Ue.info("stop paly track ".concat(this.getTrackId())),this.element&&(Be.get(this.wrapperDom)===this&&Be.delete(this.wrapperDom),this.wrapperDom&&(this.wrapperDom.removeChild(this.element),this.wrapperDom=null),this.element.pause(),this.element.srcObject=null,"audio"===this.trackMediaType?Ce().pushElement(this.element):_e().pushElement(this.element),this.setMediaElement(null))}},{key:"innnerPlay",value:function(t,r){var n=this,i=this.element;r&&(this.playerConfig=r);var o,a,s,c=this.playerConfig||{},u=c.mirror,d=c.fit;if(t&&(o="string"==typeof t?document.querySelector(t):t,!document.contains(o)))throw new e.DingRTCError(e.ErrorCode.InvaildArgument,"wrapper dom not found");if(i){if(o&&this.wrapperDom&&o!==this.wrapperDom)return this.stop(),void this.innnerPlay(t,r);i.pause(),i.style.transform=!this.sourceMirror!=!u?"scaleX(-1)":"",i.srcObject=this.sfuStream||new MediaStream([this.getMediaStreamTrack()]),i.load()}else{if("audio"===this.trackMediaType){a=this.sfuStream||new MediaStream([this.getMediaStreamTrack()]),(s=Ce().popElement()).srcObject=a,i=s;try{"running"!==this.audioContext.state&&this.audioContext.resume()}catch(t){Ue.debug("resume audioContext failed: ".concat(e.tryJsonStringify(t)))}}else{var l=Be.get(o);l&&l.stop();var p=function(e,t,r){var n=_e().popElement();if(n.style.width="100%",n.style.height="100%",r){var i=r.fit;!0===r.mirror&&(n.style.transform="scaleX(-1)"),i&&(n.style.objectFit=i)}return e.appendChild(n),n.pause(),n.srcObject=t,n.load(),n}(o,new MediaStream([this.getMediaStreamTrack()]),{mirror:!this.sourceMirror!=!u,fit:d});this.wrapperDom=o,i=p,Be.set(this.wrapperDom,this)}this.setMediaElement(i)}i.paused&&i.play().then(function(){n.isPlaying=!0}).catch(function(t){"NotAllowedError"===t.name?(n.isPlaying=!1,Ue.error("autoplay failed",e.tryJsonStringify(t)),e.EventBus.emit("autoplay-failed",n)):Ue.warn("".concat(n.trackMediaType," play has exception"),e.tryJsonStringify(t))})}},{key:"setMediaElement",value:function(e){this.element=e}},{key:"getMediaStreamTrack",value:function(){return this.mediaStreamTrack}}])}();function He(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){var r=null==e?null:"undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=r){var n,i,o,a,s=[],c=!0,u=!1;try{if(o=(r=r.call(e)).next,0===t){if(Object(r)!==r)return;c=!1}else for(;!(c=(n=o.call(r)).done)&&(s.push(n.value),s.length!==t);c=!0);}catch(e){u=!0,i=e}finally{try{if(!c&&null!=r.return&&(a=r.return(),Object(a)!==a))return}finally{if(u)throw i}}return s}}(e,t)||pe(e,t)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}var Je=e.getReporter().log,Ye=new(function(){return u(function t(){o(this,t),Object.defineProperty(this,"system",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"browser",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"browserVersion",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),this.system=e.Environment.system,this.browser=e.Environment.browserType,this.browserVersion=e.Environment.browserVersion},[{key:"getSupportedCodec",value:(t=i($.mark(function t(){var r,n,i;return $.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return r={audio:[],video:[]},t.prev=1,(n=new RTCPeerConnection).addTransceiver("video",{direction:"recvonly"}),n.addTransceiver("audio",{direction:"recvonly"}),t.next=2,n.createOffer();case 2:if(i=t.sent.sdp){t.next=3;break}return t.abrupt("return",r);case 3:return n.close(),n=null,i.match(/ VP8/i)&&r.video.push("VP8"),i.match(/ VP9/i)&&r.video.push("VP9"),i.match(/ AV1/i)&&r.video.push("AV1"),i.match(/ H264/i)&&r.video.push("H264"),i.match(/ H265/i)&&r.video.push("H265"),i.match(/ opus/i)&&r.audio.push("OPUS"),i.match(/ PCMU/i)&&r.audio.push("PCMU"),i.match(/ PCMA/i)&&r.audio.push("PCMA"),i.match(/ G722/i)&&r.audio.push("G722"),t.abrupt("return",r);case 4:throw t.prev=4,t.catch(1),Je.error("get supportedCodecs failed"),new e.DingRTCError(e.ErrorCode.IceConnectionSetLocalDescFail,"get supportedCodecs failed");case 5:case"end":return t.stop()}},t,null,[[1,4]])})),function(){return t.apply(this,arguments)})},{key:"checkSupported",value:function(){var t=!1;try{var r=window.RTCPeerConnection,n=navigator.mediaDevices&&navigator.mediaDevices.getUserMedia,i=window.WebSocket;t=!!(r&&n&&i)}catch(e){return!1}var o=!1;o=e.Environment.isChrome()||e.Environment.isFirefox()?parseInt(e.Environment.browserVersion,10)>=69:e.Environment.isOpera()?parseInt(e.Environment.browserVersion,10)>=45:e.Environment.isSafari()?parseInt(e.Environment.browserVersion,10)>=11:(e.Environment.isWeixin()||e.Environment.isQQBrowser(),!0);var a=t&&o;return Je.debug("checkSystemRequirements, api:",t,"browser",o),a}},{key:"isSupportScreenShare",value:function(){return!this.system.includes(e.SystemType.ANDROID)&&this.system!==e.SystemType.IOS&&((this.browser!==e.BrowserType.SAFARI||parseInt(this.browserVersion)>=13)&&((this.browser!==e.BrowserType.FIREFOX||parseInt(this.browserVersion)>=66)&&!!(navigator&&navigator.mediaDevices&&navigator.mediaDevices.getDisplayMedia)))}}]);var t}());function We(){try{var e=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(e){}return(We=function(){return!!e})()}var Qe,Ke=new(function(){function t(){var e,r,n,i;return o(this,t),r=this,n=l(n=t),e=d(r,We()?Reflect.construct(n,[],l(r).constructor):n.apply(r,i)),Object.defineProperty(e,"gslb",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(e,"simulcast",{enumerable:!0,configurable:!0,writable:!0,value:!1}),Object.defineProperty(e,"grouptalk",{enumerable:!0,configurable:!0,writable:!0,value:!0}),Object.defineProperty(e,"audioSFU",{enumerable:!0,configurable:!0,writable:!0,value:!0}),e.setClientConfig({gslb:["https://gslb.dingrtc.com"]}),e}return f(t,e.EventEmitter),u(t,[{key:"setClientConfig",value:function(t){var r=t||{},n=r.gslb,i=r.simulcast,o=r.audioSFU;"string"==typeof n&&(this.gslb=[n],e.setGslb(n)),Array.isArray(n)&&e.isString(n[0])&&(this.gslb=n,e.setGslb(n[0])),null!=i&&function(){var t,r=(null===(t=window.RTCRtpSender)||void 0===t?void 0:t.prototype)||{};return!(!r.setParameters||!r.getParameters||e.Environment.isFirefox()||(e.Environment.isSafari()?14>parseInt(e.Environment.browserVersion):e.Environment.isChrome()&&81>parseInt(e.Environment.browserVersion)))}()&&(this.simulcast=!!i),null!=o&&(this.audioSFU=!!o)}}])}());function ze(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),r.push.apply(r,n)}return r}function $e(e){for(var t=1;arguments.length>t;t++){var r=null!=arguments[t]?arguments[t]:{};t%2?ze(Object(r),!0).forEach(function(t){X(e,t,r[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):ze(Object(r)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))})}return e}!function(e){e[e.LLD=0]="LLD",e[e.LD=1]="LD",e[e.SD=2]="SD",e[e.HD=3]="HD",e[e.FHD=4]="FHD"}(Qe||(Qe={}));var Xe=X(X(X(X(X({},Qe.LLD,"lld"),Qe.LD,"ld"),Qe.SD,"sd"),Qe.HD,"hd"),Qe.FHD,"fhd"),Ze={high:[1228800,2764800],FHD:[1228800,2764800],HD:[307200,1228800],SD:[76800,307200],LD:[0,76800],low:[0,76800]},et=function(e,t){var r=tt(e,t),n=function(e,t){var r={high:z.FHD,low:z.LD,FHD:z.FHD,HD:z.HD,SD:z.SD,LD:z.LD},n=r[e]||z.None,i=t[t.length-1].width*t[t.length-1].height;if(Ze[e][0]>i){var o=Object.entries(Ze).find(function(e){var t=He(e,2)[1];return i>t[0]&&t[1]>=i});n=r[He(o,1)[0]]}return n}(e,t);return{resolution:r,resolutionLevel:n}},tt=function(e,t){var r=Ze[e],n=t.length;if(t[0].width*t[0].height>Ze.FHD[1])return t[0];for(var i=0;n>i;i++){var o=t[i].width*t[i].height;if(o>=r[0]&&r[1]>=o)return t[i]}for(var a=n-1;a>=0;a--){if(r[1]>t[a].width*t[a].height)return t[a]}return t[0]},rt=[49152,76800,307200,1228800,2764800],nt=[200,350,1e3,1800,2828],it=[[256,144],[320,180],[640,360],[1280,720],[1920,1080]],ot=[[256,192],[320,240],[640,480],[1280,960],[1920,1440]],at=function(e,t){var r=Qe.FHD,n=e*t;return n>rt[Qe.LLD]?n>rt[Qe.LD]?n>rt[Qe.SD]?n>rt[Qe.HD]?n>rt[Qe.FHD]||(r=Qe.FHD):r=Qe.HD:r=Qe.SD:r=Qe.LD:r=Qe.LLD,r},st=function(e,t){var r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:0;if(!r){var n=1;30!==t&&(n=Math.sqrt(t/30));var i=e.getSettings(),o=nt[at(i.width,i.height)];r=Math.round(Math.max(n*o,50))}return r},ct=function(e){var t=e.getMaxBitrate(),r=e.trackSettings,n=r.height,i=r.width,o=r.frameRate,a=[],s=at(i,n);if(!Ke.simulcast||e.source===exports.VideoSourceInfo.SCREENCAST)return[{maxFramerate:o,maxBitrate:t,scaleResolutionDownBy:1,active:!0,rid:"",minBitrate:Math.round((t+30)/2),targetWidth:i,targetHeight:n}];var c=s>Qe.HD?3:2,u=function(e){var r=function(e,t,r,n){var i=0,o=0;if(r>=n)return[i=e,o=t];if(t>e){var a=[e,t];t=a[0],e=a[1]}if(16*t==9*e)i=it[r][0],o=it[r][1];else if(4*t==3*e)i=ot[r][0],o=ot[r][1];else{var s=Math.sqrt(1*it[r][0]*it[r][1]/e/t);o=Math.round(t*(s=1*(i=(i=Math.round(e*s))+15&-16)/e))}return[i,o]}(i,n,e,s),a=He(r,2),c=a[1];return{targetWidth:a[0],rid:Xe[e],targetHeight:c,minBitrate:50,maxFramerate:o,maxBitrate:Math.round(Math.max(30,t*(nt[e]/nt[s]))),scaleResolutionDownBy:1/(c/n)}};s>Qe.LLD&&a.push($e({active:!1},u(Qe.LLD))),s>Qe.LD&&a.push($e({active:c>1},u(Qe.LD))),s>Qe.SD&&a.push($e({active:c>2},u(Qe.SD))),s>Qe.HD?(a.push($e({active:!1},u(Qe.HD))),a.push($e({active:!0},u(Qe.FHD)))):a.push($e({active:!0},u(s)));for(var d=0,l=0;a.length>l;++l)0!=l&&(a[l].minBitrate=d),d=Math.round(Math.max((a[l].maxBitrate+a[l].minBitrate)/2,a[l].maxBitrate-400));return a.shift(),a};function ut(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),r.push.apply(r,n)}return r}function dt(e){for(var t=1;arguments.length>t;t++){var r=null!=arguments[t]?arguments[t]:{};t%2?ut(Object(r),!0).forEach(function(t){X(e,t,r[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):ut(Object(r)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))})}return e}function lt(e,t,r){return t=l(t),d(e,pt()?Reflect.construct(t,r||[],l(e).constructor):t.apply(e,r))}function pt(){try{var e=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(e){}return(pt=function(){return!!e})()}function ft(e,t,r,n){var i=de(l(e.prototype),t,r);return"function"==typeof i?function(e){return i.apply(r,e)}:i}var vt=e.getReporter().log,mt=function(){function t(e,r){var n;(o(this,t),n=lt(this,t,[e]),Object.defineProperty(n,"deviceId",{enumerable:!0,configurable:!0,writable:!0,value:r}),Object.defineProperty(n,"muted",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(n,"maxBitrate",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(n,"enabled",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(n,"config",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(n,"isClosed",{enumerable:!0,configurable:!0,writable:!0,value:!1}),e)&&(n.muted=e.muted);return n.enabled=!0,n.isPlaying=!1,n.deviceId=r,n}return f(t,qe),u(t,[{key:"setMediaStreamTrack",value:function(e){var r,n=this;ft(t,"setMediaStreamTrack",this)([e]),e&&(this.trackSettings=e.getSettings(),null===(r=this.element)||void 0===r||r.addEventListener("loadeddata",function(){n.emit("first-frame-decoded")}),e.onended=function(){n.stop(),n.close&&n.close(),n.emit("track-ended")})}},{key:"play",value:function(e,t){this.innnerPlay(e,t)}},{key:"setEnabled",value:function(t){return vt.info("setEnabled",t),this.isClosed?Promise.reject(new e.DingRTCError(e.ErrorCode.InvaildState)):(this.enabled=t,this.emit(oe,t?"unmute":"mute"),t?this.updateNewTrack():(null===(r=this.mediaStreamTrack)||void 0===r||r.stop(),this.setMediaStreamTrack(null),this.source===exports.VideoSourceInfo.CAMERA?this.logger.sendEvent("VIDEO_DEVICE_STOP"):this.source===exports.VideoSourceInfo.SCREENCAST&&this.logger.sendEvent("SCREEN_DEVICE_STOP"),Promise.resolve()));var r}},{key:"close",value:function(){var e;vt.info("".concat(this.source," track:").concat(this.getTrackId()," close")),this.isClosed||(this.isClosed=!0,this.isPlaying&&this.stop(),this.emit(oe,"stop"),null===(e=this.mediaStreamTrack)||void 0===e||e.stop(),this.setMediaStreamTrack(null),this.audioContext&&(this.sourceNode=null,this.analyser=null,this.audioContext=null),this.source===exports.VideoSourceInfo.CAMERA?this.logger.sendEvent("VIDEO_DEVICE_STOP"):this.source===exports.VideoSourceInfo.SCREENCAST&&this.logger.sendEvent("SCREEN_DEVICE_STOP"))}},{key:"setMuted",value:function(t){return vt.info("setMuted",t),this.isClosed?Promise.reject(new e.DingRTCError(e.ErrorCode.InvaildState)):(this.muted=t,this.mediaStreamTrack.enabled=!t,this.emit(oe,t?"mute":"unmute"),Promise.resolve())}},{key:"getAudioTrack",value:function(){var t=this;return vt.debug("gengrate new audioTrack"),new Promise(function(r,n){var i;ue({audio:dt(dt({source:t.source},t.config),{},{deviceId:t.deviceId})}).then(function(e){i=e.getAudioTracks()[0]}).catch(function(r){try{var o=t.audioContext.createOscillator(),a=t.audioContext.createMediaStreamDestination();o.connect(a),i=a.stream.getAudioTracks()[0]}catch(t){vt.error("gengrate new audioTrack error",e.parseAudioDeviceError(r)),n(e.parseAudioDeviceError(r))}}).finally(function(){i&&r(i)})})}},{key:"getVideoTrack",value:function(){var t=this;return vt.debug("gengrate new videoTrack"),new Promise(function(r,n){var i;ue({video:dt(dt({source:t.source},t.config),{},{deviceId:t.deviceId}),audio:!1}).then(function(e){i=e.getVideoTracks()[0],r(i)}).catch(function(t){vt.error("gengrate new videoTrack error",e.parseVideoDeviceError(t)),n(e.parseVideoDeviceError(t))})})}},{key:"updateNewTrack",value:function(){var e=this,t=this.getMediaStreamTrack();return t.onended=null,vt.debug("stop oldTrack first"),t.stop(),"audio"===this.trackMediaType?this.getAudioTrack().then(function(t){return e.replaceTrackInner(t)}):"video"===this.trackMediaType?this.getVideoTrack().then(function(t){return e.replaceTrackInner(t)}):void 0}},{key:"setDevice",value:(r=i($.mark(function e(t){return $.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:if(vt.info("setDevice",t),!this.isClosed){e.next=1;break}return e.abrupt("return");case 1:if(!(this instanceof gt)||"user"!==t&&"environment"!==t){e.next=2;break}this.config.facingMode=t,e.next=4;break;case 2:if(this.deviceId!==t){e.next=3;break}return e.abrupt("return");case 3:this.deviceId=t;case 4:return e.abrupt("return",this.updateNewTrack());case 5:case"end":return e.stop()}},e,this)})),function(e){return r.apply(this,arguments)})},{key:"getTrackLabel",value:function(){if(vt.info("getTrackLabel"),!this.isClosed)return this.mediaStreamTrack.label}},{key:"getMaxBitrate",value:function(){if(!this.isClosed)return this.maxBitrate}}]);var r}(),ht=function(){function t(e,r,n){var i;return o(this,t),(i=lt(this,t,[e,r])).config=n,e&&(i.maxBitrate=st(e,n.frameRate,n.maxBitrate)),i}return f(t,mt),u(t,[{key:"optimizationMode",get:function(){return this.config.optimizationMode}},{key:"setEncoderConfiguration",value:function(t){var r=this;vt.info("videoTrack ".concat(this.getTrackId()," setEncoderConfiguration"),t);var n=t.dimension,i=t.frameRate,o=t.maxBitrate,a=t.optimizationMode,s=t.mirror;if(i&&Number.isNaN(i))return Promise.reject(new e.DingRTCError(e.ErrorCode.InvaildArgument,"invalid frameRate"));if(n&&!ee[n])return Promise.reject(new e.DingRTCError(e.ErrorCode.InvaildArgument,"invalid dimension"));!s!=!this.config.mirror&&(this.emit(oe,"mirror",s),this.config.mirror=s),a&&a!==this.optimizationMode&&(this.config.optimizationMode=a,this.emit(oe,"optimizationMode"));var c=!1;if(n&&this.config.dimension!==n&&(this.config.dimension=n,c=!0),i&&this.config.frameRate!==Math.min(30,i)&&(this.config.frameRate=Math.min(30,i),c=!0),o&&this.maxBitrate!==o&&(c=!0),!c)return Promise.resolve();var u=dt({frameRate:this.config.frameRate},ae(this.config.dimension)),d=this.getMediaStreamTrack();return null==d?void 0:d.applyConstraints(u).then(function(){r.maxBitrate=st(r.getMediaStreamTrack(),r.config.frameRate,o),r.emit(oe,"republish",r)}).catch(function(t){var n=e.parseVideoDeviceError(t);throw vt.error("videoTrack ".concat(r.getTrackId()," setEncoderConfiguration error"),n),n})}},{key:"getCurrentFrameData",value:function(){return vt.info("getCurrentFrameData"),this.isClosed||!this.isPlaying?null:Le(this.element)}},{key:"play",value:function(e,r){return vt.info("local video play"),ft(t,"play",this)([e,r])}}])}(),yt=function(){function e(t,r){return o(this,e),lt(this,e,[t,r])}return f(e,mt),u(e,[{key:"setVolume",value:function(e){vt.info("setVolume",e),this.isClosed||this.element&&(this.element.volume=e)}},{key:"getVolume",value:function(){if(vt.info("getVolume"),!this.isClosed)return this.element?this.element.volume:void 0}},{key:"getVolumeLevel",value:function(){return this.isClosed?0:Ne(this.audioContext,this.analyser,this.sourceNode)}},{key:"play",value:function(){return vt.info("local audio play"),ft(e,"play",this)([])}}])}(),gt=function(){function e(t,r){var n;return o(this,e),(n=lt(this,e,[t,r.deviceId,r])).setSource(exports.VideoSourceInfo.CAMERA),n}return f(e,ht),u(e)}(),bt=function(){function e(t,r){var n;return o(this,e),(n=lt(this,e,[t,(r||{}).deviceId])).config=r,n.setSource(exports.AudioSourceInfo.MIC),n.analyser=n.audioContext.createAnalyser(),n}return f(e,yt),u(e,[{key:"setVolume",value:function(e){vt.info("setVolume",e),this.isClosed||this.element&&(this.element.volume=e)}},{key:"getVolume",value:function(){if(vt.info("getVolume"),!this.isClosed)return this.element?this.element.volume:void 0}}])}(),St=function(){var t=i($.mark(function t(r){var n,i,o,a,s,c,u,d,l,p;return $.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return n={AEC:!0,AGC:!0,ANS:!0},a=void 0===(o=(i=r||n).AEC)||o,c=void 0===(s=i.AGC)||s,d=void 0===(u=i.ANS)||u,t.prev=1,t.next=2,ue({video:!1,audio:{deviceId:null==r?void 0:r.deviceId,source:exports.AudioSourceInfo.MIC,AEC:a,AGC:c,ANS:d}});case 2:return l=t.sent.getAudioTracks()[0],vt.info("MicrophoneAudioTrack created"),t.abrupt("return",new bt(l,Object.assign({},r,{AEC:a,AGC:c,ANS:d})));case 3:throw t.prev=3,p=t.catch(1),e.parseAudioDeviceError(p);case 4:case"end":return t.stop()}},t,null,[[1,3]])}));return function(e){return t.apply(this,arguments)}}(),kt=function(){var t=i($.mark(function t(r){var n,i,o,a,s,c,u,d,l;return $.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return n=r.deviceId,i=r.facingMode,a=void 0===(o=r.dimension)?"VD_640x480":o,c=void 0===(s=r.optimizationMode)?"balanced":s,u=Math.min(30,r.frameRate||15),t.prev=1,t.next=2,ue({video:{deviceId:n,source:exports.VideoSourceInfo.CAMERA,frameRate:u,dimension:a,facingMode:i},audio:!1});case 2:return d=t.sent.getVideoTracks()[0],vt.info("CameraVideoTrack created"),t.abrupt("return",new gt(d,Object.assign({},r,{frameRate:u,dimension:a,optimizationMode:c})));case 3:throw t.prev=3,l=t.catch(1),e.parseVideoDeviceError(l);case 4:case"end":return t.stop()}},t,null,[[1,3]])}));return function(e){return t.apply(this,arguments)}}(),Pt=function(){var t=i($.mark(function t(r){var n,i,o,a,s,c,u,d,l;return $.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return i=void 0===(n=r.displaySurface)?"monitor":n,a=void 0===(o=r.dimension)?"VD_1920x1080":o,c=void 0===(s=r.optimizationMode)?"detail":s,u=Math.min(r.frameRate||5,30),t.prev=1,t.next=2,ue({video:{source:exports.VideoSourceInfo.SCREENCAST,displaySurface:i,frameRate:u,dimension:a},audio:!1});case 2:return(d=new ht(t.sent.getVideoTracks()[0],null,Object.assign({},r,{frameRate:u,dimension:a,optimizationMode:c}))).setSource(exports.VideoSourceInfo.SCREENCAST),vt.info("ScreenVideoTrack created"),t.abrupt("return",[d]);case 3:throw t.prev=3,l=t.catch(1),e.parseScreenShareError(l);case 4:case"end":return t.stop()}},t,null,[[1,3]])}));return function(e){return t.apply(this,arguments)}}(),Et=function(){var t=i($.mark(function t(r,n){var i,o,a,s,c,u,d,l,p,f,v,m,h,y,g,b,S,k,P,E,w;return $.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return i=Math.min(r.frameRate||15,30),o=r.deviceId,a=r.facingMode,c=void 0===(s=r.dimension)?"VD_640x480":s,d=void 0===(u=r.optimizationMode)?"balanced":u,l={AEC:!0,AGC:!0,ANS:!0},v=void 0===(f=(p=n||l).AEC)||f,h=void 0===(m=p.AGC)||m,g=void 0===(y=p.ANS)||y,t.prev=1,t.next=2,ue({video:{deviceId:o,source:exports.VideoSourceInfo.CAMERA,frameRate:i,dimension:c,facingMode:a},audio:{deviceId:null==n?void 0:n.deviceId,source:exports.AudioSourceInfo.MIC,AEC:v,AGC:h,ANS:g}});case 2:return S=(b=t.sent).getVideoTracks()[0],k=b.getAudioTracks()[0],vt.info("CameraVideoTrack and MicrophoneTrack created"),P=new gt(S,Object.assign({},r,{frameRate:i,dimension:c,optimizationMode:d})),E=new bt(k,Object.assign({},Object.assign({},n,{AEC:v,AGC:h,ANS:g}))),t.abrupt("return",[P,E]);case 3:throw t.prev=3,w=t.catch(1),e.parseVideoDeviceError(w);case 4:case"end":return t.stop()}},t,null,[[1,3]])}));return function(e,r){return t.apply(this,arguments)}}(),wt=function(){var t=i($.mark(function t(r){var n,i,o,a,s,c,u,d;return $.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:if(i=(n=r||{}).mediaStreamTrack,a=void 0===(o=n.dimension)?"VD_640x480":o,c=void 0===(s=n.optimizationMode)?"balanced":s,u=Math.min(r.frameRate||15,30),i instanceof MediaStreamTrack&&"video"===i.kind){t.next=1;break}throw new e.DingRTCError(e.ErrorCode.InvaildArgument,"missing video mediaStreamTrack");case 1:return(d=new ht(i,null,Object.assign({},r,{frameRate:u,dimension:a,optimizationMode:c}))).setSource(exports.VideoSourceInfo.CAMERA),t.abrupt("return",d);case 2:case"end":return t.stop()}},t)}));return function(e){return t.apply(this,arguments)}}(),Tt=function(){var t=i($.mark(function t(r){var n,i;return $.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:if((n=(r||{}).mediaStreamTrack)instanceof MediaStreamTrack&&"audio"===n.kind){t.next=1;break}throw new e.DingRTCError(e.ErrorCode.InvaildArgument,"missing audio mediaStreamTrack");case 1:return(i=new yt(n)).setSource(exports.AudioSourceInfo.MIC),t.abrupt("return",i);case 2:case"end":return t.stop()}},t)}));return function(e){return t.apply(this,arguments)}}();function Ot(e,t,r,n){var i=de(l(e.prototype),t,r);return 2&n&&"function"==typeof i?function(e){return i.apply(r,e)}:i}function It(e,t,r){return t=l(t),d(e,Rt()?Reflect.construct(t,r||[],l(e).constructor):t.apply(e,r))}function Rt(){try{var e=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(e){}return(Rt=function(){return!!e})()}var At,Ct=e.getReporter().log,_t=function(){function e(t,r,n){var i;return o(this,e),i=It(this,e,[t,n]),Object.defineProperty(i,"userId",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(i,"subscription",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),i.userId=r,i}return f(e,qe),u(e,[{key:"getUserId",value:function(){return Ct.info("getUserId"),this.userId}},{key:"onFirstFrame",value:function(){this.emit("first-frame-decoded")}},{key:"attachSubscription",value:function(e){this.subscription&&this.subscription.off("audio-first-frame",this.onFirstFrame),this.subscription=e,null==e||e.on("audio-first-frame",this.onFirstFrame)}}])}(),Mt=function(){function t(e,r,n){var i;return o(this,t),i=It(this,t,[e,r,n]),Object.defineProperty(i,"deviceId",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),i.deviceId="",i}return f(t,_t),u(t,[{key:"getMediaStreamTrack",value:function(){return Ke.audioSFU?je(this.sfuStream):Ot(t,"getMediaStreamTrack",this,3)([])}},{key:"replaceStream",value:function(e,t){Ct.info("replaceRemote Audio",e,t),t&&this.isPlaying&&this.stop(),this.replaceTrackInner(null,e)}},{key:"setVolume",value:function(e){Ct.info("setVolume",e),this.element&&(this.element.volume=e)}},{key:"getVolume",value:function(){if(Ct.info("getVolume"),this.element)return this.element.volume}},{key:"setSpeaker",value:function(t){var r=this;return Ct.info("setSpeaker",t),new Promise(function(n,i){var o,a=r.element;a||i(new e.DingRTCError(e.ErrorCode.InvaildState,"please playout audio first")),a.setSinkId||i(new e.DingRTCError(e.ErrorCode.SpeakerSetNotSupported)),null===(o=a.setSinkId)||void 0===o||o.call(a,t).then(function(){r.deviceId=t,n()}).catch(function(t){i(e.parseAudioDeviceError(t))})})}},{key:"getVolumeLevel",value:function(){return Ne(this.audioContext,this.analyser,this.sourceNode)}},{key:"play",value:function(){return Ct.info("remote audio play"),Ot(t,"innnerPlay",this,3)([])}}])}(),Dt=function(){function e(t,r){return o(this,e),It(this,e,[t,r])}return f(e,_t),u(e,[{key:"play",value:function(t,r){return Ct.info("remote video play"),Ot(e,"innnerPlay",this,3)([t,r])}},{key:"setSourceMirror",value:function(t){t!==this.sourceMirror&&(Ct.info("remote video track set Mirror",t),this.sourceMirror=t,this.isPlaying&&Ot(e,"innnerPlay",this,3)([]))}},{key:"setMediaElement",value:function(t){var r,n=this;Ot(e,"setMediaElement",this,3)([t]),null===(r=this.element)||void 0===r||r.addEventListener("loadeddata",function(){n.emit("first-frame-decoded")})}},{key:"getCurrentFrameData",value:function(){return Ct.info("getCurrentFrameData"),this.isPlaying?Le(this.element):null}}])}();!function(e){var t,r,n,i,o,a,s,c;(t=e.DataType||(e.DataType={}))[t.DATA_TYPE_STREAM=0]="DATA_TYPE_STREAM",t[t.DATA_TYPE_PARTICIPANTS=1]="DATA_TYPE_PARTICIPANTS",t[t.DATA_TYPE_CONFERENCE=2]="DATA_TYPE_CONFERENCE",t[t.DATA_TYPE_GROUP_LIST=3]="DATA_TYPE_GROUP_LIST",t[t.DATA_TYPE_GROUP=4]="DATA_TYPE_GROUP",(r=e.OptType||(e.OptType={}))[r.OPT_TYPE_ADD=0]="OPT_TYPE_ADD",r[r.OPT_TYPE_REMOVE=1]="OPT_TYPE_REMOVE",r[r.OPT_TYPE_UPDATE=2]="OPT_TYPE_UPDATE",(n=e.SyncResponseCode||(e.SyncResponseCode={}))[n.SYNC_OK=0]="SYNC_OK",n[n.SYNC_PART_SUC=10]="SYNC_PART_SUC",n[n.SYNC_DATA_SIZE_LIMITED=11]="SYNC_DATA_SIZE_LIMITED",n[n.SYNC_NOT_SUPPORT_TYPE=12]="SYNC_NOT_SUPPORT_TYPE",n[n.SYNC_NOT_FOUND=13]="SYNC_NOT_FOUND",n[n.SYNC_CHANNEL_NOT_EXIST=14]="SYNC_CHANNEL_NOT_EXIST",n[n.SYNC_INTERNAL_ERROR=15]="SYNC_INTERNAL_ERROR",(i=e.GroupUpdate||(e.GroupUpdate={}))[i.GROUP_UPDATE_AUDIO_STREAM_LOST=0]="GROUP_UPDATE_AUDIO_STREAM_LOST",i[i.GROUP_UPDATE_AUDIO_STREAM_RECOVER=1]="GROUP_UPDATE_AUDIO_STREAM_RECOVER",i[i.GROUP_UPDATE_ADD_PARTICIPANTS=2]="GROUP_UPDATE_ADD_PARTICIPANTS",i[i.GROUP_UPDATE_REMOVE_PARTICIPANTS=3]="GROUP_UPDATE_REMOVE_PARTICIPANTS",i[i.GROUP_UPDATE_SET_PROPERTIES=4]="GROUP_UPDATE_SET_PROPERTIES",i[i.GROUP_UPDATE_REMOVE_PROPERTIES=5]="GROUP_UPDATE_REMOVE_PROPERTIES",(o=e.GroupListUpdate||(e.GroupListUpdate={}))[o.GROUP_LIST_UPDATE_ADD_ID=0]="GROUP_LIST_UPDATE_ADD_ID",o[o.GROUP_LIST_UPDATE_REMOVE_ID=1]="GROUP_LIST_UPDATE_REMOVE_ID",(a=e.LEAVE_GROUP_REASON_CODE||(e.LEAVE_GROUP_REASON_CODE={}))[a.NORMAL_LEAVE=0]="NORMAL_LEAVE",(s=e.DismissGroupReasonCode||(e.DismissGroupReasonCode={}))[s.NORMAL_DISMISS=0]="NORMAL_DISMISS",(c=e.Result||(e.Result={}))[c.Ok=0]="Ok",c[c.Error=1]="Error"}(At||(At={}));var xt=e.getProtobufRoot({nested:{signal_msg:{nested:{AudioSsrcSpec:{fields:{ssrc:{type:"uint32",id:1},rtxSsrc:{type:"uint32",id:2}}},VideoSsrcSpec:{fields:{ssrc:{type:"uint32",id:1},rtxSsrc:{type:"uint32",id:2},fecSsrc:{type:"uint32",id:3}}},MultiPcAdaptRequestInfo:{fields:{audioSsrcSpec:{rule:"repeated",type:"AudioSsrcSpec",id:1},videoSsrcSpec:{rule:"repeated",type:"VideoSsrcSpec",id:2}}},AudioStreamFormat:{fields:{codec:{type:"string",id:1},sampleRate:{type:"int64",id:2},channelNum:{type:"int64",id:3}}},AudioFormatPreference:{fields:{preferred:{type:"AudioStreamFormat",id:1},optional:{rule:"repeated",type:"AudioStreamFormat",id:2}}},AudioStreamOptional:{fields:{format:{rule:"repeated",type:"AudioStreamFormat",id:1}}},VideoStreamFormat:{fields:{codec:{type:"string",id:1},profile:{type:"string",id:2}}},VideoFormatPreference:{fields:{preferred:{type:"VideoStreamFormat",id:1},optional:{rule:"repeated",type:"VideoStreamFormat",id:2}}},FormatPreference:{fields:{audio:{type:"AudioFormatPreference",id:1},video:{type:"VideoFormatPreference",id:2}}},Resolution:{fields:{width:{type:"uint32",id:1},height:{type:"uint32",id:2}}},VideoSsrcParameters:{fields:{ssrc:{type:"uint32",id:1},framerate:{type:"int32",id:2},resolution:{type:"Resolution",id:3},maxBitrate:{type:"int32",id:4},minBitrate:{type:"int32",id:5},active:{type:"bool",id:6},bitrate:{type:"int64",id:7},tlayer:{type:"int64",id:8},multiSlice:{type:"int64",id:9},keyFrameInterval:{type:"int64",id:10},constantPpsid:{type:"int64",id:11},rid:{type:"string",id:12}}},VideoParameters:{oneofs:{_resolutionLevel:{oneof:["resolutionLevel"]}},fields:{ssrc:{type:"uint32",id:1},resolution:{type:"Resolution",id:2},framerate:{type:"int32",id:3},bitrate:{type:"string",id:4},multiSlice:{type:"int32",id:5},keyFrameInterval:{type:"int64",id:6},constantPpsid:{type:"int64",id:7},resolutionLevel:{type:"uint32",id:8,options:{proto3_optional:!0}}}},GroupVersion:{fields:{id:{type:"string",id:1},ver:{type:"int64",id:2}}},StreamInfo:{fields:{type:{type:"string",id:1},owner:{type:"string",id:2},attributesJsonStr:{type:"string",id:3},label:{type:"string",id:4},createTime:{type:"int64",id:7}}},StreamVideoParameters:{fields:{resolution:{type:"Resolution",id:1},framerate:{type:"int64",id:2},bitrate:{type:"int64",id:3},keyFrameInterval:{type:"int64",id:4},multiSlice:{type:"int64",id:5},constantPpsid:{type:"int64",id:6}}},VideoStreamPara:{fields:{specs:{rule:"repeated",type:"string",id:1},resolution:{rule:"repeated",type:"Resolution",id:2},framerate:{rule:"repeated",type:"int32",id:3},bitrate:{rule:"repeated",type:"string",id:4},keyFrameInterval:{rule:"repeated",type:"int32",id:5}}},VideoStreamOptional:{fields:{format:{rule:"repeated",type:"VideoStreamFormat",id:1},parameters:{type:"VideoStreamPara",id:2}}},StreamAudioDesc:{fields:{trackId:{type:"string",id:1},msid:{type:"string",id:2},status:{type:"string",id:3},format:{type:"AudioStreamFormat",id:4},source:{type:"string",id:5},ssrc:{rule:"repeated",type:"uint32",id:6},ssrcGroup:{rule:"repeated",type:"AudioSsrcSpec",id:7},optional:{type:"AudioStreamOptional",id:8}}},StreamVideoDesc:{fields:{trackId:{type:"string",id:1},msid:{type:"string",id:2},status:{type:"string",id:3},source:{type:"string",id:4},format:{type:"VideoStreamFormat",id:5},ssrc:{rule:"repeated",type:"uint32",id:6},ssrcGroup:{rule:"repeated",type:"VideoSsrcSpec",id:7},parameters:{type:"StreamVideoParameters",id:8},optional:{type:"VideoStreamOptional",id:9}}},StreamMediaDesc:{fields:{audio:{type:"StreamAudioDesc",id:1},video:{type:"StreamVideoDesc",id:2}}},Stream:{fields:{id:{type:"string",id:1},type:{type:"string",id:2},media:{type:"StreamMediaDesc",id:3},info:{type:"StreamInfo",id:4},version:{type:"int64",id:5}}},OriginMsg:{fields:{type:{type:"string",id:1},id:{type:"string",id:2}}},ErrorMsg:{fields:{id:{type:"string",id:1},code:{type:"int32",id:2},msg:{type:"string",id:3},origin:{type:"OriginMsg",id:4}}},ErrorMsgs:{fields:{globalStatus:{type:"string",id:1},detailStatus:{rule:"repeated",type:"ErrorMsg",id:2}}},DataType:{values:{DATA_TYPE_STREAM:0,DATA_TYPE_PARTICIPANTS:1,DATA_TYPE_CONFERENCE:2,DATA_TYPE_GROUP_LIST:3,DATA_TYPE_GROUP:4}},OptType:{values:{OPT_TYPE_ADD:0,OPT_TYPE_REMOVE:1,OPT_TYPE_UPDATE:2}},SyncResponseCode:{values:{SYNC_OK:0,SYNC_PART_SUC:10,SYNC_DATA_SIZE_LIMITED:11,SYNC_NOT_SUPPORT_TYPE:12,SYNC_NOT_FOUND:13,SYNC_CHANNEL_NOT_EXIST:14,SYNC_INTERNAL_ERROR:15}},GroupParticipant:{fields:{uid:{type:"string",id:1},pid:{type:"string",id:2},userData:{type:"string",id:3}}},GroupAudioInfo:{fields:{label:{type:"string",id:1},audio:{type:"Stream",id:2}}},GroupInfo:{fields:{id:{type:"string",id:1},ver:{type:"int64",id:2},participants:{rule:"repeated",type:"GroupParticipant",id:3},audioInfo:{type:"GroupAudioInfo",id:4},properties:{rule:"repeated",type:"GroupProperty",id:5}}},GroupProperty:{fields:{key:{type:"string",id:1},value:{type:"string",id:2}}},SyncFullData:{oneofs:{_ver:{oneof:["ver"]},_totalPages:{oneof:["totalPages"]},_pagingSeq:{oneof:["pagingSeq"]}},fields:{ver:{type:"int64",id:1,options:{proto3_optional:!0}},totalPages:{type:"int32",id:2,options:{proto3_optional:!0}},pagingSeq:{type:"int64",id:3,options:{proto3_optional:!0}},groupData:{type:"GroupPagingData",id:10},groupListData:{type:"GroupListPagingData",id:11}}},GroupPagingData:{fields:{pagingSeq:{type:"int64",id:1},curPage:{type:"int32",id:2},groupInfos:{rule:"repeated",type:"GroupInfo",id:3}}},GroupListPagingData:{fields:{pagingSeq:{type:"int64",id:1},curPage:{type:"int32",id:2},groupIds:{rule:"repeated",type:"string",id:3}}},SyncChangeLog:{fields:{groupListChangeLogs:{rule:"repeated",type:"GroupListChangeLog",id:1},groupChangeLogs:{rule:"repeated",type:"GroupChangeLog",id:2}}},SyncDataRequest:{oneofs:{_id:{oneof:["id"]}},fields:{type:{type:"DataType",id:1},id:{type:"string",id:2,options:{proto3_optional:!0}},ver:{type:"int64",id:3},forceFullSync:{type:"bool",id:4},supportPagingSync:{type:"bool",id:5}}},SyncDataResponse:{fields:{code:{type:"SyncResponseCode",id:1},errMsg:{type:"string",id:2},fullSync:{type:"SyncFullData",id:3},changeLogs:{rule:"repeated",type:"SyncChangeLog",id:4}}},SyncIds:{fields:{id:{type:"string",id:1},ver:{type:"int64",id:2}}},SyncDataByIdsRequest:{fields:{type:{type:"DataType",id:1},ids:{rule:"repeated",type:"SyncIds",id:2},forceFullSync:{type:"bool",id:3},supportPagingSync:{type:"bool",id:4}}},SyncDataByIdsResponse:{fields:{code:{type:"SyncResponseCode",id:1},errMsg:{type:"string",id:2},notFoundIds:{rule:"repeated",type:"string",id:3},fullSync:{type:"SyncFullData",id:4},changeLogs:{rule:"repeated",type:"SyncChangeLog",id:5}}},GroupUpdate:{values:{GROUP_UPDATE_AUDIO_STREAM_LOST:0,GROUP_UPDATE_AUDIO_STREAM_RECOVER:1,GROUP_UPDATE_ADD_PARTICIPANTS:2,GROUP_UPDATE_REMOVE_PARTICIPANTS:3,GROUP_UPDATE_SET_PROPERTIES:4,GROUP_UPDATE_REMOVE_PROPERTIES:5}},GroupUpdateOpt:{fields:{updateAction:{type:"GroupUpdate",id:1},participants:{rule:"repeated",type:"GroupParticipant",id:2},properties:{rule:"repeated",type:"GroupProperty",id:3}}},GroupChangeLog:{oneofs:{_groupInfo:{oneof:["groupInfo"]},_updateOpt:{oneof:["updateOpt"]},_msgId:{oneof:["msgId"]}},fields:{ver:{type:"int64",id:1},type:{type:"OptType",id:2},id:{type:"string",id:3},groupInfo:{type:"GroupInfo",id:4,options:{proto3_optional:!0}},updateOpt:{type:"GroupUpdateOpt",id:5,options:{proto3_optional:!0}},msgId:{type:"string",id:6,options:{proto3_optional:!0}}}},GroupListUpdate:{values:{GROUP_LIST_UPDATE_ADD_ID:0,GROUP_LIST_UPDATE_REMOVE_ID:1}},GroupListUpdateOpt:{fields:{updateAction:{type:"GroupListUpdate",id:1},id:{type:"string",id:2}}},GroupListChangeLog:{oneofs:{_msgId:{oneof:["msgId"]}},fields:{ver:{type:"int64",id:1},type:{type:"OptType",id:2},updateOpt:{type:"GroupListUpdateOpt",id:3},msgId:{type:"string",id:4,options:{proto3_optional:!0}}}},JoinGroupRequest:{fields:{groupId:{type:"string",id:1},userData:{type:"string",id:2},autoJoinGroupAudio:{type:"bool",id:3},autoLeaveChannelAudio:{type:"bool",id:4}}},JoinGroupResponse:{oneofs:{_joinGroupAudioSuccess:{oneof:["joinGroupAudioSuccess"]}},fields:{code:{type:"int32",id:1},errMsg:{type:"string",id:2},group:{type:"GroupInfo",id:3},joinGroupAudioSuccess:{type:"bool",id:4,options:{proto3_optional:!0}}}},LEAVE_GROUP_REASON_CODE:{values:{NORMAL_LEAVE:0}},LeaveGroupRequest:{fields:{groupId:{type:"string",id:1},reasonCode:{type:"LEAVE_GROUP_REASON_CODE",id:2},autoJoinChannelAudio:{type:"bool",id:3}}},LeaveGroupResponse:{oneofs:{_joinChannelAudioSuccess:{oneof:["joinChannelAudioSuccess"]}},fields:{code:{type:"int32",id:1},errMsg:{type:"string",id:2},joinChannelAudioSuccess:{type:"bool",id:3,options:{proto3_optional:!0}}}},DismissGroupReasonCode:{values:{NORMAL_DISMISS:0}},DismissGroupRequest:{fields:{groupId:{type:"string",id:1},reasonCode:{type:"DismissGroupReasonCode",id:2}}},DismissGroupResponse:{fields:{code:{type:"int32",id:1},errMsg:{type:"string",id:2}}},ObserveAllGroupsRequest:{fields:{}},ObserveAllGroupsResponse:{fields:{code:{type:"int32",id:1},errMsg:{type:"string",id:2}}},UnobserveAllGroupsRequest:{fields:{}},UnobserveAllGroupsResponse:{fields:{code:{type:"int32",id:1},errMsg:{type:"string",id:2}}},SetGroupPropertiesRequest:{fields:{groupId:{type:"string",id:1},properties:{rule:"repeated",type:"GroupProperty",id:2}}},SetGroupPropertiesResponse:{fields:{code:{type:"int32",id:1},errMsg:{type:"string",id:2}}},RemoveGroupPropertiesRequest:{fields:{groupId:{type:"string",id:1},keys:{rule:"repeated",type:"string",id:2}}},RemoveGroupPropertiesResponse:{fields:{code:{type:"int32",id:1},errMsg:{type:"string",id:2}}},SetParticipantPropertiesRequest:{fields:{roomId:{type:"string",id:1},participantId:{type:"string",id:2},propertiesJsonStr:{type:"string",id:3},tid:{type:"string",id:4},traceId:{type:"string",id:5}}},RemoveParticipantPropertiesRequest:{fields:{roomId:{type:"string",id:1},participantId:{type:"string",id:2},propertiesJsonStr:{type:"string",id:3},tid:{type:"string",id:4},traceId:{type:"string",id:5}}},Result:{values:{Ok:0,Error:1}},Response:{oneofs:{data:{oneof:["reason","createPeerConnectionResponse","errorMsg","queryStreamsVerResponse","queryStreamsResponse","publishResponse","subscribeResponse","joinGroupResponse","leaveGroupResponse","dismissGroupResponse","observeAllGroupsResponse","unobserveAllGroupsResponse","syncDataResponse","syncDataByIdsResponse","setGroupPropertiesResponse","removeGroupPropertiesResponse"]}},fields:{result:{type:"Result",id:1},tid:{type:"string",id:2},traceId:{type:"string",id:3},code:{type:"int32",id:4},reason:{type:"string",id:11},createPeerConnectionResponse:{type:"CreatePeerConnectionResponse",id:15},errorMsg:{type:"ErrorMsgs",id:16},queryStreamsVerResponse:{type:"QueryStreamsVerResponse",id:17},queryStreamsResponse:{type:"QueryStreamsResponse",id:18},publishResponse:{type:"PublishResponse",id:21},subscribeResponse:{type:"SubscribeResponse",id:22},joinGroupResponse:{type:"JoinGroupResponse",id:24},leaveGroupResponse:{type:"LeaveGroupResponse",id:25},dismissGroupResponse:{type:"DismissGroupResponse",id:26},observeAllGroupsResponse:{type:"ObserveAllGroupsResponse",id:27},unobserveAllGroupsResponse:{type:"UnobserveAllGroupsResponse",id:28},syncDataResponse:{type:"SyncDataResponse",id:29},syncDataByIdsResponse:{type:"SyncDataByIdsResponse",id:30},setGroupPropertiesResponse:{type:"SetGroupPropertiesResponse",id:31},removeGroupPropertiesResponse:{type:"RemoveGroupPropertiesResponse",id:32}}},NotificationItem:{oneofs:{notification:{oneof:["streamNotification","serverFailoverNotification","progressNotification","groupNotification","groupListNotification"]}},fields:{event:{type:"string",id:1},streamNotification:{type:"StreamNotification",id:11},serverFailoverNotification:{type:"ServerFailoverNotification",id:13},progressNotification:{type:"ProgressNotification",id:14},groupNotification:{type:"GroupChangeLog",id:17},groupListNotification:{type:"GroupListChangeLog",id:18}}},BatchNotification:{fields:{notificationItem:{rule:"repeated",type:"NotificationItem",id:1},tid:{type:"string",id:2},traceId:{type:"string",id:3}}},MediaMessage:{fields:{payload:{type:"string",id:1}}},AudioStreamTrackDesc:{fields:{streamId:{type:"string",id:1},trackId:{type:"string",id:2},msid:{type:"string",id:3},source:{type:"string",id:4},uplinkSsrcGroup:{rule:"repeated",type:"AudioSsrcSpec",id:5},format:{type:"AudioStreamFormat",id:6},autoMix:{rule:"repeated",type:"string",id:7},attributesJsonString:{type:"string",id:8}}},VideoStreamTrackDesc:{fields:{streamId:{type:"string",id:1},trackId:{type:"string",id:2},msid:{type:"string",id:3},source:{type:"string",id:4},logicSsrc:{rule:"repeated",type:"uint32",id:5},uplinkSsrcGroup:{rule:"repeated",type:"VideoSsrcSpec",id:6},ssrcParameters:{rule:"repeated",type:"VideoSsrcParameters",id:7},streamParameters:{type:"VideoParameters",id:8},attributesJsonString:{type:"string",id:9},forwardOnly:{type:"bool",id:10},mid:{type:"string",id:11}}},MediaStreamTrackDesc:{fields:{audio:{rule:"repeated",type:"AudioStreamTrackDesc",id:1},video:{rule:"repeated",type:"VideoStreamTrackDesc",id:2}}},StreamVersion:{fields:{streamId:{type:"string",id:1},streamVer:{type:"int64",id:2}}},StreamData:{fields:{id:{type:"string",id:1},stream:{type:"Stream",id:2}}},AudioPubOptions:{fields:{source:{type:"string",id:1},format:{type:"AudioStreamFormat",id:2},autoMix:{rule:"repeated",type:"string",id:3}}},VideoPubOptions:{fields:{source:{type:"string",id:1},format:{type:"VideoStreamFormat",id:2},parameters:{type:"VideoParameters",id:3},forwardOnly:{type:"bool",id:4}}},MediaPubOptionsSpecify:{fields:{audio:{type:"AudioPubOptions",id:1},video:{type:"VideoPubOptions",id:2}}},BatchPublishRequest:{fields:{roomId:{type:"string",id:1},participantId:{type:"string",id:2},connectionId:{type:"string",id:3},type:{type:"string",id:4},simulcast:{type:"bool",id:5},simulcastVersion:{type:"string",id:6},supportTemporalLayer:{type:"bool",id:7},clientType:{type:"string",id:8},clientVersion:{type:"string",id:9},media:{type:"MediaStreamTrackDesc",id:10},event:{type:"string",id:11},tid:{type:"string",id:12},traceId:{type:"string",id:13}}},BatchUnpublishRequest:{fields:{roomId:{type:"string",id:1},participantId:{type:"string",id:2},connectionId:{type:"string",id:3},audio:{rule:"repeated",type:"string",id:4},video:{rule:"repeated",type:"string",id:5},tid:{type:"string",id:6},traceId:{type:"string",id:7}}},QueryStreamsVerRequest:{fields:{roomId:{type:"string",id:1},participantId:{type:"string",id:2},streamIds:{rule:"repeated",type:"string",id:3},tid:{type:"string",id:4},traceId:{type:"string",id:5}}},QueryStreamsVerResponse:{fields:{streamVersions:{rule:"repeated",type:"StreamVersion",id:1},totalVer:{type:"int32",id:2},msg:{type:"string",id:3}}},StreamControlRequest:{fields:{roomId:{type:"string",id:1},participantId:{type:"string",id:2},streamId:{type:"string",id:3},operation:{type:"string",id:4},data:{type:"string",id:5},tid:{type:"string",id:6},traceId:{type:"string",id:7}}},QueryStreamsRequest:{fields:{roomId:{type:"string",id:1},participantId:{type:"string",id:2},streamIds:{rule:"repeated",type:"string",id:3},tid:{type:"string",id:4},traceId:{type:"string",id:5}}},QueryStreamsResponse:{fields:{totalVer:{type:"int64",id:1},msg:{type:"string",id:2},streams:{rule:"repeated",type:"StreamData",id:3}}},SetStreamPropertiesRequest:{fields:{roomId:{type:"string",id:1},streamId:{type:"string",id:2},propertiesJsonStr:{type:"string",id:3},tid:{type:"string",id:4},traceId:{type:"string",id:5}}},PublishRequest:{fields:{roomId:{type:"string",id:1},participantId:{type:"string",id:2},type:{type:"string",id:3},event:{type:"string",id:4},media:{type:"MediaPubOptionsSpecify",id:5},attributesJsonStr:{type:"string",id:6},tid:{type:"string",id:7},traceId:{type:"string",id:8}}},PublishResponse:{fields:{id:{type:"string",id:1}}},UnpublishRequest:{fields:{roomId:{type:"string",id:1},participantId:{type:"string",id:2},streamId:{type:"string",id:3},tid:{type:"string",id:4},traceId:{type:"string",id:5}}},NetworkHealth:{fields:{receiving:{type:"bool",id:1},lossRate:{type:"int32",id:2},timestamp:{type:"int64",id:3},cutoff:{type:"bool",id:4},tid:{type:"string",id:5}}},StreamMsg:{oneofs:{value:{oneof:["networkHealth","streamStatus","stream","activeStream","propertiesJsonStr"]}},fields:{field:{type:"string",id:1},streamVer:{type:"int64",id:2},expiredMs:{type:"int64",id:3},extraValue:{rule:"repeated",type:"string",id:4},tid:{type:"string",id:5},networkHealth:{type:"NetworkHealth",id:10},streamStatus:{type:"string",id:11},stream:{type:"Stream",id:12},activeStream:{type:"string",id:13},propertiesJsonStr:{type:"string",id:14}}},StreamNotification:{oneofs:{data:{oneof:["stream","msg"]}},fields:{streamId:{type:"string",id:1},status:{type:"string",id:2},totalVer:{type:"int64",id:3},msgId:{type:"string",id:4},ts:{type:"int64",id:5},tid:{type:"string",id:6},traceId:{type:"string",id:7},stream:{type:"Stream",id:10},msg:{type:"StreamMsg",id:11}}},Candidate:{fields:{candidate:{type:"string",id:1},sdpMlineIndex:{type:"int32",id:2},sdpMid:{type:"string",id:3}}},SessionSignaling:{fields:{type:{type:"string",id:1},sdp:{type:"string",id:2},candidate:{type:"Candidate",id:3},optionsJsonStr:{type:"string",id:4}}},SignalingData:{fields:{type:{type:"string",id:1},sdp:{type:"string",id:2}}},CreatePeerConnectionRequest:{fields:{roomId:{type:"string",id:1},participantId:{type:"string",id:2},connectionId:{type:"string",id:3},tid:{type:"string",id:4},event:{type:"string",id:5},direction:{type:"string",id:6},sdpOffer:{type:"string",id:7},type:{type:"string",id:8},isOca:{type:"bool",id:9},isFailover:{type:"bool",id:10},multiPcAdaptInfo:{type:"MultiPcAdaptRequestInfo",id:11},pcFormatPreference:{type:"FormatPreference",id:12},optionsJsonStr:{type:"string",id:13},traceId:{type:"string",id:14},sfuSsrcGroup:{rule:"repeated",type:"AudioSsrcSpec",id:15}}},CreatePeerConnectionResponse:{fields:{connectionId:{type:"string",id:1},sdpAnswer:{type:"string",id:2}}},ClosePeerConnectionRequest:{fields:{roomId:{type:"string",id:1},participantId:{type:"string",id:2},connectionId:{type:"string",id:3},direction:{type:"string",id:4},tid:{type:"string",id:5},traceId:{type:"string",id:6}}},SoacRequest:{fields:{id:{type:"string",id:1},signaling:{type:"SessionSignaling",id:2},tid:{type:"string",id:3},traceId:{type:"string",id:4}}},NotifyAction:{fields:{actionName:{type:"string",id:1},connectionId:{type:"string",id:2},traceId:{type:"string",id:3}}},ServerFailoverNotification:{fields:{actions:{rule:"repeated",type:"NotifyAction",id:1},msgId:{type:"string",id:2},tid:{type:"string",id:3},traceId:{type:"string",id:4}}},ProgressNotification:{fields:{id:{type:"string",id:1},status:{type:"string",id:2},data:{type:"SignalingData",id:3},msgId:{type:"string",id:4},tid:{type:"string",id:5},traceId:{type:"string",id:6}}},AudioBatchSubOptions:{fields:{subscriptionId:{type:"string",id:1},from:{type:"string",id:2},trackId:{type:"string",id:3},ssrcGroup:{rule:"repeated",type:"AudioSsrcSpec",id:4},format:{type:"AudioStreamFormat",id:5}}},VideoBatchSubOptions:{fields:{subscriptionId:{type:"string",id:1},from:{type:"string",id:2},trackId:{type:"string",id:3},ssrcGroup:{rule:"repeated",type:"VideoSsrcSpec",id:4},parameters:{type:"VideoParameters",id:5},format:{type:"VideoStreamFormat",id:6},subSsrcGroup:{type:"VideoSsrcSpec",id:7}}},MediaBatchSubOptions:{fields:{audio:{rule:"repeated",type:"AudioBatchSubOptions",id:1},video:{rule:"repeated",type:"VideoBatchSubOptions",id:2}}},Audio:{fields:{from:{type:"string",id:1}}},Video:{fields:{from:{type:"string",id:1},params:{type:"VideoParameters",id:2}}},MediaUpdateDesc:{fields:{audio:{type:"Audio",id:1},video:{type:"Video",id:2}}},AudioSubOptions:{fields:{from:{type:"string",id:1},format:{type:"AudioStreamFormat",id:2}}},VideoSubOptions:{fields:{from:{type:"string",id:1},format:{type:"VideoStreamFormat",id:2},parameters:{type:"VideoParameters",id:3}}},MediaSubOptionsSpecify:{fields:{audio:{type:"AudioSubOptions",id:1},video:{type:"VideoSubOptions",id:2}}},SubscribeRequest:{fields:{roomId:{type:"string",id:1},participantId:{type:"string",id:2},tid:{type:"string",id:3},event:{type:"string",id:4},media:{type:"MediaSubOptionsSpecify",id:5},type:{type:"string",id:6},propertiesJsonStr:{type:"string",id:7},traceId:{type:"string",id:8}}},SubscribeResponse:{fields:{id:{type:"string",id:1}}},UnsubscribeRequest:{fields:{roomId:{type:"string",id:1},participantId:{type:"string",id:2},subscriptionId:{type:"string",id:3},tid:{type:"string",id:4},traceId:{type:"string",id:5}}},BatchSubscribeRequest:{fields:{roomId:{type:"string",id:1},participantId:{type:"string",id:2},connectionId:{type:"string",id:3},supportTemporalLayer:{type:"bool",id:4},clientType:{type:"string",id:5},clientVersion:{type:"string",id:6},media:{type:"MediaBatchSubOptions",id:7},tid:{type:"string",id:8},type:{type:"string",id:9},event:{type:"string",id:10},propertiesJsonStr:{type:"string",id:11},traceId:{type:"string",id:12}}},BatchUnsubscribeRequest:{fields:{roomId:{type:"string",id:1},participantId:{type:"string",id:2},connectionId:{type:"string",id:3},audio:{rule:"repeated",type:"string",id:4},video:{rule:"repeated",type:"string",id:5},tid:{type:"string",id:6},traceId:{type:"string",id:7}}},SubscriptionControlRequest:{oneofs:{data:{oneof:["updateDesc","track"]}},fields:{roomId:{type:"string",id:1},participantId:{type:"string",id:2},subscriptionId:{type:"string",id:3},operation:{type:"string",id:4},updateDesc:{type:"MediaUpdateDesc",id:6},track:{type:"string",id:7},tid:{type:"string",id:8},traceId:{type:"string",id:9}}}}}}}),jt=xt.lookupType("signal_msg.Response"),Nt=xt.lookupType("signal_msg.BatchNotification"),Lt=xt.lookupType("signal_msg.MediaMessage"),Vt=xt.lookupType("signal_msg.StreamNotification");xt.lookupType("signal_msg.ProgressNotification");var Gt=xt.lookupType("signal_msg.ServerFailoverNotification"),Ut=xt.lookupType("signal_msg.PublishRequest"),Ft=xt.lookupType("signal_msg.SoacRequest"),Bt=xt.lookupType("signal_msg.UnpublishRequest"),qt=xt.lookupType("signal_msg.StreamControlRequest"),Ht=xt.lookupType("signal_msg.SubscribeRequest"),Jt=xt.lookupType("signal_msg.SetStreamPropertiesRequest"),Yt=xt.lookupType("signal_msg.UnsubscribeRequest"),Wt=xt.lookupType("signal_msg.SubscriptionControlRequest"),Qt=xt.lookupType("signal_msg.CreatePeerConnectionRequest"),Kt=xt.lookupType("signal_msg.ClosePeerConnectionRequest"),zt=xt.lookupType("signal_msg.BatchPublishRequest"),$t=xt.lookupType("signal_msg.BatchUnpublishRequest"),Xt=xt.lookupType("signal_msg.BatchSubscribeRequest"),Zt=xt.lookupType("signal_msg.BatchUnsubscribeRequest"),er=xt.lookupType("signal_msg.JoinGroupRequest"),tr=xt.lookupType("signal_msg.SetGroupPropertiesRequest"),rr=xt.lookupType("signal_msg.DismissGroupRequest"),nr=xt.lookupType("signal_msg.LeaveGroupRequest"),ir=xt.lookupType("signal_msg.SyncDataRequest"),or=xt.lookupType("signal_msg.SyncDataByIdsRequest"),ar=xt.lookupType("signal_msg.GroupChangeLog"),sr=xt.lookupType("signal_msg.GroupListChangeLog"),cr=xt.lookupType("signal_msg.SetParticipantPropertiesRequest"),ur=xt.lookupType("signal_msg.QueryStreamsVerRequest"),dr=xt.lookupType("signal_msg.QueryStreamsRequest");function lr(){try{var e=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(e){}return(lr=function(){return!!e})()}var pr=function(){function t(e){var r,n,i,a;return o(this,t),n=this,i=l(i=t),r=d(n,lr()?Reflect.construct(i,[],l(n).constructor):i.apply(n,a)),Object.defineProperty(r,"loggedIn",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(r,"channel",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(r,"rpcId",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(r,"reporter",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),r.channel=e,r.rpcId=0,r.reporter=e.reporter,r.handleBatchNotifyEvent=r.handleBatchNotifyEvent.bind(r),r.handleNotifyEvent=r.handleNotifyEvent.bind(r),r.handleConnectionStateChangeEvent=r.handleConnectionStateChangeEvent.bind(r),r.handleSyncEvent=r.handleSyncEvent.bind(r),r.handleUserEvent=r.handleUserEvent.bind(r),r.channel.on("connection-state-change",r.handleConnectionStateChangeEvent),r.channel.on("sync",r.handleSyncEvent),r.channel.on("batch-notify",r.handleBatchNotifyEvent),r.channel.on("notify",r.handleNotifyEvent),r.channel.on("user",r.handleUserEvent),r}return f(t,e.EventEmitter),u(t,[{key:"join",value:function(e,t){return this.channel.join(e,t).then(function(e){return{joinResponse:e.joinResponse,iceConfig:e.iceConfig}})}},{key:"leave",value:function(){return this.channel.leave()}},{key:"handleUserEvent",value:function(e,t){this.emit("user",e,t)}},{key:"handleSyncEvent",value:function(e){this.emit("sync",e)}},{key:"handleConnectionStateChangeEvent",value:function(e,t,r){this.emit("connection-state-change",e,t,r)}},{key:"handleNotifyEvent",value:function(e,t){"stream"===e?this.emit("stream",Vt.decode(t)):"serverFailover"===e?this.emit("serverFailover",Gt.decode(t)):"media-message"===e?this.emit("media-message",Lt.decode(t)):"group"===e?this.emit("group",ar.decode(t)):"group-list"===e&&this.emit("group-list",sr.decode(t))}},{key:"handleBatchNotifyEvent",value:function(e){var t=this;Nt.decode(e).notificationItem.forEach(function(e){"stream"===e.event?t.emit("stream",e.streamNotification):"serverFailover"===e.event?t.emit("serverFailover",e.serverFailoverNotification):"group"===e.event?t.emit("group",e.groupNotification):"group-list"===e.event&&t.emit("group-list",e.groupListNotification)})}},{key:"createPeerConnection",value:function(e){var t=Qt.encode(e).finish();return this.rpc("create-peer-connection",t,e).then(function(e){return e.createPeerConnectionResponse})}},{key:"closePeerConnection",value:function(e){var t=Kt.encode(e).finish();return this.rpc("close-peer-connection",t,e)}},{key:"batchSubscribe",value:function(e){var t=Xt.encode(e).finish();return this.rpc("batch-subscribe",t,e).then(function(e){return e.errorMsg})}},{key:"setGroupProperties",value:function(e){var t=tr.encode(e).finish();return this.rpc("set-group-properties",t,e).then(function(e){return e.setGroupPropertiesResponse})}},{key:"batchUnSubscribe",value:function(e){var t=Zt.encode(e).finish();return this.rpc("batch-unsubscribe",t,e)}},{key:"batchPublish",value:function(e){var t=zt.encode(e).finish();return this.rpc("batch-publish",t,e).then(function(e){return e.errorMsg})}},{key:"batchUnPublish",value:function(e){var t=$t.encode(e).finish();return this.rpc("batch-unpublish",t,e)}},{key:"publish",value:function(e){var t=Ut.encode(e).finish();return this.rpc("publish",t,e).then(function(e){return e.publishResponse})}},{key:"setParticipantProperties",value:function(e){var t=cr.encode(e).finish();return this.rpc("set-participant-properties",t,e)}},{key:"soac",value:function(e){var t=Ft.encode(e).finish();return this.rpc("soac",t,e)}},{key:"unpublish",value:function(e){var t=Bt.encode(e).finish();return this.rpc("unpublish",t,e)}},{key:"streamControl",value:function(e){var t=qt.encode(e).finish();return this.rpc("stream-control",t,e)}},{key:"setStreamProperties",value:function(e){var t=Jt.encode(e).finish();return this.rpc("set-stream-properties",t,e)}},{key:"subscribe",value:function(e){var t=Ht.encode(e).finish();return this.rpc("subscribe",t,e).then(function(e){return e.subscribeResponse})}},{key:"unsubscribe",value:function(e){var t=Yt.encode(e).finish();return this.rpc("unsubscribe",t,e)}},{key:"subscriptionControl",value:function(e){var t=Wt.encode(e).finish();return this.rpc("subscription-control",t,e)}},{key:"getStreamsVer",value:function(e){var t=ur.encode(e).finish();return this.rpc("query-streams-ver",t,e).then(function(e){return e.queryStreamsVerResponse})}},{key:"getStreams",value:function(e){var t=dr.encode(e).finish();return this.rpc("query-streams",t,e).then(function(e){return e.queryStreamsResponse})}},{key:"joinGroup",value:function(e){var t=er.encode(e).finish();return this.rpc("join-group",t,e).then(function(e){return e.joinGroupResponse})}},{key:"leaveGroup",value:function(e){var t=nr.encode(e).finish();return this.rpc("leave-group",t,e).then(function(e){return e.leaveGroupResponse})}},{key:"dismissGroup",value:function(e){var t=rr.encode(e).finish();return this.rpc("dismiss-group",t,e).then(function(e){return e.dismissGroupResponse})}},{key:"syncData",value:function(e){var t=ir.encode(e).finish();return this.rpc("sync-data",t,e).then(function(e){return e.syncDataResponse})}},{key:"syncDataByIds",value:function(e){var t=or.encode(e).finish();return this.rpc("sync-data-by-ids",t,e).then(function(e){return e.syncDataByIdsResponse})}},{key:"observeAllGroups",value:function(){return this.rpc("observe-all-groups",null).then(function(e){return e.observeAllGroupsResponse})}},{key:"unobserveAllGroups",value:function(){return this.rpc("unobserve-all-groups",null).then(function(e){return e.unobserveAllGroupsResponse})}},{key:"rpc",value:function(e,t){var r=this,n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:void 0;return new Promise(function(i,o){var a=r.rpcId++;r.reporter.log.debug("rtc rpcId ".concat(a,":").concat(e," param====> ").concat(JSON.stringify(n||""))),r.channel.signaling.rpc(e,t,n).then(function(t){var n=jt.decode(t);n.code===At.Result.Ok?(r.reporter.log.debug("rtc rpcId ".concat(a,":").concat(e," result====> ").concat(JSON.stringify(n))),i(n)):(r.reporter.log.debug("rtc rpcId ".concat(a,":").concat(e," error====> ").concat(JSON.stringify(n))),o(n))})})}}])}();function fr(){try{var e=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(e){}return(fr=function(){return!!e})()}var vr=function(){function t(){var r,n,i,a;o(this,t),n=this,i=l(i=t),r=d(n,fr()?Reflect.construct(i,[],l(n).constructor):i.apply(n,a)),Object.defineProperty(r,"interval",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(r,"timer",{enumerable:!0,configurable:!0,writable:!0,value:void 0});var s=e.getReporter().statsConfig;return r.interval=(null==s?void 0:s.statsIntervalMs)||2e3,r.start(),r}return f(t,e.EventEmitter),u(t,[{key:"start",value:function(){var t=this;this.stop(),this.makeReport&&this.makeReport(),this.timer=e.addTimer(function(){t.makeReport()},this.interval,"interval")}},{key:"stop",value:function(){this.timer&&(e.removeTimer(this.timer,"interval"),this.timer=null)}}])}();function mr(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),r.push.apply(r,n)}return r}function hr(e){for(var t=1;arguments.length>t;t++){var r=null!=arguments[t]?arguments[t]:{};t%2?mr(Object(r),!0).forEach(function(t){X(e,t,r[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):mr(Object(r)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))})}return e}function yr(e,t){var r="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!r){if(Array.isArray(e)||(r=function(e,t){if(e){if("string"==typeof e)return gr(e,t);var r={}.toString.call(e).slice(8,-1);return"Object"===r&&e.constructor&&(r=e.constructor.name),"Map"===r||"Set"===r?Array.from(e):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?gr(e,t):void 0}}(e))||t){r&&(e=r);var n=0,i=function(){};return{s:i,n:function(){return e.length>n?{done:!1,value:e[n++]}:{done:!0}},e:function(e){throw e},f:i}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var o,a=!0,s=!1;return{s:function(){r=r.call(e)},n:function(){var e=r.next();return a=e.done,e},e:function(e){s=!0,o=e},f:function(){try{a||null==r.return||r.return()}finally{if(s)throw o}}}}function gr(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=Array(t);t>r;r++)n[r]=e[r];return n}function br(){try{var e=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(e){}return(br=function(){return!!e})()}var Sr={timestamp:0,audioLevel:0,bytesSent:0,packetsSent:0,packetsLost:0,roundTripTime:0},kr={totalFramesSent:0,totalBytesSent:0,totalPacketsLost:0,totalPacketsSent:0,totalFramesEncoded:0,timestamp:0,totalQpSum:0,maxSendFrameHeight:0,maxSendFrameWidth:0,captureFrameHeight:0,captureFrameWidth:0,captureFramesPerSecond:0,sendFramesPerSecond:0,availableOutgoingBitrate:0,targetBitrate:0,roundTripTime:0,encodeFramesPerSecond:0,totalEncodedTime:0,trackStats:new Map},Pr=function(){function t(e){var r,n,i,a;o(this,t),n=this,i=l(i=t),r=d(n,br()?Reflect.construct(i,[],l(n).constructor):i.apply(n,a)),Object.defineProperty(r,"videoSendReport",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(r,"audioSendReport",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(r,"bweReport",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(r,"lastVideoSendInfo",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(r,"lastAudioSendInfo",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(r,"track",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(r,"source",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(r,"pc",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(r,"tranceiver",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(r,"connection",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),r.connection=e.connection,r.pc=e.connection.pc;var s=e.tracks.filter(function(e){return"video"===e.trackMediaType})[0];return r.source=null==s?void 0:s.source,r.track=e.tracks[0],r.tranceiver=e.transceiver,r.lastVideoSendInfo=Object.assign({},kr),r.videoSendReport={attr_bitrate:0,attr_capture_frames:0,attr_enc_average_elapsed_ms:0,attr_encode_qp_sim:"",attr_encoded_framerate_sim:"",attr_resolution_sim:"",attr_stream_options:"",attr_duration_ms:0},r.lastAudioSendInfo=Object.assign({},Sr),r.audioSendReport={attr_duration_ms:0,attr_bitrate:0},r.bweReport={attr_rtt:0,attr_lossrate:0,attr_reported_bitrate:0,attr_duration_ms:0},r}return f(t,vr),u(t,[{key:"extractVideoMetrics",value:function(t){var r=this,n=Object.assign({source:this.source,trackStats:[]},kr,this.connection.peerConnectionStats);if(n.timestamp=Date.now(),this.track){var i=this.track.getMediaStreamTrack().getSettings(),o=i.width,a=i.height,s=i.frameRate;n.captureFramesPerSecond=s===1/0?0:s||0,n.captureFrameWidth=o||0,n.captureFrameHeight=a||0}var c=new Map,u=ge(n,this.lastVideoSendInfo);return t.forEach(function(t){if(/outboundrtp|outbound-rtp/i.test(t.type)){var i=c.get(t.ssrc)||{},o=r.lastVideoSendInfo.trackStats.get(t.ssrc)||{};if(i.sendFrameWidth=t.frameWidth||0,i.sendFrameHeight=t.frameHeight||0,i.framesSent=t.framesSent||0,i.framesEncoded=t.framesEncoded||0,i.targetBitrate=t.targetBitrate||0,i.qpSum=t.qpSum||0,i.bytesSent=t.bytesSent||0,i.packetsSent=t.packetsSent||0,i.packetsSentForLost=i.packetsSent||0,i.totalEncodeTime=t.totalEncodeTime||0,i.keyFramesEncoded=t.keyFramesEncoded||0,i.firCount=t.firCount||0,i.pliCount=t.pliCount||0,i.retransmittedBytesSent=t.retransmittedBytesSent||0,i.retransmittedPacketsSent=t.retransmittedPacketsSent||0,i.qualityLimitationReason=t.qualityLimitationReason||"",i.sendFramesPerSecond=t.framesPerSecond||0,i.sendFrameWidth>n.maxSendFrameWidth){if(n.maxSendFrameWidth=i.sendFrameWidth,!i.sendFramesPerSecond&&o){var a=Se(i.framesSent||i.framesEncoded,o.framesSent||o.framesEncoded);i.sendFramesPerSecond=Math.round(a/u)}if(i.framesEncoded){var s=Se(i.framesEncoded,null==o?void 0:o.framesEncoded);n.encodeFramesPerSecond=Math.round(s/u)}n.sendFramesPerSecond=i.sendFramesPerSecond}c.set(t.ssrc,i),n.targetBitrate=i.targetBitrate,n.totalBytesSent+=i.bytesSent,n.totalPacketsSent+=i.packetsSent,n.totalEncodedTime+=i.totalEncodeTime,n.totalFramesEncoded+=i.framesEncoded,n.totalFramesSent+=i.framesSent,n.totalQpSum+=i.qpSum,n.maxSendFrameHeight=Math.max(i.sendFrameHeight,n.maxSendFrameHeight),c.set(t.ssrc,i)}else if(/track/i.test(t.type)&&!1===t.remoteSource){if(e.Environment.isSafari()){var d=c.get(t.ssrc)||{};d.sendFrameHeight>0||(d.sendFrameWidth=t.frameWidth||0,d.sendFrameHeight=t.frameHeight||0),d.framesSent=t.framesSent||0,d.totalEncodeTime=t.totalEncodeTime||0,c.set(t.ssrc,d),n.totalFramesEncoded+=d.framesEncoded,n.totalEncodedTime+=d.totalEncodeTime,n.totalFramesSent+=d.framesSent,c.set(t.ssrc,d)}}else if(/remote-inbound-rtp/i.test(t.type)){var l=c.get(t.ssrc)||{},p=r.lastVideoSendInfo.trackStats.get(t.ssrc)||{};l.packetsLost=t.packetsLost||0,l.lostTimestamp=t.timestamp,n.totalPacketsLost+=l.packetsLost,l.packetsLost===(p.packetsLost||0)&&(l.packetsSentForLost=p.packetsSentForLost||0,l.lostTimestamp=p.lostTimestamp||0),c.set(t.ssrc,l)}}),n.trackStats=c,n}},{key:"getLayersMetricInfo",value:function(e){var t,r=[],n=yr(e.trackStats.entries());try{for(n.s();!(t=n.n()).done;){var i=He(t.value,2),o=i[1],a=this.lastVideoSendInfo.trackStats.get(i[0])||{},s=Se(o.framesSent,a.framesSent),c=Se(o.framesEncoded,a.framesEncoded),u=Se(o.keyFramesEncoded,a.keyFramesEncoded),d=Se(o.retransmittedBytesSent,a.retransmittedBytesSent),l=Se(o.retransmittedPacketsSent,a.retransmittedPacketsSent),p=Se(o.firCount,a.firCount),f=Se(o.pliCount,a.pliCount),v=Se(o.packetsSent,a.packetsSent),m=Se(o.packetsSentForLost,a.packetsSentForLost),h=Se(o.lostTimestamp,a.lostTimestamp),y=Se(o.packetsLost,a.packetsLost),g=Se(o.totalEncodeTime,a.totalEncodeTime),b=Se(o.qpSum,a.qpSum),S=hr(hr({sendFrameHeight:o.sendFrameHeight,sendFrameWidth:o.sendFrameWidth,qualityLimitationReason:o.qualityLimitationReason},o),{},{deltaQbSum:b,deltaPacketsSent:v,deltaPacketsLost:y,deltaFramesSent:s,deltaTimestampForLost:h,deltaFramesEncoded:c,deltaKeyFramesEncoded:u,deltaFirCount:p,deltaEncodedTime:g,deltaPliCount:f,deltaPacketsSentForLost:m,deltaRetransmittedBytesSent:d,deltaRetransmittedPacketsSent:l});r.push(S)}}catch(e){n.e(e)}finally{n.f()}return{tracksStatInfo:r,totalBytesSent:e.totalBytesSent,totalFramesEncoded:e.totalFramesEncoded||e.totalFramesSent,totalPacketsSent:e.totalPacketsSent,totalEncodedTime:e.totalEncodedTime,totalQpSum:e.totalQpSum,totalPacketsLost:e.totalPacketsLost}}},{key:"makeVideoReport",value:function(e){var t={attr_capture_frames:Math.round(e.captureFramesPerSecond),attr_stream_options:"audio:false/video:".concat(this.source,"/resolution:").concat(e.captureFrameWidth,"*").concat(e.captureFrameHeight,"/")};if(this.lastVideoSendInfo.timestamp){for(var r=this.getLayersMetricInfo(e),n=r.tracksStatInfo,i=r.totalBytesSent,o=r.totalFramesEncoded,a=r.totalEncodedTime,s={attr_encoded_framerate_sim:[],attr_enc_key_frames_sim:[],attr_fir_count_sim:[],attr_pli_count_sim:[],attr_quality_limitation_reason_sim:[],attr_retx_bytes_sim:[],attr_retx_packets_sim:[],attr_resolution_sim:[],attr_encode_qp_sim:[]},c=[],u=0,d=Se(e.timestamp,this.lastVideoSendInfo.timestamp),l=0,p=0;n.length>p;p++){var f=n[p];s.attr_enc_key_frames_sim.push(f.deltaKeyFramesEncoded),s.attr_fir_count_sim.push(f.deltaFirCount),s.attr_pli_count_sim.push(f.deltaPliCount),s.attr_quality_limitation_reason_sim.push(f.qualityLimitationReason),s.attr_retx_bytes_sim.push(f.deltaRetransmittedBytesSent),s.attr_retx_packets_sim.push(f.deltaRetransmittedPacketsSent),l=Math.max(f.deltaTimestampForLost),f.sendFrameWidth&&(f.deltaFramesEncoded||f.deltaFramesSent)&&(s.attr_resolution_sim.push({count:f.deltaFramesSent||f.deltaFramesEncoded,index:p,resolution:"".concat(f.sendFrameWidth,"*").concat(f.sendFrameHeight)}),s.attr_encoded_framerate_sim.push(X({},p,Math.round(1e3*(f.deltaFramesEncoded||f.deltaFramesSent)/d))),s.attr_encode_qp_sim.push(X({},p,Math.round((f.deltaQbSum||0)/(f.deltaFramesEncoded||f.deltaFramesSent))))),f.deltaPacketsLost&&f.deltaPacketsSentForLost&&c.push(f.deltaPacketsLost/f.deltaPacketsSentForLost*255)}for(var v=0,m=Object.entries(s);m.length>v;v++){var h=He(m[v],2),y=h[1];t[h[0]]=y.length?JSON.stringify(y):""}var g=0,b=Se(o,this.lastVideoSendInfo.totalFramesEncoded),S=Se(a,this.lastVideoSendInfo.totalEncodedTime);b&&S&&(g=Math.round(1e3*S/b));var k=Se(i,this.lastVideoSendInfo.totalBytesSent);t.attr_duration_ms=d,t.attr_bitrate=d>0?Math.min(Math.round(8*k*1e3/d),2e7):0,t.attr_enc_average_elapsed_ms=g,this.videoSendReport=t,this.emit("video-send-stream",Object.assign({},this.videoSendReport)),c.length&&(u=Math.min(Math.round(c.reduce(function(e,t){return t+e},0)/c.length),255),this.bweReport={attr_duration_ms:l,attr_rtt:Math.round(e.roundTripTime||0),attr_reported_bitrate:Math.max(0,Math.min(e.availableOutgoingBitrate||0,2e7)),attr_lossrate:u},this.emit("bwe",Object.assign({},this.bweReport)))}this.lastVideoSendInfo=e}},{key:"extractAudioMetrics",value:function(e){var t=this,r=Object.assign({},Sr,this.connection.peerConnectionStats);return e.forEach(function(e){if(/outboundrtp|outbound-rtp/i.test(e.type)?(r.timestamp=e.timestamp,r.bytesSent=e.bytesSent||0,r.packetsSent=e.packetsSent):/remote-inbound-rtp|remoteinboundrt/i.test(e.type)?void 0!==e.packetsLost&&(r.packetsLost=e.packetsLost):/media-source/i.test(e.type)&&e.audioLevel&&(r.audioLevel=e.audioLevel),t.track){var n=t.track.getMediaStreamTrack().getSettings(),i=n.sampleRate;r.channels=n.channelCount,r.sampleRate=i}}),r}},{key:"makeAudioReport",value:function(e){this.lastAudioSendInfo.timestamp>0&&e.timestamp&&(this.audioSendReport={attr_duration_ms:Math.round(Se(e.timestamp,this.lastAudioSendInfo.timestamp)),attr_bitrate:Math.round(8*Se(e.bytesSent,this.lastAudioSendInfo.bytesSent)*1e3/Se(e.timestamp,this.lastAudioSendInfo.timestamp))},this.emit("audio-send-stream",Object.assign({},this.audioSendReport))),this.lastAudioSendInfo=e}},{key:"makeReport",value:function(){var e=this;this.getStats().then(function(t){null!=t&&t.audioMetrics&&e.makeAudioReport(t.audioMetrics),null!=t&&t.videoMetrics&&e.makeVideoReport(t.videoMetrics)})}},{key:"getStats",value:function(){var t,r,n=this,i=this.tranceiver,o=this.pc;if(!o||null==i||null===(t=i.sender)||void 0===t||!t.track)return Promise.resolve({});if(null==o||!o.getStats)throw new e.DingRTCError(e.ErrorCode.BrowserNotSupported,"getStats is not supported");return null===(r=this.pc.getStats(i.sender.track))||void 0===r?void 0:r.then(function(e){return{videoMetrics:n.source?n.extractVideoMetrics(e):void 0,audioMetrics:n.source?void 0:n.extractAudioMetrics(e)}})}}])}();function Er(e,t){var r="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!r){if(Array.isArray(e)||(r=function(e,t){if(e){if("string"==typeof e)return wr(e,t);var r={}.toString.call(e).slice(8,-1);return"Object"===r&&e.constructor&&(r=e.constructor.name),"Map"===r||"Set"===r?Array.from(e):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?wr(e,t):void 0}}(e))||t){r&&(e=r);var n=0,i=function(){};return{s:i,n:function(){return e.length>n?{done:!1,value:e[n++]}:{done:!0}},e:function(e){throw e},f:i}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var o,a=!0,s=!1;return{s:function(){r=r.call(e)},n:function(){var e=r.next();return a=e.done,e},e:function(e){s=!0,o=e},f:function(){try{a||null==r.return||r.return()}finally{if(s)throw o}}}}function wr(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=Array(t);t>r;r++)n[r]=e[r];return n}function Tr(){try{var e=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(e){}return(Tr=function(){return!!e})()}var Or={timestamp:0,packetsLost:0,packetsReceived:0,bytesReceived:0,audioLevel:0,decodingNormal:0,roundTripTime:0},Ir={packetsLost:0,packetsReceived:0,framesDropped:0,frameHeight:0,frameWidth:0,framesDecoded:0,framesReceived:0,timestamp:0,framesPerSecond:0,bytesReceived:0,roundTripTime:0},Rr=function(){function t(r){var n,i,a,s,c;o(this,t),a=this,s=l(s=t),i=d(a,Tr()?Reflect.construct(s,[],l(a).constructor):s.apply(a,c)),Object.defineProperty(i,"videoReceiveReport",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(i,"audioReceiveReport",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(i,"lastVideoReceiveInfo",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(i,"lastAudioReceiveInfo",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(i,"source",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(i,"firstReportFlag",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(i,"firstReportTimer",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(i,"pc",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(i,"tranceiver",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(i,"tranceivers",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(i,"connection",{enumerable:!0,configurable:!0,writable:!0,value:void 0});var u=r.connection,p=r.transceiver,f=r.uid,v=r.stream,m=r.transceivers;return i.connection=u,i.pc=u.pc,i.tranceiver=p,i.tranceivers=m,i.firstReportTimer=e.addTimer(function(){i.getStats().then(function(e){i.makeFirstReport(e)})},400,"interval"),i.source="mcu"!==f&&(null===(n=v.media)||void 0===n||null===(n=n.video)||void 0===n?void 0:n.source),i.videoReceiveReport={attr_duration_ms:0,attr_bitrate:0,attr_current_delay:0,attr_stream_options:"",attr_resolution:"",attr_dec_frames:0,attr_decode_qp:0,attr_fraction_lost:0,attr_network_framerate:0,attr_render_delay:0,attr_dec_key_frames:-1},i.lastVideoReceiveInfo=Object.assign({},Ir),i.firstReportFlag={audioFirstPacket:!1,videoFirstPacket:!1,audioFirstFrame:!1},i.lastAudioReceiveInfo=Object.assign({},Or),i.audioReceiveReport={attr_duration_ms:0,attr_delay_estimate:0,attr_bitrate:0},i}return f(t,vr),u(t,[{key:"extractAudioMetrics",value:function(e){var t=this,r=arguments.length>1&&void 0!==arguments[1]&&arguments[1],n=Object.assign({},Or,this.connection.peerConnectionStats);return n.timestamp=Date.now(),e.forEach(function(e){e.isRemote||(/inboundrtp|inbound-rtp/i.test(e.type)?(n.bytesReceived=e.bytesReceived||0,n.packetsReceived=e.packetsReceived||0,r||(n.packetsReceivedForLost=n.packetsLost===(t.lastAudioReceiveInfo.packetsLost||0)?t.lastAudioReceiveInfo.packetsReceived||0:n.packetsReceived||0),n.packetsLost=e.packetsLost||0,n.audioLevel=e.audioLevel||0,n.decodingNormal=Number(e.googDecodingNormal||0)):/track/i.test(e.type)&&(n.audioLevel=e.audioLevel))}),n}},{key:"extractMultipleAudioMetrics",value:function(e){var t=this,r=e.map(function(e){return t.extractAudioMetrics(e,!0)}),n=Object.assign({},Or,this.connection.peerConnectionStats);n.timestamp=Date.now();var i,o=Er(r);try{for(o.s();!(i=o.n()).done;){var a=i.value;n.bytesReceived+=a.bytesReceived||0,n.packetsLost+=a.packetsLost||0,n.packetsReceived+=a.packetsReceived||0,n.audioLevel=Math.max(n.audioLevel,a.audioLevel||0),n.decodingNormal=Math.max(n.decodingNormal,a.decodingNormal||0)}}catch(e){o.e(e)}finally{o.f()}return n.packetsReceivedForLost=n.packetsLost===(this.lastAudioReceiveInfo.packetsLost||0)?this.lastAudioReceiveInfo.packetsReceived||0:n.packetsReceived||0,n}},{key:"extractVideoMetrics",value:function(e){var t=this,r=Object.assign({source:this.source},Ir,this.connection.peerConnectionStats);return r.timestamp=Date.now(),e.forEach(function(e){if(!e.isRemote)if(/inboundrtp|inbound-rtp/i.test(e.type))r.framesDecoded=e.framesDecoded,r.packetsReceived=e.packetsReceived||0,r.framesReceived=e.framesReceived,r.keyFramesDecoded=e.keyFramesDecoded||0,r.packetsLost=e.packetsLost||0,r.packetsReceivedForLost=r.packetsLost===(t.lastVideoReceiveInfo.packetsLost||0)?t.lastVideoReceiveInfo.packetsReceived||0:r.packetsReceived||0,r.bytesReceived=e.bytesReceived||0,r.firCount=e.firCount||0,r.pliCount=e.pliCount||0,r.freezeCount=e.freezeCount||0,r.retransmittedBytesReceived=e.retransmittedBytesReceived||0,r.retransmittedPacketsReceived=e.retransmittedPacketsReceived||0,void 0!==e.frameHeight&&(r.frameWidth=e.frameWidth||0,r.frameHeight=e.frameHeight||0);else if(/track/i.test(e.type))r.frameWidth=e.frameWidth||0,r.frameHeight=e.frameHeight||0;else if(/codec/i.test(e.type)){var n;null!==(n=e.mimeType)&&void 0!==n&&n.includes("video")&&(r.sdpFmtpLine=e.sdpFmtpLine)}}),r}},{key:"makeAudioReport",value:function(e){if(this.lastAudioReceiveInfo.timestamp>0&&e.timestamp){var t=Math.round(Se(e.timestamp,this.lastAudioReceiveInfo.timestamp)),r=Se(e.packetsLost,this.lastAudioReceiveInfo.packetsLost),n=Se(e.packetsReceivedForLost,this.lastAudioReceiveInfo.packetsReceivedForLost),i=Se(e.bytesReceived,this.lastAudioReceiveInfo.bytesReceived),o=0;try{o=Math.max(r/n,0)}catch(e){o=0}isNaN(o)&&(o=0),this.audioReceiveReport={attr_delay_estimate:0,attr_duration_ms:t,attr_bitrate:Math.round(8*i/(t/1e3))},this.emit("audio-net-eq",{attr_speech_expand_rate:0,attr_duration_ms:this.audioReceiveReport.attr_duration_ms,attr_packet_lossrate:Math.round(Math.min(16384*o,16384))}),this.emit("audio-recv-stream",Object.assign({},this.audioReceiveReport))}this.lastAudioReceiveInfo=e}},{key:"makeVideoReport",value:function(e){var t=this.lastVideoReceiveInfo,r=t.firCount,n=t.pliCount,i=t.timestamp,o=t.freezeCount,a=t.packetsLost,s=t.framesDecoded,c=t.framesDropped,u=t.bytesReceived,d=t.packetsReceivedForLost,l=t.retransmittedBytesReceived,p=t.retransmittedPacketsReceived;if(i>0&&e.timestamp){var f=Se(e.timestamp,i);if(e.bytesReceived-u>=0){var v=Se(e.packetsLost,a),m=Se(e.packetsReceivedForLost,d),h=0;try{h=Math.round(v/m*255)}catch(e){h=0}isNaN(h)&&(h=0);var y=Se(e.framesDecoded,s);this.videoReceiveReport={attr_network_framerate:Math.round(1e3*y/f),attr_dec_frames:y,attr_dec_key_frames:e.keyFramesDecoded,attr_decode_qp:0,attr_render_delay:0,attr_current_delay:0,attr_dropped_count:Se(e.framesDropped,c),attr_fir_count:Se(e.firCount,r),attr_freeze_count:Se(e.freezeCount,o),attr_pli_count:Se(e.pliCount,n),attr_retx_bytes:Se(e.retransmittedBytesReceived,l),attr_retx_packets:Se(e.retransmittedPacketsReceived,p),attr_bitrate:Math.round(8*Se(e.bytesReceived,u)*1e3/f),attr_stream_options:"audio:false/video:".concat(this.source,"/resolution:").concat(e.frameWidth,"*").concat(e.frameHeight,"/"),attr_fraction_lost:Math.max(0,Math.min(h,255)),attr_resolution:JSON.stringify([{count:y,resolution:"".concat(e.frameWidth,"*").concat(e.frameHeight)}]),attr_duration_ms:Math.round(f)},e.frameWidth&&e.frameHeight&&this.emit("video-recv-stream",Object.assign({},this.videoReceiveReport))}}this.lastVideoReceiveInfo=e}},{key:"makeReport",value:function(){var e=this;this.getStats().then(function(t){t.audioMetrics&&e.makeAudioReport(t.audioMetrics),t.videoMetrics&&e.makeVideoReport(t.videoMetrics)})}},{key:"makeFirstReport",value:function(t){var r=this.firstReportFlag,n=r.audioFirstFrame,i=r.audioFirstPacket,o=r.videoFirstPacket,a=t.audioMetrics,s=t.videoMetrics;if(a&&s){if((n||-1===(null==a?void 0:a.decodingNormal))&&i&&o)return void(this.firstReportTimer&&(e.removeTimer(this.firstReportTimer,"interval"),this.firstReportTimer=null))}else if(a){if((n||-1===(null==a?void 0:a.decodingNormal))&&i)return void(this.firstReportTimer&&(e.removeTimer(this.firstReportTimer,"interval"),this.firstReportTimer=null))}else if(s&&o)return void(this.firstReportTimer&&(e.removeTimer(this.firstReportTimer,"interval"),this.firstReportTimer=null));null!=a&&a.packetsReceived&&!i&&(this.emit("audio-first-packet"),this.firstReportFlag.audioFirstPacket=!0),Number(null==a?void 0:a.decodingNormal)>0&&!n&&(this.emit("audio-first-frame"),this.firstReportFlag.audioFirstPacket=!0),null!=s&&s.packetsReceived&&!o&&(this.emit("video-first-packet"),this.firstReportFlag.videoFirstPacket=!0)}},{key:"getStats",value:function(){var t,r=this,n=this.tranceiver,i=this.tranceivers,o=this.pc;if(!(o&&(null!=i&&i.length||null!=n&&n.receiver.track)))return Promise.resolve({});if(null==o||!o.getStats)throw new e.DingRTCError(e.ErrorCode.BrowserNotSupported,"getStats is not supported");if(i&&i.length){var a=i.map(function(e){return e.receiver.track}).filter(function(e){return!!e});return Promise.all(a.map(function(e){return o.getStats(e)})).then(function(e){return{audioMetrics:r.extractMultipleAudioMetrics(e)}})}return null!=n&&null!==(t=n.receiver)&&void 0!==t&&t.track?o.getStats(n.receiver.track).then(function(e){return{videoMetrics:r.source?r.extractVideoMetrics(e):void 0,audioMetrics:r.source?void 0:r.extractAudioMetrics(e)}}):void 0}},{key:"stop",value:function(){var r,n,i;(r="stop",n=this,"function"==typeof(i=de(l(t.prototype),r,n))?function(e){return i.apply(n,e)}:i)([]),this.firstReportTimer&&(e.removeTimer(this.firstReportTimer,"interval"),this.firstReportTimer=null)}}])}(),Ar=function(e,t){return e.width!==t.width?e.width-t.width:e.height-t.height},Cr=function(e){var t;if(!e)return[];var r=e.media.video;if(!r)return[];var n=[],i=r.optional,o=r.parameters;return null!=o&&o.resolution&&n.push(o.resolution),null!=i&&null!==(t=i.parameters)&&void 0!==t&&null!==(t=t.resolution)&&void 0!==t&&t.length&&n.push.apply(n,fe(i.parameters.resolution)),n.sort(Ar),n},_r=function(t,r){var n,i=t.media,o=i.audio,a=i.video;if(r===Q.QuotaLimit)return n=new e.DingRTCError(e.ErrorCode.QuotaLimitExceed);if(o)n=new e.DingRTCError(e.ErrorCode.SubscribeAudioStreamFailed,r);else if(a){var s=a.source;s===exports.VideoSourceInfo.CAMERA?n=new e.DingRTCError(e.ErrorCode.SubscribeVideoStreamFailed,r):s===exports.VideoSourceInfo.SCREENCAST&&(n=new e.DingRTCError(e.ErrorCode.SubscribeScreenShareFailed,r))}return n},Mr=function(t,r){var n,i=t.trackMediaType;if(r===Q.QuotaLimit)return n=new e.DingRTCError(e.ErrorCode.QuotaLimitExceed);if("audio"===i)n=new e.DingRTCError(e.ErrorCode.PublishAudioStreamFailed,r);else{var o=t.source;o===exports.VideoSourceInfo.CAMERA?n=new e.DingRTCError(e.ErrorCode.PublishVideoStreamFailed,r):o===exports.VideoSourceInfo.SCREENCAST&&(n=new e.DingRTCError(e.ErrorCode.PublishScreenShareFailed,r))}return n},Dr=function(e,t,r,n){var i=n,o=e.getVideoTracks(),a=e.getAudioTracks();return"audio"===t&&a.length?Ke.audioSFU?n?n.replaceStream(e):i=new Mt(null,r,e):n?n.replaceTrack(a[0]):i=new Mt(a[0],r):"video"===t&&o.length&&(n?n.replaceTrack(o[0]):i=new Dt(o[0],r)),i};function xr(e,t){var r="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!r){if(Array.isArray(e)||(r=function(e,t){if(e){if("string"==typeof e)return jr(e,t);var r={}.toString.call(e).slice(8,-1);return"Object"===r&&e.constructor&&(r=e.constructor.name),"Map"===r||"Set"===r?Array.from(e):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?jr(e,t):void 0}}(e))||t){r&&(e=r);var n=0,i=function(){};return{s:i,n:function(){return e.length>n?{done:!1,value:e[n++]}:{done:!0}},e:function(e){throw e},f:i}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var o,a=!0,s=!1;return{s:function(){r=r.call(e)},n:function(){var e=r.next();return a=e.done,e},e:function(e){s=!0,o=e},f:function(){try{a||null==r.return||r.return()}finally{if(s)throw o}}}}function jr(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=Array(t);t>r;r++)n[r]=e[r];return n}function Nr(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),r.push.apply(r,n)}return r}function Lr(e){for(var t=1;arguments.length>t;t++){var r=null!=arguments[t]?arguments[t]:{};t%2?Nr(Object(r),!0).forEach(function(t){X(e,t,r[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):Nr(Object(r)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))})}return e}function Vr(){try{var e=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(e){}return(Vr=function(){return!!e})()}var Gr=function(){function t(e){var r,n,i,a;o(this,t),n=this,i=l(i=t),r=d(n,Vr()?Reflect.construct(i,[],l(n).constructor):i.apply(n,a)),Object.defineProperty(r,"stream",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(r,"resolutionInfo",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(r,"ssrc",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(r,"startTime",{enumerable:!0,configurable:!0,writable:!0,value:Date.now()}),Object.defineProperty(r,"uid",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(r,"id",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(r,"state",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(r,"monitor",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(r,"connection",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(r,"signaling",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(r,"_stream",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(r,"reporter",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(r,"metricsMap",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(r,"audioStatsMap",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(r,"videoStatsMap",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(r,"transceiver",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(r,"transceivers",{enumerable:!0,configurable:!0,writable:!0,value:void 0});var s=e.connection,c=e.stream,u=e.uid,p=e.resolutionInfo;return r.connection=s,r.resolutionInfo=p,r.signaling=s.signaling,r.stream=c,r.uid=u,r.reporter=s.reporter,r.connection.once("ended",function(){r.clear()}),r.videoStatsMap=new Map,r.audioStatsMap=new Map,r.metricsMap=new Map,r.state=Y.Processing,r.handleStreamAdd=r.handleStreamAdd.bind(r),r.connection.on("track",r.handleStreamAdd),r}return f(t,e.EventEmitter),u(t,[{key:"handleStreamAdd",value:function(e,t){var r,n=this,i=function(){n.reporter.trace.subscribe({init:!1,capabilities:n.stream.media,remoteStreamId:n.stream.id,remoteUserId:n.uid,sessionId:n.id,elapse:Date.now()-n.startTime,resolutionInfo:n.resolutionInfo}),n.startTime=Date.now()};if(Ke.audioSFU&&"audio"===e.kind){var o,a=null===(o=this.transceivers)||void 0===o?void 0:o.map(function(e){var t;return null===(t=e.receiver)||void 0===t||null===(t=t.track)||void 0===t?void 0:t.id});null!=a&&a.includes(e.id)&&!this._stream&&(this._stream=t,i())}else e.id===(null===(r=this.transceiver)||void 0===r||null===(r=r.receiver)||void 0===r||null===(r=r.track)||void 0===r?void 0:r.id)&&(this._stream=new MediaStream([e]),i())}},{key:"mediaStream",get:function(){return this._stream||this.connection.mcuAudioStream}},{key:"stop",value:function(){var e=this;if(this.state===Y.Processing)return this.clear(),this.signaling.unsubscribe({subscriptionId:this.id}).catch(function(t){e.reporter.log.warn("negative ack for unsubscribing, ".concat(t))})}},{key:"mute",value:function(e){return this.signaling.subscriptionControl({subscriptionId:this.id,operation:"pause",track:e})}},{key:"unmute",value:function(e){return this.signaling.subscriptionControl({subscriptionId:this.id,operation:"play",track:e})}},{key:"applyOptions",value:function(e){var t=this.stream.id;return this.resolutionInfo=e,this.signaling.subscriptionControl({subscriptionId:this.id,operation:"update",updateDesc:{video:{from:t,params:e}}})}},{key:"clear",value:function(){this.state!==Y.End&&(this.connection.off("track",this.handleStreamAdd),this.monitor&&(this.monitor.stop(),this.monitor.removeAllListeners(),this.monitor=null),this.metricsMap.clear(),this.audioStatsMap.clear(),this.videoStatsMap.clear(),this.state=Y.End,this.connection.reset(),this.emit("ended"))}},{key:"addTransceiver",value:function(e){this.monitor&&(this.monitor.stop(),this.monitor.removeAllListeners(),this.monitor=null),this.metricsMap.clear(),this.audioStatsMap.clear(),this.videoStatsMap.clear(),this.transceiver=e,this.monitor=new Rr(this),this.onMonitor()}},{key:"addTransceivers",value:function(e){this.monitor&&(this.monitor.stop(),this.monitor.removeAllListeners(),this.monitor=null),this.transceivers=e,this.monitor=new Rr(this),this.onMonitor()}},{key:"handleVideoFirstFrame",value:function(){this.reporter.trace.videoFirstFrame({sessionId:this.id,remoteStreamId:this.stream.id,attr_elapse_time:-1,remoteUserId:this.uid})}},{key:"handleMetrics",value:function(e,t){var r=e.audioMetrics,n=e.videoMetrics;if(r){var i,o=(null===(i=this.metricsMap.get(t))||void 0===i?void 0:i.audioMetrics)||{},a=ge(r,o),s=Se(r.bytesReceived,o.bytesReceived);this.audioStatsMap.set(t,{codec:this.connection.peerConnectionStats.audioCodec||r.codec,receiveBytes:r.bytesReceived,receivePackets:r.packetsReceived,receivePacketsLost:r.packetsLost,rtt:r.roundTripTime,audioLevel:Math.max(r.audioLevel,0),timestamp:r.timestamp,receiveBitrate:8*s/a})}else if(n){var c,u=(null===(c=this.metricsMap.get(t))||void 0===c?void 0:c.videoMetrics)||{},d=ge(n,u),l=Se(n.bytesReceived,u.bytesReceived),p={codec:this.connection.peerConnectionStats.videoCodec||n.codec,receiveResolution:{width:n.frameWidth,height:n.frameHeight},receiveBitrate:8*l/d,decodeFrameRate:Math.round(Se(null==n?void 0:n.framesDecoded,u.framesDecoded)/d),receiveFrameRate:Math.round(Se(null==n?void 0:n.framesReceived,u.framesReceived)/d),receiveBytes:n.bytesReceived,receivePackets:n.packetsReceived,receivePacketsLost:n.packetsLost,rtt:n.roundTripTime,timestamp:n.timestamp};this.videoStatsMap.set(t,p)}this.metricsMap.set(t,e)}},{key:"getMetrics",value:function(e){var t,r=this;return null===(t=this.connection)||void 0===t?void 0:t.getStats().then(function(){var t;null===(t=r.monitor)||void 0===t||t.getStats().then(function(t){return r.handleMetrics(t,e)})})}},{key:"onMonitor",value:function(){var e=this;"mcu"===this.uid?(this.monitor.on("audio-net-eq",function(t){e.reporter.metric.audioNetEQ(Lr({sessionId:e.id,remoteStreamId:e.stream.id,remoteUserId:e.uid},t))}),this.monitor.on("audio-recv-stream",function(t){e.reporter.metric.audioRecvStream(Lr({sessionId:e.id,remoteStreamId:e.stream.id,remoteUserId:e.uid},t))}),this.monitor.on("audio-first-packet",function(){e.reporter.trace.audioFirstPacket({sessionId:e.id,remoteStreamId:e.stream.id,remoteUserId:e.uid})}),this.monitor.on("audio-first-frame",function(){e.emit("audio-first-frame")})):(this.monitor.on("video-first-packet",function(){e.reporter.trace.videoFirstPacket({sessionId:e.id,remoteStreamId:e.stream.id,remoteUserId:e.uid})}),this.monitor.on("video-recv-stream",function(t){e.reporter.metric.videoRecvStream(Lr({sessionId:e.id,remoteStreamId:e.stream.id,remoteUserId:e.uid},t))}))}}])}(),Ur=function(e){var t,r={audio:[],video:[]},n=xr(e);try{for(n.s();!(t=n.n()).done;){var i=t.value,o=i.stream;if(!i.error){var a=Fr(o,i.resolutionInfo),s=a.audio,c=a.video;if(s){var u=Lr(Lr({},s),{},{trackId:o.media.audio.trackId,ssrcGroup:[{ssrc:Zr()}]});Ke.audioSFU&&(u.ssrcGroup=[,,,,,,].fill(0).map(function(){return{ssrc:Zr()}})),r.audio.push(u)}else if(c){var d,l;r.video.push(Lr(Lr({},c),{},{trackId:null===(d=o.media)||void 0===d||null===(d=d.video)||void 0===d?void 0:d.trackId,ssrcGroup:null===(l=o.media)||void 0===l||null===(l=l.video)||void 0===l?void 0:l.ssrcGroup,subSsrcGroup:{ssrc:Zr(),rtxSsrc:Zr()}}))}}}}catch(e){n.e(e)}finally{n.f()}return r},Fr=function(e,t){var r=e.id,n=e.media,i=n.video,o={};if(n.audio)o.audio={from:r};else if(i){var a;o.video={from:r,format:null===(a=n.video)||void 0===a?void 0:a.format,parameters:t}}return o},Br=function(){var e=i($.mark(function e(t,r){var n,o,a,s,c;return $.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return n=r.connection,o=[],a={},t.forEach(function(e,t){var n=e.stream,i=e.error,s=e.uid,c=e.resolutionInfo;if(o[t]={stream:n,error:i,uid:s,resolutionInfo:c},!i){var u=new Gr(Lr(Lr({},r),{},{uid:s,resolutionInfo:c,stream:n}));a[n.id]=u}}),c=new Promise(function(e,r){s=function(){var s=i($.mark(function s(){var c;return $.wrap(function(s){for(;;)switch(s.prev=s.next){case 0:return c=Ur(t),s.next=1,an(n,c,a);case 1:n.signaling.batchSubscribe({connectionId:n.id,propertiesJsonStr:JSON.stringify({opusExtendInbandFec:!0,type:Ke.audioSFU?"selective":"mixed"}),supportTemporalLayer:!1,media:c}).then(function(){var r=i($.mark(function r(n){var i,s,c,u,d,l;return $.wrap(function(r){for(;;)switch(r.prev=r.next){case 0:if(i=n.detailStatus,"ok"===(s=n.globalStatus)){r.next=1;break}return o.forEach(function(e){e.error=e.error||_r(e.stream,s)}),r.abrupt("return",e(o));case 1:c=xr(i),r.prev=2,d=$.mark(function e(){var r,n,i,s,c,d;return $.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:n=(r=u.value).id,i=r.msg,c=a[(s=r.origin).id],d=t.findIndex(function(e){return e.stream.id===s.id}),"ok"===i&&c?(c.id=n,o[d].id=n,o[d].subscription=c):"ok"!==i&&(o[d].error=_r(c.stream,i));case 1:case"end":return e.stop()}},e)}),c.s();case 3:if((u=c.n()).done){r.next=5;break}return r.delegateYield(d(),"t0",4);case 4:r.next=3;break;case 5:r.next=7;break;case 6:r.prev=6,l=r.catch(2),c.e(l);case 7:return r.prev=7,c.f(),r.finish(7);case 8:e(o);case 9:case"end":return r.stop()}},r,null,[[2,6,7,8]])}));return function(e){return r.apply(this,arguments)}}()).catch(r);case 2:case"end":return s.stop()}},s)}));return function(){return s.apply(this,arguments)}}()}),n.addTask(s),e.abrupt("return",c);case 1:case"end":return e.stop()}},e)}));return function(t,r){return e.apply(this,arguments)}}(),qr=function(){var e=i($.mark(function e(t,r){var n,o,a;return $.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return o=r.connection,a=new Promise(function(e,r){n=function(){var n=i($.mark(function n(){var i,a;return $.wrap(function(n){for(;;)switch(n.prev=n.next){case 0:return i=t.filter(function(e){var t;return!(null===(t=e.stream)||void 0===t||null===(t=t.media)||void 0===t||!t.audio)}).map(function(e){return e.id}),a=t.filter(function(e){var t;return!(null===(t=e.stream)||void 0===t||null===(t=t.media)||void 0===t||!t.video)}).map(function(e){return e.id}),n.next=1,sn(o,t);case 1:o.signaling.batchUnSubscribe({connectionId:o.id,audio:i,video:a}).then(function(){t.forEach(function(e){e.state=Y.End,e.clear()}),e(void 0)}).catch(r);case 2:case"end":return n.stop()}},n)}));return function(){return n.apply(this,arguments)}}()}),r.connection.addTask(n),e.abrupt("return",a);case 1:case"end":return e.stop()}},e)}));return function(t,r){return e.apply(this,arguments)}}();function Hr(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),r.push.apply(r,n)}return r}function Jr(e){for(var t=1;arguments.length>t;t++){var r=null!=arguments[t]?arguments[t]:{};t%2?Hr(Object(r),!0).forEach(function(t){X(e,t,r[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):Hr(Object(r)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))})}return e}function Yr(e,t){var r="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!r){if(Array.isArray(e)||(r=function(e,t){if(e){if("string"==typeof e)return Wr(e,t);var r={}.toString.call(e).slice(8,-1);return"Object"===r&&e.constructor&&(r=e.constructor.name),"Map"===r||"Set"===r?Array.from(e):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?Wr(e,t):void 0}}(e))||t){r&&(e=r);var n=0,i=function(){};return{s:i,n:function(){return e.length>n?{done:!1,value:e[n++]}:{done:!0}},e:function(e){throw e},f:i}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var o,a=!0,s=!1;return{s:function(){r=r.call(e)},n:function(){var e=r.next();return a=e.done,e},e:function(e){s=!0,o=e},f:function(){try{a||null==r.return||r.return()}finally{if(s)throw o}}}}function Wr(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=Array(t);t>r;r++)n[r]=e[r];return n}var Qr={motion:"maintain-framerate",detail:"maintain-resolution",balanced:"balanced"},Kr=0,zr=0,$r=0,Xr=new Set,Zr=function(){if(0==Kr||0==zr)return 0;var e=Math.min(zr+1,1e4);do{var t=Kr+(zr&$r++);if(0!=t&&!Xr.has(t))return t}while(--e>0);return 0},en=function(t,r){var n,i;if((null===(n=t.rids)||void 0===n?void 0:n.length)>1)return e.Environment.isFirefox()&&(r=on(r)),r.rids=null===(i=t.rids)||void 0===i?void 0:i.map(function(e){return{direction:"recv",id:e.id}}),r.simulcast={dir1:"recv",list1:t.simulcast.list1},r},tn=function(){var r=i($.mark(function r(n,i){var o,a,s,c,u,d,l,p,f,v,m;return $.wrap(function(r){for(;;)switch(r.prev=r.next){case 0:return o=n.pc,a=n.idToTransceiverMap,s=n.remoteSDP,c=new MediaStream(i.map(function(e){return e.getMediaStreamTrack()})),u=i.map(function(e){var t={direction:"sendonly"};if(e instanceof ht){var r=ct(e).filter(function(e){return e.active});t.sendEncodings=r.map(function(t){return{rid:t.rid||void 0,maxBitrate:1e3*t.maxBitrate,maxFramerate:t.maxFramerate,active:!Ke.simulcast||e.source===exports.VideoSourceInfo.SCREENCAST}})}var i=n.pc.addTransceiver(e.getMediaStreamTrack()||e.trackMediaType,t);if(e instanceof ht&&i.sender.setParameters){var o=e.optimizationMode,s=i.sender.getParameters();s.degradationPreference=Qr[o]||"balanced",i.sender.setParameters(s)}return a.set(e.getTrackId(),i),i}),r.next=1,o.createOffer();case 1:return l=t.parse((d=r.sent).sdp),r.next=2,o.setLocalDescription(d);case 2:n.localSDP=l,s.groups[0].mids=n.localSDP.groups[0].mids,p=Yr(u),r.prev=3,v=$.mark(function t(){var r,n,i,o;return $.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:r=f.value,n=s.media.find(function(e){return e.type===r.sender.track.kind}),e.Environment.isFirefox()&&"video"===n.type&&(delete n.rids,delete n.simulcast),i=Jr(Jr({},n),{},{ext:fe(n.ext),mid:r.mid}),o=l.media.find(function(e){return e.mid==r.mid}),en(o,i),s.media.push(i);case 1:case"end":return t.stop()}},t)}),p.s();case 4:if((f=p.n()).done){r.next=6;break}return r.delegateYield(v(),"t0",5);case 5:r.next=4;break;case 6:r.next=8;break;case 7:r.prev=7,m=r.catch(3),p.e(m);case 8:return r.prev=8,p.f(),r.finish(8);case 9:return r.next=10,o.setRemoteDescription({type:"answer",sdp:t.write(s)});case 10:return n.remoteSDP=s,r.abrupt("return",{localSDP:n.localSDP,stream:c});case 11:case"end":return r.stop()}},r,null,[[3,7,8,9]])}));return function(e,t){return r.apply(this,arguments)}}(),rn=function(){var e=i($.mark(function e(r,n){var i,o,a,s;return $.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return i=r.pc,o=r.remoteSDP,n.map(function(e){return e.transceiver}).forEach(function(e){if(e){i.removeTrack(e.sender);var t=o.media.find(function(t){return t.mid==(null==e?void 0:e.mid)});e.direction="inactive",t.direction="inactive"}}),e.next=1,i.createOffer();case 1:return s=t.parse((a=e.sent).sdp),e.next=2,i.setLocalDescription(a);case 2:return r.localSDP=s,o.groups[0].mids=s.groups[0].mids,r.remoteSDP=o,e.next=3,i.setRemoteDescription({type:"answer",sdp:t.write(o)});case 3:case"end":return e.stop()}},e)}));return function(t,r){return e.apply(this,arguments)}}(),nn=function(t,r,n){var i=t.ssrc,o=t.rtxSsrc;!function(e){e.ssrc&&Xr.add(e.ssrc),e.rtxSsrc&&Xr.add(e.rtxSsrc)}(t),r.ssrcGroups=[],o&&r.ssrcGroups.push({semantics:"FID",ssrcs:"".concat(i," ").concat(o)}),r.ssrcs=[],[i,o].filter(function(e){return void 0!==e}).forEach(function(t){r.ssrcs.push({attribute:"msid",value:"".concat(n," v").concat(i),id:t},{attribute:"cname",value:e.createUuid(),id:t})})},on=function(e){var t;return null!=e&&null!==(t=e.ext)&&void 0!==t&&t.some(function(e){return e.uri.includes("rtp-stream-id")})||e.ext.push({value:8,uri:"urn:ietf:params:rtp-hdrext:sdes:rtp-stream-id"},{value:9,uri:"urn:ietf:params:rtp-hdrext:sdes:repaired-rtp-stream-id"}),e},an=function(){var e=i($.mark(function e(r,n,i){var o,a,s,c,u,d,l,p,f,v,m,h,y,g,b,S,k,P,E,w,T,O,I,R,A,C,_,M,D;return $.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:if(s=r.pc,c=r.idToTransceiverMap,d=r.idToTransceiversMap,l=(u=r.remoteSDP).media.find(function(e){return"video"===e.type}),p=u.media.find(function(e){return"audio"===e.type}),f=null===(o=l.ssrcs)||void 0===o?void 0:o.find(function(e){return"msid"===e.attribute}).value.split(" ")[0],null!==(a=n.audio)&&void 0!==a&&a[0])if(m=null===(v=n.audio)||void 0===v?void 0:v[0],h=m.from,Ke.audioSFU){if(d.get(h)){y=Yr(d.get(h));try{for(y.s();!(g=y.n()).done;)g.value.direction="recvonly"}catch(e){y.e(e)}finally{y.f()}b=u.media.filter(function(e){return"audio"===e.type}),S=Yr(b);try{for(S.s();!(k=S.n()).done;)k.value.direction="sendonly"}catch(e){S.e(e)}finally{S.f()}}else r.mcuAudioTranceivers=[,,,,,,].fill(0).map(function(e){return r.pc.addTransceiver("audio",{direction:"recvonly"})}),d.set(h,r.mcuAudioTranceivers);i[h].addTransceivers(d.get(h))}else c.get(h)||c.set(h,r.mcuAudioTranceiver),c.get(h).direction="recvonly",p.direction="sendonly",i[h].addTransceiver(c.get(h));P=Yr(n.video),e.prev=1,w=$.mark(function e(){var r,n,o;return $.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:if(n=c.get(r=E.value.from)){e.next=1;break}c.set(r,s.addTransceiver("video",{direction:"recvonly"})),e.next=5;break;case 1:if("inactive"===n.direction){e.next=4;break}return n.direction="inactive",e.next=2,s.createOffer();case 2:return o=e.sent,e.next=3,s.setLocalDescription(o);case 3:return u.media.find(function(e){return e.mid==n.mid}).direction="inactive",e.next=4,s.setRemoteDescription({type:"answer",sdp:t.write(u)});case 4:c.get(r).direction="recvonly";case 5:i[r].addTransceiver(c.get(r));case 6:case"end":return e.stop()}},e)}),P.s();case 2:if((E=P.n()).done){e.next=4;break}return e.delegateYield(w(),"t0",3);case 3:e.next=2;break;case 4:e.next=6;break;case 5:e.prev=5,M=e.catch(1),P.e(M);case 6:return e.prev=6,P.f(),e.finish(6);case 7:return e.next=8,s.createOffer();case 8:return O=t.parse((T=e.sent).sdp),u.groups[0].mids=O.groups[0].mids,e.next=9,s.setLocalDescription(T);case 9:r.localSDP=O,Ke.audioSFU&&n.audio[0]&&(R=(I=n.audio[0]).ssrcGroup,d.get(I.from).forEach(function(e,t){var r,n=null===(r=R[t])||void 0===r?void 0:r.ssrc,i=u.media.find(function(t){return t.mid==e.mid&&"audio"===t.type});i||(i=Jr(Jr({},p),{},{mid:e.mid}),u.media.push(i)),i.ssrcs=cn(n,f),i.direction="sendonly"})),A=Yr(n.video),e.prev=10,_=$.mark(function e(){var t,r,n,o,a;return $.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:n=(t=C.value).subSsrcGroup,o=c.get(r=t.from),(a=u.media.find(function(e){return e.mid==o.mid&&"video"===e.type}))||((a=Jr({},l)).mid=o.mid,u.media.push(a)),a.direction="sendonly",i[r].ssrc=null==n?void 0:n.ssrc,nn(n,a,f);case 1:case"end":return e.stop()}},e)}),A.s();case 11:if((C=A.n()).done){e.next=13;break}return e.delegateYield(_(),"t1",12);case 12:e.next=11;break;case 13:e.next=15;break;case 14:e.prev=14,D=e.catch(10),A.e(D);case 15:return e.prev=15,A.f(),e.finish(15);case 16:return r.remoteSDP=u,e.next=17,s.setRemoteDescription({type:"answer",sdp:t.write(u)});case 17:case"end":return e.stop()}},e,null,[[1,5,6,7],[10,14,15,16]])}));return function(t,r,n){return e.apply(this,arguments)}}(),sn=function(){var e=i($.mark(function e(r,n){var i,o,a,s,c,u,d,l,p,f,v,m;return $.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:i=r.pc,o=r.remoteSDP,a=[],s=Yr(n);try{for(s.s();!(c=s.n()).done;)l=(u=c.value).transceivers,(d=u.transceiver)?a.push(d):l&&a.push.apply(a,fe(l))}catch(e){s.e(e)}finally{s.f()}return a.forEach(function(e){e.direction="inactive"}),e.next=1,i.createOffer();case 1:return p=e.sent,e.next=2,i.setLocalDescription(p);case 2:r.localSDP=t.parse(p.sdp),f=$.mark(function e(){var t;return $.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:t=m[v],o.media.find(function(e){return e.mid==t.mid}).direction="inactive";case 1:case"end":return e.stop()}},e)}),v=0,m=a;case 3:if(m.length<=v){e.next=5;break}return e.delegateYield(f(),"t0",4);case 4:v++,e.next=3;break;case 5:return r.remoteSDP=o,e.next=6,i.setRemoteDescription({type:"answer",sdp:t.write(o)});case 6:case"end":return e.stop()}},e)}));return function(t,r){return e.apply(this,arguments)}}(),cn=function(t,r){return[{attribute:"msid",value:"".concat(r," v").concat(t),id:t},{attribute:"cname",value:e.createUuid(),id:t}]},un=function(r,n,i){var o=arguments.length>3&&void 0!==arguments[3]?arguments[3]:"all",a=n.direction,s=n.remoteSDP,c=t.parse(r);"relay"===o&&c.media.forEach(function(t){t.candidates=t.candidates.filter(function(t){return e.isPrivateIP(t.ip)})}),i&&(c=function(e,t){var r=t.media.find(function(e){return"audio"===e.type}),n=t.media.find(function(e){return"video"===e.type});return e.media.forEach(function(t,i){var o=t.mid,a=t.ssrcGroups,s=void 0===a?[]:a,c=t.ssrcs,u=void 0===c?[]:c,d=t.rids,l=void 0===d?[]:d;"audio"===t.type?e.media[i]=Jr(Jr({},r),{},{mid:o,ssrcs:u}):"video"===t.type&&(e.media[i]=Jr(Jr({},n),{},{mid:o,ssrcGroups:s,ssrcs:u}),l.length&&(e.media[i].rids=l,e.media[i].simulcast={dir1:"recv",list1:l.map(function(e){return"~".concat(e.id)}).join(";")}))}),e}(s,c));var u=c.media.find(function(e){return"video"===e.type});if("uplink"===a&&e.Environment.isFirefox()&&Ke.simulcast&&(u.ext=u.ext.filter(function(e){return!e.uri.includes("rtp-stream-id")})),!u.ssrcs&&"downlink"===a){var d=Zr();u.ssrcs=cn(d,c.msidSemantic.token)}return n.remoteSDP=c,c},dn=function(e,t){if(e){var r,n=e.fmtp,i=e.payloads,o=e.rtp,a=e.rtcpFb,s=[],c={},u=Yr(n);try{for(u.s();!(r=u.n()).done;){var d=r.value,l=d.payload,p=d.config.split(";");c[l]={};var f,v=Yr(p);try{for(v.s();!(f=v.n()).done;){var m=He(f.value.split("="),2);c[l][m[0]]=m[1]}}catch(e){v.e(e)}finally{v.f()}}}catch(e){u.e(e)}finally{u.f()}for(var h in c){var y=c[h];(t(y)||s.includes(+y.apt))&&s.push(parseInt(h))}if(s.length){for(var g=n.length-1;g>=0;g--){s.includes(n[g].payload)&&n.splice(g,1)}for(var b=o.length-1;b>=0;b--)s.includes(o[b].payload)&&o.splice(b,1);for(var S=a.length-1;S>=0;S--)s.includes(a[S].payload)&&a.splice(S,1);e.payloads=i.split(" ").map(Number).filter(function(e){return!s.includes(e)}).join(" ")}}},ln=function(e,t){var r=e.media.find(function(e){return"video"===e.type});return dn(r,function(e){var r;return null===(r=e["profile-level-id"])||void 0===r?void 0:r.includes(t)}),e},pn=function(e){var t=e.media.find(function(e){return"video"===e.type});return dn(t,function(e){return e["profile-level-id"]&&!e["packetization-mode"]}),e};function fn(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),r.push.apply(r,n)}return r}function vn(e){for(var t=1;arguments.length>t;t++){var r=null!=arguments[t]?arguments[t]:{};t%2?fn(Object(r),!0).forEach(function(t){X(e,t,r[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):fn(Object(r)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))})}return e}function mn(e,t){var r="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!r){if(Array.isArray(e)||(r=function(e,t){if(e){if("string"==typeof e)return hn(e,t);var r={}.toString.call(e).slice(8,-1);return"Object"===r&&e.constructor&&(r=e.constructor.name),"Map"===r||"Set"===r?Array.from(e):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?hn(e,t):void 0}}(e))||t){r&&(e=r);var n=0,i=function(){};return{s:i,n:function(){return e.length>n?{done:!1,value:e[n++]}:{done:!0}},e:function(e){throw e},f:i}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var o,a=!0,s=!1;return{s:function(){r=r.call(e)},n:function(){var e=r.next();return a=e.done,e},e:function(e){s=!0,o=e},f:function(){try{a||null==r.return||r.return()}finally{if(s)throw o}}}}function hn(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=Array(t);t>r;r++)n[r]=e[r];return n}function yn(){try{var e=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(e){}return(yn=function(){return!!e})()}var gn=function(){function t(e){var r,n,i,a;o(this,t),n=this,i=l(i=t),r=d(n,yn()?Reflect.construct(i,[],l(n).constructor):i.apply(n,a)),Object.defineProperty(r,"uid",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(r,"connection",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(r,"tracks",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(r,"id",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(r,"signaling",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(r,"transceiver",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(r,"metricsMap",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(r,"audioStatsMap",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(r,"videoStatsMap",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(r,"state",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(r,"reporter",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(r,"mid",{enumerable:!0,configurable:!0,writable:!0,value:""}),Object.defineProperty(r,"encodings",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(r,"feedbackIndex",{enumerable:!0,configurable:!0,writable:!0,value:-1}),Object.defineProperty(r,"monitor",{enumerable:!0,configurable:!0,writable:!0,value:void 0});var s=e.connection,c=e.uid,u=e.tracks,p=void 0===u?[]:u;return r.tracks=p,r.connection=s,r.signaling=s.signaling,r.uid=c,r.reporter=s.reporter,r.state=Y.Idle,r.videoStatsMap=new Map,r.audioStatsMap=new Map,r.metricsMap=new Map,r.handleTracEvent=r.handleTracEvent.bind(r),p.forEach(function(e){e.on(oe,r.handleTracEvent)}),r.encodings=ct(p[0]),r.state=Y.Processing,r.connection.once("ended",function(){r.clear()}),r}return f(t,e.EventEmitter),u(t,[{key:"stop",value:function(){var t=this;return this.state!==Y.Processing?Promise.resolve():Sn([this],{connection:this.connection}).catch(function(r){t.clear(),t.reporter.log.warn("negative ack for unpublish, ".concat(e.tryJsonStringify(r)))})}},{key:"mute",value:function(){if(this.tracks.length&&this.state===Y.Processing){var e=this.tracks[0].trackMediaType;return this.reporter.trace.localControl(e,!0,this.id),this.signaling.streamControl({streamId:this.id,operation:"pause",data:e})}}},{key:"unmute",value:function(){if(this.tracks.length&&this.state===Y.Processing){var e=this.tracks[0].trackMediaType;return this.reporter.trace.localControl(e,!1,this.id),this.signaling.streamControl({streamId:this.id,operation:"play",data:e})}}},{key:"initInner",value:function(e){this.id=e;var t=this.tracks[0];this.addTransceiver(this.connection.idToTransceiverMap.get(t.getTrackId())),"video"===t.trackMediaType&&t.config.mirror&&this.handleMirror(t.config.mirror)}},{key:"handleMirror",value:function(e){return this.signaling.setStreamProperties({streamId:this.id,propertiesJsonStr:JSON.stringify({mirror:!!e})})}},{key:"handleTracEvent",value:function(e,t){var r,n=this,i={replace:function(){return n.replaceTrack(t.getMediaStreamTrack())},mute:function(){return n.mute()},unmute:function(){return n.unmute()},republish:function(){n.stop().then(function(){n.connection.sessionManager.channel.client.publish([t])})},stop:function(){return n.stop()},optimizationMode:function(){return n.updateOptionzationMode()},mirror:function(){return n.handleMirror(t)}};return null===(r=i[e])||void 0===r?void 0:r.call(i)}},{key:"clear",value:function(){var e=this;this.state!==Y.End&&(this.monitor&&(this.monitor.stop(),this.monitor.removeAllListeners(),this.monitor=null),this.tracks.forEach(function(t){t.off(oe,e.handleTracEvent)}),this.tracks=[],this.metricsMap.clear(),this.audioStatsMap.clear(),this.videoStatsMap.clear(),this.connection.reset(),this.state=Y.End,this.emit("ended"))}},{key:"applyOptions",value:function(e){var t=this,r=e[0],n=r.index,i=r.bitrate;if(n>=this.feedbackIndex&&this.state===Y.Processing){this.feedbackIndex=n;var o,a=0===i,s=this.transceiver,c=!1,u=!1,d=s.sender.getParameters(),l=e.map(function(e){return e.rid}),p=mn(d.encodings);try{for(p.s();!(o=p.n()).done;){var f,v=o.value,m=mn(e);try{var h=function(){var e=f.value,r=t.encodings.find(function(t){return t.rid===e.rid});if(e.rid!==v.rid&&v.rid||v.active||a||(v.active=!0,v.scaleResolutionDownBy=r.scaleResolutionDownBy,c=!0),e.rid===v.rid&&!a){var n=Math.max(Math.min(e.bitrate,r.maxBitrate),r.minBitrate);n!==Math.round(v.maxBitrate/1e3)&&(v.maxBitrate=1e3*n,u=!0)}};for(m.s();!(f=m.n()).done;)h()}catch(e){m.e(e)}finally{m.f()}!v.active||l.includes(v.rid)&&!a||(v.active=!1,c=!0)}}catch(e){p.e(e)}finally{p.f()}(c||u)&&s.sender.setParameters(d)}}},{key:"updateOptionzationMode",value:function(){var e;if(this.tracks[0]instanceof ht&&null!==(e=this.transceiver)&&void 0!==e&&null!==(e=e.sender)&&void 0!==e&&e.setParameters){var t=this.tracks[0].optimizationMode,r=this.transceiver.sender.getParameters();r.degradationPreference=Qr[t]||"balanced",this.transceiver.sender.setParameters(r)}}},{key:"addTransceiver",value:function(e){this.monitor&&(this.monitor.stop(),this.monitor.removeAllListeners(),this.monitor=null),this.metricsMap.clear(),this.audioStatsMap.clear(),this.videoStatsMap.clear(),this.transceiver=e,this.mid||(this.mid=null==e?void 0:e.mid),this.state=Y.Processing,this.feedbackIndex=-1,this.monitor=new Pr(this),this.onMonitor()}},{key:"replaceTrack",value:function(e){var t;this.transceiver&&(null===(t=this.transceiver.sender.track)||void 0===t||t.stop(),this.transceiver.sender.replaceTrack(e))}},{key:"handleMetrics",value:function(e,t){var r=e.audioMetrics,n=e.videoMetrics;if(r){var i,o=(null===(i=this.metricsMap.get(t))||void 0===i?void 0:i.audioMetrics)||{},a=ge(r,o),s=Se(r.bytesSent,o.bytesSent);this.audioStatsMap.set(t,{codec:this.connection.peerConnectionStats.audioCodec||r.codec,sendBytes:r.bytesSent,audioLevel:Math.max(r.audioLevel,0),sendPackets:r.packetsSent,sendPacketsLost:r.packetsLost,sampleRate:r.sampleRate,channelCount:r.channels,rtt:this.connection.peerConnectionStats.roundTripTime||r.roundTripTime,timestamp:r.timestamp,sendBitrate:8*s/a})}else if(n){var c,u,d=((null===(c=this.transceiver)||void 0===c||null===(c=c.sender)||void 0===c?void 0:c.getParameters())||{}).encodings,l=void 0===d?[]:d,p=(null===(u=this.metricsMap.get(t))||void 0===u?void 0:u.videoMetrics)||{},f=ge(n,p),v=Se(n.totalBytesSent,p.totalBytesSent),m={codec:this.connection.peerConnectionStats.videoCodec||n.codec,sendFrameRate:Math.round(n.sendFramesPerSecond),captureFrameRate:n.captureFramesPerSecond,encodeFrameRate:n.encodeFramesPerSecond,qpSum:n.totalQpSum||0,targetBitrate:n.targetBitrate,encodeLayers:l.length,sendLayers:l.filter(function(e){return e.active}).length,outgingBitrate:n.availableOutgoingBitrate,sendResolution:{width:n.maxSendFrameWidth,height:n.maxSendFrameHeight},captureResolution:{width:n.captureFrameWidth,height:n.captureFrameHeight},sendBytes:n.totalBytesSent,sendPackets:n.totalPacketsSent,sendPacketsLost:n.totalPacketsLost,timestamp:n.timestamp,rtt:this.connection.peerConnectionStats.roundTripTime||n.roundTripTime,sendBitrate:8*v/f};this.videoStatsMap.set(t,m)}this.metricsMap.set(t,e)}},{key:"getMetrics",value:function(e){var t,r=this;return null===(t=this.connection)||void 0===t?void 0:t.getStats().then(function(){var t;null===(t=r.monitor)||void 0===t||t.getStats().then(function(t){return r.handleMetrics(t,e)})})}},{key:"onMonitor",value:function(){var e=this;this.monitor.on("audio-send-stream",function(t){e.reporter.metric.audioSendStream(vn({sessionId:e.id},t))}),this.monitor.on("video-send-stream",function(t){e.reporter.metric.videoSendStream(vn({sessionId:e.id},t))}),this.monitor.on("bwe",function(t){e.reporter.metric.bwe(vn({sessionId:e.id},t))})}}])}(),bn=function(){var e=i($.mark(function e(t,r){var n,i,o,a,s,c=arguments;return $.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return n=c.length>2&&void 0!==c[2]?c[2]:["common"],i={},e.next=1,tn(r,t);case 1:return a=(o=e.sent).localSDP,s=o.stream,t.forEach(function(e){var t=e.getTrackId(),o=a.media.find(function(e){return e.mid==r.idToTransceiverMap.get(t).mid});if("audio"===e.trackMediaType)i.audio=[{source:"mic",autoMix:n,trackId:t,msid:s.id,uplinkSsrcGroup:[{ssrc:Number(o.ssrcs[0].id)}]}];else if(e instanceof ht){var c;i.video=i.video||[];var u=e.trackSettings,d=o.ssrcGroups,l=void 0===d?[]:d,p=ct(e);p.length>1&&(l=p.map(function(){return{semantics:"FID",ssrcs:"".concat(Zr()," ").concat(Zr())}}));var f=l.filter(function(e){return"FID"===e.semantics}).map(function(e){return{ssrc:Number(e.ssrcs.split(" ")[0]),rtxSsrc:Number(e.ssrcs.split(" ")[1])}}),v={trackId:e.getTrackId(),forwardOnly:e.source===exports.VideoSourceInfo.SCREENCAST,msid:s.id,mid:"".concat(o.mid),uplinkSsrcGroup:f,source:e.source||exports.VideoSourceInfo.CAMERA,streamParameters:{ssrc:null==f||null===(c=f[0])||void 0===c?void 0:c.ssrc,bitrate:"".concat(p[p.length-1].maxBitrate),resolution:{width:u.width,height:u.height},framerate:u.frameRate},ssrcParameters:f.map(function(e,t){var r;return{ssrc:e.ssrc,active:p[t].active,tlayer:1,bitrate:p[t].maxBitrate,rid:(null===(r=p[t])||void 0===r?void 0:r.rid)||void 0,maxBitrate:p[t].maxBitrate,minBitrate:p[t].minBitrate,framerate:p[t].maxFramerate,resolution:{width:p[t].targetWidth,height:p[t].targetHeight}}})};i.video.push(v)}}),e.abrupt("return",i);case 2:case"end":return e.stop()}},e)}));return function(t,r){return e.apply(this,arguments)}}(),Sn=function(){var e=i($.mark(function e(t,r){var n,o;return $.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return o=new Promise(function(e,o){n=function(){var n=i($.mark(function n(){var i,a;return $.wrap(function(n){for(;;)switch(n.prev=n.next){case 0:return i=t.filter(function(e){var t;return"audio"===(null===(t=e.tracks)||void 0===t||null===(t=t[0])||void 0===t?void 0:t.trackMediaType)}).map(function(e){return e.id}),a=t.filter(function(e){var t;return"video"===(null===(t=e.tracks)||void 0===t||null===(t=t[0])||void 0===t?void 0:t.trackMediaType)}).map(function(e){return e.id}),n.next=1,rn(r.connection,t);case 1:r.connection.signaling.batchUnPublish({connectionId:r.connection.id,audio:i,video:a}).then(function(){t.forEach(function(e){e.clear(),e.state=Y.End}),e(void 0)}).catch(o);case 2:case"end":return n.stop()}},n)}));return function(){return n.apply(this,arguments)}}()}),r.connection.addTask(n),e.abrupt("return",o);case 1:case"end":return e.stop()}},e)}));return function(t,r){return e.apply(this,arguments)}}();function kn(){try{var e=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(e){}return(kn=function(){return!!e})()}var Pn={audioCodec:"",videoCodec:"",roundTripTime:-1,availableOutgoingBitrate:-1},En=function(){function t(e){var r,n,i,a;return o(this,t),n=this,i=l(i=t),r=d(n,kn()?Reflect.construct(i,[],l(n).constructor):i.apply(n,a)),Object.defineProperty(r,"connectionMetrics",{enumerable:!0,configurable:!0,writable:!0,value:Object.assign({},Pn)}),Object.defineProperty(r,"pc",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),r.pc=e.pc,r}return f(t,vr),u(t,[{key:"extractMetrics",value:function(t){var r=Object.assign({},Pn),n="";return t.forEach(function(t){var i;if(!t.isRemote)if(/local-candidate/i.test(t.type)&&t.id===n)e.Environment.networkType=(null!==(i=t.networkType)&&void 0!==i?i:e.Environment.networkType).replace("vpn","unknown");else if(/candidate-pair/i.test(t.type)&&"succeeded"===t.state)n=t.localCandidateId,e.Environment.isFirefox()||(r.roundTripTime=1e3*(t.currentRoundTripTime||t.totalRoundTripTime/t.responsesReceived)),void 0!==t.availableOutgoingBitrate&&(r.availableOutgoingBitrate=t.availableOutgoingBitrate);else if(/codec/i.test(t.type)){var o,a;null!==(o=t.mimeType)&&void 0!==o&&o.includes("audio")?r.audioCodec=t.mimeType.replace("audio/",""):null!==(a=t.mimeType)&&void 0!==a&&a.includes("video")&&(r.videoCodec=t.mimeType.replace("video/",""))}}),this.connectionMetrics=Object.assign({},r),this.connectionMetrics}},{key:"makeReport",value:function(){var e=this;this.getStats().then(function(t){e.emit("metrics",t)})}},{key:"getStats",value:function(){var t=this;if(!this.pc)return Promise.resolve({});if(!this.pc.getStats)throw new e.DingRTCError(e.ErrorCode.BrowserNotSupported,"getStats is not supported");return this.pc.getStats(null).then(function(e){return t.extractMetrics(e)})}}])}();function wn(e,t){var r="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!r){if(Array.isArray(e)||(r=function(e,t){if(e){if("string"==typeof e)return Tn(e,t);var r={}.toString.call(e).slice(8,-1);return"Object"===r&&e.constructor&&(r=e.constructor.name),"Map"===r||"Set"===r?Array.from(e):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?Tn(e,t):void 0}}(e))||t){r&&(e=r);var n=0,i=function(){};return{s:i,n:function(){return e.length>n?{done:!1,value:e[n++]}:{done:!0}},e:function(e){throw e},f:i}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var o,a=!0,s=!1;return{s:function(){r=r.call(e)},n:function(){var e=r.next();return a=e.done,e},e:function(e){s=!0,o=e},f:function(){try{a||null==r.return||r.return()}finally{if(s)throw o}}}}function Tn(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=Array(t);t>r;r++)n[r]=e[r];return n}function On(){try{var e=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(e){}return(On=function(){return!!e})()}var In={uplink:"",downlink:""},Rn=function(){function r(t){var n,i,a,s;o(this,r),i=this,a=l(a=r),n=d(i,On()?Reflect.construct(a,[],l(i).constructor):a.apply(i,s)),Object.defineProperty(n,"pc",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(n,"pendingTask",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(n,"signaling",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(n,"state",{enumerable:!0,configurable:!0,writable:!0,value:W.New}),Object.defineProperty(n,"exchangeSdpTask",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(n,"monitor",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(n,"peerConnectionTimer",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(n,"createPeerConnectionPromise",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(n,"peerConnectionStats",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(n,"reporter",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(n,"createPeerConnectionTimer",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(n,"mcuAudioStream",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(n,"idToTransceiverMap",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(n,"mcuAudioTranceiver",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(n,"idToTransceiversMap",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(n,"mcuAudioTranceivers",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(n,"localSDP",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(n,"remoteSDP",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(n,"sessionManager",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(n,"prevId",{enumerable:!0,configurable:!0,writable:!0,value:""}),Object.defineProperty(n,"offerSDP",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(n,"clientFailoverTimer",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(n,"audioSfuSsrcs",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(n,"id",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(n,"enquenTask",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(n,"direction",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(n,"onIceGatheringStateChange",{enumerable:!0,configurable:!0,writable:!0,value:function(e){n.reporter.log.debug("ice gathering state: ".concat(e.target.iceGatheringState))}}),n.pc=null;var c=t.direction,u=t.sessionManager;return n.signaling=u.channel.signaling,n.sessionManager=u,n.reporter=u.reporter,n.enquenTask=function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:1,t=[],r=0,n=!1,i=function(){for(;e>r&&t.length;){r++;var n=t.shift();n&&n().finally(function(){r--,i()})}};return{add:function(e){t.push(e),n&&i()},start:function(){n=!0,i()}}}(),n.direction=c,n.idToTransceiverMap=new Map,n.idToTransceiversMap=new Map,n.createPeerConnection(),n.id="".concat(n.direction,"_").concat(e.createUuid()),n.startSinglePC().then(function(){n.state=W.Idle,n.enquenTask.start()}),n}return f(r,e.EventEmitter),u(r,[{key:"startSinglePC",value:function(){var e=arguments.length>0&&void 0!==arguments[0]&&arguments[0];return"uplink"===this.direction?(this.pc.addTransceiver("audio",{direction:"sendonly"}),this.pc.addTransceiver("video",{direction:"sendonly"})):(this.mcuAudioStream=null,this.mcuAudioTranceiver=this.pc.addTransceiver("audio",{direction:"recvonly"}),this.pc.addTransceiver("video",{direction:"recvonly"})),e&&function(e){var t=e.remoteSDP,r=e.sessionManager,n=e.mcuAudioTranceiver,i=e.pc,o=e.idToTransceiverMap,a=e.idToTransceiversMap,s=e.direction,c=e.localSDP.media.slice(2),u=fe(r.sessions.values());if("downlink"===s){var d=t.media.slice(2),l=u.filter(function(e){return e instanceof Gr}),p=l.find(function(e){var t;return"admin"===(null===(t=e.stream)||void 0===t||null===(t=t.info)||void 0===t?void 0:t.owner)});p&&!Ke.audioSFU&&(o.set(p.id,n),p.addTransceiver(n));var f=[];c.forEach(function(e){var t={direction:e.direction},r=d.find(function(t){return t.type===e.type&&e.mid==t.mid}),n=l.find(function(e){return(null==e?void 0:e.ssrc)===(null==r?void 0:r.ssrcs[0].id)}),a=i.addTransceiver(e.type,t);"recvonly"===e.direction&&("video"===e.type&&n?(o.set(n.stream.id,a),n.addTransceiver(a)):"audio"===e.type&&f.push(a))}),f.length&&p&&(e.mcuAudioTranceivers=f,a.set(p.id,f),p.addTransceivers(f))}else{var v=u.filter(function(e){return e instanceof gn});c.forEach(function(e){var t={direction:e.direction},r=v.find(function(t){return t.mid==e.mid});if("sendonly"===e.direction&&r){var n=r.tracks[0],a=(null==n?void 0:n.getMediaStreamTrack())||(null==n?void 0:n.trackMediaType);if(n instanceof ht){var s=ct(n).filter(function(e){return e.active});t.sendEncodings=s.map(function(e){return{rid:e.rid||void 0,maxBitrate:1e3*e.maxBitrate,maxFramerate:e.maxFramerate,active:!Ke.simulcast||n.source===exports.VideoSourceInfo.SCREENCAST}})}var c=i.addTransceiver(a,t);o.set(n.getTrackId(),c),r.addTransceiver(c)}else i.addTransceiver(e.type,t)})}}(this),this.exchangeSDP(e)}},{key:"stopSinglePC",value:function(){return arguments.length>0&&void 0!==arguments[0]&&arguments[0]||this.emit("ended"),this.signaling.closePeerConnection({connectionId:this.id,direction:"downlink"===this.direction?"out":"in"})}},{key:"reset",value:function(){this.pendingTask&&(this.pendingTask=null)}},{key:"closePeerConnection",value:function(){this.pc&&(this.reporter.log.debug("sessionId ".concat(this.id,": clear RTC PeerConnection.")),this.detachEvents(),"closed"!==this.pc.signalingState&&this.pc.close(),this.pc=null)}},{key:"onTrack",value:function(e){var t=e.track;"audio"===t.kind?Ke.audioSFU?this.emit("track",t,e.streams[0]):this.mcuAudioStream=new MediaStream([t]):this.emit("track",t)}},{key:"fireEndedEvent",value:function(){this.state!==W.Ended&&(this.state=W.Ended,this.emit("ended"))}},{key:"onIceConnectionStateChange",value:function(){var e=this.pc.iceConnectionState;this.reporter.log.debug("sessionId ".concat(this.id,": ICE connection state changed to ").concat(e))}},{key:"handleClientReoffer",value:(n=i($.mark(function t(){var r;return $.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:if(this.state!==W.New){t.next=1;break}return t.abrupt("return",Promise.reject());case 1:return this.reporter.log.debug("sessionId ".concat(this.id,": start client reoffer process")),t.prev=2,t.next=3,this.stopSinglePC(!0);case 3:this.removeAllListeners(),t.next=5;break;case 4:t.prev=4,r=t.catch(2),this.reporter.log.debug("sessionId ".concat(this.id,": client reoffer close failed ").concat(e.tryJsonStringify(r)));case 5:this.closePeerConnection();case 6:case"end":return t.stop()}},t,this,[[2,4]])})),function(){return n.apply(this,arguments)})},{key:"addTask",value:function(e){this.enquenTask.add(e)}},{key:"onConnectionStateChange",value:function(){var t=this,r=this.pc.connectionState;this.reporter.trace.connectionsEvent(this.id,r),"failed"===r||"closed"===r?(this.clientFailoverTimer&&e.removeTimer(this.clientFailoverTimer),this.clientFailoverTimer=e.addTimer(function(){t.state!==W.New&&t.emit("reoffer")},1e4)):"connected"===r&&(this.clientFailoverTimer&&(e.removeTimer(this.clientFailoverTimer),this.clientFailoverTimer=null),this.createPeerConnectionTimer&&(e.removeTimer(this.createPeerConnectionTimer),this.createPeerConnectionTimer=null))}},{key:"getPeerConnectionConfig",value:function(){var t=this.sessionManager.channel.iceConfig,r=t.username,n=t.password,i=t.port,o=t.iceServerList,a={bundlePolicy:"max-bundle",iceTransportPolicy:o.length?"relay":"all",sdpSemantics:"unified-plan"};if(o.length){var s,c=[],u=wn(o);try{for(u.s();!(s=u.n()).done;){var d=s.value;c.push("turn:".concat(d,":").concat(i,"?transport=udp"),"turn:".concat(d,":").concat(i,"?transport=tcp"))}}catch(e){u.e(e)}finally{u.f()}e.Environment.isFirefox()&&c.splice(4,2),"relay"===In[this.direction]&&(In[this.direction]="all",a.iceTransportPolicy="all"),a.iceServers=[{urls:c,username:r,credential:n}]}return In[this.direction]=a.iceTransportPolicy,this.reporter.log.debug("PeerConnectionConfig",a),a}},{key:"createPeerConnection",value:function(){var t=this;this.pc?this.reporter.log.warn("sessionId ".concat(this.id,": A PeerConnection was created. Cannot create again for the same PeerConnectionChannel.")):(this.pc=new RTCPeerConnection(this.getPeerConnectionConfig()),this.attachEvents(),this.createPeerConnectionTimer=e.addTimer(function(){var e;"connected"===(null===(e=t.pc)||void 0===e?void 0:e.connectionState)||t.exchangeSdpTask||t.emit("reoffer")},4e3))}},{key:"attachEvents",value:function(){var e=this;this.pc&&(this.pc.ontrack=function(t){e.onTrack(t)},this.pc.oniceconnectionstatechange=function(){e.onIceConnectionStateChange()},this.pc.onconnectionstatechange=function(){e.onConnectionStateChange()},this.pc.onicegatheringstatechange=function(t){e.onIceGatheringStateChange(t)},this.monitor=new En(this),this.monitor.on("metrics",function(t){e.peerConnectionStats=t}))}},{key:"getStats",value:function(){var e,t,r=this;return this.monitor?null===(e=this.monitor)||void 0===e||null===(t=e.getStats)||void 0===t?void 0:t.call(e).then(function(e){r.peerConnectionStats=e}):Promise.resolve()}},{key:"detachEvents",value:function(){this.createPeerConnectionTimer&&e.removeTimer(this.createPeerConnectionTimer),this.clientFailoverTimer&&e.removeTimer(this.clientFailoverTimer),this.pc&&(this.pc.ontrack=null,this.pc.oniceconnectionstatechange=null,this.pc.onconnectionstatechange=null,this.pc.onicegatheringstatechange=null,this.monitor.stop(),this.monitor.removeAllListeners(),this.monitor=null)}},{key:"startTask",value:function(){var t=this;return new Promise(function(r,n){t.pendingTask={resolve:r,reject:n},t.exchangeSDP(),e.addTimer(function(){var e;t.pendingTask&&t.state===W.Processing&&(null===(e=t.pendingTask)||void 0===e||e.reject(),t.fireEndedEvent())},15e3)})}},{key:"exchangeSDP",value:function(){var r,n=this,o=arguments.length>0&&void 0!==arguments[0]&&arguments[0];return new Promise(function(a,s){n.exchangeSdpTask={resolve:a,reject:s},n.pc.createOffer().then(function(e){var i,a,s;return r=e,o&&(r.sdp=t.write((i=n.localSDP,a=t.parse(r.sdp),s=a.media,i.media.forEach(function(e){var t=e.mid,r=e.ssrcGroups,n=void 0===r?[]:r,i=e.ssrcs,o=void 0===i?[]:i,a=e.type,c=s.findIndex(function(e){return e.mid==t&&e.type===a});c>-1&&(s[c]=Jr(Jr({},s[c]),{},{ssrcGroups:n,ssrcs:o}))}),a))),n.pc.setLocalDescription(r).catch(function(e){throw n.reporter.log.error("sessionId ".concat(n.id,": Failed to create offer or set SDP. Message: ").concat(e.message,")}")),e})}).then(function(){n.reporter.log.debug("sessionId ".concat(n.id,": set local sdp success"));var a=function(r,n){var i=n.direction,o=["uplink"===i,"downlink"===i&&"macOS"===e.Environment.system&&e.Environment.isChrome()],a=t.parse(r);if(o.some(function(e){return e})&&(a=ln(a,"64")),e.Environment.isFirefox()&&(a=pn(a)),"uplink"===i&&e.Environment.isFirefox()&&Ke.simulcast){var s=a.media.find(function(e){return"video"===e.type});on(s)}return n.localSDP=a,a}(r.sdp,n);r.sdp=t.write(a),n.offerSDP=a,r.sdp=t.write(a);var s,c={direction:"downlink"!==n.direction?"in":"out",sdpOffer:r.sdp,connectionId:n.id,isFailover:o,optionsJsonStr:JSON.stringify({supportCVO:1})};if(o){var u=t.parse(r.sdp);u.media=u.media.slice(0,2),u.groups=[{mids:"0 1",type:"BUNDLE"}],c.sdpOffer=t.write(u)}return function(t){var r=t.fn,n=t.times,o=t.interval,a=void 0===o?0:o,s=t.key,c=ke.get(s),u=function(){c&&(e.removeTimer(c),ke.delete(s),c=null)};u();var d=function(){var t=i($.mark(function t(){var i;return $.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return t.prev=0,n--,t.next=1,r();case 1:u(),t.next=4;break;case 2:if(t.prev=2,i=t.catch(0),n>0){t.next=3;break}throw u(),i;case 3:c=e.addTimer(function(){d()},a),ke.set(s,c);case 4:case"end":return t.stop()}},t,null,[[0,2]])}));return function(){return t.apply(this,arguments)}}();return d()}({key:"createPeerConnection_".concat(n.direction),fn:(s=i($.mark(function r(){var i;return $.wrap(function(r){for(;;)switch(r.prev=r.next){case 0:if("connected"===(null===(i=n.sessionManager)||void 0===i||null===(i=i.channel)||void 0===i||null===(i=i.client)||void 0===i?void 0:i.connectionState)){r.next=1;break}return r.abrupt("return");case 1:if(c.isFailover||!n.prevId){r.next=3;break}return r.next=2,n.stopSinglePC(!0);case 2:n.id="".concat(n.direction,"_").concat(e.createUuid()),c.connectionId=n.id;case 3:return n.prevId=n.id,r.abrupt("return",n.signaling.createPeerConnection(c).then(function(r){var i=un(r.sdpAnswer,n,o,In[n.direction]);n.pc.setRemoteDescription({sdp:t.write(i),type:"answer"}).then(function(){var e;n.reporter.log.debug("sessionId ".concat(n.id,": receive answer success")),null===(e=n.exchangeSdpTask)||void 0===e||e.resolve(),n.exchangeSdpTask=void 0}).catch(function(t){var r,i;n.reporter.log.error("sessionId ".concat(n.id,": Set remote description failed: ").concat(t)),null===(r=n.exchangeSdpTask)||void 0===r||r.reject(t),n.exchangeSdpTask=void 0,null===(i=n.pendingTask)||void 0===i||i.reject(new e.DingRTCError(e.ErrorCode.IceConnectionAnswerFail)),n.fireEndedEvent()})}));case 4:case"end":return r.stop()}},r)})),function(){return s.apply(this,arguments)}),times:3,interval:2e3})}).catch(function(t){var r,i;n.reporter.log.error("sessionId ".concat(n.id,": Failed to create offer or set SDP. Message: ").concat(t.message)),null===(r=n.pendingTask)||void 0===r||r.reject(new e.DingRTCError(e.ErrorCode.IceConnectionSetLocalDescFail)),n.fireEndedEvent(),null===(i=n.exchangeSdpTask)||void 0===i||i.reject(t),n.exchangeSdpTask=void 0})})}},{key:"reoffer",value:function(){var e=this;return this.state===W.New?Promise.reject():(this.reporter.log.debug("sessionId ".concat(this.id,": start reoffer process")),this.closePeerConnection(),this.idToTransceiverMap=new Map,this.idToTransceiversMap=new Map,this.createPeerConnection(),this.state=W.New,this.startSinglePC(!0).then(function(){e.state=W.Idle,e.enquenTask.start()}))}}]);var n}();function An(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),r.push.apply(r,n)}return r}function Cn(e){for(var t=1;arguments.length>t;t++){var r=null!=arguments[t]?arguments[t]:{};t%2?An(Object(r),!0).forEach(function(t){X(e,t,r[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):An(Object(r)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))})}return e}function _n(e,t){var r="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!r){if(Array.isArray(e)||(r=function(e,t){if(e){if("string"==typeof e)return Mn(e,t);var r={}.toString.call(e).slice(8,-1);return"Object"===r&&e.constructor&&(r=e.constructor.name),"Map"===r||"Set"===r?Array.from(e):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?Mn(e,t):void 0}}(e))||t){r&&(e=r);var n=0,i=function(){};return{s:i,n:function(){return e.length>n?{done:!1,value:e[n++]}:{done:!0}},e:function(e){throw e},f:i}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var o,a=!0,s=!1;return{s:function(){r=r.call(e)},n:function(){var e=r.next();return a=e.done,e},e:function(e){s=!0,o=e},f:function(){try{a||null==r.return||r.return()}finally{if(s)throw o}}}}function Mn(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=Array(t);t>r;r++)n[r]=e[r];return n}function Dn(){try{var e=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(e){}return(Dn=function(){return!!e})()}var xn=function(){function t(e,r){var n,i,a,s;return o(this,t),i=this,a=l(a=t),n=d(i,Dn()?Reflect.construct(a,[],l(i).constructor):a.apply(i,s)),Object.defineProperty(n,"client",{enumerable:!0,configurable:!0,writable:!0,value:e}),Object.defineProperty(n,"sessions",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(n,"networkQualityInterval",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(n,"lastChannelNetworkQuality",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(n,"uplink",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(n,"downlink",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(n,"streamIdToSessionId",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(n,"channel",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(n,"reporter",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),n.channel=r,n.client=e,n.reporter=r.reporter,n.streamIdToSessionId=new Map,n.sessions=new Map,n.handleMediaMessage=n.handleMediaMessage.bind(n),n.handleServerFailover=n.handleServerFailover.bind(n),n.handleRepulish=n.handleRepulish.bind(n),n.handleResubscribe=n.handleResubscribe.bind(n),n}return f(t,e.EventEmitter),u(t,[{key:"getOrCreatePeerConnection",value:function(e){var t=this;return"uplink"===e?(this.uplink||(this.uplink=new Rn({direction:e,sessionManager:this}),this.uplink.on("reoffer",this.handleRepulish),this.uplink.on("ended",function(){t.uplink=null})),this.uplink):(this.downlink||(this.downlink=new Rn({direction:e,sessionManager:this}),this.downlink.on("reoffer",this.handleResubscribe),this.downlink.on("ended",function(){t.downlink=null})),this.downlink)}},{key:"handleRepulish",value:(h=i($.mark(function t(){var r,n,i,o,a,s,c,u;return $.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:n=fe(this.client.localTracks),i=_n(this.sessions.values());try{for(i.s();!(o=i.n()).done;)(a=o.value)instanceof gn&&a.state===Y.Processing&&(a.clear(),this.sessions.delete(a.id))}catch(e){i.e(e)}finally{i.f()}return this.client.emit("media-reconnect-start",this.client.userId),s=null===(r=this.uplink)||void 0===r?void 0:r.id,t.prev=1,this.reporter.trace.connectionsEvent(s,"clientReofferStart"),t.next=2,null===(c=this.uplink)||void 0===c?void 0:c.handleClientReoffer();case 2:if(this.uplink=null,this.reporter.log.info("".concat(this.client.userId," republish ").concat(n.map(function(e){return e.trackMediaType}).join()," start")),!n.length){t.next=3;break}return t.next=3,this.batchPublish(n);case 3:this.reporter.trace.connectionsEvent(s,"clientReofferSuccess"),this.client.emit("media-reconnect-end",this.client.userId),t.next=5;break;case 4:t.prev=4,u=t.catch(1),this.reporter.log.debug("".concat(this.client.userId," republish failed for ").concat(e.tryJsonStringify(u))),this.reporter.trace.connectionsEvent(s,"clientReofferFailed"),this.client.emit("media-reconnect-end",this.client.userId),this.channel.signaling.emit("connection-state-change","disconnected",this.client.connectionState,"network_error");case 5:case"end":return t.stop()}},t,this,[[1,4]])})),function(){return h.apply(this,arguments)})},{key:"handleResubscribe",value:(m=i($.mark(function t(){var r,n,i,o,a,s,c,u,d,l,p,f,v,m,h,y,g=arguments;return $.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:n=g.length>0&&void 0!==g[0]&&g[0],i=[],o=_n(this.sessions.values());try{for(o.s();!(a=o.n()).done;)(s=a.value)instanceof Gr&&s.state===Y.Processing&&(i.push({stream:s.stream,uid:s.uid}),s.clear(),this.sessions.delete(s.id))}catch(e){o.e(e)}finally{o.f()}return c=n?"server":"client",u=i.map(function(e){return e.uid}).join(),this.client.emit("media-reconnect-start",u),this.reporter.log.info("resubscribe ".concat(u," start")),d=null===(r=this.downlink)||void 0===r?void 0:r.id,t.prev=1,this.reporter.trace.connectionsEvent(d,"".concat(c,"ReofferStart")),t.next=2,null===(l=this.downlink)||void 0===l?void 0:l.handleClientReoffer();case 2:if(this.downlink=null,!i.length){t.next=4;break}return t.next=3,this.batchSubscribe(i);case 3:p=_n(t.sent);try{for(p.s();!(f=p.n()).done;)h=(v=f.value).error,(m=v.subscription)&&!h&&this.handleSubscribeReoffer(m)}catch(e){p.e(e)}finally{p.f()}case 4:this.reporter.trace.connectionsEvent(d,"".concat(c,"ReofferSuccess")),this.client.emit("media-reconnect-end",u),t.next=6;break;case 5:t.prev=5,y=t.catch(1),this.reporter.log.debug("".concat(this.client.userId," resubscribe failed for ").concat(e.tryJsonStringify(y))),this.reporter.trace.connectionsEvent(d,"".concat(c,"ReofferFailed")),this.client.emit("media-reconnect-end",u),this.channel.signaling.emit("connection-state-change","disconnected",this.client.connectionState,"network_error");case 6:case"end":return t.stop()}},t,this,[[1,5]])})),function(){return m.apply(this,arguments)})},{key:"getSessionByStreamId",value:function(e){return this.sessions.get(this.streamIdToSessionId.get(e))}},{key:"handleSubscribeReoffer",value:function(e){var t,r=e.uid,n=e.mediaStream,i=(null===(t=e.stream.media.video)||void 0===t?void 0:t.source)===exports.VideoSourceInfo.SCREENCAST,o=n.getAudioTracks()[0],a=n.getVideoTracks()[0],s=o?"audio":i?"screen":"camera";if(this.reporter.log.debug("".concat(r," resubscribe ").concat(s," success")),o&&this.channel.remoteAudioTrack){var c,u;if(Ke.audioSFU)null===(c=(u=this.channel.remoteAudioTrack).replaceStream)||void 0===c||c.call(u,n);else this.channel.remoteAudioTrack.replaceTrack(o)}else{var d=this.channel.userManager.remoteUsers.find(function(e){return e.userId===r});a&&null!=d&&d.auxiliaryTrack&&i?d.auxiliaryTrack.replaceTrack(a):a&&null!=d&&d.videoTrack&&!i&&d.videoTrack.replaceTrack(a)}}},{key:"handleServerFailover",value:function(t){var r=this;this.reporter.log.debug("serverFailover ".concat(JSON.stringify(t)));var n,i=t.actions,o=_n(void 0===i?[]:i);try{var a=function(){var t,i,o=n.value,a=o.connectionId;if("reoffer"!==o.actionName)return 1;if(a===(null===(t=r.uplink)||void 0===t?void 0:t.id)){var s=r.uplink,c=r.client,u=c.userId,d=c.localTracks;r.client.emit("media-reconnect-start",u),r.reporter.trace.connectionsEvent(a,"serverReofferStart"),s.reoffer().then(function(){r.reporter.log.info("".concat(u," republish ").concat(d.map(function(e){return e.trackMediaType}).join()," success")),r.reporter.trace.connectionsEvent(a,"serverReofferSuccess"),r.client.emit("media-reconnect-end",u)}).catch(function(t){r.reporter.log.debug("".concat(r.client.userId," resubscribe failed for ").concat(e.tryJsonStringify(t))),r.reporter.trace.connectionsEvent(a,"serverReofferFailed"),r.channel.signaling.emit("connection-state-change","disconnected",r.client.connectionState,"network_error")})}else a===(null===(i=r.downlink)||void 0===i?void 0:i.id)&&r.handleResubscribe(!0)};for(o.s();!(n=o.n()).done;)a()}catch(e){o.e(e)}finally{o.f()}}},{key:"addSession",value:function(e,t){this.sessions.set(t.id,t),this.streamIdToSessionId.set(e,t.id)}},{key:"getNetworkQuality",value:function(e,t){return e>50||t>600?B.BAD:e>30||t>450?B.POOR:e>20||t>300?B.NORMAL:e>10||t>200?B.GOOD:0>e&&0>t?B.UNKNOWN:B.GREAT}},{key:"checkChannelNetworkQuality",value:(v=i($.mark(function e(){var t,r=this;return $.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:if(0!==(t=fe(this.sessions.values())).length){e.next=1;break}return this.emit("network-quality",B.UNKNOWN,B.UNKNOWN),e.abrupt("return");case 1:if(0!==t.filter(function(e){var t,r=e.connection;return"connected"===(null==r||null===(t=r.pc)||void 0===t?void 0:t.connectionState)}).length){e.next=2;break}return this.emit("network-quality",B.DISCONNECTED,B.DISCONNECTED),e.abrupt("return");case 2:Promise.all([this.getLocalVideoStats(),this.getLocalAudioStats(),this.getRemoteAudioStats(),this.getRemoteVideoStats()]).then(function(e){var t=He(e,4),n=t[0],i=t[1],o=t[2],a=t[3],s=0,c=0,u=0,d=0,l=0,p=0;if(n){var f=n.camera,v=n.auxiliary;f&&(c+=f.sendPacketsLost,s+=f.sendPackets,l=Math.max(l,f.rtt||0)),v&&(c+=v.sendPacketsLost,s+=v.sendPackets,l=Math.max(l,v.rtt||0))}for(var m in i&&(c+=i.sendPacketsLost||0,s+=i.sendPackets||0,l=Math.max(l,i.rtt||0)),o&&(u+=o.receivePacketsLost||0,d+=o.receivePackets||0,p=Math.max(p,o.rtt||0)),a){var h=a[m],y=h.camera,g=h.auxiliary;y&&(u+=y.receivePacketsLost,d+=y.receivePackets,p=Math.max(p,y.rtt||0)),g&&(u+=g.receivePacketsLost,d+=g.receivePackets,p=Math.max(p,g.rtt||0))}var b=-1,S=-1,k={timestamp:Date.now(),totalUplinkPacketsLost:c,totalUplinkPacketsSent:s,totalDownlinkPacketsLost:u,totalDownlinkPacketsRecv:d};if(s){var P,E,w=c-((null===(P=r.lastChannelNetworkQuality)||void 0===P?void 0:P.totalUplinkPacketsLost)||0);if(0>w&&(w=c),k.totalUplinkPacketsSentForLost=(null===(E=r.lastChannelNetworkQuality)||void 0===E?void 0:E.totalUplinkPacketsSentForLost)||0,0!==w){var T;k.totalUplinkPacketsSentForLost=s;var O=s-((null===(T=r.lastChannelNetworkQuality)||void 0===T?void 0:T.totalUplinkPacketsSentForLost)||0);0>O&&(O=s),b=w/O}}if(d){var I,R,A,C=u-((null===(I=r.lastChannelNetworkQuality)||void 0===I?void 0:I.totalDownlinkPacketsLost)||0);0>C&&(C=u),k.totalDownlinkPacketsRecvForLost=(null===(R=r.lastChannelNetworkQuality)||void 0===R?void 0:R.totalDownlinkPacketsRecvForLost)||0,C&&(u!==((null===(A=r.lastChannelNetworkQuality)||void 0===A?void 0:A.totalDownlinkPacketsLost)||0)&&(k.totalDownlinkPacketsRecvForLost=d),S=C/d)}r.emit("network-quality",r.getNetworkQuality(Math.min(100*b,100),l),r.getNetworkQuality(Math.min(100*S,100),p)),r.lastChannelNetworkQuality=k});case 3:case"end":return e.stop()}},e,this)})),function(){return v.apply(this,arguments)})},{key:"removeSession",value:function(e,t){t&&(e=this.streamIdToSessionId.get(t),this.streamIdToSessionId.delete(t));var r=this.sessions.get(e);r&&(r.clear(),this.sessions.delete(e))}},{key:"batchPublish",value:function(e,t){var r=this,n=Date.now();return function(e){var t,r=e.tracks,n=e.connection,o=e.labels,a=r.map(function(t){return{publication:new gn(vn(vn({},e),{},{tracks:[t]})),track:t}}),s=new Promise(function(e,s){t=function(){var t=i($.mark(function t(){return $.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=1,bn(r,n,o);case 1:return t.abrupt("return",n.signaling.batchPublish({connectionId:n.id,media:t.sent,simulcast:Ke.simulcast,simulcastVersion:"1.0",clientType:"web",supportTemporalLayer:!1,type:"webrtc"}).then(function(){var t=i($.mark(function t(r){var n,i,o,s,c,u;return $.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:if(n=r.detailStatus,"ok"===(i=r.globalStatus)){t.next=1;break}return a.forEach(function(e){e.error=Mr(e.track,i)}),t.abrupt("return",e(a));case 1:o=mn(n),t.prev=2,c=$.mark(function e(){var t,r,n,i,o,c;return $.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:r=(t=s.value).id,n=t.origin,i=t.msg,o=a.findIndex(function(e){return e.track.getTrackId()===n.id}),c=(a[o]||{}).publication,"ok"===i&&c?c.initInner(r):"ok"!==i&&(a[o].error=Mr(a[o].track,i));case 1:case"end":return e.stop()}},e)}),o.s();case 3:if((s=o.n()).done){t.next=5;break}return t.delegateYield(c(),"t0",4);case 4:t.next=3;break;case 5:t.next=7;break;case 6:t.prev=6,u=t.catch(2),o.e(u);case 7:return t.prev=7,o.f(),t.finish(7);case 8:e(a);case 9:case"end":return t.stop()}},t,null,[[2,6,7,8]])}));return function(e){return t.apply(this,arguments)}}()).catch(function(e){s(e)}));case 2:case"end":return t.stop()}},t)}));return function(){return t.apply(this,arguments)}}()});return n.addTask(t),s}({uid:this.client.userId,tracks:e,connection:this.getOrCreatePeerConnection("uplink"),labels:t}).then(function(e){var t,i=_n(e);try{var o=function(){var e=t.value,i=e.publication,o=e.track;e.error?r.reporter.trace.publish(!1,o,"",Date.now()-n):(r.addSession(o.getTrackId(),i),r.reporter.trace.publish(!0,o,i.id,Date.now()-n),r.reporter.trace.publish(!1,o,i.id,Date.now()-n),i.on("ended",function(){r.removeSession(i.id)}))};for(i.s();!(t=i.n()).done;)o()}catch(e){i.e(e)}finally{i.f()}})}},{key:"batchUnPublish",value:function(e){var t=this;return e.length?Sn(e,{connection:this.getOrCreatePeerConnection("uplink")}).then(function(){var r,n=_n(e);try{for(n.s();!(r=n.n()).done;){var i,o,a=r.value;t.streamIdToSessionId.delete(null===(i=a.tracks)||void 0===i||null===(i=i[0])||void 0===i||null===(o=i.getTrackId)||void 0===o?void 0:o.call(i)),t.removeSession(a.id)}}catch(e){n.e(e)}finally{n.f()}}):Promise.resolve()}},{key:"batchSubscribe",value:function(e){var t=this,r=Date.now(),n=0,o=function(e){return Br(e,{connection:t.getOrCreatePeerConnection("downlink")}).then(function(){var r=i($.mark(function r(i){var a,s,c,u;return $.wrap(function(r){for(;;)switch(r.prev=r.next){case 0:for(a=new Map,s=[],c=0;i.length>c;c++)"RoomBusy"===(null===(u=i[c].error)||void 0===u?void 0:u.message)&&(s.push(e[c]),a.set(s.length-1,c));if(!s.length||n>3){r.next=3;break}return n++,r.next=1,Pe(1);case 1:if("connected"!==t.client.connectionState){r.next=3;break}return r.next=2,o(s);case 2:r.sent.forEach(function(e,t){var r=a.get(t);i[r]=e});case 3:return r.abrupt("return",i);case 4:case"end":return r.stop()}},r)}));return function(e){return r.apply(this,arguments)}}())};return o(e).then(function(e){var n,i=_n(e);try{var o=function(){var e=n.value,i=e.error,o=e.subscription,a=e.id,s=e.stream,c=e.uid,u=e.resolutionInfo;o&&(t.reporter.trace.subscribe({init:!0,capabilities:s.media,remoteStreamId:s.id,remoteUserId:c,elapse:Date.now()-r,sessionId:a,resolutionInfo:u}),"mcu"===o.uid&&t.reporter.trace.subscribe({init:!1,capabilities:s.media,remoteStreamId:s.id,remoteUserId:c,elapse:Date.now()-r,sessionId:o.id,resolutionInfo:u}),t.addSession(s.id,o),o.on("ended",function(){t.removeSession(a)})),i&&t.reporter.trace.subscribe({init:!1,capabilities:(null==s?void 0:s.media)||{},remoteStreamId:null==s?void 0:s.id,remoteUserId:c,elapse:Date.now()-r,sessionId:"",resolutionInfo:u})};for(i.s();!(n=i.n()).done;)o()}catch(e){i.e(e)}finally{i.f()}return e})}},{key:"batchUnscribe",value:(p=i($.mark(function e(t){var r,n,i,o=this;return $.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return r=Array(t.length),n=[],i={},t.forEach(function(e,t){var o=e.error,a=e.stream,s=e.session;o?r[t]={error:o}:(i[null==a?void 0:a.id]=t,n.push(s))}),e.abrupt("return",qr(n,{connection:this.getOrCreatePeerConnection("downlink")}).then(function(){for(var e=0,t=n;t.length>e;e++)o.removeSession(t[e].id)}));case 1:case"end":return e.stop()}},e,this)})),function(e){return p.apply(this,arguments)})},{key:"clear",value:function(){var t,r,n=this;this.sessions.forEach(function(e){n.removeSession(e.id)}),null===(t=this.uplink)||void 0===t||t.closePeerConnection(),this.uplink=null,null===(r=this.downlink)||void 0===r||r.closePeerConnection(),this.downlink=null,this.streamIdToSessionId.clear(),this.networkQualityInterval&&(e.removeTimer(this.networkQualityInterval,"interval"),this.networkQualityInterval=null),this.channel.signaling.off("media-message",this.handleMediaMessage),this.channel.signaling.off("serverFailover",this.handleServerFailover)}},{key:"start",value:function(){this.startNetworkQualityTimer(),this.uplink=this.getOrCreatePeerConnection("uplink"),this.downlink=this.getOrCreatePeerConnection("downlink"),this.channel.signaling.on("media-message",this.handleMediaMessage),this.channel.signaling.on("serverFailover",this.handleServerFailover)}},{key:"startNetworkQualityTimer",value:function(){var t=this;this.networkQualityInterval=e.addTimer(function(){navigator&&void 0!==navigator.onLine&&!navigator.onLine?t.emit("network-quality",B.DISCONNECTED,B.DISCONNECTED):"connected"!==t.client.connectionState?t.emit("network-quality",B.BAD,B.BAD):"connected"===t.client.connectionState?t.checkChannelNetworkQuality():t.emit("network-quality",B.UNKNOWN,B.UNKNOWN)},2e3,"interval")}},{key:"getLocalAudioStats",value:(c=i($.mark(function e(){var t,r,n,i=arguments;return $.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return r=i.length>0&&void 0!==i[0]?i[0]:"network",n=fe(this.sessions.values()).filter(function(e){var t,r;return e instanceof gn&&"connected"===(null===(t=e.connection)||void 0===t||null===(t=t.pc)||void 0===t?void 0:t.connectionState)&&"audio"===(null===(r=e.tracks)||void 0===r||null===(r=r[0])||void 0===r?void 0:r.trackMediaType)}),e.next=1,Promise.all(n.map(function(e){return e.getMetrics(r)}));case 1:return e.abrupt("return",(null===(t=n[0])||void 0===t?void 0:t.audioStatsMap.get(r))||{});case 2:case"end":return e.stop()}},e,this)})),function(){return c.apply(this,arguments)})},{key:"getLocalVideoStats",value:(s=i($.mark(function e(){var t,r,n,i,o,a,s,c,u,d,l,p,f,v,m=arguments;return $.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return n=m.length>0&&void 0!==m[0]?m[0]:"network",i=fe(this.sessions.values()).filter(function(e){var t;return e instanceof gn&&"connected"===(null===(t=e.connection)||void 0===t||null===(t=t.pc)||void 0===t?void 0:t.connectionState)&&"video"===e.tracks[0].trackMediaType}),e.next=1,Promise.all(i.map(function(e){return e.getMetrics(n)}));case 1:o=function(e){var t;return(null==e||null===(t=e.fmtp)||void 0===t?void 0:t.filter(function(e){var t;return null==e||null===(t=e.config)||void 0===t?void 0:t.includes("profile-level-id")}).map(function(e){var t,r=(null==e||null===(t=e.config)||void 0===t?void 0:t.split(";"))||[],n=r.findIndex(function(e){return e.includes("profile-level-id")});return r[n].split("=")[1]}))||[]},a=null===(t=this.uplink)||void 0===t||null===(t=t.offerSDP)||void 0===t||null===(t=t.media)||void 0===t?void 0:t.find(function(e){return"video"===e.type}),s=null===(r=this.downlink)||void 0===r||null===(r=r.offerSDP)||void 0===r||null===(r=r.media)||void 0===r?void 0:r.find(function(e){return"video"===e.type}),c={uplinkProfile:fe(new Set(o(a))),downlinkProfile:fe(new Set(o(s)))},u=_n(i),e.prev=2,u.s();case 3:if((d=u.n()).done){e.next=6;break}if(p=(l=d.value).videoStatsMap.get(n)){e.next=4;break}return e.abrupt("continue",5);case 4:f=l.tracks[0].source===exports.VideoSourceInfo.SCREENCAST,c[f?"auxiliary":"camera"]=p;case 5:e.next=3;break;case 6:e.next=8;break;case 7:e.prev=7,v=e.catch(2),u.e(v);case 8:return e.prev=8,u.f(),e.finish(8);case 9:return e.abrupt("return",c);case 10:case"end":return e.stop()}},e,this,[[2,7,8,9]])})),function(){return s.apply(this,arguments)})},{key:"getRemoteVideoStats",value:(a=i($.mark(function e(){var t,r,n,i,o,a,s,c,u,d,l,p,f=arguments;return $.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return t=f.length>0&&void 0!==f[0]?f[0]:"network",r=fe(this.sessions.values()).filter(function(e){var t;return e instanceof Gr&&"connected"===(null===(t=e.connection)||void 0===t||null===(t=t.pc)||void 0===t?void 0:t.connectionState)&&e.stream.media.video}),e.next=1,Promise.all(r.map(function(e){return e.getMetrics(t)}));case 1:n={},i=_n(r),e.prev=2,i.s();case 3:if((o=i.n()).done){e.next=6;break}if(c=(s=o.value).uid,u=s.stream,d=s.videoStatsMap.get(t)){e.next=4;break}return e.abrupt("continue",5);case 4:l=(null===(a=u.media.video)||void 0===a?void 0:a.source)===exports.VideoSourceInfo.SCREENCAST?"auxiliary":"camera",n[c]=Cn(Cn({},n[c]||{}),{},X({},l,d));case 5:e.next=3;break;case 6:e.next=8;break;case 7:e.prev=7,p=e.catch(2),i.e(p);case 8:return e.prev=8,i.f(),e.finish(8);case 9:return e.abrupt("return",n);case 10:case"end":return e.stop()}},e,this,[[2,7,8,9]])})),function(){return a.apply(this,arguments)})},{key:"getRemoteAudioStats",value:(n=i($.mark(function e(){var t,r,n,i=arguments;return $.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return r=i.length>0&&void 0!==i[0]?i[0]:"network",n=fe(this.sessions.values()).filter(function(e){var t;return e instanceof Gr&&"connected"===(null===(t=e.connection)||void 0===t||null===(t=t.pc)||void 0===t?void 0:t.connectionState)&&e.stream.media.audio}),e.next=1,Promise.all(n.map(function(e){return e.getMetrics(r)}));case 1:return e.abrupt("return",(null===(t=n[0])||void 0===t?void 0:t.audioStatsMap.get(r))||{});case 2:case"end":return e.stop()}},e,this)})),function(){return n.apply(this,arguments)})},{key:"handleMediaMessage",value:(r=i($.mark(function e(t){var r,n,i,o,a,s;return $.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:if(this.reporter.log.debug("remote feedback: ".concat(t.payload)),r=JSON.parse(t.payload),Array.isArray(r)&&0!==r.length){e.next=1;break}return e.abrupt("return");case 1:n=fe(this.sessions.values()).filter(function(e){return e instanceof gn&&e.state===Y.Processing&&e.tracks[0].source===exports.VideoSourceInfo.CAMERA}),i=_n(n),e.prev=2,a=$.mark(function e(){var t,n;return $.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:t=o.value,(n=r.filter(function(e){return e.mid==t.transceiver.mid})).length&&t.applyOptions(n);case 1:case"end":return e.stop()}},e)}),i.s();case 3:if((o=i.n()).done){e.next=5;break}return e.delegateYield(a(),"t0",4);case 4:e.next=3;break;case 5:e.next=7;break;case 6:e.prev=6,s=e.catch(2),i.e(s);case 7:return e.prev=7,i.f(),e.finish(7);case 8:case"end":return e.stop()}},e,this,[[2,6,7,8]])})),function(e){return r.apply(this,arguments)})}]);var r,n,a,s,c,p,v,m,h}();function jn(e,t){var r="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!r){if(Array.isArray(e)||(r=function(e,t){if(e){if("string"==typeof e)return Nn(e,t);var r={}.toString.call(e).slice(8,-1);return"Object"===r&&e.constructor&&(r=e.constructor.name),"Map"===r||"Set"===r?Array.from(e):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?Nn(e,t):void 0}}(e))||t){r&&(e=r);var n=0,i=function(){};return{s:i,n:function(){return e.length>n?{done:!1,value:e[n++]}:{done:!0}},e:function(e){throw e},f:i}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var o,a=!0,s=!1;return{s:function(){r=r.call(e)},n:function(){var e=r.next();return a=e.done,e},e:function(e){s=!0,o=e},f:function(){try{a||null==r.return||r.return()}finally{if(s)throw o}}}}function Nn(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=Array(t);t>r;r++)n[r]=e[r];return n}function Ln(){try{var e=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(e){}return(Ln=function(){return!!e})()}var Vn={name:"name"},Gn=function(){function t(e){var r,n,i,a;return o(this,t),n=this,i=l(i=t),r=d(n,Ln()?Reflect.construct(i,[],l(n).constructor):i.apply(n,a)),Object.defineProperty(r,"channel",{enumerable:!0,configurable:!0,writable:!0,value:e}),Object.defineProperty(r,"groupIds",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(r,"groups",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(r,"default",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(r,"listVer",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(r,"client",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),r.channel=e,r.groups=new Map,r.listVer=0,r.groupIds=new Set,r.handleGroupListEvents=r.handleGroupListEvents.bind(r),r.handleGroupEvents=r.handleGroupEvents.bind(r),r.handleSyncEvent=r.handleSyncEvent.bind(r),r}return f(t,e.EventEmitter),u(t,[{key:"joinedIds",get:function(){var e=this.channel.userManager.currentPid,t=new Set;return this.groups.forEach(function(r){var n=r.id;r.participants.some(function(t){return t.pid===e})&&t.add(n)}),t}},{key:"parseGroup",value:function(e){var t,r=this,n=e.properties,i=e.participants;return{id:e.id,name:(null==n||null===(t=n.find(function(e){return"name"===e.key}))||void 0===t?void 0:t.value)||"",joined:i.some(function(e){return e.pid===r.channel.userManager.currentPid}),users:i.map(function(e){return{userId:e.uid,userData:e.userData}})}}},{key:"groupList",get:function(){var e=this,t=[];return this.groups.forEach(function(r){t.push(e.parseGroup(r))}),t}},{key:"init",value:function(e,t){this.listVer=t,this.groupIds=new Set(e),this.batchSyncGroup(e),this.observerAllGroup(),this.channel.signaling.on("group-list",this.handleGroupListEvents),this.channel.signaling.on("group",this.handleGroupEvents),this.channel.signaling.on("sync",this.handleSyncEvent)}},{key:"clear",value:function(){this.listVer=0,this.channel.signaling.off("group",this.handleGroupEvents),this.channel.signaling.off("group-list",this.handleGroupListEvents),this.channel.signaling.off("sync",this.handleSyncEvent),this.groupIds.clear(),this.groups.clear()}},{key:"join",value:function(t){var r=t.publishAudioToGroup,n=void 0===r||r,i=t.groupId,o=t.userData;if(this.joinedIds.has(i))throw new e.DingRTCError(e.ErrorCode.InvaildArgument,"you were in group already");return this.channel.signaling.joinGroup({groupId:i,userData:o,autoJoinGroupAudio:!!n,autoLeaveChannelAudio:!0})}},{key:"leave",value:function(t){var r=t.groupId,n=t.publishAudioToChannel,i=void 0===n||n;if(!this.joinedIds.has(r))throw new e.DingRTCError(e.ErrorCode.InvaildArgument,"you are not in the group");return this.channel.signaling.leaveGroup({groupId:r,reasonCode:At.LEAVE_GROUP_REASON_CODE.NORMAL_LEAVE,autoJoinChannelAudio:i})}},{key:"dismiss",value:function(t){if(!this.groupIds.has(t))throw new e.DingRTCError(e.ErrorCode.InvaildArgument,"group not existed");return this.channel.signaling.dismissGroup({groupId:t})}},{key:"addUser",value:function(e,t){var r,n=null===(r=this.groups.get(t))||void 0===r?void 0:r.participants;n&&!n.find(function(t){return t.pid===e.pid})&&n.push(e)}},{key:"removeUser",value:function(e,t){var r,n=null===(r=this.groups.get(t))||void 0===r?void 0:r.participants;if(n){var i=n.findIndex(function(t){return t.pid===e.pid});i>-1&&n.splice(i,1)}}},{key:"observerAllGroup",value:function(){return this.channel.signaling.observeAllGroups()}},{key:"unobserverAllGroup",value:function(){return this.channel.signaling.unobserveAllGroups()}},{key:"setProperties",value:function(e,t){return this.channel.signaling.setGroupProperties({groupId:e,properties:[t]})}},{key:"handleGroupListEvents",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]&&arguments[1],r=e.ver,n=e.type,i=e.updateOpt;if(this.channel.reporter.log.debug("groupList ".concat(JSON.stringify(e))),r!==this.listVer+1&&!t||n!==At.OptType.OPT_TYPE_UPDATE)r>this.listVer+1&&this.syncGroupList();else{var o=i.updateAction,a=i.id;o===At.GroupListUpdate.GROUP_LIST_UPDATE_ADD_ID?this.groupIds.add(a):o===At.GroupListUpdate.GROUP_LIST_UPDATE_REMOVE_ID&&this.groupIds.delete(a),this.listVer=r}}},{key:"handleGroupEvents",value:function(e){var t=this,r=arguments.length>1&&void 0!==arguments[1]&&arguments[1];this.channel.reporter.log.debug("group ".concat(JSON.stringify(e)));var n,i=e.id,o=e.ver,a=e.groupInfo,s=e.type,c=e.updateOpt,u=this.groups.get(i);if(s!==At.OptType.OPT_TYPE_ADD||u){if(s===At.OptType.OPT_TYPE_REMOVE&&u)this.groups.delete(i),this.emit("group","remove",this.parseGroup(u));else if(s===At.OptType.OPT_TYPE_UPDATE){var d=c.updateAction,l=c.participants;if(u&&(u.ver+1===o||r)){if(d===At.GroupUpdate.GROUP_UPDATE_ADD_PARTICIPANTS){var p,f=u.participants.map(function(e){return e.pid}),v=jn(l);try{for(v.s();!(p=v.n()).done;){var m=p.value;f.includes(m.pid)||(u.participants.push(m),this.emit("group","user-join",i,{userId:m.uid,userData:m.userData}))}}catch(e){v.e(e)}finally{v.f()}}else if(d===At.GroupUpdate.GROUP_UPDATE_REMOVE_PARTICIPANTS){var h=l.map(function(e){return e.pid}),y=fe(u.participants);u.participants=u.participants.filter(function(e){return!h.includes(e.pid)}),y.forEach(function(e){h.includes(e.pid)&&t.emit("group","user-leave",i,{userId:e.uid,userData:e.userData})})}else if(d===At.GroupUpdate.GROUP_UPDATE_AUDIO_STREAM_LOST)this.channel.reporter.log.debug("group ".concat(i," audioStream lost"));else if(d===At.GroupUpdate.GROUP_UPDATE_AUDIO_STREAM_RECOVER)this.channel.reporter.log.debug("group ".concat(i," audioStream recover"));else if(d===At.GroupUpdate.GROUP_UPDATE_SET_PROPERTIES)c.properties.forEach(function(e){var r=!0;u.properties||(u.properties=[]),u.properties.forEach(function(t){t.key===e.key&&(t.value=e.value,r=!1)}),r&&u.properties.push(e),t.emit("group","info-updated",i,{key:"set-".concat(Vn[e.key]),value:e.value})});else if(d===At.GroupUpdate.GROUP_UPDATE_REMOVE_PROPERTIES){var g,b=c.properties.map(function(e){return e.key});u.properties=null===(g=u.properties)||void 0===g?void 0:g.filter(function(e){return!b.includes(e.key)}),c.properties.forEach(function(e){t.emit("group","info-updated",i,{key:"remove-".concat(Vn[e.key])})})}u.ver=o}else u&&o>u.ver+1&&this.syncGroup(u.id)}}else null==a||null===(n=a.audioInfo)||void 0===n||null===(n=n.audio)||void 0===n||null===(n=n.media)||void 0===n||delete n.video,null==a.ver&&(a.ver=o),this.groups.set(i,a),this.emit("group","add",this.parseGroup(a))}},{key:"syncGroup",value:function(e){var t=this,r=this.groups.get(e);return this.channel.signaling.syncData({type:At.DataType.DATA_TYPE_GROUP,id:e,ver:null==r?void 0:r.ver}).then(function(n){var i=n.fullSync.groupData.groupInfos,o=(void 0===i?[]:i)[0];if(o){var a=o.participants,s=o.properties,c=void 0===s?[]:s,u=(null==r?void 0:r.participants)||[],d=new Map(((null==r?void 0:r.properties)||[]).map(function(e){return[e.key,e.value]})),l=u.map(function(e){return e.pid}),p=a.map(function(e){return e.pid}),f=c.filter(function(e){return e.value!==d[e.key]}),v=c.filter(function(e){return!d.has(e.key)}),m=a.filter(function(e){return!l.includes(e.pid)}),h=u.filter(function(e){return!p.includes(e.pid)});m.length&&t.handleGroupEvents({id:e,type:At.OptType.OPT_TYPE_REMOVE,ver:o.ver,updateOpt:{updateAction:At.GroupUpdate.GROUP_UPDATE_ADD_PARTICIPANTS,participants:m}},!0),h.length&&t.handleGroupEvents({id:e,ver:o.ver,type:At.OptType.OPT_TYPE_REMOVE,updateOpt:{updateAction:At.GroupUpdate.GROUP_UPDATE_REMOVE_PARTICIPANTS,participants:h}},!0),f.length&&t.handleGroupEvents({id:e,ver:o.ver,type:At.OptType.OPT_TYPE_UPDATE,updateOpt:{updateAction:At.GroupUpdate.GROUP_UPDATE_SET_PROPERTIES,properties:f}},!0),v.length&&t.handleGroupEvents({id:e,ver:o.ver,type:At.OptType.OPT_TYPE_UPDATE,updateOpt:{updateAction:At.GroupUpdate.GROUP_UPDATE_REMOVE_PROPERTIES,properties:v}},!0)}else t.handleGroupEvents({id:e,type:At.OptType.OPT_TYPE_REMOVE})})}},{key:"batchSyncGroup",value:function(e){var t=this;if(e.length)return this.channel.signaling.syncDataByIds({type:At.DataType.DATA_TYPE_GROUP,ids:e.map(function(e){return{id:e}})}).then(function(e){e.fullSync.groupData.groupInfos.forEach(function(e){t.groupIds.add(e.id),t.groups.set(e.id,e)})})}},{key:"syncGroupList",value:function(){var e=this;this.channel.signaling.syncData({type:At.DataType.DATA_TYPE_GROUP_LIST,forceFullSync:!0,ver:this.listVer}).then(function(t){var r=t.fullSync,n=r.ver,i=r.groupListData.groupIds,o=void 0===i?[]:i,a=o.filter(function(t){return!e.groupIds.has(t)}),s=fe(e.groupIds).filter(function(e){return!o.includes(e)});a.length&&a.forEach(function(t){e.handleGroupListEvents({ver:n,updateOpt:{updateAction:At.GroupListUpdate.GROUP_LIST_UPDATE_ADD_ID,id:t}},!0)}),s.length&&s.forEach(function(t){e.handleGroupListEvents({ver:n,updateOpt:{updateAction:At.GroupListUpdate.GROUP_LIST_UPDATE_REMOVE_ID,id:t}},!0)})})}},{key:"handleSyncEvent",value:function(e){var t=this,r=e.groupListVer,n=e.groupVer,i=void 0===n?[]:n;r>this.listVer&&(this.syncGroupList(),this.listVer=r),i.forEach(function(e){var r=e.id,n=e.ver,i=t.groups.get(r);n>(null==i?void 0:i.ver)&&(t.syncGroup(r),i.ver=n)})}}])}();function Un(){try{var e=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(e){}return(Un=function(){return!!e})()}var Fn=function(){function t(e,r){var n,i,a,s;return o(this,t),i=this,a=l(a=t),n=d(i,Un()?Reflect.construct(a,[],l(i).constructor):a.apply(i,s)),Object.defineProperty(n,"channel",{enumerable:!0,configurable:!0,writable:!0,value:r}),Object.defineProperty(n,"userId",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(n,"id",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(n,"userName",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(n,"version",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(n,"streamMap",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(n,"videoTrack",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(n,"auxiliaryTrack",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(n,"audioTrack",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(n,"joinedTime",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(n,"properties",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),n.userId=e.user,n.videoTrack=null,n.audioTrack=null,n.auxiliaryTrack=null,n.channel=r,n.joinedTime=Date.now(),n.update(e),n}return f(t,e.EventEmitter),u(t,[{key:"relatedStreams",get:function(){var e=this;return fe(this.channel.streamManager.streams.values()).filter(function(t){var r;return(null==t||null===(r=t.info)||void 0===r?void 0:r.owner)===e.id})}},{key:"hasAuxiliary",get:function(){return this.relatedStreams.some(function(e){var t;return(null===(t=e.media)||void 0===t||null===(t=t.video)||void 0===t?void 0:t.source)===exports.VideoSourceInfo.SCREENCAST})}},{key:"hasVideo",get:function(){return this.relatedStreams.some(function(e){var t,r=e.media;return(null==r||null===(t=r.video)||void 0===t?void 0:t.source)===exports.VideoSourceInfo.CAMERA})}},{key:"hasAudio",get:function(){return this.relatedStreams.some(function(e){var t,r=e.media;return(null==r||null===(t=r.audio)||void 0===t?void 0:t.source)===exports.AudioSourceInfo.MIC})}},{key:"audioMuted",get:function(){return this.relatedStreams.some(function(e){var t,r,n=e.media;return"active"!==(null==n||null===(t=n.audio)||void 0===t?void 0:t.status)&&(null==n||null===(r=n.audio)||void 0===r?void 0:r.source)===exports.AudioSourceInfo.MIC})}},{key:"auxiliaryMuted",get:function(){return this.relatedStreams.some(function(e){var t,r,n=e.media;return"active"!==(null==n||null===(t=n.video)||void 0===t?void 0:t.status)&&(null==n||null===(r=n.video)||void 0===r?void 0:r.source)===exports.VideoSourceInfo.SCREENCAST})}},{key:"videoMuted",get:function(){return this.relatedStreams.some(function(e){var t,r,n=e.media;return"active"!==(null==n||null===(t=n.video)||void 0===t?void 0:t.status)&&(null==n||null===(r=n.video)||void 0===r?void 0:r.source)===exports.VideoSourceInfo.CAMERA})}},{key:"updateNetworkOfUser",value:function(t){var r;if(this.properties.SdkType!==e.SdkType.Web&&t){var n=t.split("");n[K.UPLINK]=be(n[K.UPLINK]),n[K.DOWNLINK]=be(n[K.DOWNLINK]),t=n.join("")}t!==(null===(r=this.properties)||void 0===r?void 0:r[ie])&&(this.properties[ie]=t)}},{key:"update",value:function(e){var t=e.id,r=e.ver,n=JSON.parse(e.propertiesJsonStr||"{}");this.id=t,this.userName=n.__nick,this.version=r,this.properties=n,this.updateNetworkOfUser(n[ie])}},{key:"getRemoteVideoTrack",value:function(e,t){var r=t?this.auxiliaryTrack:this.videoTrack,n=JSON.parse(e.stream.info.attributesJsonStr),i=Dr(e.mediaStream,"video",this.userId,r);return r||i.once("first-frame-decoded",function(){e.handleVideoFirstFrame()}),t?this.auxiliaryTrack=i:this.videoTrack=i,n.mirror&&i.setSourceMirror(n.mirror),i}}])}();function Bn(e,t){var r="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!r){if(Array.isArray(e)||(r=function(e,t){if(e){if("string"==typeof e)return qn(e,t);var r={}.toString.call(e).slice(8,-1);return"Object"===r&&e.constructor&&(r=e.constructor.name),"Map"===r||"Set"===r?Array.from(e):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?qn(e,t):void 0}}(e))||t){r&&(e=r);var n=0,i=function(){};return{s:i,n:function(){return e.length>n?{done:!1,value:e[n++]}:{done:!0}},e:function(e){throw e},f:i}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var o,a=!0,s=!1;return{s:function(){r=r.call(e)},n:function(){var e=r.next();return a=e.done,e},e:function(e){s=!0,o=e},f:function(){try{a||null==r.return||r.return()}finally{if(s)throw o}}}}function qn(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=Array(t);t>r;r++)n[r]=e[r];return n}function Hn(){try{var e=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(e){}return(Hn=function(){return!!e})()}var Jn=function(){function t(e){var r,n,i,a;return o(this,t),n=this,i=l(i=t),r=d(n,Hn()?Reflect.construct(i,[],l(n).constructor):i.apply(n,a)),Object.defineProperty(r,"channel",{enumerable:!0,configurable:!0,writable:!0,value:e}),Object.defineProperty(r,"users",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(r,"currentUid",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(r,"currentPid",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(r,"reporter",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),r.users=new Map,r.channel=e,r.reporter=e.reporter,r.handleEvent=r.handleEvent.bind(r),r}return f(t,e.EventEmitter),u(t,[{key:"remoteUsers",get:function(){var t=this;return e.uniqBy(fe(this.users.values()).sort(function(e,t){return e.joinedTime-t.joinedTime}),"userId").filter(function(e){return e.userId&&e.id!==t.currentPid})}},{key:"init",value:function(e,t){var r,n=Bn(e);try{for(n.s();!(r=n.n()).done;){var i=r.value,o=new Fn(i,this.channel);this.users.set(i.user,o),t===i.user&&(this.currentUid=i.user)}}catch(e){n.e(e)}finally{n.f()}this.currentPid=t,this.channel.internalChannel.on("user",this.handleEvent)}},{key:"clear",value:function(){this.currentPid="",this.currentUid="",this.users.clear(),this.channel.internalChannel.off("user",this.handleEvent)}},{key:"handleEvent",value:function(e,t){if(this.reporter.log.debug("userEvent ".concat(e," ").concat(JSON.stringify(t))),"join"===e){var r=new Fn(t,this.channel);this.users.set(t.user,r),this.emit("user","join",r)}else if("leave"===e){var n=this.users.get(t.user);this.users.delete(t.user),this.emit("user","leave",n)}else if("update"===e){var i=this.users.get(t.user);null==i||i.update(t)}}},{key:"setParticipantProperties",value:function(e){return this.channel.signaling.setParticipantProperties({participantId:this.currentPid,roomId:this.channel.roomId,propertiesJsonStr:JSON.stringify(X({},ie,e))})}}])}();function Yn(e,t){var r="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!r){if(Array.isArray(e)||(r=function(e,t){if(e){if("string"==typeof e)return Wn(e,t);var r={}.toString.call(e).slice(8,-1);return"Object"===r&&e.constructor&&(r=e.constructor.name),"Map"===r||"Set"===r?Array.from(e):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?Wn(e,t):void 0}}(e))||t){r&&(e=r);var n=0,i=function(){};return{s:i,n:function(){return e.length>n?{done:!1,value:e[n++]}:{done:!0}},e:function(e){throw e},f:i}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var o,a=!0,s=!1;return{s:function(){r=r.call(e)},n:function(){var e=r.next();return a=e.done,e},e:function(e){s=!0,o=e},f:function(){try{a||null==r.return||r.return()}finally{if(s)throw o}}}}function Wn(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=Array(t);t>r;r++)n[r]=e[r];return n}function Qn(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),r.push.apply(r,n)}return r}function Kn(e){for(var t=1;arguments.length>t;t++){var r=null!=arguments[t]?arguments[t]:{};t%2?Qn(Object(r),!0).forEach(function(t){X(e,t,r[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):Qn(Object(r)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))})}return e}function zn(){try{var e=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(e){}return(zn=function(){return!!e})()}var $n=function(){function t(e){var r,n,i,a;o(this,t),n=this,i=l(i=t),r=d(n,zn()?Reflect.construct(i,[],l(n).constructor):i.apply(n,a)),Object.defineProperty(r,"streams",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(r,"totalVer",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(r,"reporter",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(r,"signaling",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),r.streams=new Map;var s=e.reporter;return r.signaling=e.signaling,r.reporter=s,r.handleEvent=r.handleEvent.bind(r),r.handleSyncEvent=r.handleSyncEvent.bind(r),r.sync=r.sync.bind(r),r}return f(t,e.EventEmitter),u(t,[{key:"clear",value:function(){this.streams.clear(),this.totalVer=0,this.signaling.off("stream",this.handleEvent),this.signaling.off("sync",this.handleSyncEvent)}},{key:"init",value:function(e,t){var r,n=e.find(function(e){return"admin"===e.info.owner&&"mixed"===e.type});null==n||null===(r=n.media)||void 0===r||delete r.video,this.streams=new Map(e.map(function(e){return[e.id,e]})),this.totalVer=t,this.signaling.on("stream",this.handleEvent),this.signaling.on("sync",this.handleSyncEvent)}},{key:"add",value:function(t){var r,n=t.id,i=t.info.owner,o=t.media,a=o.video,s=o.audio;if(!this.streams.get(n)){var c=null===(r=t.media)||void 0===r||null===(r=r.video)||void 0===r?void 0:r.source,u=fe(this.streams.values()).find(function(e){var t;return e.info.owner===i&&(null===(t=e.media)||void 0===t||null===(t=t.video)||void 0===t?void 0:t.source)===c});u&&this.remove(u.id),this.reporter.trace.streamsEvent(n,"add"),this.streams.set(t.id,t);var d=(null==a?void 0:a.source)===e.VideoSourceInfo.SCREENCAST;((null==a?void 0:a.source)===e.VideoSourceInfo.CAMERA||d)&&this.emit("stream","add",{id:n,owner:i,mediaType:"video",auxiliary:d}),(null==s?void 0:s.source)!==exports.AudioSourceInfo.MIC&&(null==s?void 0:s.source)!==exports.AudioSourceInfo.MIXED||this.emit("stream","add",{id:n,owner:i,mediaType:"audio"})}}},{key:"remove",value:function(t){var r=arguments.length>1&&void 0!==arguments[1]&&arguments[1],n=this.streams.get(t);if(n&&(this.streams.delete(t),r)){this.reporter.trace.streamsEvent(t,"remove");var i=n.media,o=i.video,a=i.audio,s=n.info.owner,c=(null==o?void 0:o.source)===e.VideoSourceInfo.SCREENCAST;((null==o?void 0:o.source)===e.VideoSourceInfo.CAMERA||c)&&this.emit("stream","remove",{id:t,owner:s,mediaType:"video",auxiliary:c}),(null==a?void 0:a.source)!==exports.AudioSourceInfo.MIC&&(null==a?void 0:a.source)!==exports.AudioSourceInfo.MIXED||this.emit("stream","remove",{id:t,owner:s,mediaType:"audio"})}}},{key:"getStreamByTrackId",value:function(e){return fe(this.streams.values()).find(function(t){var r,n;return(null===(r=t.media.audio)||void 0===r?void 0:r.trackId)===e||(null===(n=t.media.video)||void 0===n?void 0:n.trackId)===e})}},{key:"handleEvent",value:function(t,r){var n=this,i=t.streamId,o=t.status,a=t.stream,s=t.msg,c=t.totalVer,u={add:[],remove:[],update:["audio.status","video.status","properties"]}[o];u.length&&!u.includes(s.field)||this.reporter.log.debug("streamEvent ".concat(JSON.stringify(t)));var d=this.totalVer;if(c===d+1||c==re||r)if("add"===o){if(!a||!a.media||!a.info)return;this.add(a)}else if("remove"===o)this.remove(i,!0);else if("update"===o){var l=s.field,p=s.streamStatus,f=s.activeStream,v=s.extraValue,m=s.streamVer,h=s.propertiesJsonStr,y=this.streams.get(i);if(y){m!==re&&(y.version=m);var g,b=y.media,S=b.video,k=y.info.owner;if("audio.status"===l||"video.status"===l)"audio.status"===l?(g="audio",b.audio.status=p):"video.status"===l&&(g="video",S.status=p),this.reporter.trace.streamsEvent(i,"".concat(g," ").concat(p)),this.emit("stream","update",{owner:k,id:i,updateStatus:"".concat("active"===p?"unmute":"mute","-").concat(g)});else if("activeInput"===l){var P=[f].concat(v||[]).map(function(e){var t;return null===(t=n.streams.get(e))||void 0===t||null===(t=t.info)||void 0===t?void 0:t.owner}).filter(function(e){return!!e});this.reporter.trace.streamsEvent(JSON.stringify(P),l),this.emit("stream","volumeActive",{owners:P})}else if("properties"==l){var E,w=JSON.parse(h);y.info.attributesJsonStr=JSON.stringify(Kn(Kn({},JSON.parse(y.info.attributesJsonStr)),w));var T=(null===(E=y.media)||void 0===E||null===(E=E.video)||void 0===E?void 0:E.source)===e.VideoSourceInfo.SCREENCAST;this.emit("stream","update",{owner:k,id:i,properties:w,auxiliary:T})}}}r||this.totalVer>=c&&c!==re||(c===d+1&&(this.totalVer=c),c>d+1&&!r&&this.sync())}},{key:"sync",value:(r=i($.mark(function e(){var t,r,n,i,o,a,s,c,u,d,l,p,f,v,m,h=this;return $.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return t=[],r=[],e.next=1,this.signaling.getStreamsVer({});case 1:i=(n=e.sent).streamVersions,o=n.totalVer,a=fe(this.streams.keys()).filter(function(e){return!e.includes("vad")}),s=Yn(i),e.prev=2,s.s();case 3:if((c=s.n()).done){e.next=6;break}if(l=(u=c.value).streamVer,!(d=u.streamId).includes("vad")){e.next=4;break}return e.abrupt("continue",5);case 4:(p=this.streams.get(d))?p&&p.version!==l&&t.push(d):(r.push(d),t.push(d));case 5:e.next=3;break;case 6:e.next=8;break;case 7:e.prev=7,m=e.catch(2),s.e(m);case 8:return e.prev=8,s.f(),e.finish(8);case 9:if(f=i.map(function(e){return e.streamId}),v=a.filter(function(e){return!f.includes(e)}),this.reporter.trace.syncEvent("stream",a,f),this.totalVer=o,0!==t.length){e.next=10;break}return e.abrupt("return");case 10:this.signaling.getStreams({streamIds:t}).then(function(e){var n,i=e.totalVer,o=e.streams,a=new Map,s=Yn(h.streams.values());try{for(s.s();!(n=s.n()).done;){var c=n.value;a.set(c.id,c)}}catch(e){s.e(e)}finally{s.f()}var u,d=Yn(o);try{for(d.s();!(u=d.n()).done;){var l=u.value;h.streams.has(l.id)?h.streams.set(l.id,l.stream):a.set(l.id,l.stream)}}catch(e){d.e(e)}finally{d.f()}for(var p=t.map(function(e){return a.get(e)}).filter(function(e){return!!e}).sort(function(e,t){return e.version-t.version}),f=0;p.length>f;f++){var m=p[f];v.includes(m.id)?h.handleEvent({status:"remove",streamId:m.id,stream:m,totalVer:i},!0):r.includes(m.id)&&h.handleEvent({status:"add",streamId:m.id,stream:m,totalVer:i},!0)}a.clear(),h.totalVer=i});case 11:case"end":return e.stop()}},e,this,[[2,7,8,9]])})),function(){return r.apply(this,arguments)})},{key:"handleSyncEvent",value:function(e){e.streamsVer>this.totalVer&&this.sync()}}]);var r}();function Xn(e,t){var r="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!r){if(Array.isArray(e)||(r=function(e,t){if(e){if("string"==typeof e)return Zn(e,t);var r={}.toString.call(e).slice(8,-1);return"Object"===r&&e.constructor&&(r=e.constructor.name),"Map"===r||"Set"===r?Array.from(e):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?Zn(e,t):void 0}}(e))||t){r&&(e=r);var n=0,i=function(){};return{s:i,n:function(){return e.length>n?{done:!1,value:e[n++]}:{done:!0}},e:function(e){throw e},f:i}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var o,a=!0,s=!1;return{s:function(){r=r.call(e)},n:function(){var e=r.next();return a=e.done,e},e:function(e){s=!0,o=e},f:function(){try{a||null==r.return||r.return()}finally{if(s)throw o}}}}function Zn(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=Array(t);t>r;r++)n[r]=e[r];return n}function ei(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),r.push.apply(r,n)}return r}function ti(e){for(var t=1;arguments.length>t;t++){var r=null!=arguments[t]?arguments[t]:{};t%2?ei(Object(r),!0).forEach(function(t){X(e,t,r[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):ei(Object(r)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))})}return e}function ri(){try{var e=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(e){}return(ri=function(){return!!e})()}var ni=function(){function t(n,i){var a,s,c,u;return o(this,t),s=this,c=l(c=t),a=d(s,ri()?Reflect.construct(c,[],l(s).constructor):c.apply(s,u)),Object.defineProperty(a,"signaling",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(a,"sessionManager",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(a,"groupManager",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(a,"userManager",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(a,"streamManager",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(a,"remoteAudioTrack",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(a,"internalChannel",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(a,"reporter",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(a,"roomId",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(a,"defaultVideoStreamType",{enumerable:!0,configurable:!0,writable:!0,value:"high"}),Object.defineProperty(a,"client",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(a,"subscribedAudioStream",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(a,"micMixedGroups",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(a,"iceConfig",{enumerable:!0,configurable:!0,writable:!0,value:{level:0,iceServerList:[]}}),Object.defineProperty(a,"handleSubscribeParam",{enumerable:!0,configurable:!0,writable:!0,value:function(t){var r,n=t.mediaType,i=t.action,o=t.uid,s=t.auxiliary,c=a.getStream(t),u=a.userManager.users.get(o),d=a.groups.some(function(e){return e.joined}),l="mcu"===o?a.remoteAudioTrack:s?null==u?void 0:u.auxiliaryTrack:null==u?void 0:u.videoTrack;return"mcu"===o&&"video"===n||o&&"mcu"!==o&&"audio"===n?r=new e.DingRTCError(e.ErrorCode.InvaildArgument,"only support ".concat(i," mcu audio")):"mcu"===o&&d&&"subscribe"===i?r=new e.DingRTCError(e.ErrorCode.SubscribeInvaild,"cannot subscribe mcu while in group"):"subscribe"===i&&l?r=new e.DingRTCError(e.ErrorCode.SubscribeInvaild,"duplicated subscription"):c&&("unsubscribe"!==i||l)||(a.reporter.log.warn("".concat(o," videoTrack not existed")),r=new e.DingRTCError(e.ErrorCode.SubscribeStreamNotExisted)),{uid:o,user:u,error:r,stream:c,session:"unsubscribe"===i?a.sessionManager.getSessionByStreamId(c.id):null,resolutionInfo:"video"===n?et(a.defaultVideoStreamType,Cr(c)):null}}}),Object.defineProperty(a,"handleJoinResponse",{enumerable:!0,configurable:!0,writable:!0,value:function(e){var t=e.room,r=e.id,n=t.participants,i=t.groupList,o=t.groupListVer;a.streamManager.init(t.streams,t.streamsVer),Ke.grouptalk&&a.groupManager.init(i,o),a.userManager.init(n,r),a.streamManager.on("stream",a.handleStreamEvent),a.userManager.on("user",a.handleUserEvent),a.groupManager.on("group",a.handleGroupEvent)}}),a.reporter=i,a.internalChannel=new r.DingRTCChannel({reporter:i,gslb:Ke.gslb[0],sdkVersion:te}),a.signaling=new pr(a.internalChannel),a.client=n,a.micMixedGroups=new Set,a.groupManager=new Gn(a),a.userManager=new Jn(a),a.streamManager=new $n(a),a.sessionManager=new xn(n,a),a.subscribedAudioStream="",a.handleStreamEvent=a.handleStreamEvent.bind(a),a.handleUserEvent=a.handleUserEvent.bind(a),a.handleGroupEvent=a.handleGroupEvent.bind(a),a}return f(t,e.EventEmitter),u(t,[{key:"localTracks",get:function(){return fe(this.sessionManager.sessions.values()).filter(function(e){return e.state===Y.Processing&&e instanceof gn}).map(function(e){return e.tracks[0]})}},{key:"groups",get:function(){var e=this;return this.groupManager.groupList.map(function(t){return ti(ti({},t),{},{audioPublished:e.micMixedGroups.has(t.id)})})}},{key:"handleStreamEvent",value:function(e,t){var r=t.id,n=t.owner,i=t.mediaType,o=t.auxiliary,a=t.owners,s=t.updateStatus,c=t.properties,u=this.internalChannel.userManager.participants,d=u.get(n),l=this.userManager.users.get(null==d?void 0:d.user);if("add"===e&&!(n===this.userManager.currentPid)&&l)this.client.emit("user-published",l,i,o);else if("remove"===e&&l)this.sessionManager.removeSession(void 0,r),"video"===i&&(o&&l.auxiliaryTrack&&(l.auxiliaryTrack.stop(),l.auxiliaryTrack=null),!o&&l.videoTrack&&(l.videoTrack.stop(),l.videoTrack=null)),this.client.emit("user-unpublished",l,i,o);else if("update"===e){if(s)this.client.emit("user-info-updated",(null==l?void 0:l.userId)||this.userManager.currentUid,s);else if(null!=(null==c?void 0:c.mirror)){var p=o?l.auxiliaryTrack:l.videoTrack;null==p||p.setSourceMirror(c.mirror)}}else if("volumeActive"===e){var f=a.map(function(e){return u.get(e)}).map(function(e){return null==e?void 0:e.user}).filter(function(e){return!!e});this.client.emit("volume-indicator",f)}}},{key:"handleGroupEvent",value:function(e,t,r){if("add"===e)this.client.emit("group-add",t);else if("remove"===e)this.client.emit("group-remove",t);else if("user-join"===e)this.client.emit("group-user-join",t,r);else if("user-leave"===e)this.client.emit("group-user-leave",t,r);else if("info-updated"===e){this.client.emit("group-info-updated",t,r.key,r.value)}}},{key:"handleUserEvent",value:function(e,t){"join"===e?(this.client.emit("user-joined",t),t.hasVideo&&this.client.emit("user-published",t,"video"),t.hasAudio&&this.client.emit("user-published",t,"audio"),t.hasAuxiliary&&this.client.emit("user-published",t,"video",!0)):"leave"===e&&this.client.emit("user-left",t)}},{key:"getStream",value:function(t){var r,n=t.groupId,i=t.uid,o=t.auxiliary;if(n){var a,s=this.groupManager.groups.get(n);return null==s||null===(a=s.audioInfo)||void 0===a?void 0:a.audio}var c="mcu"===i?fe(this.streamManager.streams.values()):null===(r=this.userManager.users.get(i))||void 0===r?void 0:r.relatedStreams;return c.find("mcu"===i?function(e){return"admin"===e.info.owner&&"mixed"===e.type}:function(t){var r=t.media.video;return(null==r?void 0:r.source)===(o?e.VideoSourceInfo.SCREENCAST:e.VideoSourceInfo.CAMERA)})}},{key:"join",value:(v=i($.mark(function e(t){var r=this;return $.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",this.signaling.join(t,Ke.gslb[0]).then(function(e){var t,n,i,o=e.joinResponse,a=e.iceConfig;return r.roomId=o.room.id,n=o.room.ssrcClientSequence,i=Math.log2((t=o.room.ssrcMask)+1),n>2147483647>>i||(zr=t,Kr=(n<<i|2147483648)>>>0),r.reporter.updateCommonInfo({roomId:r.roomId,participantId:o.id}),a&&a.uis&&r.setIceConfig(a.uis),r.sessionManager.start(),r.handleJoinResponse(o),o}));case 1:case"end":return e.stop()}},e,this)})),function(e){return v.apply(this,arguments)})},{key:"setIceConfig",value:function(e){var t=e.iceServerList;e.level&&(e.iceServerList=(void 0===t?[]:t).filter(function(e){return/([0-9]{1,3}\.){3}[0-9]{1,3}/i.test(e)}),this.iceConfig=e)}},{key:"clear",value:function(){var e;this.userManager.clear(),this.streamManager.clear(),this.sessionManager.clear(),this.micMixedGroups.clear(),this.groupManager.clear(),this.subscribedAudioStream="",null===(e=this.remoteAudioTrack)||void 0===e||e.stop(),this.remoteAudioTrack=null,this.iceConfig=null,this.roomId="",this.streamManager.off("stream",this.handleStreamEvent),this.userManager.off("user",this.handleUserEvent),this.groupManager.off("group",this.handleGroupEvent)}},{key:"leave",value:function(){if("disconnected"!==this.internalChannel.connectionState)return this.reporter.trace.leave(),this.signaling.leave()}},{key:"publish",value:(p=i($.mark(function e(t){var r,n,i;return $.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return r=this.micMixedGroups,n=this.groupManager,i=[],this.groups.some(function(e){return e.joined})?i.push.apply(i,fe(fe(r).map(function(e){var t;return null===(t=n.groups.get(e))||void 0===t||null===(t=t.audioInfo)||void 0===t?void 0:t.label}).filter(function(e){return!!e}))):i.push("common"),e.abrupt("return",this.sessionManager.batchPublish(t,i));case 1:case"end":return e.stop()}},e,this)})),function(e){return p.apply(this,arguments)})},{key:"unpublish",value:function(e){var t=this,r=new Set(e.map(function(e){return e.getTrackId()})),n=fe(this.sessionManager.sessions.values()).filter(function(e){var t;return e instanceof gn&&r.has(null===(t=e.tracks)||void 0===t||null===(t=t[0])||void 0===t?void 0:t.getTrackId())});return n.forEach(function(e){t.reporter.trace.unpublish(e.id)}),this.sessionManager.batchUnPublish(n)}},{key:"getRemoteTrack",value:function(e,t){var r=this;if(!t.mediaStream)return null;var n=this.userManager.users.get(e.uid);if("audio"===e.mediaType){var i=this.remoteAudioTrack;return this.remoteAudioTrack=Dr(t.mediaStream,"audio","mcu",this.remoteAudioTrack),i||t.once("audio-first-frame",function(){r.remoteAudioTrack.emit("first-frame-decoded")}),this.remoteAudioTrack}return n.getRemoteVideoTrack(t,e.auxiliary)}},{key:"subscribe",value:(c=i($.mark(function e(t){var r,n,i,o,a=this;return $.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:if(r=this.handleSubscribeParam(t),i=r.stream,o=r.resolutionInfo,!(n=r.error)){e.next=1;break}throw n;case 1:return e.abrupt("return",this.sessionManager.batchSubscribe([{stream:i,uid:t.uid,resolutionInfo:o}]).then(function(e){var r=e[0],n=r.error;if(n)throw n;return a.getRemoteTrack(t,r.subscription)}));case 2:case"end":return e.stop()}},e,this)})),function(e){return c.apply(this,arguments)})},{key:"batchSubscribe",value:(s=i($.mark(function e(t){var r=this;return $.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",this.sessionManager.batchSubscribe(t.map(this.handleSubscribeParam)).then(function(){var e=i($.mark(function e(n){var i;return $.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return i=[],t.forEach(function(e,t){var o=n[t];i.push({uid:e.uid,auxiliary:e.auxiliary,error:o.error,track:r.getRemoteTrack(e,o.subscription)})}),e.abrupt("return",i);case 1:case"end":return e.stop()}},e)}));return function(t){return e.apply(this,arguments)}}()));case 1:case"end":return e.stop()}},e,this)})),function(e){return s.apply(this,arguments)})},{key:"unsubscribe",value:function(e){var t=this,r=this.getStream(e),n=e.mediaType,i=e.auxiliary,o=this.handleSubscribeParam(e),a=o.user,s=o.stream,c=o.session,u=o.error;if(u)throw u;this.reporter.trace.unsubscribe({sessionId:null==c?void 0:c.id,remoteStreamId:null==r?void 0:r.id,remoteUserId:e.uid});return t.sessionManager.batchUnscribe([{stream:s,session:c,error:u}]).then(function(){"audio"===n?(t.subscribedAudioStream="",t.remoteAudioTrack.stop(),t.remoteAudioTrack=null):i?a.auxiliaryTrack=null:a.videoTrack=null})}},{key:"batchUnsubscribe",value:function(e){var t,r=this,n=[],i=Xn(e);try{for(i.s();!(t=i.n()).done;){var o=t.value,a=this.handleSubscribeParam(ti(ti({},o),{},{action:"unsubscribe"})),s=a.session,c=a.stream,u=a.user;this.reporter.trace.unsubscribe({sessionId:s.id,remoteStreamId:c.id,remoteUserId:u.userId}),c&&n.push(ti({stream:c,user:u,session:s},o))}}catch(e){i.e(e)}finally{i.f()}return n.length?this.sessionManager.batchUnscribe(n).then(function(){for(var e=0,t=n;t.length>e;e++){var i,o=t[e],a=o.user,s=o.auxiliary;if("audio"===o.mediaType)null===(i=r.remoteAudioTrack)||void 0===i||i.stop(),r.remoteAudioTrack=null;else if(s){var c;null===(c=a.auxiliaryTrack)||void 0===c||c.stop(),a.auxiliaryTrack=null}else{var u;null===(u=a.videoTrack)||void 0===u||u.stop(),a.videoTrack=null}}}):Promise.resolve()}},{key:"subscribeGroup",value:function(t){var r=this,n=this.getStream({groupId:t});if(!n)throw new e.DingRTCError(e.ErrorCode.InvaildArgument,"cannot find audio info of the group");if(this.subscribedAudioStream)throw new e.DingRTCError(e.ErrorCode.InvaildState,"you were subscribed group or channel already");return this.sessionManager.batchSubscribe([{stream:n,uid:t}]).then(function(e){return r.subscribedAudioStream=n.id,r.remoteAudioTrack=Dr(e[0].subscription.mediaStream,"audio",t,r.remoteAudioTrack),r.remoteAudioTrack})}},{key:"unsubscribeGroup",value:function(t){var r=this,n=this.getStream({groupId:t});if(!n)throw new e.DingRTCError(e.ErrorCode.InvaildArgument,"cannot find audio info of the group");if(this.subscribedAudioStream!==n.id)throw new e.DingRTCError(e.ErrorCode.InvaildState,"you were not subscribed the group");return this.sessionManager.batchUnscribe([{stream:n,session:this.sessionManager.getSessionByStreamId(n.id)}]).then(function(){n.id===r.subscribedAudioStream&&(r.subscribedAudioStream="",r.remoteAudioTrack.stop(),r.remoteAudioTrack=null)})}},{key:"setRemoteStreamType",value:function(e,t,r){this.reporter.log.info("setRemoteStreamType",e,t,r);var n=this.getStream({uid:e,mediaType:"video",auxiliary:r}),i=this.sessionManager.getSessionByStreamId(n.id),o=et(t,Cr(n));return i.applyOptions(o)}},{key:"joinGroup",value:function(e){var t=this,r=e.groupId,n=e.publishAudioToGroup;return this.groupManager.join(e).then(function(e){n&&e.joinGroupAudioSuccess&&t.micMixedGroups.add(r)})}},{key:"leaveGroup",value:function(e){var t=this,r=e.groupId;return this.groupManager.leave(e).then(function(){t.micMixedGroups.delete(r)})}},{key:"dismissGroup",value:function(e){var t=this;return this.groupManager.dismiss(e).then(function(){t.micMixedGroups.delete(e)})}},{key:"mixGroupAudio",value:function(e,t,r){return this.signaling.streamControl({operation:r,streamId:e,data:t})}},{key:"setGroupProperties",value:function(e,t){return this.groupManager.setProperties(e,t)}},{key:"publishToGroup",value:(a=i($.mark(function e(t,r){var n,i,o,a=arguments;return $.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:if(n=2>=a.length||void 0===a[2]||a[2],i=[],null!=r&&i.push(this.groupManager.groups.get(r).audioInfo.label),!this.localTracks.includes(t)){e.next=5;break}if(o=this.streamManager.getStreamByTrackId(t.getTrackId()),null==r){e.next=3;break}return e.next=1,this.mixGroupAudio(o.id,i[0],"mix");case 1:if(this.micMixedGroups.add(r),!n){e.next=2;break}return e.next=2,this.mixGroupAudio(o.id,"common","unmix");case 2:e.next=4;break;case 3:return e.next=4,this.mixGroupAudio(o.id,"common","mix");case 4:e.next=7;break;case 5:return n||i.push("common"),e.next=6,this.sessionManager.batchPublish([t],i);case 6:this.micMixedGroups.add(r);case 7:case"end":return e.stop()}},e,this)})),function(e,t){return a.apply(this,arguments)})},{key:"unpublishFromGroup",value:(n=i($.mark(function e(t,r){var n,i,o,a=arguments;return $.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return n=a.length>2&&void 0!==a[2]&&a[2],i=this.groupManager.groups.get(r).audioInfo.label,o=this.streamManager.getStreamByTrackId(t.getTrackId()),e.next=1,this.mixGroupAudio(o.id,i,"unmix");case 1:if(this.micMixedGroups.delete(r),!n){e.next=2;break}return e.next=2,this.mixGroupAudio(o.id,"common","mix");case 2:case"end":return e.stop()}},e,this)})),function(e,t){return n.apply(this,arguments)})}]);var n,a,s,c,p,v}();function ii(){try{var e=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(e){}return(ii=function(){return!!e})()}var oi={timestamp:-1,maxPlayLevel:-1,maxRecLevel:-1},ai=function(){function e(t){var r,n,a,s,c;return o(this,e),n=this,a=l(a=e),r=d(n,ii()?Reflect.construct(a,[],l(n).constructor):a.apply(n,s)),Object.defineProperty(r,"audioDeviceBufferReport",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(r,"audioDeviceBufferInfo",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(r,"client",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(r,"makeReport",{enumerable:!0,configurable:!0,writable:!0,value:(c=i($.mark(function e(){var t,n,i;return $.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=1,r.client.getLocalAudioStats();case 1:return t=e.sent.audioLevel,e.next=2,r.client.getRemoteAudioStats();case 2:n=e.sent.audioLevel,i={timestamp:Date.now(),maxRecLevel:Math.min(1,t||0),maxPlayLevel:Math.min(1,Math.max(0,n||0))},r.audioDeviceBufferInfo.timestamp>0&&(r.audioDeviceBufferReport={attr_duration_ms:Se(i.timestamp,r.audioDeviceBufferInfo.timestamp),attr_play_level:Math.round(32767*i.maxPlayLevel),attr_rec_level:Math.round(32767*i.maxRecLevel)},r.emit("audio-device-buffer",Object.assign({},r.audioDeviceBufferReport))),r.audioDeviceBufferInfo=i;case 3:case"end":return e.stop()}},e)})),function(){return c.apply(this,arguments)})}),r.audioDeviceBufferReport={attr_duration_ms:0,attr_rec_level:0,attr_play_level:0},r.audioDeviceBufferInfo=Object.assign({},oi),r.client=t,r}return f(e,vr),u(e)}();function si(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),r.push.apply(r,n)}return r}function ci(e){for(var t=1;arguments.length>t;t++){var r=null!=arguments[t]?arguments[t]:{};t%2?si(Object(r),!0).forEach(function(t){X(e,t,r[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):si(Object(r)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))})}return e}function ui(e,t){var r="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!r){if(Array.isArray(e)||(r=function(e,t){if(e){if("string"==typeof e)return di(e,t);var r={}.toString.call(e).slice(8,-1);return"Object"===r&&e.constructor&&(r=e.constructor.name),"Map"===r||"Set"===r?Array.from(e):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?di(e,t):void 0}}(e))||t){r&&(e=r);var n=0,i=function(){};return{s:i,n:function(){return e.length>n?{done:!1,value:e[n++]}:{done:!0}},e:function(e){throw e},f:i}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var o,a=!0,s=!1;return{s:function(){r=r.call(e)},n:function(){var e=r.next();return a=e.done,e},e:function(e){s=!0,o=e},f:function(){try{a||null==r.return||r.return()}finally{if(s)throw o}}}}function di(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=Array(t);t>r;r++)n[r]=e[r];return n}function li(){try{var e=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(e){}return(li=function(){return!!e})()}var pi=function(){function t(){var r,n,i,a;return o(this,t),n=this,i=l(i=t),r=d(n,li()?Reflect.construct(i,[],l(n).constructor):i.apply(n,a)),Object.defineProperty(r,"channelName",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(r,"id",{enumerable:!0,configurable:!0,writable:!0,value:e.createUuid(6)}),Object.defineProperty(r,"reporter",{enumerable:!0,configurable:!0,writable:!0,value:e.registerReporter(r.id)}),Object.defineProperty(r,"channel",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(r,"monitor",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(r,"syncStatTimer",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(r,"clientStatSync",{enumerable:!0,configurable:!0,writable:!0,value:[0,0,0,0,0,0]}),Object.defineProperty(r,"currentClientState",{enumerable:!0,configurable:!0,writable:!0,value:""}),r.channel=new ni(r,r.reporter),r.handleVisibilitychange=r.handleVisibilitychange.bind(r),r.handleNetworkQuality=r.handleNetworkQuality.bind(r),r.handleConnectionChangeEvent=r.handleConnectionChangeEvent.bind(r),r.handlePageUnload=r.handlePageUnload.bind(r),r.init(),r}return f(t,e.EventEmitter),u(t,[{key:"remoteUsers",get:function(){return this.channel.userManager.remoteUsers}},{key:"groups",get:function(){return this.channel.groups}},{key:"userId",get:function(){var e;return(null===(e=this.channel.internalChannel)||void 0===e||null===(e=e.joinInfo)||void 0===e?void 0:e.uid)||""}},{key:"localTracks",get:function(){return this.channel.localTracks}},{key:"connectionState",get:function(){var e;return(null===(e=this.channel.internalChannel)||void 0===e?void 0:e.connectionState)||"disconnected"}},{key:"init",value:function(){this.syncStatTimer&&(e.removeTimer(this.syncStatTimer,"interval"),this.syncStatTimer=null),this.currentClientState="",this.channelName="",this.channel.clear(),this.removeEventListeners(),this.monitor&&(this.monitor.stop(),this.monitor.removeAllListeners(),this.monitor=null),this.clientStatSync=[0,0,0,0,0,0]}},{key:"join",value:function(t){var r=this;return this.addEventListeners(),this.channel.join(t).then(function(n){var i;return r.channelName=t.channel,r.monitor=new ai(r),r.monitor.on("audio-device-buffer",function(e){r.reporter.metric.audioDeviceBuffer(e)}),r.syncStatTimer=e.addTimer(function(){r.sendClientStatToRemote()},2e3,"interval"),{remoteUsers:r.remoteUsers,timeLeft:null===(i=n.room)||void 0===i?void 0:i.timeLeft}}).catch(function(e){throw r.init(),e})}},{key:"setRemoteDefaultVideoStreamType",value:function(e){this.reporter.log.info("setRemoteDefaultVideoStreamType",e),this.channel.defaultVideoStreamType=e}},{key:"leave",value:function(){this.reporter.log.info("leave"),this.channel.leave(),this.init()}},{key:"publish",value:function(t){var r=this;if(this.reporter.log.info("publish",(Array.isArray(t)?t:[t]).map(function(e){return e.trackMediaType})),"connected"!==this.connectionState)return Promise.reject(new e.DingRTCError(e.ErrorCode.PublishNotJoinChannel));var n,i=(Array.isArray(t)?t:[t]).filter(function(e){return e instanceof mt&&!r.localTracks.includes(e)}),o=i.concat(this.localTracks),a=X(X(X(X({},exports.VideoSourceInfo.CAMERA,0),exports.VideoSourceInfo.SCREENCAST,0),exports.AudioSourceInfo.MIC,0),exports.AudioSourceInfo.MIXED,0),s=ui(o);try{for(s.s();!(n=s.n()).done;){var c=n.value;if(a[c.source]++,a[c.source]>=2)throw new e.DingRTCError(e.ErrorCode.QuotaLimitExceed,"".concat(c.source," published already"))}}catch(e){s.e(e)}finally{s.f()}if(!i.length)throw new e.DingRTCError(e.ErrorCode.PublishNoStream);return this.channel.publish(i)}},{key:"unpublish",value:function(e){var t=Array.isArray(e)?e:[e];return e||(t=this.localTracks),this.reporter.log.info("unpublish",t.map(function(e){return e.trackMediaType})),this.channel.unpublish(t)}},{key:"subscribe",value:(n=i($.mark(function t(r,n,i){return $.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:if(this.reporter.log.info("subscribe",r,n),"connected"===this.connectionState){t.next=1;break}throw new e.DingRTCError(e.ErrorCode.SubscribeNotJoinChannel);case 1:return t.abrupt("return",this.channel.subscribe({uid:r,mediaType:n,action:"subscribe",auxiliary:i}));case 2:case"end":return t.stop()}},t,this)})),function(e,t,r){return n.apply(this,arguments)})},{key:"batchSubscribe",value:function(t){if(Array.isArray(t)&&t.length){if(this.reporter.log.info("batchSubscribe",t),"connected"!==this.connectionState)throw new e.DingRTCError(e.ErrorCode.SubscribeNotJoinChannel);return this.channel.batchSubscribe(t.map(function(e){return ci(ci({},e),{},{action:"subscribe"})}))}}},{key:"unsubscribe",value:(r=i($.mark(function e(t,r,n){return $.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return this.reporter.log.info("unsubscribe",t,r),e.abrupt("return",this.channel.unsubscribe({uid:t,auxiliary:n,mediaType:r,action:"unsubscribe"}));case 1:case"end":return e.stop()}},e,this)})),function(e,t,n){return r.apply(this,arguments)})},{key:"batchUnsubscribe",value:function(t){if(Array.isArray(t)&&t.length)return this.reporter.log.info("batchUnsubscribe",t),"connected"!==this.connectionState?Promise.reject(new e.DingRTCError(e.ErrorCode.SubscribeNotJoinChannel)):this.channel.batchUnsubscribe(t.map(function(e){return ci(ci({},e),{},{action:"unsubscribe"})}))}},{key:"getLocalAudioStats",value:function(){return this.channel.sessionManager.getLocalAudioStats("user")}},{key:"getLocalVideoStats",value:function(){return this.channel.sessionManager.getLocalVideoStats("user")}},{key:"setRemoteVideoStreamType",value:function(e,t,r){var n=this;this.reporter.log.info("setRemoteVideoStreamType",e,t);var i=this.remoteUsers.find(function(t){return t.userId===e});return null!=i&&i.relatedStreams?this.channel.setRemoteStreamType(e,t,r).then(function(){n.emit("stream-type-changed",e,t,r)}):(this.reporter.log.warn("".concat(e," videoTrack not existed")),Promise.reject("viedoTrack doesnt exiested"))}},{key:"getRemoteVideoStats",value:function(){return this.channel.sessionManager.getRemoteVideoStats("user")}},{key:"getRemoteAudioStats",value:function(){return this.channel.sessionManager.getRemoteAudioStats("user")}},{key:"getRemoteNetworkQuality",value:function(){var e={};return this.remoteUsers.forEach(function(t){var r,n,i=t.properties;e[t.userId]={downlinkNetworkQuality:Number((null==i||null===(r=i[ie])||void 0===r?void 0:r[K.DOWNLINK])||0),uplinkNetworkQuality:Number((null==i||null===(n=i[ie])||void 0===n?void 0:n[K.UPLINK])||0)}}),e}},{key:"handleConnectionChangeEvent",value:function(e,t,r){this.reporter.log.debug("connectionStateChange from ".concat(t," to ").concat(e," ").concat(r||"")),this.emit("connection-state-change",e,t,r)}},{key:"sendClientStatToRemote",value:function(){var e=this.clientStatSync.join("");if(e!==this.currentClientState){var t=be(null,e[K.UPLINK]),r=be(null,this.currentClientState[K.UPLINK]),n=be(null,e[K.DOWNLINK]),i=be(null,this.currentClientState[K.DOWNLINK]);t===r&&n===i||this.channel.userManager.setParticipantProperties(e),this.currentClientState=e}}},{key:"handleVisibilitychange",value:function(){var t="visible"!==document.visibilityState,r=t?e.TraceEvent.APP_BACKGROUND:e.TraceEvent.APP_FOREGROUND;(e.Environment.isAndroid()||e.Environment.isIOS())&&(this.reporter.sender.sendEvent(r),this.clientStatSync[K.BACKGROUND_MODE]=Number(t))}},{key:"handleNetworkQuality",value:function(e,t){this.clientStatSync[K.UPLINK]=e,this.clientStatSync[K.DOWNLINK]=t,this.emit("network-quality",e,t)}},{key:"handlePageUnload",value:function(e){"connected"===this.connectionState&&(this.reporter.log.info("leave for ".concat(e.type)),this.leave())}},{key:"addEventListeners",value:function(){window.addEventListener(e.Environment.isSafari()?"beforeunload":"pagehide",this.handlePageUnload),document.addEventListener("visibilitychange",this.handleVisibilitychange),this.channel.sessionManager.on("network-quality",this.handleNetworkQuality),this.channel.signaling.on("connection-state-change",this.handleConnectionChangeEvent)}},{key:"removeEventListeners",value:function(){window.removeEventListener(e.Environment.isSafari()?"beforeunload":"pagehide",this.handlePageUnload),document.removeEventListener("visibilitychange",this.handleVisibilitychange),this.channel.sessionManager.off("network-quality",this.handleNetworkQuality),this.channel.signaling.off("connection-state-change",this.handleConnectionChangeEvent)}},{key:"joinGroup",value:function(t){var r=t.userData,n=t.groupId,i=new TextEncoder;if(!n||i.encode(n).length>64)throw new e.DingRTCError(e.ErrorCode.InvaildArgument,"join group with invalid groupId");if(r){var o=new TextEncoder;if("string"!=typeof r||o.encode(r).length>64)throw new e.DingRTCError(e.ErrorCode.InvaildArgument,"join group with invalid userData")}return this.channel.joinGroup(t)}},{key:"leaveGroup",value:function(e){return this.channel.leaveGroup({groupId:e,publishAudioToChannel:!1})}},{key:"setGroupName",value:function(t,r){var n=new TextEncoder;if(!r||n.encode(r).length>64)throw new e.DingRTCError(e.ErrorCode.InvaildArgument,"update group with invalid name");return this.channel.setGroupProperties(t,{key:"name",value:r})}},{key:"subscribeGroup",value:function(e){return this.channel.subscribeGroup(e)}},{key:"unsubscribeGroup",value:function(e){return this.channel.unsubscribeGroup(e)}},{key:"mixAudioToGroup",value:function(t,r,n){if("audio"!==t.trackMediaType)throw new e.DingRTCError(e.ErrorCode.InvaildArgument,"only support publish audio to group");if("connected"!==this.connectionState)throw new e.DingRTCError(e.ErrorCode.PublishNotJoinChannel);if(r){if(this.reporter.log.info("mix audio track:".concat(t.getTrackId()," to group ").concat(n)),null==n&&this.channel.micMixedGroups.size)throw new e.DingRTCError(e.ErrorCode.InvaildState,"cannot mix audio to channel while mixing to others group");return this.channel.publishToGroup(t,n,!0)}if(this.reporter.log.info("unmix audio track:".concat(t.getTrackId()," from group ").concat(n)),!this.channel.micMixedGroups.has(n))throw new e.DingRTCError(e.ErrorCode.InvaildState,"cannot unmix audio from the unmixed group");return this.channel.unpublishFromGroup(t,n)}},{key:"dismissGroup",value:function(e){return this.channel.dismissGroup(e)}},{key:"register",value:function(e){e.attach(this.channel.internalChannel)}},{key:"ungister",value:function(e){e.detach(this.channel.internalChannel)}}]);var r,n}();function fi(e,t){var r="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!r){if(Array.isArray(e)||(r=function(e,t){if(e){if("string"==typeof e)return vi(e,t);var r={}.toString.call(e).slice(8,-1);return"Object"===r&&e.constructor&&(r=e.constructor.name),"Map"===r||"Set"===r?Array.from(e):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?vi(e,t):void 0}}(e))||t){r&&(e=r);var n=0,i=function(){};return{s:i,n:function(){return e.length>n?{done:!1,value:e[n++]}:{done:!0}},e:function(e){throw e},f:i}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var o,a=!0,s=!1;return{s:function(){r=r.call(e)},n:function(){var e=r.next();return a=e.done,e},e:function(e){s=!0,o=e},f:function(){try{a||null==r.return||r.return()}finally{if(s)throw o}}}}function vi(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=Array(t);t>r;r++)n[r]=e[r];return n}function mi(){try{var e=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(e){}return(mi=function(){return!!e})()}var hi=function(){function t(){var e,r,n,a,s;return o(this,t),r=this,n=l(n=t),e=d(r,mi()?Reflect.construct(n,[],l(r).constructor):n.apply(r,a)),Object.defineProperty(e,"deviceList",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(e,"checking",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(e,"checkDeviceUpdate",{enumerable:!0,configurable:!0,writable:!0,value:(s=i($.mark(function r(){var n;return $.wrap(function(r){for(;;)switch(r.prev=r.next){case 0:if(!e.checking){r.next=1;break}return r.abrupt("return");case 1:return e.checking=!0,r.next=2,t.getDevices();case 2:e.compareDevices(n=r.sent,"audiooutput"),e.compareDevices(n,"videoinput"),e.compareDevices(n,"audioinput"),e.deviceList=n,e.checking=!1;case 3:case"end":return r.stop()}},r)})),function(){return s.apply(this,arguments)})}),Object.defineProperty(e,"compareDevices",{enumerable:!0,configurable:!0,writable:!0,value:function(t,r){var n,i=t.filter(function(e){return e.kind===r}),o=e.deviceList.filter(function(e){return e.kind===r}),a=i.map(function(e){return e.deviceId}),s=o.map(function(e){return e.deviceId}),c=i.filter(function(e){return!s.includes(e.deviceId)}),u=o.filter(function(e){return!a.includes(e.deviceId)}),d={audioinput:"microphone-changed",audiooutput:"playback-device-changed",videoinput:"camera-changed"},l=fi(c);try{for(l.s();!(n=l.n()).done;){e.emit(d[r],{device:n.value,state:"active"})}}catch(e){l.e(e)}finally{l.f()}var p,f=fi(u);try{for(f.s();!(p=f.n()).done;){e.emit(d[r],{device:p.value,state:"inactive"})}}catch(e){f.e(e)}finally{f.f()}}}),t._instance?d(e,t._instance):(e.deviceList=[],Ye.checkSupported()?(t.getDevices().then(function(t){e.deviceList=t,e.addEventListeners()}),e):d(e))}return f(t,e.EventEmitter),u(t,[{key:"addEventListeners",value:function(){"ondevicechange"in navigator.mediaDevices?navigator.mediaDevices.addEventListener("devicechange",this.checkDeviceUpdate):e.addTimer(this.checkDeviceUpdate,1e3,"interval")}}],[{key:"getInstance",value:function(){return t._instance}},{key:"getDevices",value:function(){return new Promise(function(t,r){var n,i;null!==(n=navigator.mediaDevices)&&void 0!==n&&n.enumerateDevices?null===(i=navigator.mediaDevices)||void 0===i||i.enumerateDevices().then(function(e){return t(e.filter(function(e){return e.deviceId}))}).catch(r):r(new e.DingRTCError(e.ErrorCode.BrowserNotSupported,"enumerateDevices is not supported"))})}}])}();Object.defineProperty(hi,"_instance",{enumerable:!0,configurable:!0,writable:!0,value:new hi}),Object.defineProperty(hi,"getPlaybackDevices",{enumerable:!0,configurable:!0,writable:!0,value:function(){return hi.getDevices().then(function(e){return e.filter(function(e){return"audiooutput"===e.kind})}).catch(function(t){throw e.parseAudioDeviceError(t)})}}),Object.defineProperty(hi,"getCameras",{enumerable:!0,configurable:!0,writable:!0,value:function(){return hi.getDevices().then(function(e){return e.filter(function(e){return"videoinput"===e.kind})}).catch(function(t){throw e.parseVideoDeviceError(t)})}}),Object.defineProperty(hi,"getMicrophones",{enumerable:!0,configurable:!0,writable:!0,value:function(){return hi.getDevices().then(function(e){return e.filter(function(e){return"audioinput"===e.kind})}).catch(function(t){throw e.parseAudioDeviceError(t)})}});function yi(){try{var e=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(e){}return(yi=function(){return!!e})()}De();var gi=e.getReporter().log,bi=new(function(){function t(){var r,n,i,a;if(o(this,t),n=this,i=l(i=t),r=d(n,yi()?Reflect.construct(i,[],l(n).constructor):i.apply(n,a)),Object.defineProperty(r,"VERSION",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),r.VERSION=te,!Ye.checkSupported())return d(r);var s=hi.getInstance();return s.on("camera-changed",function(e){r.emit("camera-changed",e)}),s.on("microphone-changed",function(e){r.emit("microphone-changed",e)}),s.on("playback-device-changed",function(e){r.emit("playback-device-changed",e)}),e.EventBus.on("autoplay-failed",function(e){r.emit("autoplay-failed",e)}),r}return f(t,e.EventEmitter),u(t,[{key:"createClient",value:function(){return gi.info("createClient"),new pi}},{key:"checkSystemRequirements",value:function(){return gi.info("checkSystemRequirements"),Ye.checkSupported()}},{key:"getSupportedCodec",value:function(){return gi.info("getSupportedCodec"),Ye.getSupportedCodec()}},{key:"createCameraVideoTrack",value:function(e){return gi.info("createCameraVideoTrack",e),kt(e)}},{key:"createMicrophoneAudioTrack",value:function(e){return gi.info("createMicrophoneAudioTrack",e),St(e)}},{key:"createCustomVideoTrack",value:function(e){return gi.info("createCustomVideoTrack",e),wt(e)}},{key:"createCustomAudioTrack",value:function(e){return gi.info("createCustomAudioTrack",e),Tt(e)}},{key:"createScreenVideoTrack",value:function(e){return gi.info("createScreenVideoTrack",e),Pt(e)}},{key:"createMicrophoneAndCameraTracks",value:(r=i($.mark(function e(t,r){return $.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return gi.info("createMicrophoneAndCameraTracks",{videoConfig:t,audioConfig:r}),e.abrupt("return",Et(t,r));case 1:case"end":return e.stop()}},e)})),function(e,t){return r.apply(this,arguments)})},{key:"getCameras",value:function(){return gi.info("getCameras"),hi.getCameras()}},{key:"getDevices",value:function(){return gi.info("getDevices"),hi.getDevices()}},{key:"getPlaybackDevices",value:function(){return gi.info("getPlaybackDevices"),hi.getPlaybackDevices()}},{key:"getMicrophones",value:function(){return gi.info("getMicrophones"),hi.getMicrophones()}},{key:"setLogLevel",value:function(t){e.setLogLevel(t),gi.info("setLogLevel",t)}},{key:"setClientConfig",value:function(e){gi.info("setClientConfig",e),Ke.setClientConfig(e)}}]);var r}());Object.defineProperty(exports,"ErrorCodeAndMsgMap",{enumerable:!0,get:function(){return e.ErrorCodeAndMsgMap}}),exports.FALLBACK_SUB_VIDEO_PROFILE={height:360,width:640},exports.default=bi;