chore: add comments
This commit is contained in:
parent
8381455f4d
commit
701c4fcf84
@ -44,7 +44,7 @@ app.use(cors())
|
|||||||
const httpServer = createServer(app)
|
const httpServer = createServer(app)
|
||||||
const io = new Server(httpServer, {
|
const io = new Server(httpServer, {
|
||||||
cors: {
|
cors: {
|
||||||
origin: "*",
|
origin: "*", // Allow connections from any origin
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -97,7 +97,7 @@ io.on("connection", async (socket) => {
|
|||||||
isOwner: boolean
|
isOwner: boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
// Handle connection based on user type (owner or not)
|
// Disable access unless the sandbox owner is connected
|
||||||
if (data.isOwner) {
|
if (data.isOwner) {
|
||||||
connectionManager.ownerConnected(data.sandboxId)
|
connectionManager.ownerConnected(data.sandboxId)
|
||||||
} else {
|
} else {
|
||||||
@ -108,14 +108,17 @@ io.on("connection", async (socket) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
// Create or retrieve the sandbox manager for the given sandbox ID
|
||||||
const sandboxManager = sandboxManagers[data.sandboxId] ?? new SandboxManager(
|
const sandboxManager = sandboxManagers[data.sandboxId] ?? new SandboxManager(
|
||||||
data.sandboxId,
|
data.sandboxId,
|
||||||
data.userId,
|
data.userId,
|
||||||
{ aiWorker, dokkuClient, gitClient, socket }
|
{ aiWorker, dokkuClient, gitClient, socket }
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Initialize the sandbox container
|
||||||
sandboxManager.initializeContainer()
|
sandboxManager.initializeContainer()
|
||||||
|
|
||||||
|
// Register event handlers for the sandbox
|
||||||
Object.entries(sandboxManager.handlers()).forEach(([event, handler]) => {
|
Object.entries(sandboxManager.handlers()).forEach(([event, handler]) => {
|
||||||
socket.on(event, async (options: any, callback?: (response: any) => void) => {
|
socket.on(event, async (options: any, callback?: (response: any) => void) => {
|
||||||
try {
|
try {
|
||||||
@ -126,6 +129,7 @@ io.on("connection", async (socket) => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Handle disconnection event
|
||||||
socket.on("disconnect", async () => {
|
socket.on("disconnect", async () => {
|
||||||
try {
|
try {
|
||||||
if (data.isOwner) {
|
if (data.isOwner) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user