-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #490 from SprocketBot/feat/scrims
Initial Implementations of Scrims
- Loading branch information
Showing
96 changed files
with
1,288 additions
and
362 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,10 @@ | ||
import type {Handle} from "@sveltejs/kit"; | ||
import type {Handle, HandleServerError} from "@sveltejs/kit"; | ||
import {sequence} from "@sveltejs/kit/hooks"; | ||
import {HoudiniSessionHook} from "./hooks/HoudiniSession.hook"; | ||
|
||
export const handle: Handle = sequence(HoudiniSessionHook); | ||
export const handleError: HandleServerError = ({error, event}) => { | ||
return { | ||
message: "An Error has occurred!", | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
import {browser} from "$app/environment"; | ||
import {RefreshLoginStore} from "$houdini"; | ||
import {updateAuthCookies} from "$lib/api"; | ||
import {getExpiryFromJwt} from "$lib/utilities/getExpiryFromJwt"; | ||
import type {ClientPlugin} from "$houdini"; | ||
|
||
export const refreshAuthPlugin: ClientPlugin = () => { | ||
return { | ||
beforeNetwork: async (ctx, b) => { | ||
const {next} = b; | ||
const {session} = ctx; | ||
|
||
// TODO: Actually check the thing | ||
if (!session?.access) { | ||
next(ctx); | ||
return; | ||
} | ||
const expAt = getExpiryFromJwt(session?.access); | ||
|
||
// If there is at least one minute on the token; do nothing | ||
if (expAt.getTime() > new Date().getTime() + 60 * 1000) { | ||
next(ctx); | ||
return; | ||
} | ||
if (ctx.artifact.name === "RefreshLogin") { | ||
console.debug("Avoiding infinite loop. Will not try to refresh auth before a refresh auth call."); | ||
next(ctx); | ||
return; | ||
} | ||
|
||
// Otherwise we need to refresh | ||
console.log("Attempting to refresh authentication"); | ||
|
||
if (session.refresh) { | ||
const s = new RefreshLoginStore(); | ||
try { | ||
const result = await s.mutate(null, { | ||
metadata: { | ||
accessTokenOverride: session.refresh, | ||
}, | ||
fetch: fetch ?? ctx.fetch, | ||
}); | ||
if (!result.data) { | ||
throw new Error( | ||
result.errors?.map(e => e.message).join("\n") ?? "Refresh Login Response Empty", | ||
); | ||
} | ||
|
||
if (!ctx.session) ctx.session = {}; | ||
ctx.session.access = result.data.refreshLogin.access; | ||
ctx.session.refresh = result.data.refreshLogin.refresh; | ||
|
||
if (browser) { | ||
updateAuthCookies(result.data.refreshLogin); | ||
} else { | ||
// How do I set cookies here | ||
console.warn( | ||
"Failed to persist auth cookie updates. Setting cookies in a plugin is not possible?", | ||
); | ||
} | ||
console.debug("Auth has been refreshed"); | ||
} catch (e) { | ||
console.warn("Failed to refresh auth token!", e); | ||
} | ||
} else { | ||
console.debug("Skipping Auth Refresh"); | ||
} | ||
|
||
next(ctx); | ||
}, | ||
}; | ||
}; |
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from "./UserInfo.context"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export * from "./UserInfo"; | ||
export * from "./utils"; |
File renamed without changes.
21 changes: 21 additions & 0 deletions
21
clients/web/src/lib/api/authentication/utils/auth-refresh-interval.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import {onMount} from "svelte"; | ||
import {RefreshLoginStore} from "$houdini"; | ||
import {getAuthCookies, updateAuthCookies} from "./auth-cookies"; | ||
|
||
export const authIntervalRefresh = () => | ||
onMount(() => { | ||
const refreshStore = new RefreshLoginStore(); | ||
|
||
const refreshAuth = async () => { | ||
const {refresh} = getAuthCookies(); | ||
const r = await refreshStore.mutate(null, {metadata: {accessTokenOverride: refresh}}); | ||
if (!r.data) return; | ||
console.debug("Auth Refreshed"); | ||
updateAuthCookies(r.data?.refreshLogin); | ||
}; | ||
|
||
// Refresh auth token every 2 minutes | ||
const i = setInterval(refreshAuth, 1000 * 60 * 2); | ||
refreshAuth(); | ||
return () => clearInterval(i); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export * from "./auth-cookies"; | ||
export * from "./auth-refresh-interval"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
query MemberGames { | ||
getMemberGames @list(name: "MemberGames") { | ||
id | ||
title | ||
modes { | ||
id | ||
code | ||
description | ||
teamSize | ||
teamCount | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export * from "./authentication"; | ||
export * from "./scrims"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
mutation CreateScrim($options: CreateScrimInput!) { | ||
createScrim(data: $options) { | ||
id | ||
createdAt | ||
gameMode { | ||
description | ||
} | ||
maxPlayers | ||
playerCount | ||
settings { | ||
competitive | ||
mode | ||
observable | ||
teamCount | ||
teamSize | ||
} | ||
skillGroup { | ||
description | ||
} | ||
status | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
clients/web/src/lib/api/scrims/CurrentScrim/CurrentScrim.fragment.graphql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
fragment CurrentScrimFragment on ScrimObject { | ||
id | ||
author { | ||
displayName | ||
} | ||
playerCount | ||
maxPlayers | ||
status | ||
skillGroup { | ||
description | ||
} | ||
gameMode { | ||
description | ||
} | ||
settings { | ||
competitive | ||
mode | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
clients/web/src/lib/api/scrims/CurrentScrim/CurrentScrim.query.graphql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
query CurrentScrim { | ||
getCurrentScrim { | ||
...CurrentScrimFragment @mask_disable | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
clients/web/src/lib/api/scrims/CurrentScrim/CurrentScrim.subscription.graphql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
subscription CurrentScrimSub { | ||
followCurrentScrim { | ||
scrim { | ||
...CurrentScrimFragment @mask_disable | ||
} | ||
event | ||
} | ||
} |
37 changes: 37 additions & 0 deletions
37
clients/web/src/lib/api/scrims/CurrentScrim/CurrentScrims.Live.store.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import {readable, type Readable} from "svelte/store"; | ||
import type {CurrentScrim$result, CurrentScrimStore, CurrentScrimSub$result, CurrentScrimSubStore} from "$houdini"; | ||
|
||
export const CurrentScrimLiveStore = ( | ||
queryStore: CurrentScrimStore, | ||
subStore: CurrentScrimSubStore, | ||
eventMap?: Partial<Record<CurrentScrimSub$result["followCurrentScrim"]["event"], () => void>>, | ||
): Readable<CurrentScrim$result["getCurrentScrim"]> => { | ||
return readable<CurrentScrim$result["getCurrentScrim"]>(null, set => { | ||
const queryUnsub = queryStore.subscribe($q => { | ||
if ($q.data?.getCurrentScrim) { | ||
set($q.data?.getCurrentScrim); | ||
} | ||
}); | ||
const subUnsub = subStore.subscribe($s => { | ||
const eventName = $s.data?.followCurrentScrim.event; | ||
if (eventName) { | ||
const handler = eventMap?.[eventName]; | ||
if (handler) handler(); | ||
} | ||
if ($s.data) { | ||
if (["EMPTY", "CANCELLED", "COMPLETE"].includes($s.data.followCurrentScrim.scrim.status)) { | ||
// Scrim end states | ||
console.log("Scrim has ended"); | ||
set(null); | ||
} else { | ||
set($s.data.followCurrentScrim.scrim); | ||
} | ||
} | ||
}); | ||
|
||
return () => { | ||
queryUnsub(); | ||
subUnsub(); | ||
}; | ||
}); | ||
}; |
11 changes: 11 additions & 0 deletions
11
clients/web/src/lib/api/scrims/CurrentScrim/CurrentScrims.context.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import {getContext, setContext} from "svelte"; | ||
import type {CurrentScrim$result} from "$houdini"; | ||
import type {Readable} from "svelte/store"; | ||
|
||
const CurrentScrimContextKey = "CURRENT_SCRIM_CONTEXT_KEY"; | ||
|
||
export type CurrentScrimContextValue = Readable<CurrentScrim$result["getCurrentScrim"] | undefined>; | ||
|
||
export const CurrentScrimContext = () => getContext<CurrentScrimContextValue>(CurrentScrimContextKey); | ||
export const SetCurrentScrimContext = (v: CurrentScrimContextValue) => | ||
setContext<CurrentScrimContextValue>(CurrentScrimContextKey, v); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export * from "./CurrentScrims.Live.store"; | ||
export * from "./CurrentScrims.context"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
mutation LeaveScrim { | ||
leaveScrim | ||
} |
Oops, something went wrong.