2022-08-14 21:26:50 -05:00
|
|
|
import { useMemo } from 'react'
|
2022-08-09 22:14:59 -05:00
|
|
|
import { useParams } from 'react-router-dom'
|
2022-08-14 21:26:50 -05:00
|
|
|
import Button from '@mui/material/Button'
|
|
|
|
import Typography from '@mui/material/Typography'
|
2022-08-09 22:14:59 -05:00
|
|
|
|
2022-08-14 10:10:05 -05:00
|
|
|
import { usePeerRoom } from '../../hooks/usePeerRoom'
|
2022-08-13 12:11:59 -05:00
|
|
|
|
2022-08-14 21:26:50 -05:00
|
|
|
enum PeerActions {
|
|
|
|
MESSAGE = 'MESSAGE',
|
|
|
|
}
|
|
|
|
|
2022-08-14 10:10:05 -05:00
|
|
|
export function Room() {
|
|
|
|
const { roomId = '' } = useParams()
|
2022-08-13 12:11:59 -05:00
|
|
|
|
2022-08-14 21:26:50 -05:00
|
|
|
const { makeAction } = usePeerRoom({
|
|
|
|
appId: `${window.location.origin}_${process.env.REACT_APP_NAME}`,
|
2022-08-14 10:10:05 -05:00
|
|
|
roomId,
|
|
|
|
})
|
2022-08-13 12:11:59 -05:00
|
|
|
|
2022-08-14 21:26:50 -05:00
|
|
|
const [sendMessage, receiveMessage] = useMemo(
|
|
|
|
() => makeAction<string>(PeerActions.MESSAGE),
|
|
|
|
[makeAction]
|
|
|
|
)
|
|
|
|
|
|
|
|
receiveMessage(message => {
|
|
|
|
console.log(message)
|
|
|
|
})
|
|
|
|
|
|
|
|
return (
|
|
|
|
<div>
|
|
|
|
<Typography>Room ID: {roomId}</Typography>
|
|
|
|
<Typography>
|
|
|
|
Open this page in another tab and open the console.
|
|
|
|
</Typography>
|
|
|
|
<Button
|
|
|
|
onClick={() => {
|
|
|
|
sendMessage('Hello!')
|
|
|
|
}}
|
|
|
|
variant="contained"
|
|
|
|
>
|
|
|
|
Say hi
|
|
|
|
</Button>
|
|
|
|
</div>
|
|
|
|
)
|
2022-08-09 22:14:59 -05:00
|
|
|
}
|