mirror of
https://github.com/ershisan99/www.git
synced 2026-01-01 21:09:23 +00:00
update stream card, update leaderboards on match finished webhook
This commit is contained in:
@@ -29,7 +29,7 @@ export const env = createEnv({
|
||||
* `NEXT_PUBLIC_`.
|
||||
*/
|
||||
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,
|
||||
CRON_SECRET: process.env.CRON_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
|
||||
|
||||
@@ -30,21 +30,26 @@ export const playerStateRouter = createTRPCRouter({
|
||||
})
|
||||
)
|
||||
.subscription(async function* ({ input, ctx, signal }) {
|
||||
const iterator = createEventIterator<PlayerState>(
|
||||
globalEmitter,
|
||||
`state-change:${input.userId}`,
|
||||
{ signal: signal }
|
||||
)
|
||||
console.log('subscription started for user:', input.userId)
|
||||
|
||||
// get initial state
|
||||
const initialState = await redis.get(PLAYER_STATE_KEY(input.userId))
|
||||
if (initialState) {
|
||||
yield tracked('initial', JSON.parse(initialState) as PlayerState)
|
||||
}
|
||||
try {
|
||||
const iterator = createEventIterator<PlayerState>(
|
||||
globalEmitter,
|
||||
`state-change:${input.userId}`,
|
||||
{ signal: signal }
|
||||
)
|
||||
|
||||
// listen for updates
|
||||
for await (const [state] of iterator) {
|
||||
yield tracked(Date.now().toString(), state)
|
||||
console.log('iterator created')
|
||||
|
||||
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)
|
||||
}
|
||||
}),
|
||||
})
|
||||
|
||||
@@ -87,7 +87,12 @@ export function TRPCReactProvider(props: { children: React.ReactNode }) {
|
||||
}
|
||||
|
||||
function getBaseUrl() {
|
||||
if (typeof window !== 'undefined') return window.location.origin
|
||||
if (process.env.VERCEL_URL) return `https://${process.env.VERCEL_URL}`
|
||||
return `http://localhost:${process.env.PORT ?? 3000}`
|
||||
const url =
|
||||
process.env.NEXT_PUBLIC_API_URL ||
|
||||
(typeof window !== 'undefined'
|
||||
? window.location.origin
|
||||
: `http://localhost:${process.env.PORT ?? 3000}`)
|
||||
|
||||
console.log('using base url:', url)
|
||||
return url
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user