Loading
function(e,t,n){"use strict";n.d(t,{A:()=>m,k:()=>h}),n(142703);var r=n(473318),i=n.n(r),s=n(128080),a=n.n(s),o=n(904986),l=n(205693),u=n(405163),c=n(228272),d=n(46263),_=n(83774),f=n(731854),p=n(396574),h=function(e){return e[e.AUDIO_BITRATE=0]="AUDIO_BITRATE",e[e.VIDEO_RESOLUTION_SCALE=1]="VIDEO_RESOLUTION_SCALE",e[e.VIDEO_BITRATE=2]="VIDEO_BITRATE",e[e.VIDEO_FRAMERATE=3]="VIDEO_FRAMERATE",e}({});class m extends o.A{input;silenced=!1;interacted=!1;outputVolume=f.Hz;sinkId=f.dx;lastPingTime=0;outputs={};webrtcStats=new d.J;silenceThreshold=-100;canHavePriority=new Set;prioritySpeakers=new Set;audioContext;constructor(e){super(e.context,e.userId),this.input=new u.A(e.audioContext),e.audioContext.addEventListener("statechange",this.handleAudioContextStateChange),this.audioContext=e.audioContext,this.input.on(u.T.AudioPermission,this.handleAudioPermission),this.input.on(u.T.VideoPermission,this.handleVideoPermission),this.input.on(u.T.Video,this.handleVideo),this.input.on(u.T.Mute,e=>this.emit(l.yq.Mute,e)),this.input.on(u.T.Stream,this.handleStream),this.input.on(u.T.DesktopSourceEnd,this.handleDesktopSourceEnd),this.input.on(u.T.Speaking,this.handleInputSpeaking),this.input.on(u.T.AddVideoTrack,this.handleAddVideoTrack),this.input.on(u.T.Video,this.handleAddVideoTrack),this.on("newListener",this.handleNewListener),this.initializeStreamParameters(e.streamParameters)}interact(){for(let e of(this.interacted=!0,Object.keys(this.outputs)))this.outputs[e].play();this.input.resumeAudio()}destroy(){let e=arguments.length>0&&void 0!==arguments[0]&&arguments[0];for(let e of(super.destroy(),Object.keys(this.outputs)))this.destroyOutput(e);this.input.destroy(e)}async getStats(){if(!p.fA)return null;let e=await this.getRawStats(),t=null!==this.input.getVideoStreamId();return(0,_.A)(e,this.getUserIdBySsrc,this.remoteVideoSinkWants,this.localVideoSinkWants,t)}setEchoCancellation=e=>this.input.setEchoCancellation(e);setNoiseSuppression=e=>this.input.setNoiseSuppression(e);setNoiseCancellation=e=>this.input.setNoiseCancellation(e);getNoiseCancellation=()=>this.input.getNoiseCancellation();setAutomaticGainControl=e=>this.input.setAutomaticGainControl(e);setAudioSource=e=>this.input.setAudioSource(e);setVideoSource=e=>this.input.setVideoSource(e);setDesktopInput=e=>{if(null!=e){let t=e.stream.getVideoTracks()[0].getConstraints(),n={width:"number"==typeof t.width?t.width:t.width?.ideal??t.width?.max,height:"number"==typeof t.height?t.height:t.height?.ideal??t.height?.max},r=(n?.height??0)>720?f.oL:f.lo;this.videoQualityManager.setGoliveQuality({encode:n,capture:n,bitrateMax:r})}this.input.setDesktop(e)};setForceAudioInput=(()=>{var e=this;return function(t){return arguments.length>1&&void 0!==arguments[1]&&arguments[1],arguments.length>2&&void 0!==arguments[2]&&arguments[2],e.input.setPTTActive(t)}})();setSelfMute=e=>{this.selfMute=e,this.input.setMute(e),this.emit(l.yq.Mute,e)};setNoiseCancellationDuringProcessing(e){}setNoiseCancellationAfterProcessing(e){}setVADAfterWebrtc(e){}getSelfMute(){return this.selfMute}setInputMode(e,t){this.input.setAudioMode(e,{delay:t.pttReleaseDelay,threshold:t.vadThreshold})}setSelfDeaf(e){for(let t of(this.selfDeaf=e,Object.keys(this.outputs)))this.outputs[t].mute=e||this.localMutes[t];this.emit(l.yq.Deafen,e)}getSelfDeaf(){return this.selfDeaf}setLocalMute(e,t){this.localMutes[e]=t,null!=this.outputs[e]&&(this.outputs[e].mute=this.selfDeaf||t),this.emit(l.yq.LocalMute,e,t)}fastUdpReconnect(){}getNumFastUdpReconnects(){return null}wasRemoteDisconnected(){}setRemoteVideoSinkWants(e){this.remoteVideoSinkWants=e,this.updateVideoQuality(f.nJ)}setLocalVideoSinkWants(e){this.localVideoSinkWants=e}updateVideoQualityCore(e,t){let n;if(!this.videoSupported)return;let r=this.input.getVideoStream();if(null==r)return;if(null!=t.capture&&null!=t.capture.width&&null!=t.capture.height&&null!=e.remoteSinkWantsPixelCount&&0!==e.remoteSinkWantsPixelCount&&0!==t.capture.height){let r=t.capture.width/t.capture.height,i=Math.sqrt(e.remoteSinkWantsPixelCount*r),s=t.capture.width/i;n=s<1?void 0:s}this.logger.verbose(`BaseWebRTCConnection.updateVideoQuality: resolutionScaleFactor: ${n}, encodingVideoWidth: ${e.encodingVideoWidth}, remoteSinkWantsMaxFramerate: ${e.remoteSinkWantsMaxFramerate}, encodingVideoMaxBitRate: ${e.encodingVideoMaxBitRate}, localWant: ${this.getLocalWant()}`),this.setVideoEncoderParameters([{parameter:1,value:n},{parameter:2,value:e.encodingVideoMaxBitRate},{parameter:3,value:e.remoteSinkWantsMaxFramerate}]);let i=e.encodingVideoWidth,s=e.encodingVideoHeight;if(null!=i&&null!=s)for(let e of r.getTracks()){let t=e.getConstraints(),n=t.width?.max,r=t.height?.max;(n!==i||r!==s)&&(this.logger.info(`BaseWebRTCConnection.updateVideoQuality: old: ${n} x ${r}, new: ${i} x ${s}`),t.width={max:i},t.height={max:s},e.applyConstraints(t))}}handleAddVideoTrack=()=>{this.updateVideoQuality()};handleAudioPermission=e=>this.emit(l.yq.AudioPermission,e);handleVideoPermission=e=>this.emit(l.yq.VideoPermission,e);handleVideo=e=>this.emit(l.yq.Video,this.userId,e,this.audioSSRC,this.videoStreamParameters[0].ssrc,this.videoStreamParameters[0].rtxSsrc??0,this.videoStreamParameters);handleDesktopSourceEnd=()=>this.emit(l.yq.DesktopSourceEnd);handleStream=e=>this.setStream(e);handleVoiceActivity=e=>{let t=e<=this.silenceThreshold;this.silenced===t||this.input.mute()||(this.silenced=t,this.emit(l.yq.Silence,t))};handleNewListener=e=>{switch(e){case l.yq.Video:this.videoReady&&setImmediate(()=>this.handleVideo(this.input.getVideoStreamId()));break;case l.yq.ConnectionStateChange:this.emit(e,this.connectionState);break;case l.yq.InteractionRequired:this.interacted||"suspended"!==this.input.getAudioState()||setImmediate(()=>this.emit(e,!0))}};handleInputSpeaking=e=>{this.emit(l.yq.Speaking,this.userId,e?f.ME.VOICE:f.ME.NONE,this.audioSSRC)};handleAudioContextStateChange=()=>{this.interacted||"running"!==this.input.getAudioState()||(this.interact(),this.emit(l.yq.InteractionRequired,!1))};setCanHavePriority(e,t){let n=this.canHavePriority.size;t?this.canHavePriority.add(e):this.canHavePriority.delete(e),this.canHavePriority.size!==n&&this.recalculatePrioritySpeakers()}setSpeakingFlags(e,t){null!=t&&t!==f.ME.NONE?this.localSpeakingFlags[e]=t:delete this.localSpeakingFlags[e];let n=this.outputs[e];null!=n&&n.setSpeakingFlags(t);let r=this.wantsPriority.size,i=f.ME.VOICE|f.ME.PRIORITY;(t&i)===i?this.wantsPriority.add(e):this.wantsPriority.delete(e),this.wantsPriority.size!==r&&this.recalculatePrioritySpeakers()}clearAllSpeaking(){for(let e in this.localSpeakingFlags)delete this.localSpeakingFlags[e],null!=this.outputs[e]&&this.outputs[e].setSpeakingFlags(f.ME.NONE)}setOutputVolume(e){for(let t of(this.outputVolume=e,Object.keys(this.outputs)))this.outputs[t].volume=this.computeLocalVolume(t)}setSinkId(e){for(let t of(this.sinkId=e,Object.keys(this.outputs)))this.outputs[t].setSinkId(e)}setStreamParameters(e){return new Promise((t,n)=>{for(let t of this.videoStreamParameters){let r=e.findIndex(e=>e.rid===t.rid);if(-1===r)return void n(Error("Invalid rid"));a()(this.videoStreamParameters[r],e[r])||(this.videoStreamParameters[r]={...e[r]})}t()})}recalculatePrioritySpeakers(){this.prioritySpeakers=new Set(Array.from(this.wantsPriority).filter(e=>this.canHavePriority.has(e))),i()(this.outputs,(e,t)=>{e.volume=this.computeLocalVolume(t)})}setBitRate(e){this.voiceBitrate=e}setLocalVolume(e,t){this.localVolumes[e]=t,null!=this.outputs[e]&&(this.outputs[e].volume=this.computeLocalVolume(e))}getLocalVolume(e){let t=this.localVolumes[e];return null==t&&(t=this.context===f.x.DEFAULT?f.Hz:f.Cn),null!=t?t:f.Hz}computeLocalVolume(e){let t=this.outputVolume*this.getLocalVolume(e)/f.Hz;return this.prioritySpeakers.size>0&&!this.prioritySpeakers.has(e)?t*f.zt:t}hasDesktopSource(){return this.input?.hasDesktopSource()}createOutput(e,t){if(t.discordIsTearingDown)return void this.logger.info(`BaseWebRTCConnection.createOutput: ignoring track being torn down: ${t.id}`);let n=this.outputs[e];null==n&&((n=new c.A(e,this.audioContext)).mute=this.selfDeaf||this.localMutes[e],n.volume=this.computeLocalVolume(e),n.on(c.i.Speaking,t=>this.emit(l.yq.Speaking,e,t,this.audioSSRC)),n.on(c.i.Video,t=>this.emitUnsafe(l.yq.Video,e,t,this.audioSSRC,this.videoStreamParameters[0].ssrc,this.videoStreamParameters[0].rtxSsrc??0,this.videoStreamParameters)),n.on(c.i.InteractionRequired,e=>this.emit(l.yq.InteractionRequired,e)),n.setSpeakingFlags(this.localSpeakingFlags[e]??f.ME.NONE),n.setSinkId(this.sinkId),this.outputs[e]=n),n.addTrack(t)}destroyOutput(e,t){let n=this.outputs[e];null!=n&&(null==t||0===n.removeTrack(t))&&(n.destroy(),delete this.outputs[e])}handleStats=e=>{this.connectionState===f.$I.DISCONNECTED?this.off(l.yq.Stats,this.handleStats):null!=e&&(this.webrtcStats.update(e),this.stats=e,Date.now()-this.lastPingTime>=f.n8&&(this.emit(l.yq.Ping,e.transport.ping),this.lastPingTime=Date.now()))};setSilenceThreshold(e){this.silenceThreshold=e}setLocalPan(e,t,n){}setQoS(e){}setSoundshareDiscardRearChannels(e){}isAttenuating(){return!1}setAttenuation(e,t,n){}setEncryption(e,t){}setMinimumJitterBufferLevel(e){}setPostponeDecodeLevel(e){}setReconnectInterval(e){}setKeyframeInterval(e){}startSamplesLocalPlayback(e,t,n,r){}stopSamplesLocalPlayback(e){}stopAllSamplesLocalPlayback(){}setVideoQualityMeasurement(e){}setVideoEncoderExperiments(e){}setBandwidthEstimationExperiments(e){}prepareSecureFramesTransition(e,t,n){}prepareSecureFramesEpoch(e,t,n){}executeSecureFramesTransition(e){}getMLSKeyPackage(e){}updateMLSExternalSender(e){}processMLSProposals(e,t){}prepareMLSCommitTransition(e,t,n){}processMLSWelcome(e,t,n){}getMLSPairwiseFingerprint(e,t,n){}}}