43 lines
840 B
TypeScript
43 lines
840 B
TypeScript
import React from "react";
|
|
|
|
interface Props {
|
|
websocketRef: React.MutableRefObject<WebSocket | null>;
|
|
}
|
|
|
|
const serverControl = ({ websocketRef }: Props) => {
|
|
const setStateFunction = (state: string) => {
|
|
websocketRef.current?.send(`{"event":"set state","args":["${state}"]}`);
|
|
};
|
|
|
|
return (
|
|
<>
|
|
<button
|
|
onClick={() => {
|
|
setStateFunction("start");
|
|
}}
|
|
className="btn btn-success"
|
|
>
|
|
Start
|
|
</button>
|
|
<button
|
|
onClick={() => {
|
|
setStateFunction("restart");
|
|
}}
|
|
className="btn btn-warning"
|
|
>
|
|
Restart
|
|
</button>
|
|
<button
|
|
onClick={() => {
|
|
setStateFunction("stop");
|
|
}}
|
|
className="btn btn-danger"
|
|
>
|
|
Stop
|
|
</button>
|
|
</>
|
|
);
|
|
};
|
|
|
|
export default serverControl;
|