2023-01-07 20:07:39 +09:00
|
|
|
import React, { useMemo, useState } from "react"
|
2023-01-12 23:01:45 +09:00
|
|
|
import { ClientState } from "@dannadori/voice-changer-client-js";
|
2023-01-07 20:07:39 +09:00
|
|
|
|
|
|
|
export type UseServerControlProps = {
|
2023-01-11 00:59:09 +09:00
|
|
|
clientState: ClientState
|
2023-01-07 20:07:39 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
export const useServerControl = (props: UseServerControlProps) => {
|
|
|
|
const [isStarted, setIsStarted] = useState<boolean>(false)
|
|
|
|
|
|
|
|
const startButtonRow = useMemo(() => {
|
|
|
|
const onStartClicked = async () => {
|
|
|
|
setIsStarted(true)
|
2023-01-12 16:38:45 +09:00
|
|
|
await props.clientState.clientSetting.start()
|
2023-01-07 20:07:39 +09:00
|
|
|
}
|
|
|
|
const onStopClicked = async () => {
|
|
|
|
setIsStarted(false)
|
2023-01-23 10:16:40 +09:00
|
|
|
console.log("stop click1")
|
2023-01-12 16:38:45 +09:00
|
|
|
await props.clientState.clientSetting.stop()
|
2023-01-23 10:16:40 +09:00
|
|
|
console.log("stop click2")
|
2023-01-07 20:07:39 +09:00
|
|
|
}
|
|
|
|
const startClassName = isStarted ? "body-button-active" : "body-button-stanby"
|
|
|
|
const stopClassName = isStarted ? "body-button-stanby" : "body-button-active"
|
|
|
|
|
|
|
|
return (
|
|
|
|
<div className="body-row split-3-3-4 left-padding-1 guided">
|
|
|
|
<div className="body-item-title left-padding-1">Start</div>
|
|
|
|
<div className="body-button-container">
|
|
|
|
<div onClick={onStartClicked} className={startClassName}>start</div>
|
|
|
|
<div onClick={onStopClicked} className={stopClassName}>stop</div>
|
|
|
|
</div>
|
|
|
|
<div className="body-input-container">
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
)
|
2023-01-12 16:38:45 +09:00
|
|
|
}, [isStarted, props.clientState.clientSetting.start, props.clientState.clientSetting.stop])
|
2023-01-07 20:07:39 +09:00
|
|
|
|
|
|
|
const performanceRow = useMemo(() => {
|
|
|
|
return (
|
|
|
|
<>
|
|
|
|
<div className="body-row split-3-1-1-1-4 left-padding-1 guided">
|
|
|
|
<div className="body-item-title left-padding-1">monitor:</div>
|
2023-01-16 07:45:06 +09:00
|
|
|
<div className="body-item-text">vol<span className="body-item-text-small">(rms)</span></div>
|
|
|
|
<div className="body-item-text">buf<span className="body-item-text-small">(ms)</span></div>
|
|
|
|
<div className="body-item-text">res<span className="body-item-text-small">(ms)</span></div>
|
|
|
|
<div className="body-item-text"></div>
|
|
|
|
</div>
|
|
|
|
<div className="body-row split-3-1-1-1-4 left-padding-1 guided">
|
|
|
|
<div className="body-item-title left-padding-1"></div>
|
|
|
|
<div className="body-item-text">{props.clientState.volume.toFixed(4)}</div>
|
|
|
|
<div className="body-item-text">{props.clientState.bufferingTime}</div>
|
|
|
|
<div className="body-item-text">{props.clientState.responseTime}</div>
|
2023-01-07 20:07:39 +09:00
|
|
|
<div className="body-item-text"></div>
|
|
|
|
</div>
|
|
|
|
</>
|
|
|
|
)
|
2023-01-11 00:59:09 +09:00
|
|
|
}, [props.clientState.volume, props.clientState.bufferingTime, props.clientState.responseTime])
|
2023-01-07 20:07:39 +09:00
|
|
|
|
|
|
|
|
2023-01-08 16:18:20 +09:00
|
|
|
|
|
|
|
const infoRow = useMemo(() => {
|
|
|
|
const onReloadClicked = async () => {
|
2023-01-11 00:59:09 +09:00
|
|
|
const info = await props.clientState.getInfo()
|
2023-01-08 16:18:20 +09:00
|
|
|
console.log("info", info)
|
|
|
|
}
|
|
|
|
return (
|
|
|
|
<>
|
2023-01-11 02:19:54 +09:00
|
|
|
<div className="body-row split-3-3-4 left-padding-1 guided">
|
|
|
|
<div className="body-item-title left-padding-1">Model Info:</div>
|
|
|
|
<div className="body-item-text">
|
2023-01-12 16:38:45 +09:00
|
|
|
<span className="body-item-text-item">{props.clientState.serverSetting.serverInfo?.configFile || ""}</span>
|
|
|
|
<span className="body-item-text-item">{props.clientState.serverSetting.serverInfo?.pyTorchModelFile || ""}</span>
|
|
|
|
<span className="body-item-text-item">{props.clientState.serverSetting.serverInfo?.onnxModelFile || ""}</span>
|
2023-01-11 02:19:54 +09:00
|
|
|
|
|
|
|
|
|
|
|
</div>
|
2023-01-08 16:18:20 +09:00
|
|
|
<div className="body-button-container">
|
|
|
|
<div className="body-button" onClick={onReloadClicked}>reload</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</>
|
|
|
|
)
|
2023-01-12 16:38:45 +09:00
|
|
|
}, [props.clientState.getInfo, props.clientState.serverSetting.serverInfo])
|
2023-01-08 16:18:20 +09:00
|
|
|
|
|
|
|
|
|
|
|
|
2023-01-07 20:07:39 +09:00
|
|
|
const serverControl = useMemo(() => {
|
|
|
|
return (
|
|
|
|
<>
|
|
|
|
<div className="body-row split-3-7 left-padding-1">
|
|
|
|
<div className="body-sub-section-title">Server Control</div>
|
|
|
|
<div className="body-select-container">
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
{startButtonRow}
|
|
|
|
{performanceRow}
|
2023-01-08 16:18:20 +09:00
|
|
|
{infoRow}
|
2023-01-07 20:07:39 +09:00
|
|
|
</>
|
|
|
|
)
|
2023-01-08 16:18:20 +09:00
|
|
|
}, [startButtonRow, performanceRow, infoRow])
|
2023-01-07 20:07:39 +09:00
|
|
|
|
|
|
|
return {
|
|
|
|
serverControl,
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|