-
Notifications
You must be signed in to change notification settings - Fork 47
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 #2823 from ever-co/develop
Release
- Loading branch information
Showing
20 changed files
with
1,041 additions
and
333 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
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
File renamed without changes.
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,61 @@ | ||
"use client"; | ||
|
||
import { useAuthenticateUser } from '@app/hooks'; | ||
import { withAuthentication } from 'lib/app/authenticator'; | ||
import { BackdropLoader, Meta } from 'lib/components'; | ||
import dynamic from 'next/dynamic'; | ||
import { useRouter, useSearchParams } from 'next/navigation'; | ||
import { useCallback, useEffect, useState } from 'react'; | ||
import { useTokenLiveKit } from '@app/hooks/useLiveKit'; | ||
|
||
const LiveKit = dynamic(() => import('lib/features/integrations/livekit'), { | ||
ssr: false, | ||
loading: () => <BackdropLoader show /> | ||
}); | ||
|
||
function LiveKitPage() { | ||
const router = useRouter(); | ||
const { user } = useAuthenticateUser(); | ||
const [roomName, setRoomName] = useState<string | undefined>(undefined); | ||
const params = useSearchParams(); | ||
|
||
const onLeave = useCallback(() => { | ||
router.push('/'); | ||
}, [router]); | ||
|
||
useEffect(() => { | ||
const room = params.get("roomName"); | ||
if (room) { | ||
setRoomName(room); | ||
} | ||
}, [params]); | ||
|
||
const { token } = useTokenLiveKit({ | ||
roomName: roomName || '', | ||
username: user?.email || '', | ||
}); | ||
|
||
return ( | ||
<> | ||
<Meta title="Meet" /> | ||
{token && roomName && <LiveKit | ||
token={token!} | ||
roomName={roomName} | ||
liveKitUrl={process.env.NEXT_PUBLIC_LIVEKIT_URL || ''} | ||
onLeave={onLeave} | ||
userChoices={{ | ||
videoEnabled: true, | ||
audioEnabled: true, | ||
audioDeviceId: '', | ||
username: user?.email || '', | ||
videoDeviceId: '' | ||
}} | ||
/>} | ||
</> | ||
); | ||
} | ||
|
||
export default withAuthentication(LiveKitPage, { | ||
displayName: 'LiveKitPage', | ||
showPageSkeleton: false | ||
}); |
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,9 @@ | ||
import LiveKitPage from './component' | ||
import React from 'react' | ||
|
||
function Page() { | ||
return <LiveKitPage /> | ||
|
||
} | ||
|
||
export default Page |
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,46 @@ | ||
import { AccessToken } from "livekit-server-sdk"; | ||
import { NextRequest, NextResponse } from "next/server"; | ||
|
||
export async function GET(req: NextRequest) { | ||
const room = req.nextUrl.searchParams.get("roomName"); | ||
const username = req.nextUrl.searchParams.get("username"); | ||
|
||
if (!room || typeof room !== 'string' || room.trim() === '') { | ||
return NextResponse.json( | ||
{ error: 'Missing or invalid "roomName" query parameter' }, | ||
{ status: 400 } | ||
); | ||
} | ||
|
||
if (!username || typeof username !== 'string' || username.trim() === '') { | ||
return NextResponse.json( | ||
{ error: 'Missing or invalid "username" query parameter' }, | ||
{ status: 400 } | ||
); | ||
} | ||
|
||
const apiKey = process.env.LIVEKIT_API_KEY; | ||
const apiSecret = process.env.LIVEKIT_API_SECRET; | ||
const wsUrl = process.env.NEXT_PUBLIC_LIVEKIT_URL; | ||
|
||
if (!apiKey || !apiSecret || !wsUrl) { | ||
console.error("Server misconfigured: missing environment variables."); | ||
return NextResponse.json( | ||
{ error: "Server misconfigured" }, | ||
{ status: 500 } | ||
); | ||
} | ||
|
||
try { | ||
const at = new AccessToken(apiKey, apiSecret, { identity: username }); | ||
at.addGrant({ room, roomJoin: true, canPublish: true, canSubscribe: true, roomRecord: true }); | ||
const token = await at.toJwt(); | ||
return NextResponse.json({ token: token }); | ||
} catch (error) { | ||
console.error("Failed to generate token:", error); | ||
return NextResponse.json( | ||
{ error: "Failed to generate token" }, | ||
{ 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,33 @@ | ||
"use client"; | ||
import { tokenLiveKitRoom } from "@app/services/server/livekitroom"; | ||
import { useEffect, useState } from "react"; | ||
|
||
interface ITokenLiveKitProps { | ||
roomName: string; | ||
username: string; | ||
} | ||
|
||
export function useTokenLiveKit({ roomName, username }: ITokenLiveKitProps) { | ||
|
||
const [token, setToken] = useState<string | null>(() => { | ||
if (typeof window !== 'undefined') { | ||
return window.localStorage.getItem('token-live-kit'); | ||
} | ||
return null; | ||
}); | ||
|
||
useEffect(() => { | ||
const fetchToken = async () => { | ||
try { | ||
const response = await tokenLiveKitRoom({ roomName, username }); | ||
window.localStorage.setItem('token-live-kit', response.token); | ||
setToken(response.token); | ||
} catch (error) { | ||
console.error('Failed to fetch token:', error); | ||
} | ||
}; | ||
fetchToken(); | ||
}, [roomName, username, token]); | ||
|
||
return { token }; | ||
} |
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,42 @@ | ||
import { JwtPayload } from "jsonwebtoken"; | ||
import { LocalAudioTrack, LocalVideoTrack } from 'livekit-client'; | ||
|
||
export interface ILiveKiteCredentials { | ||
ttl?:number|string | ||
roomName?: string, | ||
identity?: string, | ||
username?: string, | ||
metadata?: string | ||
} | ||
|
||
export interface CustomJwtPayload extends JwtPayload { | ||
exp?: number; | ||
iss?: string; | ||
nbf?: number; | ||
sub?: string; | ||
video?: { | ||
canPublish: boolean; | ||
canPublishData: boolean; | ||
canSubscribe: boolean; | ||
room: string; | ||
roomJoin: boolean; | ||
}; | ||
} | ||
|
||
|
||
|
||
|
||
export interface SessionProps { | ||
roomName: string; | ||
identity: string; | ||
audioTrack?: LocalAudioTrack; | ||
videoTrack?: LocalVideoTrack; | ||
region?: string; | ||
turnServer?: RTCIceServer; | ||
forceRelay?: boolean; | ||
} | ||
|
||
export interface TokenResult { | ||
identity: string; | ||
accessToken: string; | ||
} |
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,10 @@ | ||
import { ILiveKiteCredentials } from "@app/interfaces"; | ||
|
||
export async function tokenLiveKitRoom({ roomName, username }: ILiveKiteCredentials) { | ||
try { | ||
const response = await fetch(`/api/livekit?roomName=${roomName ?? 'default'}&username=${username ?? 'employee'}`); | ||
return await response.json(); | ||
} catch (e) { | ||
console.error(e) | ||
} | ||
} |
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.