This commit is contained in:
nguyentrungthat 2025-11-06 14:33:48 +07:00
parent 8739522915
commit c09f27da86
7 changed files with 61 additions and 26 deletions

View File

@ -138,7 +138,7 @@ export default class LineConnection {
this.client.on('close', () => {
console.log(`🔌 Line ${lineNumber} disconnected`)
this.config.status = 'disconnected'
this.config.inventory = undefined
// this.config.inventory = undefined
this.socketIO.emit('line_disconnected', {
stationId,
lineId: id,

View File

@ -110,6 +110,13 @@ export class WebSocketIo {
socket.on('disconnect', () => {
console.log(`FE disconnected: ${socket.id}`)
this.userConnecting.delete(userId)
const listLineS = Array.from(this.lineMap.values()).map((el) => el.config)
listLineS.forEach((el) => {
if (el.userOpenCLI === userName) {
const line = this.lineMap.get(el.id)
if (line) line.userCloseCLI()
}
})
setTimeout(() => {
io.emit('user_connecting', Array.from(this.userConnecting.values()))
}, 200)
@ -559,7 +566,15 @@ export class WebSocketIo {
const username = station.switch_control_username as string
const password = station.switch_control_password as string
if (!ip || !port || !password) throw new Error(`Missing Switch configuration`)
if (!ip || !port || !password) {
socket.emit('switch_output', {
stationId: station.id,
portGroups: [],
status: 'DISCONNECTED',
message: `Missing Switch configuration`,
})
throw new Error(`Missing Switch configuration`)
}
// Tạo APC Controller instance
const infoSwitch = new SwitchController({

View File

@ -364,6 +364,17 @@ function App() {
setSelectedLine(data);
};
useEffect(() => {
return () => {
console.log("CLEANUP SOCKET CLI", selectedLine);
if (selectedLine)
socket?.emit("close_cli", {
lineId: selectedLine?.id,
stationId: selectedLine?.station_id,
});
};
}, []);
return (
<Container w={"100%"} style={{ maxWidth: "100%" }}>
<DraggableTabs

View File

@ -111,9 +111,9 @@ const CardLine = ({
line_id={Number(line?.id)}
station_id={Number(stationItem.id)}
isDisabled={
typeof line?.userEmailOpenCLI !== "undefined" &&
typeof line?.userEmailOpenCLI !== "string" &&
line?.userEmailOpenCLI !== user?.email
typeof line?.userOpenCLI !== "undefined" &&
typeof line?.userOpenCLI === "string" &&
line?.userOpenCLI !== user?.userName
}
line_status={line?.status || ""}
fontSize={11}

View File

@ -813,6 +813,13 @@ export const DrawerSwitchControl: React.FC<DrawerProps> = ({
}
}, [open]);
useEffect(() => {
if (loading)
setTimeout(() => {
setLoading(false);
}, 15000);
}, [loading]);
useEffect(() => {
socket?.on("switch_output", (data) => {
if (data.stationId !== stationAPI.id) return;

View File

@ -64,15 +64,15 @@ const ModalTerminal = ({
useEffect(() => {
if (
typeof dataRequestTakeOver?.userName !== "undefined" &&
line?.userEmailOpenCLI === user?.email &&
dataRequestTakeOver?.userName !== user?.email
line?.userOpenCLI === user?.userName &&
dataRequestTakeOver?.userName !== user?.userName
) {
if (dataRequestTakeOver?.userName) {
intervalTakeOverRef.current = setInterval(() => {
socket?.emit("open_cli", {
lineId: line?.id,
stationId: line?.station_id,
userEmail: user?.email,
userEmail: user?.userName,
userName: user?.userName,
});
socket?.emit("request_take_over", {
@ -96,7 +96,7 @@ const ModalTerminal = ({
opened={opened}
onClose={() => {
onClose();
if (line?.userEmailOpenCLI === user?.email)
if (line?.userOpenCLI === user?.userName)
socket?.emit("close_cli", {
lineId: line?.id,
stationId: line?.station_id,
@ -133,7 +133,9 @@ const ModalTerminal = ({
}}
>
{line?.userOpenCLI
? line?.userOpenCLI + " is using"
? (line?.userOpenCLI === user?.userName
? "You are"
: line?.userOpenCLI + " is") + " using"
: "Terminal is used"}
</div>
</Box>
@ -170,8 +172,8 @@ const ModalTerminal = ({
line_id={Number(line?.id)}
station_id={Number(stationItem?.id)}
isDisabled={
typeof line?.userEmailOpenCLI !== "undefined" &&
line?.userEmailOpenCLI !== user?.email
typeof line?.userOpenCLI !== "undefined" &&
line?.userOpenCLI !== user?.userName
}
line_status={line?.status || ""}
/>
@ -194,8 +196,8 @@ const ModalTerminal = ({
<Button
disabled={
isDisable ||
(typeof line?.userEmailOpenCLI !== "undefined" &&
line?.userEmailOpenCLI !== user?.email)
(typeof line?.userOpenCLI !== "undefined" &&
line?.userOpenCLI !== user?.userName)
}
className={classes.buttonScenario}
key={scenario.id}
@ -230,8 +232,8 @@ const ModalTerminal = ({
<Button
disabled={
disableRequestTakeOver ||
!line?.userEmailOpenCLI ||
line?.userEmailOpenCLI === user?.email
!line?.userOpenCLI ||
line?.userOpenCLI === user?.userName
}
variant="filled"
size="xs"
@ -243,7 +245,7 @@ const ModalTerminal = ({
line_id: line?.id,
station_id: Number(line?.station_id),
userName: user?.userName?.trim() || "",
userEmail: user?.email || "",
userEmail: user?.userName || "",
});
setDisableRequestTakeOver(true);
setTimeout(() => {
@ -264,7 +266,7 @@ const ModalTerminal = ({
Take over{" "}
{countDownRequest > 0 &&
(typeof dataRequestTakeOver?.userName === "undefined" ||
dataRequestTakeOver?.userEmail === user?.email)
dataRequestTakeOver?.userEmail === user?.userName)
? `(${countDownRequest}s)`
: ""}
</Button>
@ -274,8 +276,8 @@ const ModalTerminal = ({
<Dialog
opened={
typeof dataRequestTakeOver?.userName !== "undefined" &&
line?.userEmailOpenCLI === user?.email &&
dataRequestTakeOver?.userName !== user?.email
line?.userOpenCLI === user?.userName &&
dataRequestTakeOver?.userName !== user?.userName
}
position={{ bottom: 20, right: 20 }}
withCloseButton
@ -286,14 +288,14 @@ const ModalTerminal = ({
radius="md"
>
<Text size="sm" mb="xs" fw={700} c={"#ff6c6b"}>
{`${
dataRequestTakeOver?.userName
? `${dataRequestTakeOver?.userName} (${dataRequestTakeOver?.userEmail})`
{`${`${dataRequestTakeOver?.userName} ${
dataRequestTakeOver?.userEmail
? `(${dataRequestTakeOver?.userEmail})`
: ""
} want to take over this line? ${
}`} want to take over this line? ${
countDownRequest > 0 &&
typeof dataRequestTakeOver?.userName !== "undefined" &&
line?.userEmailOpenCLI === user?.email
line?.userOpenCLI === user?.userName
? `(${countDownRequest}s)`
: ""
}`}

View File

@ -123,7 +123,7 @@ const TerminalCLI: React.FC<TerminalCLIProps> = ({
}, [cliOpened]);
useEffect(() => {
if (cliOpened) {
if (cliOpened && isInit) {
if (terminal.current)
setTimeout(() => terminal.current?.write(content), 200);