50 lines
1.5 KiB
TypeScript
50 lines
1.5 KiB
TypeScript
import * as React from 'react'
|
|
|
|
import { PJ } from '@lastres/pj'
|
|
|
|
import UpperPanel from '@lastres/components/upper-panel'
|
|
import BottomPanel from '@lastres/components/bottom-panel'
|
|
import PJSelectionMenu from '@lastres/components/pj-selection-menu'
|
|
|
|
export interface GameProps {
|
|
setSelectedPJ: (set: PJ | null) => void
|
|
selectedPJ: PJ | null
|
|
userWantsToCreatePJ: boolean
|
|
setUserWantsToCreatePJ: (set: boolean) => void
|
|
error: string | null
|
|
setError: (set: string | null) => void
|
|
}
|
|
|
|
export default function Game (props: GameProps): JSX.Element {
|
|
if (props.selectedPJ === null) {
|
|
return (
|
|
<>
|
|
<PJSelectionMenu
|
|
setSelectedPJ={props.setSelectedPJ}
|
|
userWantsToCreatePJ={props.userWantsToCreatePJ}
|
|
setUserWantsToCreatePJ={props.setUserWantsToCreatePJ}
|
|
error={props.error}
|
|
setError={props.setError}/>
|
|
</>
|
|
)
|
|
}
|
|
window.setTimeout(() => {
|
|
const locationProtocol = window.location.protocol
|
|
if (locationProtocol == null) {
|
|
return
|
|
}
|
|
const protocol = locationProtocol.match(/https:/) != null ? 'wss' : 'ws'
|
|
const webSocket = new WebSocket(`${protocol}://${window.location.host}/ws`)
|
|
webSocket.onopen = () => {
|
|
webSocket.send(JSON.stringify({hola: "mundo"}))
|
|
};
|
|
|
|
}, 1);
|
|
return (
|
|
<>
|
|
<UpperPanel/>
|
|
<BottomPanel/>
|
|
</>
|
|
)
|
|
}
|