pull/134/head
Alex Kern 12 months ago
parent cb344d153f
commit 3fc13eb062
No known key found for this signature in database
GPG Key ID: EF051FACCACBEE25

@ -5,7 +5,10 @@ export async function POST(request: Request): Promise<NextResponse> {
const { uploaderPeerID } = await request.json() const { uploaderPeerID } = await request.json()
if (!uploaderPeerID) { if (!uploaderPeerID) {
return NextResponse.json({ error: 'Uploader peer ID is required' }, { status: 400 }) return NextResponse.json(
{ error: 'Uploader peer ID is required' },
{ status: 400 },
)
} }
const channel: Channel = await channelRepo.createChannel(uploaderPeerID) const channel: Channel = await channelRepo.createChannel(uploaderPeerID)

@ -20,16 +20,9 @@ const ChannelSchema = z.object({
}) })
export interface ChannelRepo { export interface ChannelRepo {
createChannel( createChannel(uploaderPeerID: string, ttl?: number): Promise<Channel>
uploaderPeerID: string,
ttl?: number,
): Promise<Channel>
fetchChannel(slug: string): Promise<Channel | null> fetchChannel(slug: string): Promise<Channel | null>
renewChannel( renewChannel(slug: string, secret: string, ttl: number): Promise<boolean>
slug: string,
secret: string,
ttl: number,
): Promise<boolean>
destroyChannel(slug: string, secret: string): Promise<void> destroyChannel(slug: string, secret: string): Promise<void>
} }
@ -61,7 +54,10 @@ export class RedisChannelRepo implements ChannelRepo {
return channel return channel
} }
async fetchChannel(slug: string, scrubSecret = false): Promise<Channel | null> { async fetchChannel(
slug: string,
scrubSecret = false,
): Promise<Channel | null> {
const shortChannelStr = await this.client.get(this.getShortSlugKey(slug)) const shortChannelStr = await this.client.get(this.getShortSlugKey(slug))
if (shortChannelStr) { if (shortChannelStr) {
return this.deserializeChannel(shortChannelStr, scrubSecret) return this.deserializeChannel(shortChannelStr, scrubSecret)

@ -7,4 +7,4 @@ export function ErrorMessage({ message }: { message: string }): JSX.Element {
<span className="block sm:inline">{message}</span> <span className="block sm:inline">{message}</span>
</div> </div>
) )
} }

@ -4,4 +4,4 @@ import * as React from 'react'
import { ThemeProvider as NextThemesProvider } from 'next-themes' import { ThemeProvider as NextThemesProvider } from 'next-themes'
export type ThemeProviderProps = Parameters<typeof NextThemesProvider>[0] export type ThemeProviderProps = Parameters<typeof NextThemesProvider>[0]
export const ThemeProvider = NextThemesProvider as React.FC<ThemeProviderProps> export const ThemeProvider = NextThemesProvider as React.FC<ThemeProviderProps>

@ -5,7 +5,12 @@ import Loading from './Loading'
import Peer from 'peerjs' import Peer from 'peerjs'
const ICE_SERVERS: RTCConfiguration = { const ICE_SERVERS: RTCConfiguration = {
iceServers: [{ urls: process.env.NEXT_PUBLIC_STUN_SERVER ?? 'stun:stun.l.google.com:19302' }], iceServers: [
{
urls:
process.env.NEXT_PUBLIC_STUN_SERVER ?? 'stun:stun.l.google.com:19302',
},
],
} }
export type WebRTCValue = Peer export type WebRTCValue = Peer

@ -63,7 +63,13 @@ export function useUploaderChannel(
}) })
const answerMutation = useMutation({ const answerMutation = useMutation({
mutationFn: async ({ offerID, answer }: { offerID: string, answer: RTCSessionDescriptionInit }) => { mutationFn: async ({
offerID,
answer,
}: {
offerID: string
answer: RTCSessionDescriptionInit
}) => {
const response = await fetch('/api/answer', { const response = await fetch('/api/answer', {
method: 'POST', method: 'POST',
headers: { 'Content-Type': 'application/json' }, headers: { 'Content-Type': 'application/json' },
@ -83,9 +89,7 @@ export function useUploaderChannel(
const run = (): void => { const run = (): void => {
timeout = setTimeout(() => { timeout = setTimeout(() => {
renewMutation.mutate( renewMutation.mutate({ secret })
{ secret },
)
run() run()
}, renewInterval) }, renewInterval)
} }

Loading…
Cancel
Save