added auto disconnect when changing link

This commit is contained in:
PxlLoewe
2025-06-02 15:04:15 -07:00
parent 72998a36a4
commit af36b82221
9 changed files with 72 additions and 5 deletions

View File

@@ -91,12 +91,14 @@ router.patch("/:id", async (req, res) => {
});
}
res.json(updatedConnectedAircraft);
// When change is only the estimated logout time, we don't need to emit an event
if (Object.keys(aircraftUpdate).length === 1 && aircraftUpdate.esimatedLogoutTime) return;
io.to("dispatchers").emit("update-connectedAircraft", updatedConnectedAircraft);
io.to(`user:${updatedConnectedAircraft.userId}`).emit(
"aircraft-update",
updatedConnectedAircraft,
);
res.json(updatedConnectedAircraft);
} catch (error) {
console.error(error);
res.status(500).json({ error: "Failed to update connectedAircraft" });