trtc-js-sdk
Version:
Tencent Cloud RTC SDK for Web
1 lines • 341 kB
JavaScript
import"webrtc-adapter/out/adapter";function e(e,t,i,s,n){var a={};return Object.keys(s).forEach((function(e){a[e]=s[e]})),a.enumerable=!!a.enumerable,a.configurable=!!a.configurable,("value"in a||a.initializer)&&(a.writable=!0),a=i.slice().reverse().reduce((function(i,s){return s(e,t,i)||i}),a),n&&void 0!==a.initializer&&(a.value=a.initializer?a.initializer.call(n):void 0,a.initializer=void 0),void 0===a.initializer&&(Object.defineProperty(e,t,a),a=null),a}let t=(new Date).getTime(),i=0;const s=function(){return(new Date).getTime()+i},n=function(){const e=new Date;return e.setTime(s()),e.toLocaleString()},a="canvas",o="audio",r="video",d="screen",c="small",l="big",h="auxiliary",u="aux",_="smallVideo",m="user",p="environment",g="mute",S="unmute",f="ended",v="playing",I="pause",y="error",T="loadeddata",b="audioinput",E="videoinput",w="detail",R="text",k="main",A="backup",C="banned",D="kick",N="user_time_out",P="room_disband",M="sei-message",O="PLAYING",L="PAUSED",V="STOPPED",U="inactive",x="sendonly",$="recvonly",F="add",B="remove",H="replace",j="track",W="wss://trtc.rtc.qq.com",J="wss://webrtc.qq.com",G="qcloud",z="trtc",q="webrtc";let K="";const Q="jssdk_log",X="jssdk_event",Y="jssdk_new_endreport",Z=e=>K=e,ee=1,te=2,ie=20,se=21,ne="5Y2wZK8nANNAoVw6dSAHVjNxrD1ObBM2kBPV",ae="224d130c-7b5c-415b-aaa2-79c2eb5a6df2",oe=2,re=k,de=h,ce="DISCONNECTED",le="CONNECTING",he="RECONNECTING",ue="CONNECTED",_e="new",me="connecting",pe="failed",ge="closed",Se="disconnected",fe="connected",ve="completed",Ie="join",ye="delta-join",Te="rejoin",be="leave",Ee="delta-leave",we="publish",Re="delta-publish",ke="unpublish",Ae="subscribe",Ce="unsubscribe",De="uplink-connection",Ne="uplink-reconnection",Pe="downlink-connection",Me="downlink-reconnection",Oe="setLocalDescription",Le="setRemoteDescription",Ve="iceConnectionState",Ue="stream-initialize",xe="websocketConnectionState",$e="websocketReconnectionState",Fe="update-stream",Be="recover-subscription",He="start-mix-transcode",je="stop-mix-transcode",We="player-error",Je="schedule",Ge="unsubscribe",ze="subscribe_change",qe={MANUAL:"manual",PRESET_LAYOUT:"preset-layout"},Ke={REMOTE:"$PLACE_HOLDER_REMOTE$"},Qe={IT_AUDIO_VIDEO:0,IT_PICTURE:2,IT_CANVAS:3,IT_PURE_AUDIO:4,IT_PURE_VIDEO:5},Xe="string",Ye="number",Ze="boolean",et="array",tt="object",it={ADD:F,REMOVE:B},st={unknown:0,wifi:1,"4g":2,"3g":3,"2g":4,wired:5},nt=-1,at=0,ot=1,rt=l,dt=c,ct="schedule.cloud-rtc.com",lt="schedule.rtc.qcloud.com",ht="schedule.rtc.tencentcloud.com",ut="schedule-ecdn.rtc.tencentcloud.com";let _t="";const mt=e=>_t=e,pt="TRTC",gt="Client",St="LocalStream",ft="RemoteStream",vt="Stream",It="web.sdk.qcloud.com",yt="web.sdk.tencent.cn",Tt="web.sdk.cloud.tencent.cn",bt=`https://${It}/trtc/webrtc/doc`,Et=`${bt}/zh-cn/`,wt={TRACE:0,DEBUG:1,INFO:2,WARN:3,ERROR:4,NONE:5},Rt=1,kt=2,At=1,Ct=2,Dt=Object.keys(wt),Nt=["normal leave","timeout leave","kick","role change"],Pt="ric",Mt="Resolution reset to 1080p, need to upgrade ability here https://cloud.tencent.com/document/product/647/85386",Ot={"TRTC.checkSystemRequirements":40001,"TRTC.isScreenShareSupported":40002,"TRTC.isSmallStreamSupported":40003,"TRTC.createClient.rtc":40004,"TRTC.createClient.live":40005,"TRTC.createClient.intRoomId":40006,"TRTC.createClient.stringRoomId":40007,"TRTC.createClient.autoSubscribe":40008,"TRTC.createClient.manualSubscribe":40009,"TRTC.enableUploadLog":40010,"TRTC.disableUploadLog":40011,"Client.publish":40012,"Client.publish.isAuxiliary":40013,"Client.switchRole":40014,"Client.startPublishCDNStream":40015,"Client.stopPublishCDNStream":40016,"Client.startMixTranscode":40017,"Client.stopMixTranscode":40018,"Client.enableAudioVolumeEvaluation":40019,"Client.enableSmallStream":40020,"Client.disableSmallStream":40021,"Client.setSmallStreamProfile":40022,"Client.setRemoteVideoStreamType":40023,"Client.sendSEIMessage":40024,"Client.setProxyServer":40025,"Client.setTurnServer":40026,"LocalStream.setAudioProfile.standard":40027,"LocalStream.setAudioProfile.high":40028,"LocalStream.setAudioProfile.standard-stereo":40029,"LocalStream.setAudioProfile.high-stereo":40030,"LocalStream.setVideoProfile.120p":40031,"LocalStream.setVideoProfile.120p_2":40032,"LocalStream.setVideoProfile.180p":40033,"LocalStream.setVideoProfile.180p_2":40034,"LocalStream.setVideoProfile.240p":40035,"LocalStream.setVideoProfile.240p_2":40036,"LocalStream.setVideoProfile.360p":40037,"LocalStream.setVideoProfile.360p_2":40038,"LocalStream.setVideoProfile.480p":40039,"LocalStream.setVideoProfile.480p_2":40040,"LocalStream.setVideoProfile.720p":40041,"LocalStream.setVideoProfile.1080p":40042,"LocalStream.setVideoProfile.1440p":40043,"LocalStream.setVideoProfile.4K":40044,"LocalStream.setScreenProfile.480p":40045,"LocalStream.setScreenProfile.480p_2":40046,"LocalStream.setScreenProfile.720p":40047,"LocalStream.setScreenProfile.720p_2":40048,"LocalStream.setScreenProfile.1080p":40049,"LocalStream.setScreenProfile.1080p_2":40050,"LocalStream.setVideoContentHint.motion":40051,"LocalStream.setVideoContentHint.detail":40052,"LocalStream.setVideoContentHint.text":40053,"LocalStream.setAudioCaptureVolume":40054,"LocalStream.getVideoFrame":40055,"RemoteStream.setAudioOutput":40056,"RemoteStream.getVideoFrame":40057,AI_DENOISER:1700,SPATIAL_AUDIO:1701,"2K_4K":1704},Lt=["width","height","frameRate","facingMode","sampleRate","sampleSize","channelCount","deviceId"],Vt="AVOID_REPEATED_CALL",Ut="INVALID_PARAMETER_REQUIRED",xt="INVALID_PARAMETER_TYPE",$t="INVALID_PARAMETER_EMPTY",Ft="INVALID_PARAMETER_INSTANCE",Bt="INVALID_PARAMETER_RANGE",Ht="API_CALL_TIMEOUT",jt="SIGNAL_CHANNEL_RECONNECTION_FAILED",Wt="SIGNAL_CHANNEL_SETUP_FAILED",Jt="ERROR_MESSAGE",Gt="EXCHANGE_SDP_TIMEOUT",zt="DOWNLINK_RECONNECTION_FAILED",qt="EXCHANGE_SDP_FAILED",Kt="UPLINK_RECONNECTION_FAILED",Qt="INVALID_PURE_AUDIO",Xt="INVALID_STREAMID",Yt="INVALID_USER_DEFINE_RECORDID",Zt="INVALID_USER_DEFINE_PUSH_ARGS",ei="INVALID_PROXY",ti="INVALID_JOIN",ii="INVALID_ROOMID_STRING",si="INVALID_ROOMID_INTEGER",ni="JOIN_ROOM_TIMEOUT",ai="JOIN_ROOM_FAILED",oi="REJOIN_ROOM_FAILED",ri="INVALID_DESTROY",di="INVALID_PUBLISH",ci="INVALID_UNPUBLISH",li="INVALID_AUDIENCE",hi="INVALID_INITIALIZE",ui="INVALID_DUPLICATE_PUBLISHING",_i="INVALID_REMOTE_STREAM",mi="SUBSCRIBE_FAILED",pi="INVALID_ROLE",gi="INVALID_OPERATION_SWITCH_ROLE",Si="SWITCH_ROLE_TIMEOUT",fi="SWITCH_ROLE_FAILED",vi="CLIENT_BANNED",Ii="INVALID_OPERATION_START_PUBLISH_CDN",yi="INVALID_OPERATION_STOP_PUBLISH_CDN",Ti="INVALID_STREAM_ID",bi="START_PUBLISH_CDN_FAILED",Ei="STOP_PUBLISH_CDN_FAILED",wi="START_MIX_TRANSCODE",Ri="STOP_MIX_TRANSCODE",ki="INVALID_AUDIO_VOLUME",Ai="ENABLE_SMALL_STREAM_PUBLISHED",Ci="DISABLE_SMALL_STREAM_PUBLISHED",Di="NOT_SUPPORTED_SMALL_STREAM",Ni="INVALID_SMALL_STREAM_PROFILE",Pi="INVALID_PARAMETER_REMOTE_STREAM",Mi="INVALID_SWITCH_DEVICE",Oi="INVALID_SWITCH_DEVICE_PUBLISHING",Li="INVALID_REPLACE_TRACK",Vi="INVALID_INITIALIZE_LOCAL_STREAM",Ui="INVALID_ADD_TRACK_REPETITIVE",xi="INVALID_ADD_TRACK_REMOVING",$i="INVALID_ADD_TRACK_PUBLISHING",Fi="INVALID_STREAM_INITIALIZED",Bi="INVALID_ADD_TRACK_NUMBER",Hi="INVALID_REMOVE_AUDIO_TRACK",ji="INVALID_REMOVE_AUDIO_ADDING",Wi="INVALID_REMOVE_AUDIO_ON",Ji="INVALID_REMOVE_TRACK_PUBLISHING",Gi="INVALID_REMOVE_TRACK_NOT_PUBLISHING",zi="INVALID_REMOVE_TRACK_NUMBER",qi="INVALID_REPLACE_TRACK_NO_TRACK",Ki="REPEAT_JOIN",Qi="CLIENT_DESTROYED",Xi="START_MIX_TRANSCODE_FAILED",Yi="STOP_MIX_TRANSCODE_FAILED",Zi="MIX_TRANSCODE_NOT_STARTED",es="CANNOT_LESS_THAN_ZERO",ts="MIX_PARAMS_VIDEO_FRAMERATE",is="MIX_PARAMS_VIDEO_GOP",ss="MIX_PARAMS_AUDIO_BITRATE",ns="MIX_PARAMS_USER_Z_ORDER",as="MIX_PARAMS_NOT_SELF",os="MIX_PARAMS_USER_STREAM",rs="INVALID_ELEMENT_ID",ds="INVALID_ELEMENT_ID_TYPE",cs="PLAY_FAILED",ls="INVALID_CREATE_STREAM_SOURCE",hs="INVALID_CREATE_STREAM_SCREEN",us="INVALID_CREATE_STREAM_AUDIO",_s="INVALID_CREATE_STREAM_SCREEN_AUDIO",ms="NOT_SUPPORTED_HTTP",ps="NOT_SUPPORTED_WEBRTC",gs="NOT_SUPPORTED_PROFILE",Ss="NOT_SUPPORTED_H264ENCODE",fs="NOT_SUPPORTED_H264DECODE",vs="NOT_SUPPORTED_TRACK",Is="NOT_SUPPORTED_SWITCH_DEVICE",ys="NOT_SUPPORTED_CAPTURE",Ts="NOT_SUPPORTED_AUX",bs="MICROPHONE_NOT_FOUND",Es="CAMERA_NOT_FOUND",ws="SIGNAL_RESPONSE_FAILED",Rs="CATCH_HANDLER_ERROR",ks="API_NOT_EXIST",As="CONNECTION_CLOSED",Cs="SUBSCRIBE_ALL_FALSE",Ds="SEI_NOT_SUPPORT",Ns="SEI_DISABLED",Ps="SEI_EMPTY",Ms="SEI_OVERSIZE",Os="SEI_BEFORE_PUBLISH",Ls="SEI_NOT_VIDEO",Vs="CALL_FREQUENCY_LIMIT",Us="CONNECTION_ABORTED",xs="API_CALL_ABORTED",$s="DUPLICATE_AUX",Fs={AVOID_REPEATED_CALL:e=>`previous ${e.name}() is ongoing, please avoid repeated calls.`,INVALID_PARAMETER_REQUIRED:({key:e,rule:t,fnName:i,value:s})=>`'${e||t.name}' is a required param when calling ${i}(), received: ${s}.`,INVALID_PARAMETER_TYPE({key:e,rule:t,fnName:i,value:s}){const n=`${e||t.name}`;let a="";return a=Array.isArray(t.type)?t.type.join("|"):t.type,`'${n}' must be type of ${a} when calling ${i}(), received type: ${Sa(s)}.`},INVALID_PARAMETER_EMPTY:({key:e,rule:t,fnName:i,value:s})=>`'${e||t.name}' cannot be '${s}' when calling ${i}().`,INVALID_PARAMETER_INSTANCE:({key:e,rule:t,fnName:i,value:s})=>`'${`${e||t.name}`}' must be instanceof ${`${t.instanceOf.name||t.instanceOf}`} when calling ${i}(), received type: ${Sa(s)}.`,INVALID_PARAMETER_RANGE:({key:e,rule:t,fnName:i,value:s})=>`'${e||t.name}' must be one of ${t.values.join("|")} when calling ${i}(), received: ${s}.`,API_CALL_TIMEOUT:e=>`${e.commandDesc||e.command} timeout observed.`,SIGNAL_CHANNEL_RECONNECTION_FAILED:"signal channel reconnection failed, please check your network.",SIGNAL_CHANNEL_SETUP_FAILED:e=>`SignalChannel setup failure: (errorCode: ${e.errorCode}, errorMsg: ${e.errorMsg} }).`,ERROR_MESSAGE(e){let t=`${e.type} failed`;return e.message&&(t=`${t}: ${e.message}.`),t},EXCHANGE_SDP_TIMEOUT:"exchange sdp timeout.",DOWNLINK_RECONNECTION_FAILED:"downlink reconnection failed, please check your network and re-join room.",EXCHANGE_SDP_FAILED:e=>`exchange sdp failed ${e.errMsg}.`,UPDATE_OFFER_TIMEOUT:"update offer timeout observed.",UPLINK_RECONNECTION_FAILED:"uplink reconnection failed, please check your network and publish again.",INVALID_RECORDID:"recordId must be an integer number.",INVALID_PURE_AUDIO:"pureAudioPushMode must be 1 or 2.",INVALID_STREAMID:"streamId must be a sting literal within 64 bytes, and not be empty.",INVALID_USER_DEFINE_RECORDID:"userDefineRecordId must be a sting literal contains (a-zA-Z),(0-9), underline and hyphen, within 64 bytes, and not be empty.",INVALID_USER_DEFINE_PUSH_ARGS:"userDefinePushArgs must be a sting literal within 256 bytes, and not be empty.",INVALID_PROXY:'proxy server url must start with "wss://".',INVALID_JOIN:"duplicate join() called.",INVALID_ROOMID_STRING:e=>`'${e}' must be validate string when useStringRoomId is true.`,INVALID_ROOMID_INTEGER:e=>`'${e}' must be an integer between [1, 4294967294] when useStringRoomId is false.`,INVALID_SIGNAL_CHANNEL:"SignalChannel is not ready yet.",JOIN_ROOM_TIMEOUT:"join room timeout.",JOIN_ROOM_FAILED:({error:e,code:t})=>`Failed to join room - ${e} code: ${t}`,REJOIN_ROOM_FAILED:e=>`reJoin room: ${e.roomId} failed, please check your network.`,INVALID_DESTROY:"please call leave() before destroy().",INVALID_PUBLISH:"please call join() before publish().",INVALID_UNPUBLISH:"stream has not been published yet.",INVALID_AUDIENCE:'no permission to publish() under live/audience, please call switchRole("anchor") firstly before publish().',INVALID_INITIALIZE:"cannot publish stream because stream is not initialized, is switching device, or has been closed.",INVALID_DUPLICATE_PUBLISHING:e=>`duplicate ${e} stream publishing, please unpublish your prev ${e} stream and then re-publish.`,INVALID_SUBSCRIBE_UNDEFINED:"stream is undefined or null.",INVALID_SUBSCRIBE_LOCAL:"stream cannot be LocalStream.",INVALID_REMOTE_STREAM:"remoteStream does not exist because it has been unpublished by remote peer.",SUBSCRIBE_FAILED:({message:e,stream:t})=>`failed to subscribe ${t.getUserId()} ${t.getType()} stream, reason: ${e}.`,INVALID_ROLE:"switchRole can only be called in live mode.",INVALID_PARAMETER_SWITCH_ROLE:"role could only be set to a value as anchor or audience.",INVALID_OPERATION_SWITCH_ROLE:"please call join() before switchRole().",SWITCH_ROLE_TIMEOUT:"switchRole timeout.",SWITCH_ROLE_FAILED:e=>`switchRole failed, errCode: ${e.code} errMsg: ${e.message}.`,CLIENT_BANNED:e=>"client was banned because of "+e.message+".",INVALID_OPERATION_START_PUBLISH_CDN:"please call startPublishCDNStream() before client join the room or after client join the room and successfully publish the local stream.",INVALID_OPERATION_STOP_PUBLISH_CDN:"please call startPublishCDNStream() before stopPublishCDNStream().",START_PUBLISH_CDN_FAILED:e=>`startPublishCDNStream failed, errMsg: ${e.message}.`,STOP_PUBLISH_CDN_FAILED:e=>`stopPublishCDNStream failed, errMsg: ${e.message}.`,INVALID_STREAM_ID:e=>`'${e}' can only consist of uppercase and lowercase english letters (a-zA-Z), numbers (0-9), hyphens and underscores.`,START_MIX_TRANSCODE:"please call startMixTranscode() after join().",STOP_MIX_TRANSCODE:"please call stopMixTranscode() after startMixTranscode().",INVALID_AUDIO_VOLUME:"interval must be a number.",ENABLE_SMALL_STREAM_PUBLISHED:"Cannot enable small stream after localStream published.",DISABLE_SMALL_STREAM_PUBLISHED:"Cannot disable small stream after localStream published.",NOT_SUPPORTED_SMALL_STREAM:"your browser does not support opening small stream.",INVALID_SMALL_STREAM_PROFILE:"small stream profile is invalid.",INVALID_PARAMETER_REMOTE_STREAM:"remoteStream is invalid.",INVALID_OPERATION_CHANGE_SMALL:"cannot switch to the small stream without subscribing to the video of remoteStream.",REMOTE_NOT_PUBLISH_SMALL_STREAM:"remote peer does not publish small stream.",INVALID_SWITCH_DEVICE:"cannot switch device on current stream.",INVALID_SWITCH_DEVICE_PUBLISHING:"cannot switch device when publishing localStream.",INVALID_REPLACE_TRACK:"cannot replace track when publishing localStream.",INVALID_INITIALIZE_LOCAL_STREAM:"local stream has not initialized yet.",INVALID_ADD_TRACK_REPETITIVE:"previous addTrack is ongoing, please avoid repetitive execution.",INVALID_ADD_TRACK_REMOVING:"cannot add track when a track is removing.",INVALID_ADD_TRACK_PUBLISHING:"cannot add track when publishing localStream.",INVALID_STREAM_INITIALIZED:"your local stream haven't been initialized yet.",INVALID_ADD_TRACK_NUMBER:"a Stream has at most one audio track and one video track.",INVALID_REMOVE_AUDIO_TRACK:"remove audio track is not supported on your browser.",INVALID_REMOVE_AUDIO_ADDING:"cannot remove track when a track is adding.",INVALID_REMOVE_AUDIO_ON:"previous removeTrack is ongoing, please avoid repetitive execution.",INVALID_REMOVE_TRACK_PUBLISHING:"cannot remove track when publishing localStream.",INVALID_REMOVE_TRACK_NOT_PUBLISHING:"the track to be removed is not being publishing.",INVALID_REMOVE_TRACK_NUMBER:"remove the only video track is not supported, please use replaceTrack or muteVideo.",INVALID_REPLACE_TRACK_NO_TRACK:e=>`cannot replace ${e.kind} track because stream has not ${e.kind} track`,START_MIX_TRANSCODE_FAILED:e=>`startMixTranscode failed, errMsg: ${e.message}.`,STOP_MIX_TRANSCODE_FAILED:e=>`stopMixTranscode failed, errMsg: ${e.message}.`,MIX_TRANSCODE_NOT_STARTED:"mixTranscode has not been started.",CANNOT_LESS_THAN_ZERO:({key:e,rule:t,fnName:i,value:s})=>`'${e||t.name}' cannot be less than 0 when calling ${i}().`,MIX_PARAMS_VIDEO_FRAMERATE:"'config.videoFramerate' should be an integer between 0 and 30, excluding 0.",MIX_PARAMS_VIDEO_GOP:"'config.videoGOP' should be an integer between 1 and 8.",MIX_PARAMS_AUDIO_BITRATE:"'config.audioBitrate' should be an integer between 32 and 192.",MIX_PARAMS_USER_Z_ORDER:e=>`'${e}' is required and must be between 1 and 15.`,MIX_PARAMS_NOT_SELF:"'config.mixUsers' must contain self.",MIX_PARAMS_USER_STREAM:"'config.videoWidth' and 'config.videoHeight' of output stream should be contain all mix stream.",INVALID_PLAY:"duplicate play() call observed, please stop() firstly.",INVALID_ELEMENT_ID:({key:e,fnName:t})=>`'${e}' is not found in the document object when calling ${t}().`,INVALID_ELEMENT_ID_TYPE:({key:e,fnName:t,type:i})=>`the element corresponding to '${e}' must be instanceof HTMLDivElement when calling ${t}(), received: ${i}.`,PLAY_FAILED:e=>`${e.media} play failed,browser exception: ${e.error.toString()}`,INVALID_USERID:"userId cannot be all spaces.",INVALID_CREATE_STREAM_SOURCE:"LocalStream must be created by createStream() with either audio/video or audioSource/videoSource, but can not be mixed with audio/video and audioSource/videoSource.",INVALID_CREATE_STREAM_SCREEN:"screen/video cannot be both true.",INVALID_CREATE_STREAM_AUDIO:"audio/screenAudio cannot be both true.",INVALID_CREATE_STREAM_SCREEN_AUDIO:"when screen is true, screenAudio can be configured.",NOT_SUPPORTED_HTTP:"http protocol does not support the ability to capture and publish streams, please use the https protocol.",NOT_SUPPORTED_WEBRTC:"your browser or environment does not support full WebRTC capabilities.",NOT_SUPPORTED_PROFILE:"your browser does not support setVideoProfile.",NOT_SUPPORTED_MEDIA:"your browser or environment does not support navigator.mediaDevices.",NOT_SUPPORTED_H264ENCODE:"your device does not support H.264 encoding.",NOT_SUPPORTED_H264DECODE:"your device does not support H.264 decoding.",NOT_SUPPORTED_TRACK:e=>`${e}Track is not supported on your browser.`,NOT_SUPPORTED_SWITCH_DEVICE:"switchDevice is not supported on your browser.",NOT_SUPPORTED_CAPTURE:"Your browser or environment does not support screen sharing, please check whether the browser version.",MICROPHONE_NOT_FOUND:"no microphone detected, please check your microphone and the configuration on TRTC.createStream.",CAMERA_NOT_FOUND:"no camera detected, please check your camera and the configuration on TRTC.createStream.",SIGNAL_RESPONSE_FAILED:e=>`${e.signalResponse} failed, response code is ${e.code} , errMsg: ${e.message}.`,CATCH_HANDLER_ERROR:({name:e,event:t})=>`an error was caught on ${e}.on('${t}', handler), please check your code on 'handler'.`,API_NOT_EXIST:({name:e})=>`experimental api ${e} does not exist.`,REPEAT_JOIN:e=>`[${e}] is calling client.join api or has already joined room, please avoid repeated join.`,CONNECTION_CLOSED:"remoteStream has been unsubscribed or unpublished by remote user.",SUBSCRIBE_ALL_FALSE:"cannot subscribe when both audio & video are false, use client.unsubscribe() instead",CLIENT_DESTROYED:({funName:e})=>`failed to call ${e}() because client was destroyed.`,SEI_NOT_SUPPORT:e=>"not support to sendSEIMessage"+(!1===e?" without using h264 codec":""),SEI_DISABLED:"SEI is disabled, to enable SEI: TRTC.createClient({ enableSEI: true })",SEI_EMPTY:"buffer cannot be empty",SEI_OVERSIZE:e=>`buffer size(${e}) is over 1000 Bytes`,SEI_BEFORE_PUBLISH:"please call sendSEIMessage() after publish() success",SEI_NOT_VIDEO:"cannot send sei when localStream has not video.",CALL_FREQUENCY_LIMIT:({isSize:e,name:t,timesInSecond:i,maxSizeInSecond:s})=>`api ${t} call ${e?"size":"times"} is over ${e?s+" bytes":i} in a second.`,CONNECTION_ABORTED:e=>"connection aborted due to: "+e,API_CALL_ABORTED(e){let t;return t=e.message.includes("REMOTE_STREAM_NOT_EXIST")?`Subscribe ${e.stream.getUserId()} ${e.stream.getType()} stream aborted, reason: remote user ${e.stream.getUserId()} unpublished stream.`:`API aborted, reason: ${e.message}`,t},DUPLICATE_AUX:"only one auxiliary stream can be published in a room.",NOT_SUPPORTED_AUX:"publish auxiliary stream is not supported on your browser."},Bs=window.navigator&&window.navigator.userAgent||"",Hs=/AppleWebKit\/([\d.]+)/i.exec(Bs);Hs&&parseFloat(Hs.pop());const js=/iPad/i.test(Bs),Ws=navigator.maxTouchPoints&&navigator.maxTouchPoints>2&&/Macintosh/.test(Bs),Js=/iPhone/i.test(Bs)&&!js,Gs=/iPod/i.test(Bs),zs=Js||js||Gs||Ws,qs=/Android/i.test(Bs);qs&&function(){const e=Bs.match(/Android (\d+)(?:\.(\d+))?(?:\.(\d+))*/i);if(!e)return null;const t=e[1]&&parseFloat(e[1]),i=e[2]&&parseFloat(e[2]);t&&i&&parseFloat(e[1]+"."+e[2])}();qs&&/webkit/i.test(Bs);const Ks=/Firefox/i.test(Bs),Qs=Ks&&function(){const e=Bs.match(/Firefox\/(\d+)/);return e&&e[1]?parseFloat(e[1]):null}(),Xs=/Edge\//i.test(Bs),Ys=Xs&&function(){var e=Bs.match(/Edge\/(\d+)/i);if(e&&e[1])return e[1]}(),Zs=/Edg\//i.test(Bs),en=Zs&&function(){const e=Bs.match(/Edg\/(\d+)/);return e&&e[1]?parseFloat(e[1]):null}(),tn=/SogouMobileBrowser\//i.test(Bs),sn=tn&&function(){const e=Bs.match(/SogouMobileBrowser\/(\d+)/);return e&&e[1]?parseFloat(e[1]):null}(),nn=/MetaSr\s/i.test(Bs),an=nn&&function(){const e=Bs.match(/MetaSr(\s\d+(\.\d+)+)/);return e&&e[1]?parseFloat(e[1]):null}(),on=/TBS\/\d+/i.test(Bs),rn=on&&function(){var e=Bs.match(/TBS\/(\d+)/i);if(e&&e[1])return e[1]}(),dn=/XWEB\/\d+/i.test(Bs),cn=dn&&function(){var e=Bs.match(/XWEB\/(\d+)/i);if(e&&e[1])return e[1]}();/MSIE\s8\.0/.test(Bs);/MSIE\/\d+/i.test(Bs)&&function(){const e=/MSIE\s(\d+)\.\d/.exec(Bs);let t=e&&parseFloat(e[1]);!t&&/Trident\/7.0/i.test(Bs)&&/rv:11.0/.test(Bs)&&(t=11)}();const ln=/(micromessenger|webbrowser)/i.test(Bs),hn=ln&&function(){var e=Bs.match(/MicroMessenger\/(\d+)/i);if(e&&e[1])return e[1]}(),un=!on&&/MQQBrowser\/\d+/i.test(Bs)&&/COVC\/\d+/i.test(Bs),_n=!on&&/MQQBrowser\/\d+/i.test(Bs)&&!/COVC\/\d+/i.test(Bs),mn=(_n||un)&&function(){const e=Bs.match(/ MQQBrowser\/([\d.]+)/);return e&&e[1]?e[1]:null}(),pn=!on&&/ QQBrowser\/\d+/i.test(Bs),gn=pn&&function(){const e=Bs.match(/ QQBrowser\/([\d.]+)/);return e&&e[1]?e[1]:null}(),Sn=!on&&/QQBrowserLite\/\d+/i.test(Bs),fn=Sn&&function(){const e=Bs.match(/QQBrowserLite\/([\d.]+)/);return e&&e[1]?e[1]:null}(),vn=!on&&/MQBHD\/\d+/i.test(Bs),In=vn&&function(){const e=Bs.match(/MQBHD\/([\d.]+)/);return e&&e[1]?e[1]:null}(),yn=/Windows/i.test(Bs),Tn=!zs&&/MAC OS X/i.test(Bs),bn=!qs&&/Linux/i.test(Bs);/MicroMessenger/i.test(Bs);const En=/UCBrowser/i.test(Bs);/Electron/i.test(Bs);const wn=/MiuiBrowser/i.test(Bs),Rn=wn&&function(){const e=Bs.match(/MiuiBrowser\/([\d.]+)/);return e&&e[1]?e[1]:null}(),kn=/HuaweiBrowser/i.test(Bs),An=/Huawei/i.test(Bs),Cn=kn&&function(){const e=Bs.match(/HuaweiBrowser\/([\d.]+)/);return e&&e[1]?e[1]:null}(),Dn=/SamsungBrowser/i.test(Bs),Nn=Dn&&function(){const e=Bs.match(/SamsungBrowser\/([\d.]+)/);return e&&e[1]?e[1]:null}(),Pn=/HeyTapBrowser/i.test(Bs),Mn=Pn&&function(){const e=Bs.match(/HeyTapBrowser\/([\d.]+)/);return e&&e[1]?e[1]:null}(),On=/VivoBrowser/i.test(Bs),Ln=On&&function(){const e=Bs.match(/VivoBrowser\/([\d.]+)/);return e&&e[1]?e[1]:null}(),Vn=()=>{const e=Bs.match(/Chrome\/(\d+)/);return e&&e[1]?Number(e[1]):null},Un=/Chrome/i.test(Bs),xn=!Xs&&!nn&&!tn&&!on&&!dn&&!Zs&&!pn&&!wn&&!kn&&!Dn&&!Pn&&!On&&/Chrome/i.test(Bs),$n=xn&&Vn(),Fn=xn&&function(){const e=Bs.match(/Chrome\/([\d.]+)/);return e&&e[1]?e[1]:null}(),Bn=!Un&&!_n&&!un&&!Sn&&!vn&&/Safari/i.test(Bs),Hn=function(){if(Bn){const e=Bs.match(/Version\/([\d.]+)/);if(e&&e[1])return e[1]}return""}(),jn=/Android.*(wv|.0.0.0)/.test(Bs),Wn=(()=>{if(Ws)return Hn;if(zs){const e=Bs.match(/OS (\d+)_(\d+)/i);if(e&&e[1]){let t=e[1];return e[2]&&(t+=`.${e[2]}`),t}}return""})(),Jn=Number(Wn.split(".")[0]),Gn="15.1"===Hn,zn="15.1"===Wn,qn=(()=>{const e=Number(Wn.split(".")[0]);return 14===e||13===e})(),Kn="file:"===location.protocol||"localhost"===location.hostname||"127.0.0.1"===location.hostname,Qn=(()=>{let e;return()=>{if(la(e))try{e=window.localStorage}catch(t){Lo.warn(t),e=!1}return e}})(),Xn=new Map([[Ks,["Firefox",Qs]],[Zs,["Edg",en]],[xn,["Chrome",Fn]],[Bn,["Safari",Hn]],[on,["TBS",rn]],[dn,["XWEB",cn]],[ln&&Js,["WeChat",hn]],[pn,["QQ(Win)",gn]],[_n,["QQ(Mobile)",mn]],[un,["QQ(Mobile X5)",mn]],[Sn,["QQ(Mac)",fn]],[vn,["QQ(iPad)",In]],[wn,["MI",Rn]],[kn,["HW",Cn]],[Dn,["Samsung",Nn]],[Pn,["OPPO",Mn]],[On,["VIVO",Ln]],[Xs,["EDGE",Ys]],[tn,["SogouMobile",sn]],[nn,["Sogou",an]]]);function Yn(){let e="unknown",t="unknown";return Xn.get(!0)&&(e=Xn.get(!0)[0],t=Xn.get(!0)[1]),{name:e,version:t}}const Zn=(e,t)=>t?bt+"/"+e+"/"+t:bt+"/"+e+"/index.html",ea=()=>{if(!Qn())return!1;const e=localStorage.getItem("trtc_error_assistance");e&&!(e=>{const t=e.saveTime&&(new Date).getTime()-e.saveTime>=6048e5,i=!e.saveVersion||"4.15.22"!==e.saveVersion;return t||i})(JSON.parse(e))||(Lo.info("init debug info"),(()=>{const e=new XMLHttpRequest;if(e.open("GET","https://web.sdk.qcloud.com/trtc/webrtc/download/error-message/0.0.3/script.js",!1),e.send(null),4===e.readyState&&200===e.status){const t=document.createElement("script");t.type="text/javascript",t.text=e.responseText,document.body.appendChild(t),localStorage.setItem("trtc_error_assistance",JSON.stringify({message:e.responseText,saveTime:(new Date).getTime(),saveVersion:"4.15.22"})),document.body.removeChild(t)}})())};function ta(e){const{key:t,data:i,link:s,addDocLink:n=!0}=e;let a="",o="",r="";ca(Fs[t])?a=Fs[t](i):ha(Fs[t])&&(a=Fs[t]);const{TRTC_ERROR_INFO:d,TRTC_ERROR_LINK:c}=(()=>{if(window.TRTC_ERROR_INFO&&window.TRTC_ERROR_LINK)return{TRTC_ERROR_INFO:window.TRTC_ERROR_INFO,TRTC_ERROR_LINK:window.TRTC_ERROR_LINK};{let e=localStorage.getItem("trtc_error_assistance");if(e){e=JSON.parse(e);const t=document.createElement("script");t.type="text/javascript",t.text=e.message,document.body.appendChild(t);const i=window.TRTC_ERROR_INFO,s=window.TRTC_ERROR_LINK;return document.body.removeChild(t),{TRTC_ERROR_INFO:i,TRTC_ERROR_LINK:s}}}return{}})();s?r=`${s.className}.html#${s.fnName}`:c&&c[t]&&(ca(c[t])?r=c[t](i):ha(c[t])&&(r=c[t]));let l=a;return ya()&&(d&&d[t]&&(ca(d[t])?o=d[t](i):ha(d[t])&&(o=d[t])),o&&(l=n?o+"\n请查看文档: "+Zn("zh-cn",r)+"\n\n":o+"\n\n",l+=a)),n&&(l+=" \nRefer to: "+Zn("en",r)+"\n"),l}const ia=function(){return function(e){const t=window.location.search.match(new RegExp("(\\?|&)"+e+"=([^&]*)(&|$)"));return t?decodeURIComponent(t[2]):""}("trtc_env")},sa=e=>(e=Number(e))>0&&e<14e8,na=function(e,t){let i;i=K?K.includes("http")?K:"https://"+K:sa(e)?"https://apisgp.my-imcloud.com":"https://yun.tim.qq.com";return`${i}/v5/AVQualityReportSvc/C2S?random=${Math.floor(Math.random()*2**31)}&sdkappid=${e}&cmdtype=${t}`};function aa(){const e=navigator.userAgent,t=navigator.connection;let i=e.match(/NetType\/\w+/)?e.match(/NetType\/\w+/)[0]:"";i=i.toLowerCase().replace("nettype/",""),"3gnet"===i&&(i="3g");const s=t&&t.type&&t.type.toLowerCase();let n=t&&t.effectiveType&&t.effectiveType.toLowerCase();"slow-2"===n&&(n="2g");let a=i||"unknown";if(s)switch(s){case"cellular":case"wimax":a=n||"unknown";break;case"wifi":a="wifi";break;case"ethernet":a="wired";break;case"none":case"other":case"unknown":a="unknown"}return a}const oa=function(e){if(!e||"object"!=typeof e||"[object Object]"!=Object.prototype.toString.call(e))return!1;var t=Object.getPrototypeOf(e);if(null===t)return!0;var i=Object.prototype.hasOwnProperty.call(t,"constructor")&&t.constructor;return"function"==typeof i&&i instanceof i&&Function.prototype.toString.call(i)===Function.prototype.toString.call(Object)};function ra(e,t=1,i=1){return e<=1?i:ra(e-1,i,t+i)}function da(e){const t=Math.round(e/2)+1;return t>6?13e3:1e3*ra(t)}const ca=e=>"function"==typeof e,la=e=>void 0===e,ha=e=>"string"==typeof e,ua=e=>"number"==typeof e,_a=e=>"boolean"==typeof e,ma=e=>"object"===Sa(e),pa=e=>"array"===Sa(e),ga=e=>Sa(e)==="MediaStreamTrack".toLowerCase();function Sa(e){return Reflect.apply(Object.prototype.toString,e,[]).replace(/^\[object\s(\w+)\]$/,"$1").toLowerCase()}function fa(e){const t={};return t.urls=`turn:${e.url}`,la(e.username)||la(e.credential)||(t.username=e.username,t.credential=e.credential,t.credentialType="password",la(e.credentialType)||(t.credentialType=e.credentialType)),t}function va(){return performance&&performance.now?Math.floor(performance.now()):Date.now()}function Ia(e,t="big"){if(!ha(e))return 0;const i=e.split(".");return"big"===t?(Number(i[0])<<24|Number(i[1])<<16|Number(i[2])<<8|Number(i[3]))>>>0:(Number(i[3])<<24|Number(i[2])<<16|Number(i[1])<<8|Number(i[0]))>>>0}const ya=()=>{let e=navigator.language||navigator.userLanguage;return e=e.substr(0,2),"zh"===e},Ta=(()=>{let e=!1,t=document.visibilityState;return()=>{document.visibilityState!==t&&Lo.info(`visibility change: ${document.visibilityState}`),e||(document.addEventListener("visibilitychange",(()=>{Lo.info("visibility change: "+document.visibilityState),t=document.visibilityState})),e=!0)}})();window.AudioContext=window.AudioContext||window.webkitAudioContext||window.mozAudioContext;const ba=()=>new window.AudioContext,Ea=(()=>{let e;return()=>{if(e)return e;e=new window.AudioContext;return e.onstatechange=()=>{Lo.info(`gain context state: ${e.state}`),"suspended"===e.state?(e.resume(),document.addEventListener("click",e.resume)):"interrupted"===e.state?e.resume():document.removeEventListener("click",e.resume)},e}})(),wa=!!window.AudioWorkletNode,Ra=(e,t)=>{const i=e.emit;return e.emit=(...s)=>{try{i.apply(e,s)}catch(n){const e=ta({key:Rs,data:{name:t,event:s[0]},addDocLink:!1});Lo.warn(e+"\n\n"+n.stack)}},e},ka=e=>+e<10?`0${e}`:e,Aa=e=>{const t=e.match(/^\d+\.\d+\.\d+/)[0];if(!t)return e;const i=t.split("."),s=ka(i[1])+ka(i[2]);i[1]-15>0&&(i[1]="15"),i[2]-15>0&&(i[2]="15");return i.join(".")+"."+s};function Ca(e,t){try{if(pa(e))return`[${e.map((e=>Ca(e,t))).join(",")}]`;if(!oa(e)||!pa(t))return JSON.stringify(e);const i={},s=new Set(t);return Object.keys(e).forEach((t=>{s.has(t)&&(i[t]=e[t])})),JSON.stringify(i)}catch(i){return"{}"}}function Da(e){const{url:t,body:i,method:s,timeout:n}=e;let a=new XMLHttpRequest;return new Promise(((e,o)=>{a.onload=t=>{if(a.status>=200&&a.status<300&&a.responseText.length>0)try{let t=JSON.parse(a.response);e({data:t})}catch(i){e({data:a.response})}else a.status>0&&o({code:a.status,message:`request failed, readyState:${a.readyState} status:${a.status} loaded size:${t.loaded}`})};const r=e=>{o({code:a.readyState,message:`request ${e.type}, readyState:${a.readyState} status:${a.status} loaded size:${e.loaded}`})};a.onerror=r,a.onabort=r,a.ontimeout=r,a.timeout=n||5e3,a.open(s||"POST",t,!0),a.send(i)}))}var Na="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{},Pa={exports:{}};!function(e){var t=Object.prototype.hasOwnProperty,i="~";function s(){}function n(e,t,i){this.fn=e,this.context=t,this.once=i||!1}function a(e,t,s,a,o){if("function"!=typeof s)throw new TypeError("The listener must be a function");var r=new n(s,a||e,o),d=i?i+t:t;return e._events[d]?e._events[d].fn?e._events[d]=[e._events[d],r]:e._events[d].push(r):(e._events[d]=r,e._eventsCount++),e}function o(e,t){0==--e._eventsCount?e._events=new s:delete e._events[t]}function r(){this._events=new s,this._eventsCount=0}Object.create&&(s.prototype=Object.create(null),(new s).__proto__||(i=!1)),r.prototype.eventNames=function(){var e,s,n=[];if(0===this._eventsCount)return n;for(s in e=this._events)t.call(e,s)&&n.push(i?s.slice(1):s);return Object.getOwnPropertySymbols?n.concat(Object.getOwnPropertySymbols(e)):n},r.prototype.listeners=function(e){var t=i?i+e:e,s=this._events[t];if(!s)return[];if(s.fn)return[s.fn];for(var n=0,a=s.length,o=new Array(a);n<a;n++)o[n]=s[n].fn;return o},r.prototype.listenerCount=function(e){var t=i?i+e:e,s=this._events[t];return s?s.fn?1:s.length:0},r.prototype.emit=function(e,t,s,n,a,o){var r=i?i+e:e;if(!this._events[r])return!1;var d,c,l=this._events[r],h=arguments.length;if(l.fn){switch(l.once&&this.removeListener(e,l.fn,void 0,!0),h){case 1:return l.fn.call(l.context),!0;case 2:return l.fn.call(l.context,t),!0;case 3:return l.fn.call(l.context,t,s),!0;case 4:return l.fn.call(l.context,t,s,n),!0;case 5:return l.fn.call(l.context,t,s,n,a),!0;case 6:return l.fn.call(l.context,t,s,n,a,o),!0}for(c=1,d=new Array(h-1);c<h;c++)d[c-1]=arguments[c];l.fn.apply(l.context,d)}else{var u,_=l.length;for(c=0;c<_;c++)switch(l[c].once&&this.removeListener(e,l[c].fn,void 0,!0),h){case 1:l[c].fn.call(l[c].context);break;case 2:l[c].fn.call(l[c].context,t);break;case 3:l[c].fn.call(l[c].context,t,s);break;case 4:l[c].fn.call(l[c].context,t,s,n);break;default:if(!d)for(u=1,d=new Array(h-1);u<h;u++)d[u-1]=arguments[u];l[c].fn.apply(l[c].context,d)}}return!0},r.prototype.on=function(e,t,i){return a(this,e,t,i,!1)},r.prototype.once=function(e,t,i){return a(this,e,t,i,!0)},r.prototype.removeListener=function(e,t,s,n){var a=i?i+e:e;if(!this._events[a])return this;if(!t)return o(this,a),this;var r=this._events[a];if(r.fn)r.fn!==t||n&&!r.once||s&&r.context!==s||o(this,a);else{for(var d=0,c=[],l=r.length;d<l;d++)(r[d].fn!==t||n&&!r[d].once||s&&r[d].context!==s)&&c.push(r[d]);c.length?this._events[a]=1===c.length?c[0]:c:o(this,a)}return this},r.prototype.removeAllListeners=function(e){var t;return e?(t=i?i+e:e,this._events[t]&&o(this,t)):(this._events=new s,this._eventsCount=0),this},r.prototype.off=r.prototype.removeListener,r.prototype.addListener=r.prototype.on,r.prefixed=i,r.EventEmitter=r,e.exports=r}(Pa);var Ma=Pa.exports;const Oa=new Ma,La=1,Va=2,Ua=3,xa=4,$a=5,Fa=20,Ba=21,Ha=22,ja=23,Wa=24,Ja=27,Ga=28,za=29,qa=30,Ka=31,Qa=32,Xa=33,Ya=40,Za=41,eo=52,to=100,io=101,so=102,no=103,ao=110,oo=111,ro=112,co=113,lo=114,ho=115,uo=116,_o=120,mo=121,po=122,go=123,So=130,fo=131,vo=132,Io=133,yo=134,To=135,bo=136,Eo=137,wo=200,Ro=201,ko=300,Ao=301,Co=302,Do=303;function No({retryFunction:e,settings:t,onError:i,onRetrying:s,onRetryFailed:n,onRetrySuccess:a,context:o}){return function(...r){const d=t.retries||5;let c=0,l=-1,h=0;const u=async(_,m)=>{const p=o||this;try{const t=await e.apply(p,r);0!==c&&ca(a)&&a.call(p,c),c=0,_(t)}catch(g){const e=()=>{clearTimeout(l),c=0,h=2,m(g)},a=()=>{2!==h&&c<d?(c++,h=1,ca(s)&&s.call(p,c,e),l=setTimeout((()=>{l=-1,u(_,m)}),la(t.timeout)?1e3:t.timeout)):(e(),ca(n)&&n.call(p,g))};ca(i)?i.call(p,g,a,m,r,c):a()}};return new Promise(u)}}class Po{constructor(e){this.log=e.log,this.level=e.level,this.userId=e.userId,this.sdkAppId=e.sdkAppId,this.forAllJoinedClients=e.forAllJoinedClients,this.uploaded=!1}}class Mo{constructor(e){this.id_=e.id,this.userId_=e.userId,this.sdkAppId_=e.sdkAppId,this.type_=e.type,this.isLocal_=!_a(e.isLocal)||e.isLocal}setUserId(e){this.userId_=e}setSdkAppId(e){this.sdkAppId_=e}log(e,t){Lo.log({log:`[${this.isLocal_?"↑":"↓"}${this.id_}] ${this.type_?this.type_+" ":""}${t}`,level:e,forAllJoinedClients:la(this.userId_),userId:this.userId_,sdkAppId:this.sdkAppId_})}info(e){this.log(wt.INFO,e)}debug(e){this.log(wt.DEBUG,e)}warn(e){this.log(wt.WARN,e)}error(e){this.log(wt.ERROR,e)}}const Oo=!(zs||qs);var Lo=new class{constructor(){this.clients_=new Set,this.queue_=[],this.timeoutId_=-1,this.logLevel_=wt.DEBUG,this.logLevelToUpload_=wt.INFO,this.enableUploadLog_=!0,this.isAbleToUpload_=!1,this.checkURLParam(),Oa.on(qa,(({client:e})=>{-1===this.timeoutId_&&this.startUpload(),this.clients_.add(e)})),Oa.on(Xa,(({client:e})=>this.clients_.delete(e))),Oa.on(Ka,(e=>{e&&oa(e.config)&&Dt[e.config.logLevelToUpload]&&(this.logLevelToUpload_=e.config.logLevelToUpload)})),Oa.on(xa,this.setIsAbleToUpload,this),Oa.on($a,this.setIsAbleToUpload,this)}getIsAbleToUpload(){return this.isAbleToUpload_}setIsAbleToUpload(){this.isAbleToUpload_=!0,Oa.off(xa,this.setIsAbleToUpload,this),Oa.off($a,this.setIsAbleToUpload,this)}async startUpload(){try{await this.upload()}catch(e){}this.timeoutId_=setTimeout((()=>this.startUpload()),2e3)}getLogsToUpload(){const e={map:new Map,splicedQueue:[]};if(this.queue_[0].forAllJoinedClients&&0===this.clients_.size)return e;let t=0;for(;t<this.queue_.length&&50!==t;t++){const i=this.queue_[t];if(i.forAllJoinedClients){const t=new Set;this.clients_.forEach((s=>{if(!s.getIsJoined())return;const n=s.getUserId(),a=s.getSDKAppId();if(!t.has(`${n}-${a}`))if(t.add(`${n}-${a}`),e.map.has(n)){const{logs:t}=e.map.get(n);t.push(i)}else e.map.set(n,{userId:n,sdkAppId:a,logs:[i]})}))}else if(e.map.has(i.userId)){const{logs:t}=e.map.get(i.userId);t.push(i)}else e.map.set(i.userId,{userId:i.userId,sdkAppId:i.sdkAppId,logs:[i]})}return e.map.size>0&&(e.splicedQueue=this.queue_.splice(0,t)),e}async upload(){if(0===this.queue_.length||!this.isAbleToUpload_)return;const{map:e,splicedQueue:t}=this.getLogsToUpload();if(0===e.size)return;try{const t=[...e.values()];for(let e=0;e<t.length;e++){const{userId:i,sdkAppId:s,logs:a}=t[e];await this.uploadLogWithRetry(JSON.stringify({timestamp:n(),sdkAppId:String(s),userId:i,version:"4.15.22",log:a.map((e=>e.log)).join("\n")}),s),a.forEach((e=>e.uploaded=!0))}}catch(s){}const i=t.filter((e=>!e.uploaded));i.length>0&&(this.queue_=i.concat(this.queue_))}uploadLogWithRetry(e,t){return No({retryFunction:()=>Da({url:na(t,Q),body:e,timeout:5e3}),settings:{retries:3,timeout:1e3},onError:(e,t)=>{t()}})()}getPrefix(e){const t=new Date;return t.setTime(s()),String.prototype.padStart?`[${t.toTimeString().replace(/.*(\d{2}:\d{2}:\d{2}).*/,"$1")}:${t.getMilliseconds().toString().padStart(3,"0")}] <${Dt[e]}>`:`[${t.toTimeString().replace(/.*(\d{2}:\d{2}:\d{2}).*/,"$1")}:${t.getMilliseconds()}] <${Dt[e]}>`}getLogLevel(){return this.logLevel_}setLogLevel(e){la(Dt[e])||(this.logLevel_!==e&&this.info(`setLogLevel ${e}`),this.logLevel_=e)}enableUploadLog(){this.enableUploadLog_=!0}disableUploadLog(){this.enableUploadLog_=!1}log({log:e,level:t,forAllJoinedClients:i=!0,userId:s,sdkAppId:n}){if(e=`${this.getPrefix(t)} ${e}`,this.enableUploadLog_&&t>=this.logLevelToUpload_&&this.queue_.push(new Po({log:e,level:t,userId:s,sdkAppId:n,forAllJoinedClients:i})),t<this.logLevel_)return;let a=Dt[t]?Dt[t].toLowerCase():"info";Oo?console[a]("%cTRTC%c%s","padding: 1px 4px;border-radius: 3px;color: #fff;background: #1E88E5;","display: inline",e):console[a](e)}debug(e){this.log({log:e,level:wt.DEBUG})}info(e){this.log({log:e,level:wt.INFO})}warn(e){this.log({log:e,level:wt.WARN})}error(e){this.log({log:e,level:wt.ERROR})}createLogger(e){return new Mo(e)}checkURLParam(){const e=new URLSearchParams(location.search).get("logLevelToUpload");Dt[e]&&(this.logLevelToUpload_=e)}};let Vo=!0;const Uo=1,xo=5,$o=2,Fo=3,Bo=4,Ho="DISCONNECTED",jo="CONNECTING",Wo="RECONNECTING",Jo="CONNECTED",Go={CLIENT_BANNED:9,CHANNEL_SETUP_RESULT:19,CHANNEL_RECONNECT_RESULT:514,JOIN_ROOM_RESULT:20,PEER_JOIN:4134,PEER_LEAVE:4135,STREAM_ADDED:16,STREAM_REMOVED:18,UPLINK_NETWORK_STATS:22,UPDATE_REMOTE_MUTE_STAT:23,PUBLISH_RESULT:4098,PUBLISH_STATE_CHANGE_RESULT:4112,UNPUBLISH_RESULT:4100,SUBSCRIBE_RESULT:4102,UNSUBSCRIBE_RESULT:4104,SUBSCRIBE_CHANGE_RESULT:4106,MUTE_RESULT:4108,UPDATE_OFFER_RESULT:4128,START_PUBLISH_TENCENT_CDN_RES:1286,STOP_PUBLISH_TENCENT_CDN_RES:1288,START_PUBLISH_GIVEN_CDN_RES:777,STOP_PUBLISH_GIVEN_CDN_RES:779,START_MIX_TRANSCODE_RES:781,STOP_MIX_TRANSCODE_RES:783,USER_LIST_RES:4137,SWITCH_ROLE_RES:4110,UPDATE_CONSTRAINT_CONFIG_RES:772,CONNECT_OTHER_ROOM_RES:8209,DISCONNECT_OTHER_ROOM_RES:8211,UPDATE_OTHER_ROOM_FORWARD_MODE_RES:8213},zo=[Go.UPDATE_REMOTE_MUTE_STAT,Go.UPLINK_NETWORK_STATS,Go.USER_LIST_RES,Go.MUTE_RESULT],qo={CLIENT_BANNED:"client-banned",CHANNEL_SETUP_RESULT:"channel-setup-result",CHANNEL_RECONNECT_RESULT:"channel-reconnect-result",JOIN_ROOM_RESULT:"join-room-result",PEER_JOIN:"peer-join",PEER_LEAVE:"peer-leave",STREAM_ADDED:"stream-added",STREAM_REMOVED:"stream-removed",UPLINK_NETWORK_STATS:"uplink-network-stats",UPDATE_REMOTE_MUTE_STAT:"update-remote-mute-stat",PUBLISH_RESULT:"publish-result",PUBLISH_STATE_CHANGE_RESULT:"publish-state-change-result",UNPUBLISH_RESULT:"unpublish-result",SUBSCRIBE_RESULT:"subscribe-result",SUBSCRIBE_CHANGE_RESULT:"subscribe-change-result",UNSUBSCRIBE_RESULT:"unsubscribe-result",UPDATE_OFFER_RESULT:"update-offer-result",START_PUBLISH_TENCENT_CDN_RES:"start-publish-tencent-cdn-res",STOP_PUBLISH_TENCENT_CDN_RES:"stop-publish-tencent-cdn-res",START_PUBLISH_GIVEN_CDN_RES:"start-publish-given-cdn-res",STOP_PUBLISH_GIVEN_CDN_RES:"stop-publish-given-cdn-res",START_MIX_TRANSCODE_RES:"start-mix-transcode-res",STOP_MIX_TRANSCODE_RES:"stop-mix-transcode-res",USER_LIST_RES:"user-list-res",SWITCH_ROLE_RES:"switch_role_res",MUTE_RESULT:"mute-result",UPDATE_CONSTRAINT_CONFIG_RES:"update-contraint-config-res",CONNECT_OTHER_ROOM_RES:"connect_other_room_res",UPDATE_OTHER_ROOM_FORWARD_MODE_RES:"update_other_room_forward_mode_res",DISCONNECT_OTHER_ROOM_RES:"disconnect_other_room_res"},Ko="publish_change",Qo="publish_state_change",Xo="join",Yo="leave",Zo="quality_report",er="mute_uplink",tr="publish",ir="unpublish",sr="subscribe",nr="unsubscribe",ar="subscribe_change",or="start_publishing",rr="stop_publishing",dr="start_push_user_cdn",cr="stop_push_user_cdn",lr="start_mcu_mix",hr="stop_mcu_mix",ur="get_user_list",_r="change_role",mr="update_constraint_config",pr="connect_other_room",gr="update_other_room_forward_mode",Sr="disconnect_other_room",fr={INVALID_PARAMETER:4096,INVALID_OPERATION:4097,NOT_SUPPORTED:4098,DEVICE_NOT_FOUND:4099,INITIALIZE_FAILED:4100,SIGNAL_CHANNEL_SETUP_FAILED:16385,SIGNAL_CHANNEL_ERROR:16386,ICE_TRANSPORT_ERROR:16387,JOIN_ROOM_FAILED:16388,CREATE_OFFER_FAILED:16389,SIGNAL_CHANNEL_RECONNECTION_FAILED:16390,UPLINK_RECONNECTION_FAILED:16391,DOWNLINK_RECONNECTION_FAILED:16392,REMOTE_STREAM_NOT_EXIST:16400,CLIENT_BANNED:16448,SERVER_TIMEOUT:16449,SUBSCRIPTION_TIMEOUT:16450,PLAY_NOT_ALLOWED:16451,DEVICE_AUTO_RECOVER_FAILED:16452,START_PUBLISH_CDN_FAILED:16453,STOP_PUBLISH_CDN_FAILED:16454,START_MIX_TRANSCODE_FAILED:16455,STOP_MIX_TRANSCODE_FAILED:16456,NOT_SUPPORTED_H264:16457,SWITCH_ROLE_FAILED:16458,API_CALL_TIMEOUT:16459,SCHEDULE_FAILED:16460,API_CALL_ABORTED:16461,UNKNOWN:65535};class vr extends Error{constructor({name:e="RtcError",message:t,code:i=fr.UNKNOWN,extraCode:s=0,constraint:n}){const a=`<${function(e){for(let t in fr)if(fr[t]===e)return t;return"UNKNOWN"}(i)} 0x${i.toString(16)}>`;super(t+""+(n?` constraint: ${n}`:"")+(null!=t&&t.includes(a)?"":" "+a)),this.code_=i,this.extraCode_=s,this.name=e,this.message_=t,n&&(this.constraint=n)}getCode(){return this.code_}getExtraCode(){return this.extraCode_}}const Ir=32768,yr=32769,Tr=32770,br=32771,Er=32772,wr=32773,Rr=32774,kr=32775,Ar=32777,Cr=32778,Dr=32779,Nr=32780,Pr=32781,Mr=32782,Or=32783,Lr=32784,Vr=32785,Ur=32786,xr=32787,$r=32788,Fr=32789,Br=32790,Hr=32791,jr=32792,Wr=32793,Jr=32794,Gr=32795,zr=32796,qr=32797,Kr=32798,Qr=32799,Xr=32800,Yr=32801,Zr=32802,ed=32803,td=32804,id=new Map,sd=function(e,t){let i=id.get(e);i||(id.set(e,[]),i=id.get(e)),i.push(t)};var nd=Object.prototype.hasOwnProperty;function ad(e){if(null==e)return!0;if("boolean"==typeof e)return!1;if("number"==typeof e)return 0===e;if("string"==typeof e)return 0===e.length;if("function"==typeof e)return 0===e.length;if(Array.isArray(e))return 0===e.length;if(e instanceof Error)return""===e.message;if(oa(e))switch(Object.prototype.toString.call(e)){case"[object File]":case"[object Map]":case"[object Set]":return 0===e.size;case"[object Object]":for(var t in e)if(nd.call(e,t))return!1;return!0}return!1}var od=new class{constructor(){const{name:e,version:t}=Yn();this.roomIdMap_=new Map,this.configs_={sdkAppId:"",userId:"",version:"4.15.22",env:G,browserVersion:e+t,ua:navigator.userAgent}}setConfig({sdkAppId:e,env:t,userId:i,roomId:s}){e!==this.configs_.sdkAppId&&(this.configs_.sdkAppId=String(e)),this.configs_.env=t,this.configs_.userId=i,this.roomIdMap_.set(i,String(s))}logEvent(e){if(Kn)return;const t={...e,...this.configs_,userId:e.userId||this.configs_.userId};la(t.code)&&(t.code="failed"===t.result?fr.UNKNOWN:0),this.sendRequest(na(this.configs_.sdkAppId,X),t)}logSuccessEvent(e){Kn||(this.logEvent({...e,result:"success",roomId:this.roomIdMap_.get(e.userId)}),this.configs_.env===G&&this.uploadEventToKibana({...e,result:"success"}))}logFailedEvent(e){if(Kn)return;const{eventType:t,code:i,error:s,userId:n}=e,a={roomId:this.roomIdMap_.get(n),userId:n,eventType:t,result:"failed",code:i||(s instanceof vr?s.getExtraCode()||s.getCode():fr.UNKNOWN)};this.logEvent(a),this.configs_.env===G&&this.uploadEventToKibana({...a,error:s})}uploadEventToKibana(e){let t=`stat-${e.eventType}-${e.result}`;"delta-join"!==e.eventType&&"delta-leave"!==e.eventType&&"delta-publish"!==e.eventType||(t=`${e.eventType}:${e.delta}`),this.uploadEvent({log:t,userId:e.userId}),"failed"===e.result&&(t=`stat-${e.eventType}-${e.result}-${e.code}`,this.uploadEvent({log:t,userId:e.userId,error:e.error}))}uploadEvent({log:e,userId:t,error:i}){const s={timestamp:n(),sdkAppId:this.configs_.sdkAppId,userId:t||this.configs_.userId,version:this.configs_.version,log:e};i&&(s.errorInfo=i.message),this.sendRequest(na(this.configs_.sdkAppId,Q),s)}sendRequest(e,t){Lo.getIsAbleToUpload()?Da({url:e,body:JSON.stringify(t)}).catch((()=>{})):setTimeout((()=>{this.sendRequest(e,t)}),1e3)}};let rd=null,dd=!0;function cd(e){_a(e)&&e!==dd&&(dd=e,Lo.info("setIsNeedToSchedule "+e))}async function ld({userId:e,sdkAppId:t,useStringRoomId:i,roomId:s,userSig:n}){if(!dd&&rd)return{isCached:!0,result:rd};const a={delta:0,count:[1,1],msg:[]};try{const o=new FormData;o.append("userId",String(e)),o.append("sdkAppId",String(t)),o.append("isStrGroupId",i),o.append("groupId",String(s)),o.append("sdkVersion","4.15.22"),o.append("userSig",String(n)),_t&&o.append("oversea",!0),function(e,t){try{if(PerformanceObserver){const i=va(),s=ud(e,k),n=ud(e,A),a=new PerformanceObserver((e=>{e.getEntries().forEach((e=>{if(e.startTime>=i&&(e.name===s||e.name===n)){const i=e.name===s?k:A;if(e.code&&200!==e.code)return void Lo.warn(`${i} schedule with code ${e.code}, ${JSON.stringify(e.toJSON())}`);const n=e.responseEnd-e.startTime,o=[e.domainLookupStart-e.startTime,e.domainLookupEnd-e.domainLookupStart,e.requestStart-e.secureConnectionStart,e.secureConnectionStart-e.connectStart,e.responseStart-e.requestStart,e.responseEnd-e.responseStart].map((e=>e.toFixed(1)));a.disconnect(),od.uploadEvent({log:`stat-schedule-net:${n.toFixed(1)}(${o.join("->")}) ${i}`,userId:t})}}))}));a.observe({type:"resource",buffered:!0})}}catch(i){}}(t,e);const r=va(),d=await function(e,t,i){return new Promise(((s,n)=>{let a=null;var o;(o=[md((e=>t.count[0]=e+1),((e,i)=>{t.msg[0]=e.message,a||i()}))(ud(i,k),e,{get timeout(){return 1e3*ra(2+t.count[0])}}),md((e=>t.count[1]=e+1),((e,i)=>{t.msg[1]=e.message,a||i()}))(ud(i,A),e,{get timeout(){return 1e3*ra(2+t.count[1])}})],new Promise(((e,t)=>{let i=[];o.forEach((s=>{s.then(e).catch((e=>{i.push(e),i.length===o.length&&t(i)}))}))}))).then((e=>{a=e,s(a)})).catch(n)}))}(o,a,t);return d.config&&(d.config.loggerDomain&&Z(d.config.loggerDomain),_a(d.config.scheduleCache)&&cd(!d.config.scheduleCache)),a.delta=va()-r,hd({stat:a,userId:e}),rd=d,{isCached:!1,result:d}}catch(o){const t=pa(o)?o[0]:o,i=ua(t.code)?t.code:0,n="schedule failed"+(t.message?`: ${t.message}`:""),r=new vr({code:fr.SCHEDULE_FAILED,extraCode:i,message:ta({key:ai,data:{error:n,code:i}})});throw Lo.error(r),hd({stat:a,userId:e,roomId:s,error:r}),r}}function hd({stat:e,userId:t,error:i}){i?od.logFailedEvent({eventType:Je,error:i,userId:t}):od.logSuccessEvent({eventType:Je,delta:e.delta,userId:t}),od.uploadEvent({log:"stat-schedule:"+JSON.stringify(e),userId:t})}function ud(e,t=k){let i;return i=_t||(sa(e)?t===k?ht:ut:t===k?ct:lt),`https://${i}/api/v1/config`}function _d(e,t,i){return new Promise(((s,n)=>{Da({url:e,body:t,timeout:i.timeout}).then((e=>{0===e.data.code?s(e.data.data):n({code:e.data.code,message:e.data.msg})})).catch(n)}))}Oa.on($a,(()=>cd(!0))),Oa.on(Za,(()=>cd(!0))),Oa.on(eo,(()=>cd(!0))),Oa.on(Ya,(()=>cd(!0))),Oa.on(wo,(e=>{e.state===he&&cd(!0)}));const md=(e,t)=>No({retryFunction:_d,settings:{retries:3,timeout:0},onError:t,onRetrying:e});class pd{get urlWithParam_(){return`${this.url_}${this.urlParams}`}get backupUrlWithParam_(){return`${this.backupUrl_}${this.urlParams}`}constructor(e){this.client_=e.client,this.sdkAppId_=e.sdkAppId,this.userId_=e.userId,this.userSig_=e.userSig,this.url_=e.url,this.backupUrl_=e.backupUrl;let t=`?sdkAppId=${encodeURIComponent(this.sdkAppId_)}&userId=${encodeURIComponent(this.userId_)}&userSig=${encodeURIComponent(this.userSig_)}&roomId=${encodeURIComponent(e.roomId)}`;const i=this.client_.getSystemResult();if(i&&i.detail){const{isH264EncodeSupported:e,isVp8EncodeSupported:s,isH264DecodeSupported:n,isVp8DecodeSupported:a}=i.detail;t+=`&enc264=${Number(e)}&dec264=${Number(n)}&encVp8=${Number(s)}&decVp8=${Number(a)}`}e.signalDomainWhenUnifiedProxy&&(t+=`&signalDomain=${encodeURIComponent(e.signalDomainWhenUnifiedProxy)}`),this.urlParams=t,this.isConnected_=!1,this.isConnecting_=!1,this.socketInUse_=null,this.socket_=null,this.backupSocket_=null,this.backupTimer_=-1,this.signalInfo_={},this.currentState_=Ho,this.reconnectionCount_=0,this.reconnectionTimer_=-1,this.lastMessageTime_=-1,this.seq_=0,this.log_=Lo.createLogger({id:"ws|"+this.userId_,userId:this.userId_,sdkAppId:this.sdkAppId_}),this.emitter_=new Ma}get isOnline(){return this.currentState_===Jo&&Date.now()-this.lastMessageTime_<12e3}connect(){return new Promise(((e,t)=>{this.log_.info(`connect to url: ${this.urlWithParam_}`),this.emitConnectionStateChanged(jo),this.socket_=new WebSocket(this.urlWithParam_),this.bindSocket(this.socket_),this.backupTimer_=setTimeout((()=>{this.isConnected_||(this.log_.info("trying to connect to backupUrl"),this.tryConnectBackup())}),5e3);const i=setTimeout((()=>{this.close(),t(new vr({code:fr.JOIN_ROOM_FAILED,message:"join room timeout"}))}),1e4);this.once(Fo,(()=>{clearTimeout(i),e()})),this.once(Bo,(e=>{clearTimeout(i),t(e)}))}))}tryConnectBackup(){this.backupSocket_||(this.unbindAndCloseSocket(k),this.log_.debug(`try to connect to url: ${this.backupUrlWithParam_}`),this.backupSocket_=new WebSocket(this.backupUrlWithParam_),this.bindSocket(this.backupSocket_))}bindSocket(e){e.onopen=this.onopen.bind(this),e.onclose=this.onclose.bind(this),e.onerror=this.onerror.bind(this),e.onmessage=this.onmessage.bind(this)}unbindSocket(e){e.onopen=()=>{},e.onclose=()=>{},e.onerror=()=>{},e.onmessage=()=>{}}unbindAndCloseSocket(e){if(e===k){if(this.socket_){this.unbindSocket(this.socket_);try{this.socket_.close(1e3)}catch(t){}this.socket_=null}}else if(this.backupSocket_){this.unbindSocket(this.backupSocket_);try{this.backupSocket_.clos