Loading
function(e,t,n){"use strict";n.d(t,{Ay:()=>q,xt:()=>X});var i=n(488428),r=n(562708),a=n(179771),s=n(665260),l=n(636537),o=n(933681),d=n(73153),c=n(62583),u=n(627363),_=n(587895),E=n(306044),A=n(626584),h=n(625180),f=n(25451),I=n(953384),p=n(952818),T=n(773669),m=n(134861),g=n(760751),S=n(189081),N=n(340829),C=n(174459),O=n(339586),R=n(723702),L=n(499785),y=n(308368),D=n(933958),v=n(969151),b=n(55730);async function M(e){if(!_.A.isHydrated(e))try{await (0,u.TA)(e)}catch{}return _.A.getApplication(e)}var P=n(966563),U=n(290863),w=n(652215);async function G(e){let{userId:t,sessionId:n,applicationId:i,channelId:r,messageId:a,intent:s}=e,l=e.activity??U.A.getApplicationActivity(t,i);if(!(e.embedded??(0,b.A)(l,w.jUm.EMBEDDED))||!(0,f.X)(await M(i)))return null;let o=D.Ay.getEmbeddedActivityForUserId(t,i,!0);return null!=o?(0,c.A)({applicationId:i,activityChannelId:(0,v.H)(o.location),source:e.source,locationObject:e.locationObject??{},analyticsLocations:e.analyticsLocations??[]}):(0,P.A)({application:{id:i},userId:t,activity:l,sessionId:n,channelId:r,messageId:a,intent:s})}var x=n(59636),k=n(912851),F=n(818023),B=n(165610);let V=(0,n(403362).iT)()?void 0:window.GLOBAL_ENV.CDN_HOST;function H(e,t){return null!=V?`https://${V}${e}`:t}let j=H("/detectables/games.json",w.Rsh.GAMES_DETECTABLE),W=H("/detectables/non-games.json",w.Rsh.NON_GAMES_DETECTABLE);var Y=n(105292);let K=new A.A("GamesActionCreators");function $(e){let{applicationId:t,secret:n,joinUrl:i,channelId:r,intent:a=F.W9.PLAY,embedded:s=!1,source:l,locationObject:o,analyticsLocations:c,preferDeepLink:E=!1}=e;if(null!=i){try{if(i.startsWith("http")){let e=window.open(i,"_blank");(null==e||e.closed||void 0===e.closed)&&(window.location.href=i)}else window.location.href=i}catch(e){K.warn("Failed to open join URL",{applicationId:t,error:e.message}),d.h.dispatch({type:"ACTIVITY_JOIN_FAILED",applicationId:t})}return Promise.resolve()}if(E){let e=_.A.getApplication(t);if(e?.deepLinkUri!=null){let i=e.deepLinkUri.replace(/\/+$/,""),r=`${i}${w.O3O.GAME_INVITE_FRAGMENT}${n}`;try{if(r.startsWith("http")){let e=window.open(r,"_blank");(null==e||e.closed||void 0===e.closed)&&(K.warn("Deep link popup was blocked by browser, trying location.href",{applicationId:t}),window.location.href=r)}else window.location.href=r;return Promise.resolve()}catch(e){K.warn("Failed to open deep link, falling back to desktop launch",{applicationId:t,error:e.message})}}}z({applicationId:t,channelId:r,embedded:s,source:l,locationObject:o,analyticsLocations:c}).then(async e=>{if(0===e)return null;null==_.A.getApplication(t)&&await (0,u.TA)(t);let i=_.A.getApplication(t)?.parentId;return null!=i&&O.A.waitParentConnected(i).then(()=>O.A.waitParentSubscribed(i,w.ZE4.ACTIVITY_JOIN)).then(()=>{d.h.dispatch({type:"ACTIVITY_JOIN",applicationId:t,parentApplicationId:i,secret:n,intent:a,embedded:s})}).catch(()=>{}),d.h.dispatch({type:"ACTIVITY_JOIN_LOADING",applicationId:t}),O.A.waitConnected(t).then(()=>(d.h.dispatch({type:"ACTIVITY_JOIN_LOADING",applicationId:t}),O.A.waitSubscribed(t,w.ZE4.ACTIVITY_JOIN)))}).then(()=>{d.h.dispatch({type:"ACTIVITY_JOIN",applicationId:t,parentApplicationId:null,secret:n,intent:a,embedded:s})}).catch(()=>d.h.dispatch({type:"ACTIVITY_JOIN_FAILED",applicationId:t}))}async function z(e){let{applicationId:t,branchId:n,channelId:r,embedded:s=!1,source:o,locationObject:u={},analyticsLocations:E=[]}=e;if(s){let e=_.A.getApplication(t);return null!=e&&(0,f.X)(e)?(await h.A.launchFrame({applicationId:t,surface:B.sd}),0):await (0,c.A)({applicationId:t,activityChannelId:r??void 0,source:o,locationObject:u,analyticsLocations:E})?0:Promise.resolve()}if(m.A.isConnected(t))return Promise.resolve();let A=null;if(null==n){let e=S.A.getActiveLibraryApplication(t);n=null!=e?e.branchId:t}if(N.A.isLaunchable(t,n)){let e=N.A.getState(t,n),r=S.A.getActiveLaunchOptionId(t,n);if(null==e)throw Error("Missing dispatch game when launching");let s=S.A.getLibraryApplication(t,n);if(null==s)throw Error("Missing library application when launching");A=l.Bo.post({url:w.Rsh.OAUTH2_AUTHORIZE,query:{client_id:t,response_type:"token",scope:[a.F.IDENTIFY].join(" ")},retries:3,body:{authorize:!0},oldFormErrors:!0,rejectWithError:(0,l.fT)()}).then(e=>{let t=e.body.location.split(/#|\?/),n=i.parse(t[t.length-1]);if("invalid_request"===n.error)return null;if(null!=n.error)throw Error(`OAuth2 Error: ${n.error}: ${n.error_description??"unknown error"}`);return n.access_token},e=>{if(404===e.status)return null;throw e}).then(t=>O.A.launchDispatchApplication(e,t,T.default.locale,s.getBranchName(),r))}else{let e=_.A.getApplication(t);if(null!=e){A=O.A.launch(e);let n=g.A.getOfficialGame(e);null!=n&&n.id!==t&&(A=A.catch(()=>O.A.launch(n)))}else A=O.A.launchGame(t)}let I=Error("game not found");return null!=A?(d.h.dispatch({type:"LIBRARY_APPLICATION_ACTIVE_BRANCH_UPDATE",applicationId:t,branchId:n}),d.h.dispatch({type:"GAME_LAUNCH_START",applicationId:t}),A.then(e=>{d.h.dispatch({type:"GAME_LAUNCH_SUCCESS",applicationId:t,pids:e})}).catch(e=>{k.A.show(w.kqX.LAUNCH_GAME_FAILURE,Y.intl.string(Y.t.YZEBdj)),d.h.dispatch({type:"GAME_LAUNCH_FAIL",applicationId:t,error:I})})):(d.h.dispatch({type:"GAME_LAUNCH_FAIL",applicationId:t,error:I}),Promise.reject(I))}function X(e){d.h.dispatch({type:"RUNNING_GAME_SET_DEBUG_GAME",game:e})}let q={addGame(e,t){d.h.dispatch({type:"RUNNING_GAME_ADD_OVERRIDE",pid:e}),C.default.track(w.HAw.RUNNING_GAME_OVERRIDE_ADDED,{game_name:t})},toggleOverlay(e,t,n){let i=(0,p.Zh)(e),r=g.A.findGame(i);if(null!=r){let e=S.A.getActiveLibraryApplication(r.id);if(null!=e){let i=e.getFlags(),r=s.Lt(i,w.hM6.OVERLAY_DISABLED);t&&r!==t&&(i=s.PQ(i,w.hM6.OVERLAY_DISABLED));let a=s.Lt(i,w.hM6.OVERLAY_V3_DISABLED);null!=n&&n!==a&&(i=s.PQ(i,w.hM6.OVERLAY_V3_DISABLED)),x.V(e.id,e.branchId,i);return}}d.h.dispatch({type:"RUNNING_GAME_TOGGLE_OVERLAY",game:i,newLegacyOverlayEnabledValue:t,newOverlayV3EnabledValue:n})},toggleDetection(e){d.h.dispatch({type:"RUNNING_GAME_TOGGLE_DETECTION",game:e})},editName(e,t){d.h.dispatch({type:"RUNNING_GAME_EDIT_NAME",game:e,newName:t})},identifyGame:(e,t)=>(0,E.A)().then(t=>new Promise((n,i)=>{null==t?i(Error("Game utils module not loaded")):t.identifyGame(e,(t,r)=>{(K.log("Identified game: ",{status:t,name:r.name,iconHash:r.iconHash,sku:r.sku,executableName:r.executableName,distributor:r.distributor,publisher:r.publisher}),0!==t)?i(Error(`Error ${t} when fetching info on ${e}`)):null==r.icon||""===r.icon||null==r.name||""===r.name?i(Error(`Did not find data on ${e}`)):n(r)})})),getDetectableGames(){if(!g.A.canFetchDetectableGames())return;let e=g.A.detectableGamesEtag;d.h.dispatch({type:"GAMES_DATABASE_FETCH"}),L.A.get({url:null!=V?`https://${V}/detectables/games-v1.json`:j,headers:{"If-None-Match":e},retries:1,oldFormErrors:!0,trackedActionData:{event:r.NetworkActionNames.DETECTABLE_APPLICATIONS_FETCH,properties:t=>(0,o.e0)({sent_etag:e,received_etag:t?.headers?.etag})},rejectWithError:(0,l.fT)()}).then(e=>{let{body:t,headers:{etag:n}}=e;d.h.dispatch({type:"GAMES_DATABASE_UPDATE",games:t,etag:n})},e=>{let{status:t}=e;304===t?d.h.dispatch({type:"GAMES_DATABASE_UPDATE",games:[],etag:g.A.detectableGamesEtag}):d.h.dispatch({type:"GAMES_DATABASE_FETCH_FAIL"})})},getDetectableBlocklist(){if(!g.A.canFetchExecutableBlocklist())return;let e=g.A.blocklistEtag;d.h.dispatch({type:"GAMES_BLOCKLIST_FETCH"}),l.Bo.get({url:w.Rsh.GAMES_BLOCKLIST,headers:{"If-None-Match":e},oldFormErrors:!0,rejectWithError:(0,l.fT)()}).then(e=>{let{body:t,headers:{etag:n}}=e;d.h.dispatch({type:"GAMES_BLOCKLIST_UPDATE",executables:t.executables??[],patterns:t.patterns??[],etag:n})},e=>{let{status:t}=e;304===t?d.h.dispatch({type:"GAMES_BLOCKLIST_UPDATE",executables:[],patterns:[],etag:g.A.blocklistEtag}):(K.error("Failed to fetch games blocklist"),d.h.dispatch({type:"GAMES_BLOCKLIST_FETCH_FAIL"}))})},getDetectableNonGames(){if(!I.A.canFetch())return;let e=I.A.etag;d.h.dispatch({type:"NON_GAMES_DATABASE_FETCH"}),L.A.get({url:null!=V?`https://${V}/detectables/non-games-v1.json`:W,headers:{"If-None-Match":e},retries:1,trackedActionData:{event:r.NetworkActionNames.DETECTABLE_NON_GAMES_FETCH,properties:t=>(0,o.e0)({sent_etag:e,received_etag:t?.headers?.etag})},rejectWithError:(0,l.fT)()}).then(e=>{let{body:t,headers:{etag:n}}=e;d.h.dispatch({type:"NON_GAMES_DATABASE_UPDATE",nonGames:t,etag:n})},e=>{let{status:t}=e;304===t?d.h.dispatch({type:"NON_GAMES_DATABASE_UPDATE",nonGames:[],etag:I.A.etag}):d.h.dispatch({type:"NON_GAMES_DATABASE_FETCH_FAIL"})})},deleteEntry(e){d.h.dispatch({type:"RUNNING_GAME_DELETE_ENTRY",game:e})},launch:z,async join(e){let{userId:t,sessionId:n,applicationId:i,channelId:r,messageId:a,intent:s=F.W9.PLAY,embedded:l=!1,source:o,locationObject:c,analyticsLocations:u,remotePartyId:_}=e;if(__OVERLAY__)return d.h.dispatch({type:"OVERLAY_JOIN_GAME",userId:t,sessionId:n,applicationId:i,channelId:r,messageId:a}),Promise.resolve(!0);let E=await G(e);if(null!=E)return E;d.h.dispatch({type:"ACTIVITY_JOIN_LOADING",applicationId:i,remotePartyId:_});try{let e=(0,R.platformPrefersDeepLink)(),{secret:d,joinUrl:E}=await y.A.getJoinSecret(t,n,i,r,a);return null==_&&$({applicationId:i,secret:d,joinUrl:E,channelId:r,intent:s,embedded:l,source:o,locationObject:c,analyticsLocations:u,preferDeepLink:e}),!0}catch(e){return d.h.dispatch({type:"ACTIVITY_JOIN_FAILED",applicationId:i}),!1}},joinWithSecret:$}}