Commit d20478b7 authored by Thisara Kavinda's avatar Thisara Kavinda

fix: create and join rooms

parent 0c187126
...@@ -13,6 +13,7 @@ function App() { ...@@ -13,6 +13,7 @@ function App() {
<Box className='App'> <Box className='App'>
<Routes> <Routes>
<Route path='/' element={<VideoCall />} /> <Route path='/' element={<VideoCall />} />
<Route path='/:roomName' element={<VideoCall />} />
</Routes> </Routes>
</Box> </Box>
</ThemeProvider> </ThemeProvider>
......
...@@ -12,13 +12,29 @@ import { ...@@ -12,13 +12,29 @@ import {
import ChevronRightIcon from '@mui/icons-material/ChevronRight' import ChevronRightIcon from '@mui/icons-material/ChevronRight'
import ArrowDropDownIcon from '@mui/icons-material/ArrowDropDown' import ArrowDropDownIcon from '@mui/icons-material/ArrowDropDown'
import { useTheme, type Theme } from '@mui/material/styles' import { useTheme, type Theme } from '@mui/material/styles'
import { useState } from 'react'
import { useNavigate } from 'react-router-dom'
interface Props { interface Props {
handleJoinClick: () => void setJoined: (x: boolean) => void
} }
const Lobby = ({ handleJoinClick }: Props) => { const Lobby = ({ setJoined }: Props) => {
const theme: Theme = useTheme() const theme: Theme = useTheme()
const navigate = useNavigate()
const [roomName, setRoomName] = useState('')
const handleJoinRoom = () => {
navigate(`/${roomName}`)
setJoined(true)
}
const handleCreateRoom = () => {
const roomName = Array.from({ length: 8 }, () => Math.random().toString(36)[2] || 0).join('')
navigate(`/${roomName}`)
setJoined(true)
}
return ( return (
<Box <Box
...@@ -87,6 +103,7 @@ const Lobby = ({ handleJoinClick }: Props) => { ...@@ -87,6 +103,7 @@ const Lobby = ({ handleJoinClick }: Props) => {
}} }}
inputProps={{ style: { color: theme.palette.common.white, borderColor: 'white' } }} inputProps={{ style: { color: theme.palette.common.white, borderColor: 'white' } }}
InputLabelProps={{ style: { color: theme.palette.common.white } }} InputLabelProps={{ style: { color: theme.palette.common.white } }}
onChange={(e) => setRoomName(e.target.value)}
/> />
<IconButton <IconButton
sx={{ sx={{
...@@ -97,6 +114,7 @@ const Lobby = ({ handleJoinClick }: Props) => { ...@@ -97,6 +114,7 @@ const Lobby = ({ handleJoinClick }: Props) => {
height: '50px', height: '50px',
}} }}
aria-label='join room' aria-label='join room'
onClick={handleJoinRoom}
> >
<ChevronRightIcon /> <ChevronRightIcon />
</IconButton> </IconButton>
...@@ -118,7 +136,7 @@ const Lobby = ({ handleJoinClick }: Props) => { ...@@ -118,7 +136,7 @@ const Lobby = ({ handleJoinClick }: Props) => {
borderRadius: '10px', borderRadius: '10px',
height: '50px', height: '50px',
}} }}
onClick={handleJoinClick} onClick={handleCreateRoom}
> >
Create Room Create Room
</Button> </Button>
......
...@@ -9,10 +9,6 @@ const VideoCall = () => { ...@@ -9,10 +9,6 @@ const VideoCall = () => {
const agoraEngine = useRTCClient(AgoraRTC.createClient({ codec: 'vp8', mode: 'rtc' })) const agoraEngine = useRTCClient(AgoraRTC.createClient({ codec: 'vp8', mode: 'rtc' }))
const [joined, setJoined] = useState(false) const [joined, setJoined] = useState(false)
const handleJoinClick = () => {
setJoined(true)
}
return ( return (
<Box sx={{ height: '100vh', width: '100vw', overflow: 'hidden' }}> <Box sx={{ height: '100vh', width: '100vw', overflow: 'hidden' }}>
{joined ? ( {joined ? (
...@@ -22,7 +18,7 @@ const VideoCall = () => { ...@@ -22,7 +18,7 @@ const VideoCall = () => {
</AgoraManager> </AgoraManager>
</AgoraRTCProvider> </AgoraRTCProvider>
) : ( ) : (
<Lobby handleJoinClick={handleJoinClick} /> <Lobby setJoined={setJoined} />
)} )}
</Box> </Box>
) )
......
...@@ -5,6 +5,7 @@ import { Box } from '@mui/material' ...@@ -5,6 +5,7 @@ import { Box } from '@mui/material'
import { useTheme, type Theme } from '@mui/material/styles' import { useTheme, type Theme } from '@mui/material/styles'
import MeetingLoading from '../../Components/MeetingLoading/MeetingLoading' import MeetingLoading from '../../Components/MeetingLoading/MeetingLoading'
import MeetingLayout from '../../Components/MeetingLayout/MeetingLayout' import MeetingLayout from '../../Components/MeetingLayout/MeetingLayout'
import { useParams } from 'react-router-dom'
interface AgoraContextType { interface AgoraContextType {
localCameraTrack: ICameraVideoTrack | null localCameraTrack: ICameraVideoTrack | null
...@@ -38,6 +39,10 @@ export const AgoraManager = ({ ...@@ -38,6 +39,10 @@ export const AgoraManager = ({
children: React.ReactNode children: React.ReactNode
}) => { }) => {
const theme: Theme = useTheme() const theme: Theme = useTheme()
let { channel } = useParams<{ channel: string }>()
if (!channel) {
channel = Array.from({ length: 8 }, () => Math.random().toString(36)[2] || 0).join('')
}
const { const {
data: uid, data: uid,
...@@ -46,13 +51,17 @@ export const AgoraManager = ({ ...@@ -46,13 +51,17 @@ export const AgoraManager = ({
isLoading: isJoining, isLoading: isJoining,
} = useJoin({ } = useJoin({
appid: '3af4648782de46ddbf90005f7a68f206', appid: '3af4648782de46ddbf90005f7a68f206',
channel: 'test', channel,
token: null, token: null,
uid: null, uid: null,
}) })
const { isLoading: isLoadingCam, localCameraTrack } = useLocalCameraTrack() const { isLoading: isLoadingCam, localCameraTrack } = useLocalCameraTrack()
const { isLoading: isLoadingMic, localMicrophoneTrack } = useLocalMicrophoneTrack() const { isLoading: isLoadingMic, localMicrophoneTrack } = useLocalMicrophoneTrack()
useEffect(() => {
localStorage.setItem('myUid', uid.toString())
}, [uid])
useEffect(() => { useEffect(() => {
return () => { return () => {
localCameraTrack?.close() localCameraTrack?.close()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment