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-16 09:40:01 -05:00
|
|
|
import { usePeerRoom, usePeerRoomAction, PeerActions } from 'hooks/usePeerRoom'
|
2022-08-13 12:11:59 -05:00
|
|
|
|
2022-08-17 09:10:36 -05:00
|
|
|
export function Room() {
|
|
|
|
const { roomId = '' } = useParams()
|
|
|
|
|
|
|
|
const peerRoom = usePeerRoom({
|
|
|
|
appId: `${encodeURI(window.location.origin)}_${process.env.REACT_APP_NAME}`,
|
|
|
|
roomId,
|
|
|
|
})
|
2022-08-13 12:11:59 -05:00
|
|
|
|
2022-08-16 09:40:01 -05:00
|
|
|
const [sendMessage, receiveMessage] = usePeerRoomAction<string>(
|
|
|
|
peerRoom,
|
|
|
|
PeerActions.MESSAGE
|
2022-08-14 21:26:50 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
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
|
|
|
}
|