update stream card, update leaderboards on match finished webhook

This commit is contained in:
2025-04-24 01:17:18 +02:00
parent 68540ee136
commit 2ede20f81c
3 changed files with 28 additions and 17 deletions

View File

@@ -29,7 +29,7 @@ export const env = createEnv({
* `NEXT_PUBLIC_`. * `NEXT_PUBLIC_`.
*/ */
client: { client: {
// NEXT_PUBLIC_CLIENTVAR: z.string(), NEXT_PUBLIC_API_URL: z.string(),
}, },
/** /**
@@ -46,6 +46,7 @@ export const env = createEnv({
NODE_ENV: process.env.NODE_ENV, NODE_ENV: process.env.NODE_ENV,
CRON_SECRET: process.env.CRON_SECRET, CRON_SECRET: process.env.CRON_SECRET,
WEBHOOK_QUERY_SECRET: process.env.WEBHOOK_QUERY_SECRET, WEBHOOK_QUERY_SECRET: process.env.WEBHOOK_QUERY_SECRET,
NEXT_PUBLIC_API_URL: process.env.NEXT_PUBLIC_API_URL,
}, },
/** /**
* Run `build` or `dev` with `SKIP_ENV_VALIDATION` to skip env validation. This is especially * Run `build` or `dev` with `SKIP_ENV_VALIDATION` to skip env validation. This is especially

View File

@@ -30,21 +30,26 @@ export const playerStateRouter = createTRPCRouter({
}) })
) )
.subscription(async function* ({ input, ctx, signal }) { .subscription(async function* ({ input, ctx, signal }) {
const iterator = createEventIterator<PlayerState>( console.log('subscription started for user:', input.userId)
globalEmitter,
`state-change:${input.userId}`,
{ signal: signal }
)
// get initial state try {
const initialState = await redis.get(PLAYER_STATE_KEY(input.userId)) const iterator = createEventIterator<PlayerState>(
if (initialState) { globalEmitter,
yield tracked('initial', JSON.parse(initialState) as PlayerState) `state-change:${input.userId}`,
} { signal: signal }
)
// listen for updates console.log('iterator created')
for await (const [state] of iterator) {
yield tracked(Date.now().toString(), state) for await (const [state] of iterator) {
console.log('emitting state:', state)
yield tracked(Date.now().toString(), state)
}
} catch (error) {
console.error('subscription error:', error)
throw error
} finally {
console.log('subscription ended for user:', input.userId)
} }
}), }),
}) })

View File

@@ -87,7 +87,12 @@ export function TRPCReactProvider(props: { children: React.ReactNode }) {
} }
function getBaseUrl() { function getBaseUrl() {
if (typeof window !== 'undefined') return window.location.origin const url =
if (process.env.VERCEL_URL) return `https://${process.env.VERCEL_URL}` process.env.NEXT_PUBLIC_API_URL ||
return `http://localhost:${process.env.PORT ?? 3000}` (typeof window !== 'undefined'
? window.location.origin
: `http://localhost:${process.env.PORT ?? 3000}`)
console.log('using base url:', url)
return url
} }