import { useState } from "react"; import { Button, Card, Col, Divider, Form, Input, InputNumber, Row, Select, Badge, } from "antd"; import { red } from "@ant-design/colors"; import connection, { useConfig, useIsConnected, useRoom, useTimelineSongFileChanged, } from "../lib/Connection"; import "../css/lobby.css"; import logo from "../img/via-logo.svg"; import haramlogo from "../img/harambee_logo.png"; import beer from "../img/beer.png"; import { RoomOptions } from "../types/types"; const { Option } = Select; export interface PropType { currentUserReady: boolean; onCurrentUserReadyChange?: (ready: boolean) => void; } const Lobby = (props: PropType) => { // Form/control states. const [selectedRoomId, setSelectedRoomId] = useState(1); const [seekTime, setSeekTime] = useState(0); const [timelineName, setTimelineName] = useState(null); const [joiningLobby, setJoiningLobby] = useState(false); const [joinLobbyError, setJoinLobbyError] = useState(false); const [isPreloading, setIsPreloading] = useState(false); const timeline = useTimelineSongFileChanged(); // Room and logic states. const isConnected = useIsConnected(); const room = useRoom(); const config = useConfig(); const isLeader = room?.isLeader || false; const userCount = room?.userCount || 0; async function handleJoin() { await preloadAudio(); connection.requestSetReady(); props.onCurrentUserReadyChange?.(true); } async function applyRoomId(v: number) { setJoiningLobby(true); await connection.requestJoin(v); setJoiningLobby(false); setJoinLobbyError(!v); } function handleJoinRandomLobby() { connection.requestJoinRandom(); setJoinLobbyError(false); } function handleTimelineNameSet(timelineName: any) { setTimelineName(timelineName); connection.setRoomOptions( new RoomOptions( seekTime * 1000 || 0, timelineName || room?.timelineName || "" ) ); } function handleSetSeekTime(seekTime: number) { setSeekTime(seekTime); connection.setRoomOptions( new RoomOptions( seekTime * 1000 || 0, timelineName || room?.timelineName || "" ) ); } function preloadAudio(): Promise { setIsPreloading(true); const songFile = timeline?.songFile; if (!songFile) { return Promise.resolve(false); } return new Promise((resolve) => { const audioElement = new Audio(); audioElement.addEventListener("canplaythrough", () => { // 'canplaythrough' means the browser thinks it has buffered enough to play // until the end. setIsPreloading(false); resolve(true); }); audioElement.src = songFile; }); } const leaderConfig = (
handleSetSeekTime(parseInt(v.target.value) || 0)} />
); const nonLeaderConfig = (

{room?.running ? "We luisteren naar" : "We gaan luisteren naar"}{" "} {room && room.timelineName} en {room?.running && zijn al gestart!} {!room?.running && ( starten op {(room?.seekTime || 0) / 1000} seconden )}

); return (
beer Centurion! beer
Honderd minuten...
Honderd shots...
Kun jij het aan?

{!isConnected && (

Verbinden...

)} {isConnected && (

Huidige lobby: {room ? `#${room.id}` : "Geen lobby"}

{room && ( {userCount === 1 ? ( Er is één gebruiker aanwezig. ) : ( Er zijn {userCount} gebruikers aanwezig. )} )} {room?.users?.map((u) => ( ))} {room && Deel de link met je vrienden om mee te doen!} {room && (isLeader ? leaderConfig : nonLeaderConfig)} setSelectedRoomId(v || 0)} /> {joinLobbyError && ( Die lobby bestaat niet )} of
)} haramlogo logo
); }; export default Lobby;