UNPKG

agora-rtc-sdk-ng

Version:
5 lines (4 loc) 184 kB
/** * AgoraWebSDK_N-v4.24.3-0-g6cc16b0bb-dirty Copyright AgoraInc. */ import{logger as e,report as t,AgoraRTCError as n}from"@agora-js/report";import{IS_GLOBAL_VERSION as i,EventEmitter as o,getParameter as r,ScalabilityMode as s,parseSdp as a,isFirefox as c,jsonClone as d,printSdp as p,getRandomString as l,getBrowserInfo as h,BrowserName as u,BrowserOS as E,isSafari as _,isChromeBelow90 as C,isAboveChrome as m,isAboveEdge as R,isChrome as S,isFirefoxVersion as f,isBelowIOS14_6 as I,VideoCodec as N,QualityLimitationReason as g,OVERUSE_DETECTOR_PARAMS as T,isAboveIOS as A,isBelowIOS as D,isAboveSafari as v,isBelowSafari as O,PromiseMutex as P,createWebRTCStatsFilter as y,AgoraRTCError as L,AgoraRTCErrorCode as w,AgoraAPIName as b,AgoraAPITag as M,DEFAULT_CANDIDATE_STATS as U,isRTCIceServerList as x,isChromeKernel as V,setBigUint64 as F,getBigUint64 as k,NETWORK_STATE as B,networkIndicator as G,NETWORK_INDICATOR_EVENTS as H,emitAsPromise as K,getRetryWaitTime as W,wait as Y,emitAsInvokerNoResponse as j,ConnectionDisconnectedReason as J,Rolling as X,emitAsInvoker as Q}from"@agora-js/shared";import"@agora-js/protocol";import{LocalAudioTrack as q,MicrophoneAudioTrack as z,LocalVideoTrack as Z,getCompatibility as $,TrackHint as ee,CameraVideoTrack as te,detectSupportPreSub as ne,detectSupportSDPEndpoint as ie,VideoPlayer as oe,AgoraRTCPlayer as re,getOriginSenderConfig as se}from"@agora-js/media";import{deflateRaw as ae,inflateRaw as ce}from"pako";function de(e,t){this.v=e,this.k=t}function pe(e,t,n,i,o){var r={};return Object.keys(i).forEach((function(e){r[e]=i[e]})),r.enumerable=!!r.enumerable,r.configurable=!!r.configurable,("value"in r||r.initializer)&&(r.writable=!0),r=n.slice().reverse().reduce((function(n,i){return i(e,t,n)||n}),r),o&&void 0!==r.initializer&&(r.value=r.initializer?r.initializer.call(o):void 0,r.initializer=void 0),void 0===r.initializer?(Object.defineProperty(e,t,r),null):r}function le(e){var t={},n=!1;function i(t,i){return n=!0,i=new Promise((function(n){n(e[t](i))})),{done:!1,value:new de(i,1)}}return t["undefined"!=typeof Symbol&&Symbol.iterator||"@@iterator"]=function(){return this},t.next=function(e){return n?(n=!1,e):i("next",e)},"function"==typeof e.throw&&(t.throw=function(e){if(n)throw n=!1,e;return i("throw",e)}),"function"==typeof e.return&&(t.return=function(e){return n?(n=!1,e):i("return",e)}),t}function he(e){var t,n,i,o=2;for("undefined"!=typeof Symbol&&(n=Symbol.asyncIterator,i=Symbol.iterator);o--;){if(n&&null!=(t=e[n]))return t.call(e);if(i&&null!=(t=e[i]))return new ue(t.call(e));n="@@asyncIterator",i="@@iterator"}throw new TypeError("Object is not async iterable")}function ue(e){function t(e){if(Object(e)!==e)return Promise.reject(new TypeError(e+" is not an object."));var t=e.done;return Promise.resolve(e.value).then((function(e){return{value:e,done:t}}))}return ue=function(e){this.s=e,this.n=e.next},ue.prototype={s:null,n:null,next:function(){return t(this.n.apply(this.s,arguments))},return:function(e){var n=this.s.return;return void 0===n?Promise.resolve({value:e,done:!0}):t(n.apply(this.s,arguments))},throw:function(e){var n=this.s.return;return void 0===n?Promise.reject(e):t(n.apply(this.s,arguments))}},new ue(e)}function Ee(e){return new de(e,0)}function _e(e,t,n){return(t=function(e){var t=function(e,t){if("object"!=typeof e||!e)return e;var n=e[Symbol.toPrimitive];if(void 0!==n){var i=n.call(e,t||"default");if("object"!=typeof i)return i;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}(e,"string");return"symbol"==typeof t?t:t+""}(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function Ce(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(e);t&&(i=i.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,i)}return n}function me(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?Ce(Object(n),!0).forEach((function(t){_e(e,t,n[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):Ce(Object(n)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))}))}return e}function Re(e){return function(){return new Se(e.apply(this,arguments))}}function Se(e){var t,n;function i(t,n){try{var r=e[t](n),s=r.value,a=s instanceof de;Promise.resolve(a?s.v:s).then((function(n){if(a){var c="return"===t?"return":"next";if(!s.k||n.done)return i(c,n);n=e[c](n).value}o(r.done?"return":"normal",n)}),(function(e){i("throw",e)}))}catch(e){o("throw",e)}}function o(e,o){switch(e){case"return":t.resolve({value:o,done:!0});break;case"throw":t.reject(o);break;default:t.resolve({value:o,done:!1})}(t=t.next)?i(t.key,t.arg):n=null}this._invoke=function(e,o){return new Promise((function(r,s){var a={key:e,arg:o,resolve:r,reject:s,next:null};n?n=n.next=a:(t=n=a,i(e,o))}))},"function"!=typeof e.return&&(this.return=void 0)}Se.prototype["function"==typeof Symbol&&Symbol.asyncIterator||"@@asyncIterator"]=function(){return this},Se.prototype.next=function(e){return this._invoke("next",e)},Se.prototype.throw=function(e){return this._invoke("throw",e)},Se.prototype.return=function(e){return this._invoke("return",e)};let fe=function(e){return e[e.ACCESS_POINT=101]="ACCESS_POINT",e[e.UNILBS=201]="UNILBS",e[e.STRING_UID_ALLOCATOR=901]="STRING_UID_ALLOCATOR",e}({}),Ie=function(e){return e[e.IIIEGAL_APPID=1]="IIIEGAL_APPID",e[e.IIIEGAL_UID=2]="IIIEGAL_UID",e[e.INTERNAL_ERROR=3]="INTERNAL_ERROR",e}({}),Ne=function(e){return e[e.INVALID_VENDOR_KEY=5]="INVALID_VENDOR_KEY",e[e.INVALID_CHANNEL_NAME=7]="INVALID_CHANNEL_NAME",e[e.INTERNAL_ERROR=8]="INTERNAL_ERROR",e[e.NO_AUTHORIZED=9]="NO_AUTHORIZED",e[e.DYNAMIC_KEY_TIMEOUT=10]="DYNAMIC_KEY_TIMEOUT",e[e.NO_ACTIVE_STATUS=11]="NO_ACTIVE_STATUS",e[e.DYNAMIC_KEY_EXPIRED=13]="DYNAMIC_KEY_EXPIRED",e[e.STATIC_USE_DYNAMIC_KEY=14]="STATIC_USE_DYNAMIC_KEY",e[e.DYNAMIC_USE_STATIC_KEY=15]="DYNAMIC_USE_STATIC_KEY",e[e.USER_OVERLOAD=16]="USER_OVERLOAD",e[e.FORBIDDEN_REGION=18]="FORBIDDEN_REGION",e[e.CANNOT_MEET_AREA_DEMAND=19]="CANNOT_MEET_AREA_DEMAND",e[e.REQ_DOWNGRADE_FALLBACK=27]="REQ_DOWNGRADE_FALLBACK",e}({}),ge=function(e){return e[e.NO_FLAG_SET=100]="NO_FLAG_SET",e[e.FLAG_SET_BUT_EMPTY=101]="FLAG_SET_BUT_EMPTY",e[e.INVALID_FALG_SET=102]="INVALID_FALG_SET",e[e.FLAG_SET_BUT_NO_RE=103]="FLAG_SET_BUT_NO_RE",e[e.INVALID_SERVICE_ID=104]="INVALID_SERVICE_ID",e[e.NO_SERVICE_AVAILABLE=200]="NO_SERVICE_AVAILABLE",e[e.NO_SERVICE_AVAILABLE_P2P=201]="NO_SERVICE_AVAILABLE_P2P",e[e.NO_SERVICE_AVAILABLE_VOICE=202]="NO_SERVICE_AVAILABLE_VOICE",e[e.NO_SERVICE_AVAILABLE_WEBRTC=203]="NO_SERVICE_AVAILABLE_WEBRTC",e[e.NO_SERVICE_AVAILABLE_CDS=204]="NO_SERVICE_AVAILABLE_CDS",e[e.NO_SERVICE_AVAILABLE_CDN=205]="NO_SERVICE_AVAILABLE_CDN",e[e.NO_SERVICE_AVAILABLE_TDS=206]="NO_SERVICE_AVAILABLE_TDS",e[e.NO_SERVICE_AVAILABLE_REPORT=207]="NO_SERVICE_AVAILABLE_REPORT",e[e.NO_SERVICE_AVAILABLE_APP_CENTER=208]="NO_SERVICE_AVAILABLE_APP_CENTER",e[e.NO_SERVICE_AVAILABLE_ENV0=209]="NO_SERVICE_AVAILABLE_ENV0",e[e.NO_SERVICE_AVAILABLE_VOET=210]="NO_SERVICE_AVAILABLE_VOET",e[e.NO_SERVICE_AVAILABLE_STRING_UID=211]="NO_SERVICE_AVAILABLE_STRING_UID",e[e.NO_SERVICE_AVAILABLE_WEBRTC_UNILBS=212]="NO_SERVICE_AVAILABLE_WEBRTC_UNILBS",e[e.NO_SERVICE_AVAILABLE_UNILBS_FLV=213]="NO_SERVICE_AVAILABLE_UNILBS_FLV",e}({}),Te=function(e){return e[e.K_TIMESTAMP_EXPIRED=2]="K_TIMESTAMP_EXPIRED",e[e.K_CHANNEL_PERMISSION_INVALID=3]="K_CHANNEL_PERMISSION_INVALID",e[e.K_CERTIFICATE_INVALID=4]="K_CERTIFICATE_INVALID",e[e.K_CHANNEL_NAME_EMPTY=5]="K_CHANNEL_NAME_EMPTY",e[e.K_CHANNEL_NOT_FOUND=6]="K_CHANNEL_NOT_FOUND",e[e.K_TICKET_INVALID=7]="K_TICKET_INVALID",e[e.K_CHANNEL_CONFLICTED=8]="K_CHANNEL_CONFLICTED",e[e.K_SERVICE_NOT_READY=9]="K_SERVICE_NOT_READY",e[e.K_SERVICE_TOO_HEAVY=10]="K_SERVICE_TOO_HEAVY",e[e.K_UID_BANNED=14]="K_UID_BANNED",e[e.K_IP_BANNED=15]="K_IP_BANNED",e[e.K_CHANNEL_BANNED=16]="K_CHANNEL_BANNED",e[e.DATASTREAM2_NOT_AVAILABLE=27]="DATASTREAM2_NOT_AVAILABLE",e[e.K_AUTO_REBALANCE=28]="K_AUTO_REBALANCE",e[e.K_VOS_FALLBACK=30]="K_VOS_FALLBACK",e[e.WARN_NO_AVAILABLE_CHANNEL=103]="WARN_NO_AVAILABLE_CHANNEL",e[e.WARN_LOOKUP_CHANNEL_TIMEOUT=104]="WARN_LOOKUP_CHANNEL_TIMEOUT",e[e.WARN_LOOKUP_CHANNEL_REJECTED=105]="WARN_LOOKUP_CHANNEL_REJECTED",e[e.WARN_OPEN_CHANNEL_TIMEOUT=106]="WARN_OPEN_CHANNEL_TIMEOUT",e[e.WARN_OPEN_CHANNEL_REJECTED=107]="WARN_OPEN_CHANNEL_REJECTED",e[e.WARN_REQUEST_DEFERRED=108]="WARN_REQUEST_DEFERRED",e[e.ERR_DYNAMIC_KEY_TIMEOUT=109]="ERR_DYNAMIC_KEY_TIMEOUT",e[e.ERR_NO_AUTHORIZED=110]="ERR_NO_AUTHORIZED",e[e.ERR_VOM_SERVICE_UNAVAILABLE=111]="ERR_VOM_SERVICE_UNAVAILABLE",e[e.ERR_NO_CHANNEL_AVAILABLE_CODE=112]="ERR_NO_CHANNEL_AVAILABLE_CODE",e[e.ERR_MASTER_VOCS_UNAVAILABLE=114]="ERR_MASTER_VOCS_UNAVAILABLE",e[e.ERR_INTERNAL_ERROR=115]="ERR_INTERNAL_ERROR",e[e.ERR_NO_ACTIVE_STATUS=116]="ERR_NO_ACTIVE_STATUS",e[e.ERR_INVALID_UID=117]="ERR_INVALID_UID",e[e.ERR_DYNAMIC_KEY_EXPIRED=118]="ERR_DYNAMIC_KEY_EXPIRED",e[e.ERR_STATIC_USE_DYANMIC_KE=119]="ERR_STATIC_USE_DYANMIC_KE",e[e.ERR_DYNAMIC_USE_STATIC_KE=120]="ERR_DYNAMIC_USE_STATIC_KE",e[e.ERR_NO_VOCS_AVAILABLE=2e3]="ERR_NO_VOCS_AVAILABLE",e[e.ERR_NO_VOS_AVAILABLE=2001]="ERR_NO_VOS_AVAILABLE",e[e.ERR_JOIN_CHANNEL_TIMEOUT=2002]="ERR_JOIN_CHANNEL_TIMEOUT",e[e.ERR_REPEAT_JOIN_CHANNEL=2003]="ERR_REPEAT_JOIN_CHANNEL",e[e.ERR_JOIN_BY_MULTI_IP=2004]="ERR_JOIN_BY_MULTI_IP",e[e.ERR_NOT_JOINED=2011]="ERR_NOT_JOINED",e[e.ERR_REPEAT_JOIN_REQUEST=2012]="ERR_REPEAT_JOIN_REQUEST",e[e.ERR_INVALID_VENDOR_KEY=2013]="ERR_INVALID_VENDOR_KEY",e[e.ERR_INVALID_CHANNEL_NAME=2014]="ERR_INVALID_CHANNEL_NAME",e[e.ERR_INVALID_STRINGUID=2015]="ERR_INVALID_STRINGUID",e[e.ERR_TOO_MANY_USERS=2016]="ERR_TOO_MANY_USERS",e[e.ERR_SET_CLIENT_ROLE_TIMEOUT=2017]="ERR_SET_CLIENT_ROLE_TIMEOUT",e[e.ERR_SET_CLIENT_ROLE_NO_PERMISSION=2018]="ERR_SET_CLIENT_ROLE_NO_PERMISSION",e[e.ERR_SET_CLIENT_ROLE_ALREADY_IN_USE=2019]="ERR_SET_CLIENT_ROLE_ALREADY_IN_USE",e[e.ERR_PUBLISH_REQUEST_INVALID=2020]="ERR_PUBLISH_REQUEST_INVALID",e[e.ERR_SUBSCRIBE_REQUEST_INVALID=2021]="ERR_SUBSCRIBE_REQUEST_INVALID",e[e.ERR_NOT_SUPPORTED_MESSAGE=2022]="ERR_NOT_SUPPORTED_MESSAGE",e[e.ERR_ILLEAGAL_PLUGIN=2023]="ERR_ILLEAGAL_PLUGIN",e[e.ERR_REJOIN_TOKEN_INVALID=2024]="ERR_REJOIN_TOKEN_INVALID",e[e.ERR_REJOIN_USER_NOT_JOINED=2025]="ERR_REJOIN_USER_NOT_JOINED",e[e.ERR_INVALID_OPTIONAL_INFO=2027]="ERR_INVALID_OPTIONAL_INFO",e[e.ILLEGAL_AES_PASSWORD=2028]="ILLEGAL_AES_PASSWORD",e[e.ILLEGAL_CLIENT_ROLE_LEVEL=2029]="ILLEGAL_CLIENT_ROLE_LEVEL",e[e.ERR_TOO_MANY_BROADCASTERS=2031]="ERR_TOO_MANY_BROADCASTERS",e[e.ERR_TOO_MANY_SUBSCRIBERS=2032]="ERR_TOO_MANY_SUBSCRIBERS",e[e.ERR_LICENSE_MISSING=32769]="ERR_LICENSE_MISSING",e[e.ERR_LICENSE_EXPIRED=32771]="ERR_LICENSE_EXPIRED",e[e.ERR_LICENSE_MINUTES_EXCEEDED=32773]="ERR_LICENSE_MINUTES_EXCEEDED",e[e.ERR_LICENSE_PERIOD_INVALID=32774]="ERR_LICENSE_PERIOD_INVALID",e[e.ERR_LICENSE_MULTIPLE_SDK_SERVICE=32778]="ERR_LICENSE_MULTIPLE_SDK_SERVICE",e[e.ERR_LICENSE_ILLEGAL=32783]="ERR_LICENSE_ILLEGAL",e[e.ERR_TEST_RECOVER=9e3]="ERR_TEST_RECOVER",e[e.ERR_TEST_TRYNEXT=9001]="ERR_TEST_TRYNEXT",e[e.ERR_TEST_RETRY=9002]="ERR_TEST_RETRY",e}({}),Ae=function(e){return e.CONNECTING="connecting",e.CONNECTED="connected",e.RECONNECTING="reconnecting",e.CLOSED="closed",e}({}),De=function(e){return e.WS_CONNECTED="ws_connected",e.WS_RECONNECTING="ws_reconnecting",e.WS_CLOSED="ws_closed",e.WS_RECONNECT_CREATE_CONNECTION="ws_reconnect_create_connection",e.ON_BINARY_DATA="on_binary_data",e.REQUEST_RECOVER="request_recover",e.REQUEST_JOIN_INFO="request_join_info",e.REQUEST_JOIN_INFO_WITH_PRE_JOIN_RESPONSE="request_pre_join_response",e.REQUEST_REJOIN_INFO="req_rejoin_info",e.IS_P2P_DISCONNECTED="is_p2p_dis",e.DISCONNECT_P2P="dis_p2p",e.ABORT_P2P_EXECUTION="abort_p2p_execution",e.NEED_RENEW_SESSION="need-sid",e.REPORT_JOIN_GATEWAY="report_join_gateway",e.REQUEST_TIMEOUT="request_timeout",e.REQUEST_SUCCESS="request_success",e.JOIN_RESPONSE="join_response",e.PRE_CONNECT_PC="pre_connect_pc",e.DATACHANNEL_PRECONNECT="datachannel_preconnect",e.DATACHANNEL_CONNECTING="datachannel_connecting",e.DATACHANNEL_FAILBACK="datachannel_failback",e.P2P_CONNECTION="p2p_connection",e.P2P_REMOTE_CANDIDATE_UPDATE="p2p_remote_candidate_update",e.P2P_SUBSCRIBE="p2p_subscribe",e.P2P_UNSUBSCRIBE="p2p_unsubscribe",e.P2P_EXCHANGE_SDP="p2p_exchange_sdp",e.P2P_ON_ADD_VIDEO_STREAM="p2p_on_add_video_stream",e.P2P_ON_ADD_AUDIO_STREAM="p2p_on_add_audio_stream",e.RECOVER_NOTIFICATION="recover_notification",e.VOS_FALLBACK="vos_fallback",e.VOS_FALLBACK_PROMISE="vos_fallback_promise",e}({}),ve=function(e){return e.PING="ping",e.PING_BACK="ping_back",e.JOIN="join_v3",e.REJOIN="rejoin_v3",e.LEAVE="leave",e.SET_CLIENT_ROLE="set_client_role",e.PUBLISH="publish",e.PUBLISH_DATASTREAM="publish_datastream",e.UNPUBLISH="unpublish",e.UNPUBLISH_DATASTREAM="unpublish_datastream",e.SUBSCRIBE="subscribe",e.PRE_SUBSCRIBE="pre_subscribe",e.SUBSCRIBE_DATASTREAM="subscribe_datastream",e.SUBSCRIBE_STREAMS="subscribe_streams",e.UNSUBSCRIBE="unsubscribe",e.UNSUBSCRIBE_DATASTREAM="unsubscribe_datastream",e.UNSUBSCRIBE_STREAMS="unsubscribe_streams",e.SUBSCRIBE_CHANGE="subscribe_change",e.TRAFFIC_STATS="traffic_stats",e.RENEW_TOKEN="renew_token",e.SET_DUAL_STREAM_MODE="set_dual_stream_mode",e.SWITCH_VIDEO_STREAM="switch_video_stream",e.DEFAULT_VIDEO_STREAM="default_video_stream",e.SET_FALLBACK_OPTION="set_fallback_option",e.CONFIGURE="configure",e.GATEWAY_INFO="gateway_info",e.CONTROL="control",e.SEND_METADATA="send_metadata",e.DATA_STREAM="data_stream",e.PICK_SVC_LAYER="pick_svc_layer",e.RESTART_ICE="restart_ice",e.CONNECT_PC="connect_pc",e.SET_VIDEO_PROFILE="set_video_profile",e.SET_PARAMETER="set_parameter",e.SET_RTM2_FLAG="set_rtm2_flag",e.DOWNGRADE_CODEC="downgrade_codec",e}({}),Oe=function(e){return e.WRTC_STATS="wrtc_stats",e.WS_INFLATE_DATA_LENGTH="ws_inflate_data_length",e.DENOISER_STATS="denoiser_stats",e.EXTENSION_USAGE_STATS="extension_usage_stats",e}({}),Pe=function(e){return e.ON_USER_ONLINE="on_user_online",e.ON_USER_OFFLINE="on_user_offline",e.ON_STREAM_FALLBACK_UPDATE="on_stream_fallback_update",e.ON_PUBLISH_STREAM="on_publish_stream",e.ON_UPLINK_STATS="on_uplink_stats",e.ON_P2P_LOST="on_p2p_lost",e.ON_REMOVE_STREAM="on_remove_stream",e.ON_ADD_AUDIO_STREAM="on_add_audio_stream",e.ON_ADD_VIDEO_STREAM="on_add_video_stream",e.ON_TOKEN_PRIVILEGE_WILL_EXPIRE="on_token_privilege_will_expire",e.ON_TOKEN_PRIVILEGE_DID_EXPIRE="on_token_privilege_did_expire",e.ON_USER_BANNED="on_user_banned",e.ON_USER_LICENSE_BANNED="on_user_license_banned",e.ON_NOTIFICATION="on_notification",e.ON_CRYPT_ERROR="on_crypt_error",e.MUTE_AUDIO="mute_audio",e.MUTE_VIDEO="mute_video",e.UNMUTE_AUDIO="unmute_audio",e.UNMUTE_VIDEO="unmute_video",e.ON_P2P_OK="on_p2p_ok",e.RECEIVE_METADATA="receive_metadata",e.ON_DATA_STREAM="on_data_stream",e.ON_RTP_CAPABILITY_CHANGE="on_rtp_capability_change",e.ON_REMOTE_DATASTREAM_UPDATE="on_remote_datastream_update",e.ON_REMOTE_FULL_DATASTREAM_INFO="on_remote_full_datastream_info",e.ENABLE_LOCAL_VIDEO="enable_local_video",e.DISABLE_LOCAL_VIDEO="disable_local_video",e.ENABLE_LOCAL_AUDIO="enable_local_audio",e.DISABLE_LOCAL_AUDIO="disable_local_audio",e.ON_PUBLISHED_USER_LIST="on_published_user_list",e.ENABLE_MULTI_STREAM="enable_multi_stream",e.ON_USER_LIST="on_user_list",e}({}),ye=function(e){return e.CHINA="CHINA",e.ASIA="ASIA",e.NORTH_AMERICA="NORTH_AMERICA",e.EUROPE="EUROPE",e.JAPAN="JAPAN",e.INDIA="INDIA",e.KOREA="KOREA",e.HKMC="HKMC",e.US="US",e.OCEANIA="OCEANIA",e.SOUTH_AMERICA="SOUTH_AMERICA",e.AFRICA="AFRICA",e.OVERSEA="OVERSEA",e.GLOBAL="GLOBAL",e.EXTENSIONS="EXTENSIONS",e}({});ye.AFRICA,ye.ASIA,ye.CHINA,ye.EUROPE,ye.GLOBAL,ye.INDIA,ye.JAPAN,ye.NORTH_AMERICA,ye.OCEANIA,ye.OVERSEA,ye.SOUTH_AMERICA;let Le=function(e){return e.CHINA="CN",e.ASIA="AS",e.NORTH_AMERICA="NA",e.EUROPE="EU",e.JAPAN="JP",e.INDIA="IN",e.KOREA="KR",e.HKMC="HK",e.US="US",e.OCEANIA="OC",e.SOUTH_AMERICA="SA",e.AFRICA="AF",e.OVERSEA="OVERSEA",e.GLOBAL="GLOBAL",e.EXTENSIONS="GLOBAL",e}({});Le.ASIA,Le.NORTH_AMERICA,Le.EUROPE,Le.JAPAN,Le.INDIA,Le.KOREA,Le.HKMC,Le.US,Le.OVERSEA,Le.GLOBAL,Le.OCEANIA,Le.SOUTH_AMERICA,Le.AFRICA,i&&Le.CHINA;class we extends o{constructor(e,t){super(),this.onICEConnectionStateChange=void 0,this.onConnectionStateChange=void 0,this.onDTLSTransportStateChange=void 0,this.onDTLSTransportError=void 0,this.onICETransportStateChange=void 0,this.onFirstAudioReceived=void 0,this.onFirstVideoReceived=void 0,this.onFirstAudioDecoded=void 0,this.onFirstVideoDecoded=void 0,this.onFirstVideoRender=void 0,this.onFirstVideoBufferReady=void 0,this.onFirstVideoDecodedTimeout=void 0,this.onSelectedLocalCandidateChanged=void 0,this.onSelectedRemoteCandidateChanged=void 0,this.onICECandidateError=void 0,this.getLocalVideoStats=void 0}}class be extends we{constructor(e,t){super(e,t),this.establishPromise=void 0}}let Me=function(e){return e.VIDEO="video",e.AUDIO="audio",e}({}),Ue=function(e){return e.UDP_RELAY="udp_relay",e.UDP_TCP_RELAY="udp_tcp_relay",e.TCP_RELAY="tcp_relay",e.RELAY="relay",e}({}),xe=function(e){return e.NETWORK_ERROR="NETWORK_ERROR",e.SERVER_ERROR="SERVER_ERROR",e.MULTI_IP="MULTI_IP",e.TIMEOUT="TIMEOUT",e.OFFLINE="OFFLINE",e.LEAVE="LEAVE",e.P2P_FAILED="P2P_FAILED",e.FALLBACK="FALLBACK",e}({}),Ve=function(e){return e.CONNECTED="transmitter:connected",e.RECONNECTING="transmitter:reconnecting",e.WILL_RECONNECT="transmitter:will_reconnect",e.CLOSED="transmitter:closed",e.FAILED="transmitter:failed",e.ON_MESSAGE="transmitter:on_message",e.REQUEST_NEW_URLS="transmitter:request_new_urls",e.RECONNECT_CREATE_CONNECTION="transmitter:reconnect_create_connection",e.ON_TOKEN_PRIVILEGE_DID_EXPIRE="transmitter:on_token_privilege_did_expire",e.TO_CONNECT_DATACHANNEL="transmitter:to_connect_datachannel",e.FAILBACK="transmitter:failback",e.PRE_CONNECT_PC="transmitter:pre_connect_pc",e}({}),Fe=0;function ke(t){const n=r("TURN_DOMAINS");Fe=(Fe+1)%n.length;const i=n[Fe]||"edge.agora.io";return t.match(/^[\.\:\d]+$/)?"".concat(t.replace(/[^\d]/g,"-"),".").concat(i):(e.debug("Cannot recognized as ip address: ".concat(t,", use as host2")),t)}function Be(e){return"number"==typeof e?e:e.exact||e.ideal||e.max||e.min||0}function Ge(e){const t=e.split(":"),n=e.split(/[-.]/),i=e.includes("-")?"-":".";let o=e;return t.length>1?n.length>1?(n[1]="**",o=n[0]+i+"**:"+t[t.length-1]):o=t.length>2?t[0]+i+"**:"+t[t.length-1]:"**:"+t[t.length-1]:n.length>1&&(o=n[0]+i+"**"),o}function He(e,t){return e.getTransceivers().find((e=>e.sender.track===t||e.receiver.track===t))}function Ke(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:r("SVC_MODE");if(r("ENABLE_SVC"))return function(e){return e in s}(e)?e:s.L1T3}const We={[Me.VIDEO]:[{key:"abs-send-time",extensionName:"http://www.webrtc.org/experiments/rtp-hdrext/abs-send-time"},{key:"video-orientation",extensionName:"urn:3gpp:video-orientation"},{key:"draft-holmer-rmcat-transport-wide-cc-extensions-01",extensionName:"http://www.ietf.org/id/draft-holmer-rmcat-transport-wide-cc-extensions-01"},{key:"playout-delay",extensionName:"http://www.webrtc.org/experiments/rtp-hdrext/playout-delay"},{key:"video-content-type",extensionName:"http://www.webrtc.org/experiments/rtp-hdrext/video-content-type"},{key:"color-space",extensionName:"http://www.webrtc.org/experiments/rtp-hdrext/color-space"},{key:"video-timing",extensionName:"http://www.webrtc.org/experiments/rtp-hdrext/video-timing"}],[Me.AUDIO]:[{key:"ssrc-audio-level",extensionName:"urn:ietf:params:rtp-hdrext:ssrc-audio-level"},{key:"draft-holmer-rmcat-transport-wide-cc-extensions-01",extensionName:"http://www.ietf.org/id/draft-holmer-rmcat-transport-wide-cc-extensions-01"},{key:"abs-send-time",extensionName:"http://www.webrtc.org/experiments/rtp-hdrext/abs-send-time"}]};function Ye(e){e.send&&(Xe(Me.VIDEO,e.send.videoExtensions),Xe(Me.AUDIO,e.send.audioExtensions)),e.recv&&(Xe(Me.VIDEO,e.recv.videoExtensions),Xe(Me.AUDIO,e.recv.audioExtensions)),e.sendrecv&&(Xe(Me.VIDEO,e.sendrecv.videoExtensions),Xe(Me.AUDIO,e.sendrecv.audioExtensions))}function je(e,t){e.send&&(Je(Me.VIDEO,e.send.videoExtensions,t.send.videoExtensions),Je(Me.AUDIO,e.send.audioExtensions,t.send.audioExtensions)),e.recv&&(Je(Me.VIDEO,e.recv.videoExtensions,t.recv.videoExtensions),Je(Me.AUDIO,e.recv.audioExtensions,t.recv.audioExtensions))}function Je(e,t,n){t.forEach((t=>{const i=We[e].find((e=>{let{key:n}=e;return t.extensionName.includes(n)}));if(!i)return;const o=n.find((e=>{let{extensionName:t}=e;return t.includes(i.key)}));o&&o.extensionName.includes("gdpr_forbidden")&&(t.extensionName=o.extensionName)}))}function Xe(e,t){t.forEach((t=>{const n=We[e].find((e=>{let{key:n}=e;return t.extensionName.includes(n)}));t.extensionName.includes("gdpr_forbidden")&&n&&(t.extensionName=n.extensionName)}))}function Qe(e){return"http://www.webrtc.org/experiments/rtp-hdrext/abs-send-time"===e||e.includes("abs-send-time")}function qe(e){return"http://www.ietf.org/id/draft-holmer-rmcat-transport-wide-cc-extensions-01"===e||e.includes("draft-holmer-rmcat-transport-wide-cc-extensions-01")}function ze(t){let n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},o=arguments.length>3?arguments[3]:void 0;const{filterRTX:s,filterVideoFec:c,filterAudioFec:d,filterAudioCodec:p,filterVideoCodec:l,unsupportedVideoUplinkCodec:h,unsupportedVideoDownlinkCodec:u}=n,{useXR:E}=i;let _=[],C=[],m=[],R=[],S=!1,f=!1;if(a(t).mediaDescriptions.forEach((e=>{o&&o!==e.attributes.direction||("video"!==e.media.mediaType||S||(C=e.attributes.payloads,R=e.attributes.extmaps,S=!0),"audio"!==e.media.mediaType||f||(_=e.attributes.payloads,m=e.attributes.extmaps,f=!0))})),!R||0===C.length)throw new Error("Cannot get video capabilities from SDP.");if(!m||0===_.length)throw new Error("Cannot get audio capabilities from SDP.");if(C.forEach((e=>{var t;null!==(t=e.rtpMap)&&void 0!==t&&t.clockRate&&(e.rtpMap.clockRate=parseInt(e.rtpMap.clockRate)),E&&e.rtcpFeedbacks.push({type:"rrtr"})})),_.forEach((e=>{var t;null!==(t=e.rtpMap)&&void 0!==t&&t.clockRate&&(e.rtpMap.clockRate=parseInt(e.rtpMap.clockRate)),E&&e.rtcpFeedbacks.push({type:"rrtr"})})),s&&(_=_.filter((e=>{var t;return"rtx"!==(null===(t=e.rtpMap)||void 0===t?void 0:t.encodingName.toLowerCase())})),C=C.filter((e=>{var t;return"rtx"!==(null===(t=e.rtpMap)||void 0===t?void 0:t.encodingName.toLowerCase())}))),c){const e=C.filter((e=>{var t;return/(red)|(ulpfec)|(flexfec)/i.test((null===(t=e.rtpMap)||void 0===t?void 0:t.encodingName)||"")})),t=pt(e,C).map((e=>e.payloadType)),n=[...e.map((e=>e.payloadType)),...t];C=C.filter((e=>!n.includes(e.payloadType)))}if(d&&(_=_.filter((e=>{var t;return!/(red)|(ulpfec)|(flexfec)/i.test((null===(t=e.rtpMap)||void 0===t?void 0:t.encodingName)||"")}))),p&&(null==p?void 0:p.length)>0&&(_=_.filter((e=>{var t;return p.includes((null===(t=e.rtpMap)||void 0===t?void 0:t.encodingName.toLowerCase())||"")}))),l&&(null==l?void 0:l.length)>0){const e=C.filter((e=>{var t;return l.includes((null===(t=e.rtpMap)||void 0===t?void 0:t.encodingName.toLowerCase())||"")}));C=e.concat(s?[]:pt(e,C))}const I=r("UNSUPPORTED_VIDEO_CODEC");if(I&&I.length>0){const t=C.filter((e=>e.rtpMap&&I.includes(e.rtpMap.encodingName.toLowerCase()))),n=pt(t,C),i=t.concat(n).map((e=>e.payloadType));C=C.filter((e=>!i.includes(e.payloadType))),e.debug("unsupportedVideoCodec: ".concat(I,", toBeRemoved: ").concat(i))}if(h&&h.length>0&&"sendonly"===o){const t=C.filter((e=>e.rtpMap&&h.includes(e.rtpMap.encodingName.toLowerCase()))),n=pt(t,C),i=t.concat(n).map((e=>e.payloadType));C=C.filter((e=>!i.includes(e.payloadType))),e.debug("unsupportedVideoUplinkCodec: ".concat(h,", toBeRemoved: ").concat(i))}if(u&&u.length>0&&"recvonly"===o){const t=C.filter((e=>e.rtpMap&&u.includes(e.rtpMap.encodingName.toLowerCase()))),n=pt(t,C),i=t.concat(n).map((e=>e.payloadType));C=C.filter((e=>!i.includes(e.payloadType))),e.debug("unsupportedVideoDownlinkCodec: ".concat(u,", toBeRemoved: ").concat(i))}return{audioCodecs:_,videoCodecs:C,audioExtensions:m,videoExtensions:R}}function Ze(e){const t=a(e);let n,i;for(const e of t.mediaDescriptions){if(!n){const t=e.attributes.iceUfrag,i=e.attributes.icePwd;if(!t||!i)throw new Error("Cannot get iceUfrag or icePwd from SDP.");n={iceUfrag:t,icePwd:i}}if(!i){const t=e.attributes.fingerprints;t.length>0&&(i={fingerprints:t})}}if(!i&&t.attributes.fingerprints.length>0&&(i={fingerprints:t.attributes.fingerprints}),!i||!n)throw new Error("Cannot get iceParameters or dtlsParameters from SDP.");return{iceParameters:n,dtlsParameters:i}}function $e(e,t){const n=[],i=e.attributes.ssrcGroups.filter((e=>"FID"===e.semantic)),o=e.attributes.ssrcGroups.find((e=>"SIM"===e.semantic)),r=e.attributes.ssrcs;if(o)o.ssrcIds.forEach((e=>{var o;const r=null===(o=i.find((t=>t.ssrcIds[0]===e)))||void 0===o?void 0:o.ssrcIds[1];n.push({ssrcId:e,rtx:t?r:void 0})}));else if(i.length>0){const e=i[0].ssrcIds[0],o=i[0].ssrcIds[1];n.push({ssrcId:e,rtx:t?o:void 0})}else{if(0===r.length)throw new Error("No ssrcs found on local media description.");n.push({ssrcId:r[0].ssrcId})}return n}function et(e,t,n){const i=[],o=[];return e.forEach((e=>{let{ssrcId:r,rtx:s}=e;const a=l(8,"track-"),c={ssrcId:r,attributes:me({label:a,mslabel:n=n||l(10,""),msid:"".concat(n," ").concat(a)},t&&{cname:t})};if(i.push(c),void 0!==s){const e={ssrcId:s,attributes:me({label:a,mslabel:n,msid:"".concat(n," ").concat(a)},t&&{cname:t})};i.push(e),o.push({semantic:"FID",ssrcIds:[r,s]})}})),e.length>1&&o.push({semantic:"SIM",ssrcIds:e.map((e=>{let{ssrcId:t}=e;return t}))}),{ssrcs:i,ssrcGroups:o}}function tt(e,t){t instanceof q&&e.attributes.payloads.forEach((e=>{var n;const i=null===(n=e.rtpMap)||void 0===n?void 0:n.encodingName.toLowerCase();if(!i||-1===["opus","pcmu","pcma","g722"].indexOf(i))return;e.fmtp||(e.fmtp={parameters:{}}),"opus"===i&&"number"==typeof r("OPUS_PTIME")?e.fmtp.parameters.ptime=r("OPUS_PTIME"):e.fmtp.parameters.minptime="10",e.fmtp.parameters.useinbandfec="1";const o=t._encoderConfig;o&&("pcmu"!==i&&"pcma"!==i&&"g722"!==i&&(o.bitrate&&!c()&&(e.fmtp.parameters.maxaveragebitrate="".concat(Math.floor(1e3*o.bitrate))),o.sampleRate&&(e.fmtp.parameters.maxplaybackrate="".concat(o.sampleRate),e.fmtp.parameters["sprop-maxcapturerate"]="".concat(o.sampleRate)),o.stereo&&(e.fmtp.parameters.stereo="1",e.fmtp.parameters["sprop-stereo"]="1")),t instanceof z&&"opus"===i&&t._config.DTX&&(e.fmtp.parameters.usedtx="1"))}))}function nt(e,t,n){if(!t)return;let i,o;if("video"===e.media.mediaType?(i=n.videoExtensions,o=n.videoCodecs):(i=n.audioExtensions,o=n.audioCodecs),!0===t.twcc){const t=i.find((e=>qe(e.extensionName)));if(t){const n=t.extensionName;e.attributes.extmaps.find((e=>qe(e.extensionName)))||e.attributes.extmaps.push({entry:t.entry,extensionName:n});const i=function(e,t){return t.filter((t=>!!e.find((e=>e.payloadType===t.payloadType&&!!e.rtcpFeedbacks.find((e=>"transport-cc"===e.type))))))}(o,e.attributes.payloads);i.forEach((e=>{e.rtcpFeedbacks.find((e=>"transport-cc"===e.type))||e.rtcpFeedbacks.push({type:"transport-cc"})}))}}else if(!1===t.twcc){const t=e.attributes.extmaps.findIndex((e=>qe(e.extensionName)));-1!==t&&e.attributes.extmaps.splice(t,1),e.attributes.payloads.forEach((e=>{const t=e.rtcpFeedbacks.findIndex((e=>"transport-cc"===e.type));-1!==t&&e.rtcpFeedbacks.splice(t,1)}))}if(!0===t.remb){const t=i.find((e=>Qe(e.extensionName)));if(t){const n=t.extensionName;e.attributes.extmaps.find((e=>e.extensionName===n))||e.attributes.extmaps.push({entry:t.entry,extensionName:n});const i=function(e,t){return t.filter((t=>!!e.find((e=>e.payloadType===t.payloadType&&!!e.rtcpFeedbacks.find((e=>"goog-remb"===e.type))))))}(o,e.attributes.payloads);i.forEach((e=>{e.rtcpFeedbacks.find((e=>"goog-remb"===e.type))||e.rtcpFeedbacks.push({type:"goog-remb"})}))}}else if(!1===t.remb){const t=e.attributes.extmaps.findIndex((e=>Qe(e.extensionName)));-1!==t&&e.attributes.extmaps.splice(t,1),e.attributes.payloads.forEach((e=>{const t=e.rtcpFeedbacks.findIndex((e=>"goog-remb"===e.type));-1!==t&&e.rtcpFeedbacks.splice(t,1)}))}}function it(e,t,n){if(c())return;if("video"!==e.media.mediaType)return;if(!(t instanceof Z))return;if("vp9"!==n&&"vp8"!==n)return;if("vp8"===n&&!r("SIMULCAST"))return;if("vp9"===n&&r("ENABLE_SVC"))return;if(void 0===t._scalabilityMode||t._scalabilityMode.numSpatialLayers<=1)return;const i="vp8"===n?2:t._scalabilityMode.numSpatialLayers,o=e.attributes.ssrcs[0],s=e.attributes.ssrcGroups.find((e=>"FID"===e.semantic&&e.ssrcIds[0]===o.ssrcId)),a={semantic:"SIM",ssrcIds:[o.ssrcId]};for(let t=1;t<i;t++)e.attributes.ssrcs.push({ssrcId:o.ssrcId+t,attributes:d(o.attributes)}),a.ssrcIds.push(o.ssrcId+t),s&&(e.attributes.ssrcs.push({ssrcId:s.ssrcIds[1]+t,attributes:d(o.attributes)}),e.attributes.ssrcGroups.push({semantic:"FID",ssrcIds:[o.ssrcId+t,s.ssrcIds[1]+t]}));e.attributes.ssrcGroups.unshift(a)}async function ot(){try{const e=new RTCPeerConnection;e.addTransceiver("video",{direction:"sendonly",sendEncodings:[{scalabilityMode:s.L1T3}]});const t=await e.createOffer();if(!t.sdp)return void e.close();const n=a(t.sdp).mediaDescriptions[0];if(!n)return;const i=n.attributes.extmaps.find((e=>"https://aomediacodec.github.io/av1-rtp-spec/#dependency-descriptor-rtp-header-extension"===e.extensionName));return e.close(),i}catch(e){return}}async function rt(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};const i=new RTCPeerConnection;i.addTransceiver("video",{direction:"sendonly"}),i.addTransceiver("audio",{direction:"sendonly"}),i.addTransceiver("video",{direction:"recvonly"}),i.addTransceiver("audio",{direction:"recvonly"});const o=(await i.createOffer()).sdp,{send:s,recv:a,sendrecv:c}=function(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},i=arguments.length>2?arguments[2]:void 0;const o=ze(i,t,n,"sendonly"),s=ze(i,t,n,"recvonly"),a={audioCodecs:[],audioExtensions:[],videoCodecs:[],videoExtensions:[]},c={audioCodecs:[],audioExtensions:[],videoCodecs:[],videoExtensions:[]},d={audioCodecs:[],audioExtensions:[],videoCodecs:[],videoExtensions:[]};if(st(o,s,"videoExtensions",a,c,d),st(o,s,"videoCodecs",a,c,d),st(o,s,"audioExtensions",a,c,d),st(o,s,"audioCodecs",a,c,d),r("RAISE_H264_BASELINE_PRIORITY")){const t=[],n=[];if(d.videoCodecs.forEach(((e,i)=>{var o;if("h264"===(null===(o=e.rtpMap)||void 0===o?void 0:o.encodingName.toLocaleLowerCase())){var s,a;const o=d.videoCodecs[i+1],c=o&&Ct(e,o),p=null===(s=e.fmtp)||void 0===s?void 0:s.parameters["profile-level-id"],l=null===(a=e.fmtp)||void 0===a?void 0:a.parameters["packetization-mode"];!p||p!==r("FIRST_H264_PROFILE_LEVEL_ID")||r("FIRST_PACKETIZATION_MODE")&&l!==r("FIRST_PACKETIZATION_MODE")?c?n.push([e,o]):n.push([e]):c?t.push([e,o]):t.push([e])}})),t.length>0&&n.length>0){e.debug("raising H264 baseline profile priority"),d.videoCodecs.forEach(((e,i)=>{var o;if("h264"===(null===(o=e.rtpMap)||void 0===o?void 0:o.encodingName.toLocaleLowerCase())){const o=Ct(e,d.videoCodecs[i+1]),r=t.shift()||n.shift()||[];r.length>0&&(o?d.videoCodecs.splice(i,2,...r):d.videoCodecs.splice(i,1,...r))}}));const i=c.videoCodecs.filter((e=>{var t,n;return"h264"===(null===(t=e.rtpMap)||void 0===t?void 0:t.encodingName.toLocaleLowerCase())&&(null===(n=e.fmtp)||void 0===n?void 0:n.parameters["profile-level-id"])!==r("FIRST_H264_PROFILE_LEVEL_ID")}));if(i.length>0){const e=pt(i,c.videoCodecs).map((e=>e.payloadType)),t=[...i.map((e=>e.payloadType)),...e];c.videoCodecs=c.videoCodecs.filter((e=>!t.includes(e.payloadType)))}r("FILTER_SEND_H264_BASELINE")&&(a.videoCodecs=a.videoCodecs.filter((e=>{var t,n;return!("h264"===(null===(t=e.rtpMap)||void 0===t?void 0:t.encodingName.toLocaleLowerCase())&&(null===(n=e.fmtp)||void 0===n?void 0:n.parameters["profile-level-id"])!==r("FIRST_H264_PROFILE_LEVEL_ID"))})))}return{send:a,recv:c,sendrecv:d}}return{send:a,recv:c,sendrecv:d}}(t,n,o);try{i.close()}catch(e){}return{send:s,recv:a,sendrecv:c}}function st(e,t,n,i,o,r){if("videoExtensions"===n||"audioExtensions"===n){const s=[];return e[n].forEach((e=>{t[n].some(((t,n)=>{if(e.entry===t.entry&&e.extensionName===t.extensionName)return s.push(n),!0}))?r[n].push(e):i[n].push(e)})),void t[n].forEach(((e,t)=>{-1===s.indexOf(t)&&o[n].push(e)}))}if("videoCodecs"===n||"audioCodecs"===n){const s=[];return e[n].forEach((e=>{t[n].some(((t,n)=>{if(e.payloadType===t.payloadType&&JSON.stringify(e)===JSON.stringify(t))return s.push(n),!0}))?r[n].push(e):i[n].push(e)})),void t[n].forEach(((e,t)=>{-1===s.indexOf(t)&&o[n].push(e)}))}}function at(e){const{send:t,recv:n,sendrecv:i}=e;if(!i){if(!t||!n)throw new Error("cannot merge rtp capabilities because one of send or recv is empty!");return{send:t,recv:n}}let o,r;return t?(o={audioCodecs:[],audioExtensions:[],videoCodecs:[],videoExtensions:[]},o.audioCodecs=[...t.audioCodecs,...i.audioCodecs],o.videoCodecs=[...t.videoCodecs,...i.videoCodecs],o.audioExtensions=[...t.audioExtensions,...i.audioExtensions],o.videoExtensions=[...t.videoExtensions,...i.videoExtensions]):o=d(i),n?(r={audioCodecs:[],audioExtensions:[],videoCodecs:[],videoExtensions:[]},r.audioCodecs=[...n.audioCodecs,...i.audioCodecs],r.videoCodecs=[...n.videoCodecs,...i.videoCodecs],r.audioExtensions=[...n.audioExtensions,...i.audioExtensions],r.videoExtensions=[...n.videoExtensions,...i.videoExtensions]):r=d(i),{send:o,recv:r}}function ct(e){if("audio"!==e.media.mediaType)return;e.attributes.payloads.filter((e=>{var t;return"opus"===(null===(t=e.rtpMap)||void 0===t?void 0:t.encodingName.toLowerCase())})).forEach((e=>{e.fmtp||(e.fmtp={parameters:{}}),e.fmtp.parameters.stereo="1",e.fmtp.parameters["sprop-stereo"]="1"}))}function dt(t,n,i,o){let s=[];if(t===Me.VIDEO){if(r("H264_PROFILE_LEVEL_ID")&&"h264"===o&&(s=n.videoCodecs.filter((e=>(e.rtpMap&&e.rtpMap.encodingName.toLowerCase()||"").includes(o)&&e&&e.fmtp&&e.fmtp.parameters["profile-level-id"]===r("H264_PROFILE_LEVEL_ID")))),!Array.isArray(s)||0===s.length){let t=[];const r=[],a=[],c=[];if(i.videoCodecs.forEach((e=>{const n=e.rtpMap&&e.rtpMap.encodingName.toLowerCase()||"";n.includes(o)?t.push(e):n.includes("vp9")?r.push(e):n.includes("vp8")?a.push(e):n.includes("h264")&&c.push(e)})),0===t.length){let n="";0!==r.length?(t=r,n="vp9"):0!==a.length?(t=a,n="vp8"):0!==c.length&&(t=c,n="h264"),e.warning("codec ".concat(o," not included in rtpCapabilities, fallback to default payloads: ").concat(n))}0!==t.length&&(s=n.videoCodecs.filter((e=>t.some((t=>t.payloadType===e.payloadType)))))}if(0===s.length&&(e.warning("codec ".concat(o," not included in rtpCapabilities, fallback to default payloads: ").concat(n.videoCodecs[0].rtpMap&&n.videoCodecs[0].rtpMap.encodingName)),s=n.videoCodecs),r("USE_PUB_RTX")||r("USE_SUB_RTX")){const e=pt(s,n.videoCodecs);s=[...s,...e]}}else{s=n.audioCodecs.filter((e=>(e.rtpMap&&e.rtpMap.encodingName.toLowerCase()||"").includes(o)));const t=n.audioCodecs.filter((e=>(e.rtpMap&&e.rtpMap.encodingName.toLowerCase()||"").includes("red")));0===s.length&&(e.warning("codec ".concat(o," not included in rtpCapabilities, fallback to opus")),s=n.audioCodecs.filter((e=>(e.rtpMap&&e.rtpMap.encodingName.toLowerCase()||"").includes("opus")))),r("ENABLE_AUDIO_RED")&&0!==t.length&&(s=[...t,...s])}return s}function pt(e,t){const n=e.map((e=>e.payloadType.toString()));return t.filter((e=>e.rtpMap&&"rtx"===e.rtpMap.encodingName&&e.fmtp&&e.fmtp.parameters.apt&&n.includes(e.fmtp&&e.fmtp.parameters.apt)))}async function lt(e,t,n){const i=t.toString(),o=ut(i,"offer","remote","exchangeSDP");await e.setRemoteDescription({type:"offer",sdp:i});const r=await e.createAnswer();if(!r.sdp)throw new Error("cannot get answer sdp");let s=r.sdp;s=ht(s,n||{}),null==o||o(s||""),await e.setLocalDescription({type:"answer",sdp:s})}function ht(e,t,n){if(r("FORBID_MODIFY_LOCAL_OFFER_SDP"))return e;const i=a(e),{useXR:o}=t;return i.mediaDescriptions.forEach((e=>{e.attributes.mid&&(Array.isArray(n)&&!n.includes(e.attributes.mid)||("audio"===e.media.mediaType&&ct(e),"video"===e.media.mediaType&&function(e){if("video"!==e.media.mediaType)return;if(!r("ENABLE_DOWN_SPS_PPS"))return;e.attributes.payloads.filter((e=>{var t;return"h264"===(null===(t=e.rtpMap)||void 0===t?void 0:t.encodingName.toLowerCase())})).forEach((e=>{e.fmtp||(e.fmtp={parameters:{}}),e.fmtp.parameters["sps-pps-idr-in-keyframe"]="1"}))}(e),o&&["audio","video"].includes(e.media.mediaType)&&e.attributes.payloads.forEach((e=>{-1===e.rtcpFeedbacks.findIndex((e=>"rrtr"===e.type))&&e.rtcpFeedbacks.push({type:"rrtr"})}))))})),p(i)}function ut(t,n,i,o){if(r("SDP_LOGGING"))return e.upload("exchanging ".concat(i," ").concat(n," SDP during P2PConnection.").concat(o,"\n"),t),"offer"===n?e=>{ut(e,"answer","local"===i?"remote":"local",o)}:void 0}async function Et(t,n,i){try{var o;if(!$().supportSetRtpSenderParameters)return;if(!function(e){return"vp9"===e||"av1"===e}(t)||!r("ENABLE_SVC"))return;const s={},a={},c=n.getParameters(),d=null===(o=c.encodings)||void 0===o?void 0:o[0];a.scalabilityMode=Ke(i),d&&Object.assign(d,a),Object.assign(c,s),await n.setParameters(c),e.debug("[updateAdaptation] updateRtpSenderEncodings scalabilityMode success: ".concat(JSON.stringify(c.encodings)))}catch(t){e.debug("[updateAdaptation] updateRtpSenderEncodings scalabilityMode failed",t)}}function _t(e){const t=r("COMPATIBLE_SDP_EXTENSION");return!!(Array.isArray(t)&&t.length>0)&&t.some((t=>e.includes(t)))}function Ct(e,t){try{var n;return(null===(n=e.fmtp)||void 0===n?void 0:n.parameters.apt)===t.payloadType.toString()}catch(e){return!1}}const mt=e=>"v=0\no=- 0 0 IN IP4 127.0.0.1\ns=AgoraGateway\nt=0 0\na=group:BUNDLE 0 1 2\na=msid-semantic: WMS\na=ice-lite".concat(e?"\na=extmap-allow-mixed":"","\nm=video 9 UDP/TLS/RTP/SAVPF 0\nc=IN IP4 127.0.0.1\na=rtcp:9 IN IP4 0.0.0.0\na=sendonly\na=rtcp-mux\na=rtcp-rsize\na=mid:0\nm=audio 9 UDP/TLS/RTP/SAVPF 0\nc=IN IP4 127.0.0.1\na=rtcp:9 IN IP4 0.0.0.0\na=sendonly\na=rtcp-mux\na=rtcp-rsize\na=mid:1\nm=application 9 UDP/DTLS/SCTP webrtc-datachannel\nc=IN IP4 127.0.0.1\na=mid:2\n"),Rt="9",St=2e4,ft=4e4;class It{get localCapabilities(){return d(this._localCapabilities)}get rtpCapabilities(){return d(this._rtpCapabilities)}get candidates(){return d(this._candidates)}get iceParameters(){return d(this._iceParameters)}get dtlsParameters(){return d(this._dtlsParameters)}constructor(e){let t=arguments.length>1&&void 0!==arguments[1]&&arguments[1],n=arguments.length>2&&void 0!==arguments[2]&&arguments[2],i=arguments.length>3&&void 0!==arguments[3]&&arguments[3];this.sessionDesc=void 0,this._localCapabilities=void 0,this._rtpCapabilities=void 0,this._candidates=void 0,this._originCandidates=void 0,this._iceParameters=void 0,this._isUseExtmapAllowMixed=void 0,this._isUseLocalCodecs=void 0,this._isUseDataChannel=void 0,this._dtlsParameters=void 0,this.setup=void 0,this.currentMidIndex=void 0,this.cname=void 0,this.useLocalCodecsMids=[],this.preloadSsrcs=[],this.firefoxSsrcMidMap=new Map,this._isUseExtmapAllowMixed=t,this._isUseLocalCodecs=n,this._isUseDataChannel=i,e=d(e);const{iceParameters:o,dtlsParameters:r,candidates:s,rtpCapabilities:a,setup:c,localCapabilities:p,cname:l}=e;this._rtpCapabilities=a,this._candidates=s,this._originCandidates=d(s),this._iceParameters=o,this._dtlsParameters=r,this._localCapabilities=p,this.setup=c,this.cname=l,[this.sessionDesc]=this.updateRemoteRTPCapabilities(a),this.currentMidIndex=this.sessionDesc.mediaDescriptions.length-1}checkPreloadSsrcs(e){return e.length===this.preloadSsrcs.length&&e.every((e=>this.preloadSsrcs.includes(e)))}preloadRemoteMedia(e){let t=0;const n=[],i=[];for(;e>0;){const o=[me({ssrcId:ft+t},r("USE_SUB_RTX")?{rtx:ft+t+1}:{})],s="".concat(ft+t,"_").concat(St+t),{ssrcs:a,ssrcGroups:c}=et(o,this.cname,r("SYNC_GROUP")?s:void 0),d=this.preCreateOrRecycleSendMedia("video",a,c,void 0),p=[{ssrcId:St+t}],l="".concat(ft+t,"_").concat(St+t),{ssrcs:h,ssrcGroups:u}=et(p,this.cname,r("SYNC_GROUP")?l:void 0),E=this.preCreateOrRecycleSendMedia("audio",h,u,void 0);e--,t+=2,n.push(d,E),i.push(a[0].ssrcId,h[0].ssrcId)}return this.useLocalCodecsMids.push(...n),this.preloadSsrcs=i,{mids:n,preSSRCs:i,isAvailable:!0}}preCreateOrRecycleSendMedia(t,n,i,o){const r=this.rtpCapabilities.send.videoCodecs,s=this._isUseLocalCodecs||0===r.length?this.localCapabilities.recv:this.rtpCapabilities.send;e.debug("create or recycle send media without remote rtp capabilities, ssrcs ",n[0].ssrcId);const a=t===Me.VIDEO?s.videoCodecs:s.audioCodecs,c=t===Me.VIDEO?s.videoExtensions:s.audioExtensions;this.currentMidIndex+=1;const d="".concat(this.currentMidIndex);let p={media:{mediaType:t,port:Rt,protos:["UDP","TLS","RTP","SAVPF"],fmts:a.map((e=>e.payloadType.toString(10)))},connections:[{nettype:"IN",addrtype:"IP4",address:"127.0.0.1"}],bandwidths:[],attributes:{iceUfrag:this.iceParameters.iceUfrag,icePwd:this.iceParameters.icePwd,unrecognized:[],candidates:this.candidates,extmaps:c,fingerprints:this.dtlsParameters.fingerprints,imageattr:[],msids:[],remoteCandidatesList:[],rids:[],ssrcs:n,ssrcGroups:i,rtcpFeedbackWildcards:[],payloads:a,rtcp:{port:"9",netType:"IN",addressType:"IP4",address:"0.0.0.0"},setup:this.setup,direction:"sendonly",rtcpMux:!0,rtcpRsize:!0,mid:"".concat(d)}};return p=this.mungSendMediaDesc(p,o),this.sessionDesc.mediaDescriptions.push(p),this.updateBundleMids(),d}toString(){return p(this.sessionDesc)}send(e,t,n,i){const{ssrcs:o,ssrcGroups:s}=et(t,this.cname,r("SYNC_GROUP")?n:void 0),a=this.findPreloadMediaDesc(o);if(a){if(c()&&this.firefoxSsrcMidMap.set(o[0].ssrcId,a.attributes.mid),i&&(i.twcc||i.remb)){const e=this.sessionDesc.mediaDescriptions.indexOf(a);return this.sessionDesc.mediaDescriptions[e]=this.mungSendMediaDesc(a,i),{mid:a.attributes.mid,needExchangeSDP:!0}}return{mid:a.attributes.mid,needExchangeSDP:!1}}{const t=this.findAvailableMediaIndex(e,o);let n;return-1===t||1===t&&(_()||C()||m(143)||R(143)||r("RESERVE_MID_1_MLINE")||r("ENABLE_ENCODED_TRANSFORM")&&S())||0===t&&!f(138)&&r("USE_SUB_RTX")||I()?(n=this.createOrRecycleSendMedia(e,o,s,"sendonly",i),this.updateBundleMids()):(n=d(this.sessionDesc.mediaDescriptions[t]),n.attributes.direction="sendonly",n.attributes.ssrcs=o,n.attributes.ssrcGroups=s,this.sessionDesc.mediaDescriptions[t]=this.mungSendMediaDesc(n,i)),c()&&this.firefoxSsrcMidMap.set(o[0].ssrcId,n.attributes.mid),{mid:n.attributes.mid,needExchangeSDP:!0}}}sendDataChannel(){const{mediaDesc:e,needExchangeSDP:t}=this.createOrRecycleDataChannel();return this.updateBundleMids(),{mid:e.attributes.mid,needExchangeSDP:t}}batchSend(e){const t=e.map((e=>{let{kind:t,ssrcMsg:n,mslabel:i}=e;return this.send(t,n,i)})),n=[];let i=!1;return t.forEach((e=>{let{mid:t,needExchangeSDP:o}=e;o&&(i=!0),n.push(t)})),{mids:n,needExchangeSDP:i}}stopSending(e){const t=this.sessionDesc.mediaDescriptions.filter((t=>t.attributes.mid&&-1!==e.indexOf(t.attributes.mid)));if(t.length!==e.length)throw new Error("mediaDescriptions' length doesn't match mids' length when calling RemoteSDP.stopSending.");t.forEach((e=>{"0"===e.attributes.mid||c()||I()?e.attributes.ssrcs=[]:(e.attributes.ssrcs=[],e.attributes.direction="inactive",e.media.port="0")})),this.updateBundleMids()}mute(e){const t=this.sessionDesc.mediaDescriptions.find((t=>t.attributes.mid===e));if(!t)throw new Error("mediaDescription not found with ".concat(e," in remote SDP when calling RemoteSDP.mute."));t.attributes.direction="inactive"}unmute(e){const t=this.sessionDesc.mediaDescriptions.find((t=>t.attributes.mid===e));if(!t)throw new Error("mediaDescription not found with ".concat(e," in remote SDP when calling RemoteSDP.unmute."));t.attributes.direction="sendonly"}muteRemote(e){const t=this.sessionDesc.mediaDescriptions.filter((t=>e.includes(t.attributes.mid||"")));if(t.length!==e.length)throw new Error("mediaDescriptions' length doesn't match mids' length when calling RemoteSDP.muteRemote.");t.forEach((e=>{e.attributes.direction="inactive"}))}unmuteRemote(e){const t=this.sessionDesc.mediaDescriptions.filter((t=>e.includes(t.attributes.mid||"")));if(t.length!==e.length)throw new Error("mediaDescriptions' length doesn't match mids' length when calling RemoteSDP.muteRemote.");t.forEach((e=>{e.attributes.direction="recvonly"}))}receive(e,t,n,i){e.forEach(((e,o)=>{this.createOrRecycleRecvMedia(e,[],"recvonly",t,n,i[o])})),this.updateBundleMids()}stopReceiving(e){const t=this.sessionDesc.mediaDescriptions.filter((t=>-1!==e.indexOf(t.attributes.mid)));if(t.length!==e.length)throw new Error("MediaDescriptions' length doesn't match mids's length when calling RemoteSDP.receive.");t.forEach((e=>{e.media.port="0",e.attributes.direction="inactive"})),this.updateBundleMids()}updateRemoteRTPCapabilities(e){const t=this.sessionDesc||a((n=this._isUseExtmapAllowMixed,this._isUseDataChannel?mt(n):"v=0\no=- 0 0 IN IP4 127.0.0.1\ns=AgoraGateway\nt=0 0\na=group:BUNDLE 0 1\na=msid-semantic: WMS\na=ice-lite".concat(n?"\na=extmap-allow-mixed":"","\nm=video 9 UDP/TLS/RTP/SAVPF 0\nc=IN IP4 127.0.0.1\na=rtcp:9 IN IP4 0.0.0.0\na=sendonly\na=rtcp-mux\na=rtcp-rsize\na=mid:0\nm=audio 9 UDP/TLS/RTP/SAVPF 0\nc=IN IP4 127.0.0.1\na=rtcp:9 IN IP4 0.0.0.0\na=sendonly\na=rtcp-mux\na=rtcp-rsize\na=mid:1\n")));var n;this._rtpCapabilities=e;let i=!1;const o=this.rtpCapabilities.send,r=this.localCapabilities.send,s=this.localCapabilities.recv,c=s.videoCodecs,d=s.audioCodecs,p=s.videoExtensions,l=s.audioExtensions;for(const e of t.mediaDescriptions)if("sendonly"!==e.attributes.direction||"string"!=typeof e.attributes.mid||!this.useLocalCodecsMids.includes(e.attributes.mid)){if(i=!0,e.attributes.iceUfrag=this._iceParameters.iceUfrag,e.attributes.icePwd=this._iceParameters.icePwd,e.attributes.fingerprints=this._dtlsParameters.fingerprints,e.attributes.candidates=this._candidates,e.attributes.setup=this.setup,"application"===e.media.mediaType&&(e.attributes.sctpPort="5000"),"video"===e.media.mediaType)if(this._isUseLocalCodecs&&"sendonly"===e.attributes.direction){e.media.fmts=c.map((e=>e.payloadType.toString(10))),e.attributes.payloads=c,e.attributes.extmaps=p;const t=e.attributes.mid;"string"!=typeof t||this.useLocalCodecsMids.includes(t)||this.useLocalCodecsMids.push(t)}else if(0===o.videoCodecs.length){const t=r.videoCodecs.filter((e=>{var t;return null===(t=e.rtpMap)||void 0===t?void 0:t.encodingName.toLowerCase().includes("vp8")}));0===t.length&&t.push(r.videoCodecs[0]),e.media.fmts=t.map((e=>e.payloadType.toString(10))),e.attributes.payloads=t,e.attributes.extmaps=[]}else e.media.fmts=o.videoCodecs.map((e=>e.payloadType.toString(10))),e.attributes.payloads=o.videoCodecs,e.attributes.extmaps=o.videoExtensions;if("audio"===e.media.mediaType)if(this._isUseLocalCodecs&&"sendonly"===e.attributes.direction){e.media.fmts=d.map((e=>e.payloadType.toString(10))),e.attributes.payloads=d,e.attributes.extmaps=l;const t=e.attributes.mid;"string"!=typeof t||this.useLocalCodecsMids.includes(t)||this.useLocalCodecsMids.push(t)}else if(0===o.audioCodecs.length){const t=r.audioCodecs.filter((e=>{var t;return null===(t=e.rtpMap)||void 0===t?void 0:t.encodingName.toLowerCase().includes("opus")}))||[r.audioCodecs[0]];e.media.fmts=t.map((e=>e.payloadType.toString(10))),e.attributes.payloads=t,e.attributes.extmaps=[]}else e.media.fmts=o.audioCodecs.map((e=>e.payloadType.toString(10))),e.attributes.payloads=o.audioCodecs,e.attributes.extmaps=o.audioExtensions,ct(e)}return this.sessionDesc=t,this.currentMidIndex=t.mediaDescriptions.length-1,[this.sessionDesc,i]}updateCandidates(e){const t=this._originCandidates.filter((e=>"udp"===e.transport)),n=[];if(t.forEach((e=>{n.push(me(me({},e),{},{foundation:"tcpcandidate",priority:Number(e.priority)-1+"",transport:"tcp",port:Number(e.port)+90+""}))})),0!==t.length){switch(e){case Ue.TCP_RELAY:this._candidates=n;break;case Ue.UDP_TCP_RELAY:case Ue.RELAY:this._candidates=[...t,...n];break;default:this._candidates=t}for(const e of this.sessionDesc.mediaDescriptions)e.attributes.candidates=this.candidates}}restartICE(e){let t=!1;return e=d(e),this._iceParameters=e,this.sessionDesc.mediaDescriptions.forEach((n=>{n.attributes.iceUfrag===e.iceUfrag&&n.attributes.icePwd===e.icePwd||(t=!0),n.attributes.iceUfrag=e.iceUfrag,n.attributes.icePwd=e.icePwd})),t}predictReceivingMids(e){const t=[];for(let n=0;n<e;n++)t.push((this.currentMidIndex+n+1).toString(10));return t}findAvailableMediaIndex(e,t){return this.sessionDesc.mediaDescriptions.findIndex((n=>{const i=n.media.mediaType===e&&"0"!==n.media.port&&("sendonly"===n.attributes.direction||"sendrecv"===n.attributes.direction)&&0===n.attributes.ssrcs.length;if(c()){if(i){const e=this.firefoxSsrcMidMap.get(t[0].ssrcId);return!(e||"0"!==n.attributes.mid&&"1"!==n.attributes.mid)||!(!e||e!==n.attributes.mid)}return!1}return i}))}createOrRecycleDataChannel(){for(const e of this.sessionDesc.mediaDescriptions)if("application"===e.media.mediaType)return{mediaDesc:e,needExchangeSDP:!1};this.currentMidIndex+=1;const e="".concat(this.currentMidIndex),t={media:{mediaType:"application",port:Rt,protos:["UDP","DTLS","SCTP"],fmts:["webrtc-datachannel"]},connections:[{nettype:"IN",addrtype:"IP4",address:"127.0.0.1"}],bandwidths:[],attributes:{iceUfrag:this.iceParameters.iceUfrag,icePwd:this.iceParameters.icePwd,unrecognized:[],candidates:this.candidates,extmaps:[],fingerprints:this.dtlsParameters.fingerprints,imageattr:[],msids:[],remoteCandidatesList:[],rids:[],ssrcs:[],ssrcGroups:[],rtcpFeedbackWildcards:[],payloads:[],rtcp:{port:"9",netType:"IN",addressType:"IP4",address:"0.0.0.0"},setup:this.setup,mid:"".concat(e),sctpPort:"5000"}};return this.sessionDesc.mediaDescriptions.push(t),{mediaDesc:t,needExchangeSDP:!0}}createOrRecycleRecvMedia(e,t,n,i,o,r){const s=e._mediaStreamTrack.kind,a=this.rtpCapabilities.recv,c=dt(s,a,this.localCapabilities.send,s===Me.VIDEO?i:o),d=s===Me.VIDEO?a.videoExtensions:a.audioExtensions;this.currentMidIndex+=1;const p="".concat(this.currentMidIndex);let l={media:{mediaType:s,port:Rt,protos:["UDP","T