silphius/app/routes/_main-menu.play.$/route.jsx
2024-06-14 12:27:07 -05:00

40 lines
967 B
JavaScript

import {useEffect, useState} from 'react';
import {Outlet, useParams} from 'react-router-dom';
import LocalClient from '@/net/client/local.js';
import RemoteClient from '@/net/client/remote.js';
import {decode, encode} from '@/packets/index.js';
import styles from './play.module.css';
export default function Play() {
const [Client, setClient] = useState();
const params = useParams();
const [type] = params['*'].split('/');
useEffect(() => {
let Client;
switch (type) {
case 'local':
Client = LocalClient;
break;
case 'remote':
Client = RemoteClient;
break;
}
class SilphiusClient extends Client {
accept(packed) {
super.accept(decode(packed));
}
transmit(packet) {
super.transmit(encode(packet));
}
}
setClient(() => SilphiusClient);
}, [type]);
return (
<div className={styles.play}>
<Outlet context={Client} />
</div>
);
}