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 }) {
console.log('subscription started for user:', input.userId)
try {
const iterator = createEventIterator<PlayerState>( const iterator = createEventIterator<PlayerState>(
globalEmitter, globalEmitter,
`state-change:${input.userId}`, `state-change:${input.userId}`,
{ signal: signal } { signal: signal }
) )
// get initial state console.log('iterator created')
const initialState = await redis.get(PLAYER_STATE_KEY(input.userId))
if (initialState) {
yield tracked('initial', JSON.parse(initialState) as PlayerState)
}
// listen for updates
for await (const [state] of iterator) { for await (const [state] of iterator) {
console.log('emitting state:', state)
yield tracked(Date.now().toString(), 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
} }