generated from tldraw/make-real-starter
-
Notifications
You must be signed in to change notification settings - Fork 0
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 #16 from adityathakurxd/multiple-rooms
Creates new room code before join for participants
- Loading branch information
Showing
7 changed files
with
218 additions
and
90 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import { randomUUID } from 'crypto' | ||
import { NextRequest, NextResponse } from 'next/server' | ||
|
||
export async function GET() { | ||
try { | ||
const response = await fetch('https://api.100ms.live/v2/rooms', { | ||
method: 'POST', | ||
headers: { | ||
'Content-Type': 'application/json', | ||
Authorization: `Bearer ${process.env.MANAGEMENT_TOKEN}`, | ||
}, | ||
body: JSON.stringify({ | ||
name: `polls-ai-${randomUUID()}`, | ||
description: 'This is a sample description for the room', | ||
template_id: process.env.TEMPLATE_ID, | ||
}), | ||
}) | ||
|
||
if (response.ok) { | ||
const body = await response.json() | ||
return NextResponse.json({ body }, { status: 200 }) | ||
} else { | ||
return NextResponse.json({ message: 'Failed to create room' }, { status: 401 }) | ||
} | ||
} catch (error) { | ||
console.error('Error creating room:', error) | ||
return NextResponse.json({ message: 'Internal Server error' }, { status: 500 }) | ||
} | ||
} | ||
|
||
export async function POST(req: NextRequest) { | ||
try { | ||
const { roomId } = await req.json() | ||
const response = await fetch('https://api.100ms.live/v2/room-codes/room/' + roomId, { | ||
method: 'POST', | ||
headers: { | ||
'Content-Type': 'application/json', | ||
Authorization: `Bearer ${process.env.MANAGEMENT_TOKEN}`, | ||
}, | ||
}) | ||
|
||
if (response.ok) { | ||
const body = await response.json() | ||
return NextResponse.json({ body }, { status: 200 }) | ||
} else { | ||
return NextResponse.json({ message: 'Failed to create room codes' }, { status: 401 }) | ||
} | ||
} catch (error) { | ||
console.error('Error creating room codes:', error) | ||
return NextResponse.json({ message: 'Internal Server error' }, { status: 500 }) | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { CheckIcon, CopyIcon } from '@100mslive/react-icons' | ||
import { useState } from 'react' | ||
|
||
const CopyButton = ({ value }: { value: string }) => { | ||
const [copied, setCopied] = useState(false) | ||
|
||
const copyText = () => { | ||
navigator.clipboard.writeText(value) | ||
setCopied(true) | ||
setTimeout(() => setCopied(false), 2000) | ||
} | ||
|
||
return ( | ||
<button | ||
title="Copy" | ||
style={{ padding: '4px', display: 'flex' }} | ||
disabled={copied} | ||
onClick={copyText} | ||
> | ||
{copied ? <CheckIcon height={16} width={16} /> : <CopyIcon height={16} width={16} />} | ||
</button> | ||
) | ||
} | ||
export default CopyButton |
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
Oops, something went wrong.