refactor: keep disconnect handler in main file
This commit is contained in:
parent
ef018385ef
commit
e439816671
@ -116,20 +116,4 @@ export function handleCloseTerminal(terminalManager: TerminalManager, id: string
|
||||
export function handleGenerateCode(aiWorker: AIWorker, userId: string, fileName: string, code: string, line: number, instructions: string) {
|
||||
return aiWorker.generateCode(userId, fileName, code, line, instructions)
|
||||
}
|
||||
|
||||
// Handle a client disconnecting from the server
|
||||
export async function handleDisconnect(data: any, connections: any, terminalManager: TerminalManager, fileManager: FileManager, socket: any) {
|
||||
if (data.isOwner) {
|
||||
connections[data.sandboxId]--
|
||||
}
|
||||
|
||||
await terminalManager.closeAllTerminals()
|
||||
await fileManager.closeWatchers()
|
||||
|
||||
if (data.isOwner && connections[data.sandboxId] <= 0) {
|
||||
socket.broadcast.emit(
|
||||
"disableAccess",
|
||||
"The sandbox owner has disconnected."
|
||||
)
|
||||
}
|
||||
}
|
@ -398,7 +398,19 @@ io.on("connection", async (socket) => {
|
||||
|
||||
socket.on("disconnect", async () => {
|
||||
try {
|
||||
await handleDisconnect(data, connections, terminalManager, fileManager, socket)
|
||||
if (data.isOwner) {
|
||||
connections[data.sandboxId]--
|
||||
}
|
||||
|
||||
await terminalManager.closeAllTerminals()
|
||||
await fileManager.closeWatchers()
|
||||
|
||||
if (data.isOwner && connections[data.sandboxId] <= 0) {
|
||||
socket.broadcast.emit(
|
||||
"disableAccess",
|
||||
"The sandbox owner has disconnected."
|
||||
)
|
||||
}
|
||||
} catch (e: any) {
|
||||
console.log("Error disconnecting:", e)
|
||||
socket.emit("error", `Error: disconnecting. ${e.message ?? e}`)
|
||||
|
Loading…
x
Reference in New Issue
Block a user