|
|
@ -1,33 +1,40 @@ |
|
|
|
import React, {MouseEvent, useState} from 'react'; |
|
|
|
import React, {MouseEvent, useState} from 'react'; |
|
|
|
import {Input, Button, Card, Col, InputNumber, Row, Space, Divider} from "antd" |
|
|
|
import {Button, Card, Col, Divider, Form, Input, InputNumber, Row, Select} from "antd" |
|
|
|
import {red} from '@ant-design/colors'; |
|
|
|
import {red} from '@ant-design/colors'; |
|
|
|
|
|
|
|
|
|
|
|
import connection, {useIsConnected, useRoom} from "../lib/Connection"; |
|
|
|
import connection, {useConfig, useIsConnected, useRoom} from "../lib/Connection"; |
|
|
|
|
|
|
|
|
|
|
|
import "../css/lobby.sass"; |
|
|
|
import "../css/lobby.sass"; |
|
|
|
import beer from "../img/beer.png" |
|
|
|
import beer from "../img/beer.png" |
|
|
|
|
|
|
|
import {RoomOptions} from "../types/types"; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const {Option} = Select; |
|
|
|
|
|
|
|
|
|
|
|
const Lobby = (props: any) => { |
|
|
|
const Lobby = (props: any) => { |
|
|
|
const [seekTime, setSeekTime] = useState(0); |
|
|
|
// Form/control states.
|
|
|
|
const [selectedRoomId, setSelectedRoomId] = useState(1); |
|
|
|
const [selectedRoomId, setSelectedRoomId] = useState(1); |
|
|
|
|
|
|
|
const [seekTime, setSeekTime] = useState(0); |
|
|
|
|
|
|
|
const [timelineName, setTimelineName] = useState(null); |
|
|
|
const [joiningLobby, setJoiningLobby] = useState(false); |
|
|
|
const [joiningLobby, setJoiningLobby] = useState(false); |
|
|
|
const [joinLobbyError, setJoinLobbyError] = useState(false); |
|
|
|
const [joinLobbyError, setJoinLobbyError] = useState(false); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Room and logic states.
|
|
|
|
const isConnected = useIsConnected(); |
|
|
|
const isConnected = useIsConnected(); |
|
|
|
const room = useRoom(); |
|
|
|
const room = useRoom(); |
|
|
|
|
|
|
|
const config = useConfig(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// @ts-ignore
|
|
|
|
|
|
|
|
const connectionType = connection.socket.io.engine.transport.name; |
|
|
|
|
|
|
|
|
|
|
|
let isLeader = room?.isLeader || false; |
|
|
|
let isLeader = room?.isLeader || false; |
|
|
|
let userCount = room?.userCount || 0; |
|
|
|
let userCount = room?.userCount || 0; |
|
|
|
|
|
|
|
|
|
|
|
function handleRequestStartClicked(e: MouseEvent) { |
|
|
|
function handleRequestStartClicked(e: MouseEvent) { |
|
|
|
e.preventDefault(); |
|
|
|
connection.requestStart(seekTime * 1000); |
|
|
|
|
|
|
|
|
|
|
|
connection.requestStart(); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
function handleJoin(e: MouseEvent) { |
|
|
|
function handleJoin(e: MouseEvent) { |
|
|
|
// connection.requestStart();
|
|
|
|
connection.requestReady(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
function applyRoomId(v: number) { |
|
|
|
function applyRoomId(v: number) { |
|
|
@ -38,44 +45,79 @@ const Lobby = (props: any) => { |
|
|
|
setJoiningLobby(true) |
|
|
|
setJoiningLobby(true) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
function joinRandomLobby() { |
|
|
|
function handleJoinRandomLobby() { |
|
|
|
connection.requestJoinRandom() |
|
|
|
connection.requestJoinRandom() |
|
|
|
setJoinLobbyError(false); |
|
|
|
setJoinLobbyError(false); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// const {socket} = useSocket("welcome", async (obj: any) => {
|
|
|
|
function handleTimelineNameSet(timelineName: any) { |
|
|
|
// if (lobbyQueryId) {
|
|
|
|
setTimelineName(timelineName); |
|
|
|
// // lobbyId is already defined, this means we have a queryparam set.
|
|
|
|
connection.setRoomOptions(new RoomOptions( |
|
|
|
// await onChangeLobbyInput(lobbyQueryId);
|
|
|
|
seekTime || 0, |
|
|
|
// return;
|
|
|
|
timelineName || room?.timelineName || '')) |
|
|
|
// }
|
|
|
|
} |
|
|
|
// console.log("Got welcome", lobbyQueryId);
|
|
|
|
|
|
|
|
//
|
|
|
|
function handleSetSeekTime(seekTime: number) { |
|
|
|
// setLobbyId(obj.room.name);
|
|
|
|
setSeekTime(seekTime); |
|
|
|
// setIsLeader(socket.id === obj.room.leaderId);
|
|
|
|
connection.setRoomOptions(new RoomOptions( |
|
|
|
// setUserCount(obj.room.users?.length || 0);
|
|
|
|
seekTime * 1000 || 0, |
|
|
|
// });
|
|
|
|
timelineName || room?.timelineName || '')) |
|
|
|
|
|
|
|
|
|
|
|
// const socketRef = useRef<SocketIOClient.Socket>(socket);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async function onChangeRoomInput(i: any) { |
|
|
|
|
|
|
|
// setLobbyId(i);
|
|
|
|
|
|
|
|
// const result: any = await emit(connection.socket, 'join_room', i);
|
|
|
|
|
|
|
|
// setIsLeader(connection.socket.id === result.room.leaderId);
|
|
|
|
|
|
|
|
// setUserCount(result.room.users?.length || 0);
|
|
|
|
|
|
|
|
// connection.requestJoin(i);
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// useEffect(() => {
|
|
|
|
let leaderConfig = ( |
|
|
|
// async function wrapper() {
|
|
|
|
<Row justify="center"> |
|
|
|
// const result: any = await emit(connection.current, 'room_info');
|
|
|
|
<Col> |
|
|
|
// setIsLeader(connection.current.id === result.room.leaderId);
|
|
|
|
<Form |
|
|
|
// setUserCount(result.room.users?.length || 0);
|
|
|
|
layout='horizontal' |
|
|
|
// }
|
|
|
|
labelCol={{span: 8}} |
|
|
|
//
|
|
|
|
wrapperCol={{span: 24}} |
|
|
|
// wrapper();
|
|
|
|
> |
|
|
|
// }, []);
|
|
|
|
<Form.Item label="Starttijd"> |
|
|
|
|
|
|
|
<Input |
|
|
|
|
|
|
|
type="number" |
|
|
|
|
|
|
|
suffix="sec" |
|
|
|
|
|
|
|
value={seekTime} |
|
|
|
|
|
|
|
onChange={v => handleSetSeekTime(parseInt(v.target.value) || 0)}/> |
|
|
|
|
|
|
|
</Form.Item> |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<Form.Item label="Nummer"> |
|
|
|
|
|
|
|
<Select defaultValue={(room && room.timelineName) || ''} |
|
|
|
|
|
|
|
onChange={e => handleTimelineNameSet(e)}> |
|
|
|
|
|
|
|
{config && config.availableTimelines.map((item, i) => |
|
|
|
|
|
|
|
<Option key={item} value={item}>{item}</Option> |
|
|
|
|
|
|
|
)} |
|
|
|
|
|
|
|
</Select> |
|
|
|
|
|
|
|
</Form.Item> |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
</Form> |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<Button |
|
|
|
|
|
|
|
block |
|
|
|
|
|
|
|
type="primary" |
|
|
|
|
|
|
|
onClick={handleRequestStartClicked}>Start</Button> |
|
|
|
|
|
|
|
</Col> |
|
|
|
|
|
|
|
</Row> |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let nonLeaderConfig = ( |
|
|
|
|
|
|
|
<Row justify="center"> |
|
|
|
|
|
|
|
<Col> |
|
|
|
|
|
|
|
<p> |
|
|
|
|
|
|
|
We gaan luisteren naar <b>{room && room.timelineName}</b> en |
|
|
|
|
|
|
|
{room?.running && <span> zijn al gestart!</span>} |
|
|
|
|
|
|
|
{!room?.running && <span> starten op {room?.seekTime} seconden</span>} |
|
|
|
|
|
|
|
</p> |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<Button |
|
|
|
|
|
|
|
block |
|
|
|
|
|
|
|
type="primary" |
|
|
|
|
|
|
|
disabled={!room || room.readyToParticipate} |
|
|
|
|
|
|
|
onClick={handleJoin}>{room && room.readyToParticipate ? 'Wachten op het startsein' : 'Kom erbij'}</Button> |
|
|
|
|
|
|
|
</Col> |
|
|
|
|
|
|
|
</Row> |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// @ts-ignore
|
|
|
|
return ( |
|
|
|
return ( |
|
|
|
<div className="lobby"> |
|
|
|
<div className="lobby"> |
|
|
|
<Row> |
|
|
|
<Row> |
|
|
@ -106,51 +148,28 @@ const Lobby = (props: any) => { |
|
|
|
|
|
|
|
|
|
|
|
{isConnected && |
|
|
|
{isConnected && |
|
|
|
<Row justify="center"> |
|
|
|
<Row justify="center"> |
|
|
|
<Col xs={12} sm={10} md={10} xl={6}> |
|
|
|
<Col xs={24} sm={16} md={12} xl={10}> |
|
|
|
<Card> |
|
|
|
<Card> |
|
|
|
<h3>Huidige lobby: <b>{room?.id || 'Geen lobby'}</b></h3> |
|
|
|
<h3>Huidige lobby: <b>{room?.id || 'Geen lobby'}</b></h3> |
|
|
|
|
|
|
|
|
|
|
|
<Row> |
|
|
|
{/*<span>Verbonden met {connectionType}</span>*/} |
|
|
|
<Col> |
|
|
|
|
|
|
|
|
|
|
|
{room && |
|
|
|
|
|
|
|
<span> |
|
|
|
{userCount === 1 ? |
|
|
|
{userCount === 1 ? |
|
|
|
<p>Er is één gebruiker aanwezig.</p> |
|
|
|
<p>Er is één gebruiker aanwezig.</p> |
|
|
|
: |
|
|
|
: |
|
|
|
<p>Er zijn {userCount} gebruikers aanwezig.</p> |
|
|
|
<p>Er zijn {userCount} gebruikers aanwezig.</p> |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
<p>{isLeader ? 'Jij bent de baas van deze lobby.' : 'Wachten tot de baas de mix start.'}</p> |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
</Col> |
|
|
|
|
|
|
|
</Row> |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<Row> |
|
|
|
|
|
|
|
<Col> |
|
|
|
|
|
|
|
{isLeader && |
|
|
|
|
|
|
|
<span>Start de mix op |
|
|
|
|
|
|
|
<Input |
|
|
|
|
|
|
|
type="number" |
|
|
|
|
|
|
|
min={0} |
|
|
|
|
|
|
|
max={60000} |
|
|
|
|
|
|
|
suffix="sec" |
|
|
|
|
|
|
|
value={seekTime} |
|
|
|
|
|
|
|
onChange={v => setSeekTime(parseInt(v.target.value) || 0)}/> |
|
|
|
|
|
|
|
</span> |
|
|
|
</span> |
|
|
|
} |
|
|
|
} |
|
|
|
</Col> |
|
|
|
{room && |
|
|
|
</Row> |
|
|
|
<span>Deel de link met je vrienden om mee te doen!</span> |
|
|
|
|
|
|
|
|
|
|
|
{isLeader ? |
|
|
|
|
|
|
|
<Button |
|
|
|
|
|
|
|
block |
|
|
|
|
|
|
|
type="primary" |
|
|
|
|
|
|
|
onClick={handleRequestStartClicked}>Start</Button> |
|
|
|
|
|
|
|
: |
|
|
|
|
|
|
|
<Button |
|
|
|
|
|
|
|
block |
|
|
|
|
|
|
|
type="primary" |
|
|
|
|
|
|
|
disabled={!room} |
|
|
|
|
|
|
|
onClick={handleJoin}>Join</Button> |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
<br/> |
|
|
|
|
|
|
|
<br/> |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
{room && (isLeader ? leaderConfig : nonLeaderConfig)} |
|
|
|
|
|
|
|
|
|
|
|
<Divider/> |
|
|
|
<Divider/> |
|
|
|
|
|
|
|
|
|
|
@ -185,7 +204,7 @@ const Lobby = (props: any) => { |
|
|
|
<Col> |
|
|
|
<Col> |
|
|
|
<Button type="primary" |
|
|
|
<Button type="primary" |
|
|
|
onClick={() => { |
|
|
|
onClick={() => { |
|
|
|
joinRandomLobby() |
|
|
|
handleJoinRandomLobby() |
|
|
|
}}>Join een willekeurige lobby</Button> |
|
|
|
}}>Join een willekeurige lobby</Button> |
|
|
|
</Col> |
|
|
|
</Col> |
|
|
|
</Row> |
|
|
|
</Row> |
|
|
|