Loading
function(e,t,n){"use strict";let i;n.d(t,{A:()=>el});var r=n(284009),a=n.n(r),s=n(435558),l=n.n(s),o=n(855986),d=n(205693),c=n(73153),u=n(644727);n(321073);var _=n(499979),E=n(451988),A=n(777636),f=n(507821);class h{_report;_pids;constructor(){this._report={soundshare_attach_requested_count:0,soundshare_capturing_count:0,soundshare_capture_stopped_count:0,soundshare_hooked_count:0,soundshare_recv_connect_count:0,soundshare_recv_disconnect_count:0,soundshare_recv_started_count:0,soundshare_recv_stopped_count:0,soundshare_recv_failed_count:0,soundshare_recv_format_count:0,soundshare_send_announce_count:0,soundshare_send_start_count:0,soundshare_send_stop_count:0,soundshare_malformed_trace_count:0,soundshare_audio_detected_count:0,soundshare_state_transition_detached_count:0,soundshare_state_transition_waiting_count:0,soundshare_state_transition_attached_count:0,soundshare_state_transition_started_count:0,soundshare_state_transition_playing_count:0,soundshare_state_transition_silence_count:0,soundshare_unknown_event_count:0,soundshare_first_pid:0,soundshare_last_pid:0,soundshare_unique_pids:0,soundshare_first_session:null,soundshare_last_session:null},this._pids=new Set}traceEvent(e,t){let n,i=this._report;void 0!==i[n="soundshare_state_transition"===t.type?`soundshare_state_transition_${["detached","waiting","attached","started","playing","silence"][t.newState]}_count`:`${t.type}_count`]?i[n]<32767&&i[n]++:i.soundshare_unknown_event_count++,"pid"in t&&(0===i.soundshare_first_pid&&(i.soundshare_first_pid=t.pid),i.soundshare_last_pid=t.pid,this._pids.add(t.pid)),null!=e&&(null==i.soundshare_first_session&&(i.soundshare_first_session=e),i.soundshare_last_session=e)}restartForFragment(){let e=Object.keys(this._report).filter(e=>e.endsWith("_count"));Object.assign(this._report,Object.fromEntries(e.map(e=>[e,0])))}getStats(){return{...this._report,soundshare_unique_pids:this._pids.size}}}var I=n(419490),p=n(572164),m=n(680725),g=n(973522),T=n(967347),S=n(929921),N=n(616356),C=n(46653),O=n(734057),R=n(877717),L=n(988468),y=n(544180),D=n(495867),b=n(873985),v=n(129230),P=n(353835),M=n(927813),U=n(652215);function w(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0;return null!=e?Math.round(e):t}class G{_statInterval;_isSender;_streamEnd;_targetResolution=0;_targetFPS=0;_streamSettingsChanged=!1;_lastLayout;_lastLayoutChanged=0;_layoutChanges=0;_layoutBuckets;_automaticQualityChanges=0;constructor(e,t){this._isSender=t,this._statInterval=new E.IX,this._lastLayout=e,this._layoutBuckets={}}start(){let{resolution:e,fps:t}=S.A.getState();this._targetResolution=e,this._targetFPS=t,this._statInterval.start(1e3,this._sampleStats),this._lastLayoutChanged=(0,_.tB)()}stop(){this._statInterval.stop(),this._streamEnd=(0,_.tB)(),this._incrementLayout(this._lastLayout,(this._streamEnd-this._lastLayoutChanged)/1e3)}autoQualityChange(){this._automaticQualityChanges+=1}layoutChange(e){if(e===this._lastLayout||null!=this._streamEnd)return;let t=(0,_.tB)();this._incrementLayout(this._lastLayout,(t-this._lastLayoutChanged)/1e3),this._layoutChanges++,this._lastLayout=e,this._lastLayoutChanged=t}_incrementLayout=(e,t)=>{null==this._layoutBuckets[e]&&(this._layoutBuckets[e]=0),this._layoutBuckets[e]+=t};getLayout(){return this._lastLayout}restartForFragment(){this._layoutChanges=0,this._layoutBuckets={},this._automaticQualityChanges=0,this._lastLayoutChanged=(0,_.tB)()}getStats(){let e={...this._layoutBuckets};null==this._streamEnd&&(e[this._lastLayout]=(e[this._lastLayout]??0)+((0,_.tB)()-this._lastLayoutChanged)/1e3);let t={num_layout_changes:this._layoutChanges,duration_layout_fullscreen:w(e[U.SO9.FULL_SCREEN]),duration_layout_theatre:w(e[U.SO9.THEATRE]),duration_layout_pip:w(e[U.SO9.PIP]),duration_layout_popout:w(e[U.SO9.POPOUT]),duration_layout_portrait:w(e[U.SO9.PORTRAIT]),duration_layout_landscape:w(e[U.SO9.LANDSCAPE]),duration_layout_minimized:w(e[U.SO9.MINIMIZED])};return this._isSender?{...t,target_fps:this._targetFPS,target_resolution_height:this._targetResolution,stream_settings_changed:this._streamSettingsChanged,num_auto_quality_changes:this._automaticQualityChanges}:t}_sampleStats=()=>{let{resolution:e,fps:t}=S.A.getState();this._streamSettingsChanged=e!==this._targetResolution||t!==this._targetFPS}}var x=n(652896),k=n(965025),F=n(540305);let B=n(815706).p;var V=n(731854);let H=5*M.A.Millis.SECOND;class j{streamRegion;streamApplication;streamApplicationHistory;streamSourceType;actionContext;maxViewers;nativePickerStyleUsed;startTime;endTime;goLiveModalDurationMs;numViewers;analyticsLocations;constructor({streamRegion:e,streamApplication:t,streamSourceType:n,actionContext:i,numViewers:r,goLiveModalDurationMs:a,analyticsLocations:s}){this.streamRegion=e,this.streamApplication=t,this.streamApplicationHistory=[t],this.streamSourceType=n,this.actionContext=i,this.maxViewers=r,this.goLiveModalDurationMs=a,this.numViewers=r,this.analyticsLocations=s??[]}setActionContext(e){this.actionContext=e}updateStreamApplication(e){this.streamApplication=e,this.streamApplicationHistory=[...this.streamApplicationHistory,e]}setAnalyticsLocations(e){this.analyticsLocations=e}trackViewerCount(e){this.maxViewers=Math.max(e,this.maxViewers),this.numViewers=e}setNativePickerStyleUsed(e){this.nativePickerStyleUsed=e}trackStart(){this.startTime=performance.now()}trackEnd(){this.endTime=performance.now()}getStreamApplicationFromHistory(e){return this.streamApplicationHistory[e]}getDuration(){if(null==this.startTime)return null;let e=performance.now();return(this.endTime??e)-this.startTime}}class W extends A.A{analyticsContext;videoStreamStats;streamContext;streamKey;soundshareStats=new h;updateVideoStreamId;_firstFrameDelivered=!1;screenshareFinishedCount=0;soundshareFailuresReported={};errorTimer=new E.Ep;constructor({sessionId:e,streamKey:t,serverId:n,initialLayout:i,analyticsContext:r,parentMediaSessionId:a,channelId:s}){let o=(0,x.Iy)(t),{guildId:d,channelId:u}=o;super({userId:C.default.getId(),sessionId:e,guildId:d,channelId:u,context:V.x.STREAM,streamServerId:n,streamChannelId:s,parentMediaSessionId:a,joinVoiceId:null}),this.streamContext=o,this.streamKey=t,this.videoStreamStats=new G(i,this.isOwner),this.analyticsContext=r,this.updateVideoStreamId=l().debounce((e,t)=>{let{guildId:n,channelId:i,ownerId:r}=(0,x.Iy)(this.streamKey);c.h.dispatch({type:"RTC_CONNECTION_VIDEO",guildId:n,channelId:i,userId:r,streamId:e,rtcServerId:t,mediaEngineConnectionId:this.getMediaEngineConnectionId(),context:V.x.STREAM})},200),this.videoStreamStats.start(),this.initializeEvents(),N.A.addChangeListener(this._handleDaveVoiceStatesChange)}get isOwner(){let{ownerId:e}=this.streamContext;return C.default.getId()===e}destroy(e){this.videoStreamStats.stop(),this._flushFinalVideoStreamEndedEvents(e),this.updateVideoStreamId.cancel(),this.updateVideoStreamId(null,null),this.updateVideoStreamId.flush(),this.errorTimer.stop(),N.A.removeChangeListener(this._handleDaveVoiceStatesChange),super.destroy()}_getDaveVoiceStateUserIds(){return[this.userId,this.streamContext.ownerId,...N.A.getViewerIds(this.streamKey).map(e=>e)]}_isDaveStreamOwner(){return this.isOwner}streamUpdate(e){let t=this._videoQuality;null!=t&&(e?t.pause():t.resume())}layoutChange(e){this.videoStreamStats.layoutChange(e)}autoQualityChange(){this.videoStreamStats.autoQualityChange()}getVideoStats(){let{ownerId:e}=this.streamContext,t=this._videoQuality;return null!=t?function(e){if(1===e.length){let[{duration:t,avg_bitrate:n,avg_fps:i,avg_resolution:r,inbound_bitrate_estimate_percentile99:a}]=e;return{duration:t,avg_bitrate:n,avg_fps:i,avg_resolution:r,inbound_bitrate_estimate_percentile99:a}}let t=e.reduce((e,t)=>e+(t.duration_aggregation??0),0);function n(n){return t<=0?e[e.length-1][n]:Math.round(e.reduce((e,t)=>e+(t[n]??0)*(t.duration_aggregation??0),0)/t)}let i=e.map(e=>e.inbound_bitrate_estimate_percentile99).filter(e=>null!=e);return{duration:e.reduce((e,t)=>e+(t.duration??0),0),avg_bitrate:n("avg_bitrate"),avg_fps:n("avg_fps"),avg_resolution:n("avg_resolution"),inbound_bitrate_estimate_percentile99:i.length>0?Math.max(...i):void 0}}([...this._earlierFragmentVideoQualities,t].map(t=>this.isOwner?t.getOutboundStats()[0]??{}:t.getInboundStats(e)??{})):null}_restartFragmentAnalytics(){this.videoStreamStats.restartForFragment(),this.soundshareStats.restartForFragment()}getRegion(){return this.analyticsContext.streamRegion}getMaxViewers(){return this.analyticsContext.maxViewers}getVoiceParticipantType(){return this.isOwner?"streamer":"receiver"}initializeEvents(){let e=!1;this.on(f.q.State,(e,t,n)=>{c.h.dispatch({type:"RTC_CONNECTION_STATE",state:e,...t,...n,streamKey:this.streamKey}),e===U.S7L.RTC_CONNECTED&&(this._connection?.on(d.yq.ScreenshareFinish,(e,t,n,i,r,a,s,l,o,d,c,u,_,E,A,f,h,I,p,m,S,N,C,O,R,L)=>{let y=this.analyticsContext.getStreamApplicationFromHistory(this.screenshareFinishedCount);this.screenshareFinishedCount++;let{gameName:D,gameId:b,exe:M,distributor:w}=(0,g.wH)(y),G=this.getMediaSessionId(),x=this.getRTCConnectionId(),k=(d??0)+(c??0)+(u??0)+(_??0)+(E??0);(0,T.w)().then(g=>{let T=null!=g?{cpu_brand:g.cpu_brand,cpu_vendor:g.cpu_vendor,cpu_memory:g.cpu_memory,gpu_brand:g.gpu_brand,gpu_memory:g.gpu_memory}:null,y=(e??0)+(t??0)+(n??0)+(i??0)+(r??0)+(a??0)+(f??0)+(m??0)+(p??0)+(R??0)+(O??0);v.default.track(U.HAw.SCREENSHARE_FINISHED,{screenshare_frames:e,videohook_frames:t,hybrid_dxgi_frames:n,hybrid_gdi_frames:i,hybrid_videohook_frames:r,hybrid_graphics_capture_frames:a,hybrid_capture_method_switches:s,hybrid_gdi_bitblt_frames:l,hybrid_gdi_printwindow_frames:o,hybrid_graphics_capture_frames_unique:d,hybrid_dxgi_frames_unique:c,hybrid_videohook_frames_unique:u,hybrid_gdi_bitblt_frames_unique:_,hybrid_gdi_printwindow_frames_unique:E,skip_history_json:A,quartz_frames:f,screencapturekit_frames:m,go_live_camera_frames:p,total_frames:y,total_frames_unique:k,desktop_capturer_type:h,media_session_id:G,rtc_connection_id:x,context:V.x.STREAM,activity:I,soundshare_session:this.soundshareStats.getStats().soundshare_last_session,picker_type_used:null!=this.analyticsContext.nativePickerStyleUsed?"native":"internal",duration:this.analyticsContext.getDuration(),share_game_name:D,share_game_id:b,share_game_exe:M,share_game_distributor:w,hdr_frames_capable:S,hdr_frames:N,discord_is_elevated:P.A.getDiscordIsElevated(),target_window_elevated:C,pipewire_frames:O,x11_frames:R,videohook_backend:L,...T})})}),this._connection?.on(d.yq.SoundshareAttached,()=>{let e=L.Ay.getGoLiveSource();e?.desktopSource!=null&&v.default.track(U.HAw.SOUNDSHARE_ATTACHED,{...(0,F.A)(e?.desktopSource),...this.getSoundshareAnalyticsProperties()})}),this._connection?.on(d.yq.SoundshareFailed,e=>{let{failureCode:t,failureReason:n,willRetry:i}=e,r=L.Ay.getGoLiveSource();this.reportSoundshareFailure(r?.desktopSource,t,n,i)}),this._connection?.on(d.yq.SoundshareSpeaking,()=>{let e=L.Ay.getGoLiveSource();e?.desktopSource!=null&&(v.default.track(U.HAw.SOUNDSHARE_TRANSMITTING,{...(0,F.A)(e?.desktopSource),...this.getSoundshareAnalyticsProperties()}),null!=R.A.getHookError(U.LU7.SOUND)&&c.h.dispatch({type:"MEDIA_ENGINE_SOUNDSHARE_TRANSMITTING"}))}),this._connection?.on(d.yq.SoundshareTrace,e=>{let t=L.Ay.getGoLiveSource();switch(this.soundshareStats.traceEvent(t?.desktopSource?.soundshareSession,e),e.type){case"soundshare_attach_requested":this.errorTimer.start(H,()=>{c.h.dispatch({type:"MEDIA_ENGINE_SOUNDSHARE_FAILED",errorMessage:"Sound Hook Failed"})});break;case"soundshare_recv_failed":let n=e.reason,i=e.code,r=e.retry;t?.desktopSource!=null&&(this.reportSoundshareFailure(t?.desktopSource,i,n,r),r||(this.errorTimer.stop(),c.h.dispatch({type:"MEDIA_ENGINE_SOUNDSHARE_FAILED",errorMessage:n,errorCode:i})));break;case"soundshare_state_transition":4===e.newState&&(this.errorTimer.stop(),c.h.dispatch({type:"MEDIA_ENGINE_SOUNDSHARE_TRANSMITTING"}))}}),this._connection?.on(d.yq.FirstFrameStats,e=>{if(this._firstFrameDelivered)return;this._firstFrameDelivered=!0;let t=this.getStreamAnalyticsProperties();v.default.track(U.HAw.RECEIVER_FIRST_FRAME_DELIVERED,{guild_id:t.guild_id,channel_id:t.channel_id,rtc_connection_id:t.rtc_connection_id,media_session_id:t.media_session_id,parent_media_session_id:t.parent_media_session_id,num_viewers:this.analyticsContext.numViewers,time_connected_to_first_frame_delivered:this.getDuration(),time_total_to_first_frame:(0,_.tB)()-this.getCreatedTime(),time_remote_user_to_video_stream_created:void 0!==e.remoteVideoStreamCreatedTimestamp&&void 0!==e.remoteUserCreatedTimestamp?Number(e.remoteVideoStreamCreatedTimestamp-e.remoteUserCreatedTimestamp):null,time_video_stream_created_to_video_data_received:void 0!==e.videoDataReceivedTimestamp&&void 0!==e.remoteVideoStreamCreatedTimestamp?Number(e.videoDataReceivedTimestamp-e.remoteVideoStreamCreatedTimestamp):null,time_video_data_received_to_video_source_delivered_frame:void 0!==e.videoSourceDeliveredFrameTimestamp&&void 0!==e.videoDataReceivedTimestamp?Number(e.videoSourceDeliveredFrameTimestamp-e.videoDataReceivedTimestamp):null,time_remote_user_to_mls_external_sender_updated:void 0!==e.updateMLSExternalSenderTimestamp&&void 0!==e.remoteUserCreatedTimestamp?Number(e.updateMLSExternalSenderTimestamp-e.remoteUserCreatedTimestamp):null,time_remote_user_to_secure_frame_remote_key_ratchet_set:void 0!==e.setRemoteSecureFrameKeyRatchetTimestamp&&void 0!==e.remoteUserCreatedTimestamp?Number(e.setRemoteSecureFrameKeyRatchetTimestamp-e.remoteUserCreatedTimestamp):null,time_remote_user_to_secure_frame_local_key_ratchet_set:void 0!==e.setLocalSecureFrameKeyRatchetTimestamp&&void 0!==e.remoteUserCreatedTimestamp?Number(e.setLocalSecureFrameKeyRatchetTimestamp-e.remoteUserCreatedTimestamp):null,time_remote_user_to_first_frame_decrypted:void 0!==e.firstFrameDecryptedTimestamp&&void 0!==e.remoteUserCreatedTimestamp?Number(e.firstFrameDecryptedTimestamp-e.remoteUserCreatedTimestamp):null})}),this._connection?.on(d.yq.FirstFrameEncryptedStats,e=>{let t=this.getStreamAnalyticsProperties();v.default.track(U.HAw.STREAMER_FIRST_FRAME_ENCRYPTED,{guild_id:t.guild_id,channel_id:t.channel_id,rtc_connection_id:t.rtc_connection_id,media_session_id:t.media_session_id,parent_media_session_id:t.parent_media_session_id,time_local_user_to_video_receivers_set:void 0!==e.videoReceiversSetTimestamp&&void 0!==e.localUserCreatedTimestamp?Number(e.videoReceiversSetTimestamp-e.localUserCreatedTimestamp):null,time_local_user_to_mls_external_sender_updated:void 0!==e.updateMLSExternalSenderTimestamp&&void 0!==e.localUserCreatedTimestamp?Number(e.updateMLSExternalSenderTimestamp-e.localUserCreatedTimestamp):null,time_local_user_to_secure_frame_remote_key_ratchet_set:void 0!==e.setRemoteSecureFrameKeyRatchetTimestamp&&void 0!==e.localUserCreatedTimestamp?Number(e.setRemoteSecureFrameKeyRatchetTimestamp-e.localUserCreatedTimestamp):null,time_local_user_to_secure_frame_local_key_ratchet_set:void 0!==e.setLocalSecureFrameKeyRatchetTimestamp&&void 0!==e.localUserCreatedTimestamp?Number(e.setLocalSecureFrameKeyRatchetTimestamp-e.localUserCreatedTimestamp):null,time_local_user_to_first_frame_encrypted:void 0!==e.firstFrameEncryptedTimestamp&&void 0!==e.localUserCreatedTimestamp?Number(e.firstFrameEncryptedTimestamp-e.localUserCreatedTimestamp):null})}),this._connection?.on(d.yq.Destroy,()=>{this.errorTimer.stop()}))}),this.on(f.q.Video,(t,n,i,r,a)=>{let s=(0,x.Iy)(this.streamKey);s.guildId===t&&s.channelId===n&&s.ownerId===i&&(null==this.getMediaSessionId()||e||(this.trackVideoStartStats(),e=!0),this.updateVideoStreamId(r,a))}),this.on(f.q.VideoSourceQualityChanged,(e,t,n,i,r,a)=>{let s=n===C.default.getId();c.h.dispatch({type:"MEDIA_ENGINE_VIDEO_SOURCE_QUALITY_CHANGED",guildId:e,channelId:t,senderUserId:n,maxResolution:s?(0,k.A)("StreamRTCConnection",e,i,r):i,maxFrameRate:r,context:a})}),this.on(f.q.SecureFramesUpdate,()=>{c.h.dispatch({type:"RTC_CONNECTION_SECURE_FRAMES_UPDATE"})}),this.on(f.q.RosterMapUpdate,e=>{c.h.dispatch({type:"RTC_CONNECTION_ROSTER_MAP_UPDATE",userIds:e})})}reportSoundshareFailure(e,t,n,i){let r=e?.soundshareSession??"";null==this.soundshareFailuresReported[r]&&(this.soundshareFailuresReported[r]=new Set);let a=null!=t&&!this.soundshareFailuresReported[r].has(t);a&&this.soundshareFailuresReported[r].add(t),(null==t||a)&&v.default.track(U.HAw.SOUNDSHARE_FAILED,{soundshare_failure_code:t,soundshare_failure_reason:n,soundshare_failure_will_retry:i,...(0,F.A)(e),...this.getSoundshareAnalyticsProperties()})}getStreamAnalyticsProperties(){let{streamRegion:e,streamApplication:t,streamSourceType:n,actionContext:i}=this.analyticsContext,{ownerId:r,guildId:a}=this.streamContext,s=b.A.getRegion(D.A.getHostname()),{gameName:l,gameId:o,exe:d,distributor:c,sku:u,gameMetadata:_}=(0,g.wH)(t);return{channel_id:this.channelId,rtc_connection_id:this.getRTCConnectionId(),media_session_id:this.getMediaSessionId(),parent_media_session_id:this.parentMediaSessionId,sender_user_id:r,context:V.x.STREAM,guild_id:a,stream_region:e,stream_source_type:n,guild_region:s,participant_type:this.isOwner?"streamer":"receiver",share_application_name:l,share_application_id:o,share_application_executable:d,share_application_distributor:c,share_application_distributor_game_id:u,share_application_game_metadata:_,video_layout:this.videoStreamStats.getLayout(),client_event_source:i,voice_backend_version:this.voiceVersion,rtc_worker_backend_version:this.rtcWorkerVersion}}getSoundshareAnalyticsProperties(){return{rtc_connection_id:this.getRTCConnectionId(),soundshare_experimental:L.Ay.getExperimentalSoundshare()}}trackVideoStartStats(){let e=this.isOwner?B():null;v.default.track(U.HAw.VIDEO_STREAM_STARTED,{...this.getStreamAnalyticsProperties(),...e,connection_type:y.A.getType(),effective_connection_speed:y.A.getEffectiveConnectionSpeed(),service_provider:y.A.getServiceProvider(),duration_go_live_modal:this.analyticsContext.goLiveModalDurationMs,source_location_stack:this.analyticsContext.analyticsLocations})}_collectVideoStreamEndedEvents(e){let t={senders:[],receivers:new Map,callEnded:null},n=O.A.getChannel(this.channelId),i=null!=n?n.type:null,{ownerId:r}=this.streamContext,a=e.getNetworkStats(),s=this.isOwner?e.getCodecUsageStats("streamer",this.userId):e.getCodecUsageStats("receiver",r),l=I.Ay.getSettings(),o=this.isOwner?{clips_enabled:(0,p.T)(),clips_buffer_length:l.clipsLength}:{},d=this.isOwner?{bandwidth_estimation_experiment:this.getBandwidthEstimationExperiment()}:{};return e.getOutboundStats().forEach(e=>{(e.num_frames??0)>0&&t.senders.push({...s,...a,...null,...this.videoStreamStats.getStats(),...e,...this.soundshareStats.getStats(),...this.getStreamAnalyticsProperties(),...o,...d,app_hardware_acceleration_enabled:P.A.getAppHardwareAccelerationEnabled(),channel_type:i,max_viewers:this.analyticsContext.maxViewers,hostname:this.hostname,hardware_enabled:L.Ay.getHardwareEncoding(),device_performance_class:this.isOwner?(0,m.A)():null,soundshare_experimental:L.Ay.getExperimentalSoundshare(),quality_preset:S.A.getState().preset,discord_is_elevated:P.A.getDiscordIsElevated()})}),e.getInboundParticipants().forEach(n=>{let r=e.getInboundStats(n);(r?.num_frames??0)>0&&t.receivers.set(n,{...s,...a,...null,...this.videoStreamStats.getStats(),...r,...this.soundshareStats.getStats(),...this.getStreamAnalyticsProperties(),...o,...d,app_hardware_acceleration_enabled:P.A.getAppHardwareAccelerationEnabled(),channel_type:i,max_viewers:this.analyticsContext.maxViewers,hostname:this.hostname,hardware_enabled:L.Ay.getHardwareEncoding(),device_performance_class:this.isOwner?(0,m.A)():null})}),t}getExtraConnectionOptions(){return{streamUserId:(0,x.Iy)(this.streamKey).ownerId}}getMediaStreamKey(){return this.streamKey}isStreamSender(){return this.isOwner}sendVideo(e,t,n,i){super.sendVideo(e,t,n,i.map(e=>null!=e.maxResolution&&null!=e.maxFrameRate?{...e,maxResolution:(0,k.A)("StreamRTCConnection",this.guildId,e.maxResolution,e.maxFrameRate)}:e))}}var Y=n(834757),K=n(254057),$=n(723702),X=n(290863),z=n(55010);let q={},Q={},J={},Z={},ee={},et={},en=U.SO9.THEATRE,ei={};function er(){l().forEach(ei,(e,t)=>{e.destroy(e.isOwner?"sender-disconnect":"receiver-disconnect"),delete ei[t],delete et[t]})}function ea(){return!0}class es extends o.Ay.Store{initialize(){this.waitFor(C.default,L.Ay,D.A,u.Ay)}static displayName="StreamRTCConnectionStore";getRTCConnections(){return ei}getAllActiveStreamKeys(){return Object.keys(ei)}getRTCConnection(e){return ei[e]}getQuality(e){return(0,K.A)(L.Ay)&&null!=e?ei[e]?.quality??U.bFR.UNKNOWN:U.bFR.UNKNOWN}getMediaSessionId(e){if(null==e)return null;let t=ei[e];if(null!=t)return null!=t?t.getMediaSessionId():null}getRtcConnectionId(e){if(null==e)return null;let t=ei[e];if(null!=t)return null!=t?t.getRTCConnectionId():null}getVideoStats(e){if(null==e)return null;let t=ei[e];return null!=t?t.getVideoStats():null}getHostname(e){if(null==e)return"";let t=ei[e];return null!=t&&null!=t.hostname?t.hostname:""}getRegion(e){if(null==e)return null;let t=ei[e];return null!=t?t.getRegion():null}getMaxViewers(e){if(null==e)return null;let t=ei[e];return null!=t?t.getMaxViewers():null}getStreamSourceId(e){return Z[e]}getLastNonZeroRemoteVideoSinkWantsTime(e){return et[e]}getUserIds(e){let t=ei[e];return t?.getUserIds()}isUserConnected(e,t){let n=ei[e];return n?.getIsUserConnected(t)}getSecureFramesState(e){let t=ei[e];return t?.getSecureFramesState()}getSecureFramesRosterMapEntry(e,t){let n=ei[e],i=n?.getSecureFramesRosterMap();return i?.get(t)}getStreamPid(e){return J[e]}}let el=new es(c.h,!L.Ay.isSupported()||__OVERLAY__?{}:{CONNECTION_OPEN:function(e){i=e.sessionId,er()},CONNECTION_CLOSED:function(){i=null,er()},RTC_CONNECTION_STATE:ea,RTC_CONNECTION_PING:ea,RTC_CONNECTION_LOSS_RATE:ea,RTC_CONNECTION_UPDATE_ID:function(e){return l().some(ei,t=>t===e.connection)},RTC_CONNECTION_SECURE_FRAMES_UPDATE:ea,RTC_CONNECTION_REMOTE_VIDEO_SINK_WANTS:function(e){let{context:t,wants:n,userId:i,guildId:r,channelId:a}=e,s=(0,x._z)({streamType:null==r?z.U4.CALL:z.U4.GUILD,guildId:r,channelId:a,ownerId:i});if(t!==d.x.STREAM||null==ei[s]||!Object.entries(n).some(e=>{let[t,n]=e;return"any"!==t&&0!==n}))return!1;et[s]=performance.now()},STREAM_START:function(e){let{streamType:t,guildId:n,channelId:i,appContext:r,pid:a,sourceId:s,sourcePid:o,nativePickerStyleUsed:d,goLiveModalDurationMs:c,analyticsLocations:_}=e,E=(0,x._z)({streamType:t,guildId:n,channelId:i,ownerId:C.default.getId()});if(q[E]={appContext:r,analyticsLocations:_},l().forEach(ei,e=>{let{analyticsContext:t,isOwner:n}=e;t.setActionContext(r),t.setNativePickerStyleUsed(d),n&&t.trackStart()}),null==a&&(a=o),Z[E]=s,J[E]=a,null!=a){let e=u.Ay.getGameForPID(a);null!=e&&(Q[E]={name:e.name,id:e.id,exe:e.exeName,distributor:e.distributor,sku:e.sku,gameMetadata:e.gameMetadata}),ei[E]?.analyticsContext.updateStreamApplication(Q[E])}else ei[E]?.analyticsContext.updateStreamApplication(null);null!=c?ee[E]=c:delete ee[E]},STREAM_STOP:function(e){let{appContext:t,streamKey:n}=e;q[n]={appContext:t,analyticsLocations:void 0},l().forEach(ei,e=>{let{analyticsContext:n,isOwner:i}=e;n.setActionContext(t),i&&n.trackEnd()}),Z[n]=null,J[n]=null,delete ee[n]},STREAM_WATCH:function(e){let{streamKey:t,analyticsLocations:n}=e;return(0,x.Iy)(t).ownerId!==C.default.getId()&&(q[t]={appContext:q[t]?.appContext,analyticsLocations:n},!1)},STREAM_CREATE:function(e){let{streamKey:t,rtcServerId:n,rtcChannelId:r,region:s,viewerIds:l}=e,o=ei[t],d=(0,x.Iy)(t);if(null==o&&null!=n){null==J[t]&&(Q[t]=null),null==Q[t]&&null==Z[t]&&(Q[t]=(0,Y.Ee)(d,X.A));let e=new j({streamRegion:s,streamApplication:Q[t],streamSourceType:function(e){if(null==e)return"unknown";if($.isPlatformEmbedded||platform?.name==="Chrome"){if(e.startsWith("web-contents-media-stream:"))return"tab";else if(e.startsWith("window:"))return"window";else if(e.startsWith("screen:"))return"screen";else if(e.startsWith("activity:"))return"activity"}else if(platform?.name==="Firefox")if(""!==e)return"window";else return"screen";else if(platform?.name==="Safari")return"window";return"unknown"}(Z[t]),actionContext:q[t]?.appContext,numViewers:null!=l?l.length:0,goLiveModalDurationMs:ee[t],analyticsLocations:q[t]?.analyticsLocations});a()(null!=i,"Creating RTCConnection without session."),o=new W({sessionId:i,streamKey:t,serverId:n,channelId:r,initialLayout:en,analyticsContext:e,parentMediaSessionId:D.A.getMediaSessionId()}),ei[t]=o}delete et[t],c.h.dispatch({type:"MEDIA_ENGINE_CONNECTION_STATS_HISTORY_RESET",mediaEngineConnectionId:o.getMediaEngineConnectionId()})},STREAM_SERVER_UPDATE:function(e){let t=ei[e.streamKey];if(null==t)return!1;t.connect(e.endpoint,e.token)},STREAM_UPDATE:function(e){let{streamKey:t,viewerIds:n,paused:i}=e,r=ei[t];if(null==r)return!1;null!=n&&r.analyticsContext.trackViewerCount(n.length),r.streamUpdate(i)},STREAM_DELETE:function(e){let{streamKey:t}=e,n=ei[t];if(null==n)return!1;c.h.dispatch({type:"MEDIA_ENGINE_CONNECTION_STATS_HISTORY_RESET",mediaEngineConnectionId:n.getMediaEngineConnectionId()}),n.destroy("stream-end"),delete ei[t]},STREAM_LAYOUT_UPDATE:function(e){let{layout:t}=e;en=t,Object.values(ei).forEach(e=>e.layoutChange(t))},VIDEO_SIZE_UPDATE:function(e){let{streamId:t,dimensions:n,zoom:i}=e;l().forEach(ei,e=>{e?.setVideoSize(t,n,i)})}})}