Build 541270stable
Module 378187
7,687 characters · in no known chunkDependencies
Source Raw
function(e,t,n){"use strict";n.d(t,{A:()=>x});var i=n(412703),r=n(902173),s=n(439372),a=n(933958),o=n(952818),l=n(652896),u=n(227309),c=n(871633),d=n(616356),_=n(760751),f=n(607567),h=n(927813),p=n(403362),E=n(340124),m=n(859703),g=n(507107),A=n(759366),I=n(192444),T=n(590202),S=n(851936),N=n(710969),y=n(639214),C=n(792620),v=n(814793),O=n(190107);let R=+h.A.Millis.MINUTE,b=+h.A.Millis.SECOND,D=(0,S.L)({location:O.rE.QUESTS_MANAGER});function L(e){return!(0,N.Ic)(e)&&null!=e.userStatus&&null!=e.userStatus.enrolledAt&&null==e.userStatus.completedAt}function w(e){let t=A.A.getState().autoEnroll,{enabled:n}=I.Ym.getConfig({location:O.rE.QUEST_ACTIVITY_HEADER}),i=m.A.quests;for(let s of(0,y.jm)(i,e))if(s.config.features.includes(r.L.ACTIVITY_QUEST_AUTO_ENROLLMENT)&&!n||t&&1)return void(0,E.Oy)(s.id,{questContent:g.uF.RUNNING_ACTIVITY,questContentCTA:T.Cy.START_QUEST,sourceQuestContent:g.uF.RUNNING_ACTIVITY})}function M(e){return null!=e&&e.config.features.includes(r.L.MANUAL_HEARTBEAT_INITIALIZATION)}class P extends s.A{heartbeats={[i.n.PLAY_ON_DESKTOP]:new Map,[i.n.STREAM_ON_DESKTOP]:new Map,[i.n.PLAY_ACTIVITY]:new Map};calculateHeartbeatDurationMs=e=>{let t=m.A.quests.get(e);if(null==t||null==t.config||null==t.userStatus)return R;let{progressSeconds:n,targetSeconds:r}=(0,C.Yh)(t,i.o.DESKTOP),s=Math.max(0,(r-n)*h.A.Millis.SECOND);return s<=R?s+b:R};initiateHeartbeat=(e,t,n)=>{let r=this.heartbeats[t];if(r.has(e))return void D.log(`~ initiateHeartbeat -> Heartbeat already initiated for questId: ${e}`);let s=()=>{let a=this.getActivelyProgressingQuests(t);if(a.has(e)){let o=a.get(e),u=o?.applicationId??n?.applicationId,{enabled:c}=I.ev.getConfig({location:O.rE.QUESTS_MANAGER}),_=c?o?.executableFingerprint:void 0;if(t===i.n.STREAM_ON_DESKTOP){let n=d.A.getCurrentUserActiveStream();if(null==n){D.log(`~ initiateHeartbeat -> Attempted to beat for stream quest but no active stream, terminating heartbeat for questId: ${e}`),this.terminateHeartbeat(e,t);return}let i=(0,l._z)(n);D.log(`~ initiateHeartbeat -> Sending heartbeat for questId: ${e}`),(0,E.R2)({questId:e,streamKey:i,applicationId:u,executableFingerprint:_})}else D.log(`~ initiateHeartbeat -> Sending heartbeat for questId: ${e}`),(0,E.R2)({questId:e,applicationId:u,executableFingerprint:_});let f=this.calculateHeartbeatDurationMs(e),h=window.setTimeout(s,f);r.set(e,h)}else D.log(`~ initiateHeartbeat -> Quest ${e} is no longer actively progressing, terminating heartbeat`),this.terminateHeartbeat(e,t)};D.log(`~ initiateHeartbeat -> Initiating heartbeat for Quest ${e}`),s()};terminateHeartbeat=(e,t)=>{let n=this.heartbeats[t],i=m.A.quests,r=n.get(e);if(null!=r){D.log(`~ terminateHeartbeat -> Terminating heartbeat for questId: ${e}`),window.clearTimeout(r),n.delete(e);let t=i.get(e);null!=t&&L(t)&&(D.log(`~ terminateHeartbeat -> Sending terminal heartbeat for questId: ${e}`),(0,E.R2)({questId:e,terminal:!0}))}};handleSendHeartbeatSuccess=e=>{let{questId:t,userStatus:n}=e;if(D.log(`~ handleSendHeartbeatSuccess -> Heartbeat succeeded for questId: ${t})`),null!=n.completedAt)for(let e of(D.log(`~ handleSendHeartbeatSuccess -> Quest ${t} completed, terminating any heartbeats for it`),Object.keys(this.heartbeats)))this.terminateHeartbeat(t,e)};handleSendHeartbeatFailure=e=>{let{questId:t}=e;D.log(`~ handleSendHeartbeatFailure -> Heartbeat failed for questId: ${t}`)};syncHeartbeats(e,t,n){for(let i of("VOICE_STATE_UPDATES"!==t&&"PASSIVE_UPDATE_V2"!==t&&D.log(`~ syncHeartbeats -> syncing heartbeats for taskTypes: ${e.join(", ")} (triggered by: ${t})`),e)){let e=this.heartbeats[i],t=this.getActivelyProgressingQuests(i);for(let n of new Set(e.keys()))t.has(n)||this.terminateHeartbeat(n,i);for(let[r,s]of t.entries())!e.has(r)&&(null==n||n(m.A.quests.get(r)))&&this.initiateHeartbeat(r,i,s)}}getActivelyProgressingQuests(e){switch(e){case i.n.PLAY_ON_DESKTOP:return this.getActivelyProgressingPlayOnDesktopQuests();case i.n.STREAM_ON_DESKTOP:return this.getActivelyProgressingStreamOnDesktopQuests();case i.n.PLAY_ACTIVITY:return this.getActivelyProgressingActivityQuests();default:(0,p.xb)(e)}}getActivelyProgressingPlayOnDesktopQuests(){let e=new Map,t=o.Ay.getRunningGames(),n=o.Ay.getRunningNonGames(),i=m.A.quests;D.log("~ getActivelyProgressingPlayOnDesktopQuestIds -> Running games: ",t,"Running non-games: ",n);let r={};for(let e of t){if(e.isLauncher)continue;if(null!=e.id){r[e.id]=e;continue}let t=o.Ay.getOverrideForGame(e);if(null==e.distributor&&null!=t)continue;let n=_.A.findGame(e);if(n?.id!=null){r[n.id]=e;continue}}for(let e of n)null!=e.id&&(r[e.id]=e);for(let t of Object.keys(r)){let n=r[t];for(let r of i.values()){let i=(0,C.pU)(r);if(!L(r)||null==i)continue;let s=i.find(e=>e===t);if(null!=s)e.set(r.id,{applicationId:s,executableFingerprint:n.executableFingerprint});else null!=n&&i.some(e=>e===u.a7)&&(0,c.n1)(n)&&e.set(r.id,{applicationId:u.a7,executableFingerprint:n.executableFingerprint})}}return D.log("~ getActivelyProgressingPlayOnDesktopQuestIds -> Actively progressing questIds: ",Array.from(e.keys())),e}getActivelyProgressingStreamOnDesktopQuests(){let e=new Map,t=d.A.getCurrentUserActiveStream();if(null==t||2>f.Ay.countVoiceStatesForChannel(t.channelId))return e;let n=d.A.getStreamerActiveStreamMetadata();if(null==n)return e;D.log("~ getActivelyProgressingStreamOnDesktopQuestIds -> Active stream metadata: ",n);let i=n.id;if(null==i)return e;for(let t of m.A.quests.values()){let n=(0,C.a2)(t);L(t)&&null!=n&&n===i&&e.set(t.id,{applicationId:i})}return D.log("~ getActivelyProgressingStreamOnDesktopQuestIds -> Actively progressing questIds: ",Array.from(e.keys())),e}getActivelyProgressingActivityQuests(){let e=new Map,t=a.Ay.getSelfEmbeddedActivities(),n=t.size>0;if(D.log("~ getActivelyProgressingActivityQuestIds -> Embedded activities: ",t),!n)return e;let i=m.A.quests;for(let n of t.keys())for(let t of i.values()){let i=(0,C.vS)(t);L(t)&&null!=i&&i===n&&e.set(t.id,{applicationId:n})}for(let t of i.values())L(t)&&(0,v._e)(t)&&e.set(t.id,{applicationId:O.ej});return D.log("~ getActivelyProgressingActivityQuestIds -> Actively progressing questIds: ",Array.from(e.keys())),e}actions={QUESTS_FETCH_CURRENT_QUESTS_SUCCESS:()=>this.syncHeartbeats([i.n.PLAY_ON_DESKTOP,i.n.STREAM_ON_DESKTOP],"QUESTS_FETCH_CURRENT_QUESTS_SUCCESS"),QUESTS_ENROLL_SUCCESS:()=>this.syncHeartbeats([i.n.PLAY_ON_DESKTOP,i.n.STREAM_ON_DESKTOP,i.n.PLAY_ACTIVITY],"QUESTS_ENROLL_SUCCESS",e=>!M(e)),QUESTS_SEND_HEARTBEAT_SUCCESS:this.handleSendHeartbeatSuccess,QUESTS_SEND_HEARTBEAT_FAILURE:this.handleSendHeartbeatFailure,QUESTS_PREVIEW_UPDATE_SUCCESS:()=>this.syncHeartbeats([i.n.PLAY_ON_DESKTOP,i.n.STREAM_ON_DESKTOP,i.n.PLAY_ACTIVITY],"QUESTS_PREVIEW_UPDATE_SUCCESS"),RUNNING_GAMES_CHANGE:()=>this.syncHeartbeats([i.n.PLAY_ON_DESKTOP],"RUNNING_GAMES_CHANGE"),RUNNING_NON_GAMES_CHANGE:()=>this.syncHeartbeats([i.n.PLAY_ON_DESKTOP],"RUNNING_NON_GAMES_CHANGE"),STREAM_START:()=>this.syncHeartbeats([i.n.STREAM_ON_DESKTOP],"STREAM_START"),STREAM_CREATE:()=>this.syncHeartbeats([i.n.STREAM_ON_DESKTOP],"STREAM_CREATE"),STREAM_CLOSE:()=>this.syncHeartbeats([i.n.STREAM_ON_DESKTOP],"STREAM_CLOSE"),PASSIVE_UPDATE_V2:()=>this.syncHeartbeats([i.n.STREAM_ON_DESKTOP],"PASSIVE_UPDATE_V2"),VOICE_STATE_UPDATES:()=>this.syncHeartbeats([i.n.STREAM_ON_DESKTOP],"VOICE_STATE_UPDATES"),EMBEDDED_ACTIVITY_LAUNCH_SUCCESS:e=>{let{applicationId:t}=e;w(t)},FRAME_LAUNCH:e=>{let{applicationId:t}=e;w(t)},EMBEDDED_ACTIVITY_UPDATE_V2:()=>this.syncHeartbeats([i.n.PLAY_ACTIVITY],"EMBEDDED_ACTIVITY_UPDATE_V2",e=>!M(e)),QUEST_APPLICATION_START_TIMER:e=>{let{questId:t}=e;this.syncHeartbeats([i.n.PLAY_ACTIVITY],"QUEST_APPLICATION_START_TIMER",e=>null!=e&&e.id===t&&M(e))}}}let x=new P}