⚡ App > Stop listening to socket events
This commit is contained in:
+28
-15
@@ -223,8 +223,10 @@ class App
|
||||
console.log(`${chalk.green.bold('app > socket')} - ${chalk.cyan('connect')} - ${chalk.cyan(socket.id)}`)
|
||||
}
|
||||
|
||||
// Start project
|
||||
socket.on('start_project', (data) =>
|
||||
// Callbacks
|
||||
const callbacks = {}
|
||||
|
||||
callbacks.startProject = (data) =>
|
||||
{
|
||||
data.watcherSocket = socket // Add watcher socket
|
||||
project = this.projects.createProject(data)
|
||||
@@ -242,10 +244,9 @@ class App
|
||||
}
|
||||
|
||||
socket.emit('started')
|
||||
})
|
||||
}
|
||||
|
||||
// Update file
|
||||
socket.on('update_file', (data) =>
|
||||
callbacks.updateFile = (data) =>
|
||||
{
|
||||
project.files.createVersion(data.path, data.content)
|
||||
project.zipNeedsUpdate = true
|
||||
@@ -259,10 +260,9 @@ class App
|
||||
{
|
||||
console.log(util.inspect(project.files.describe(), { depth: null, colors: true }))
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
// Create file
|
||||
socket.on('create_file', (data) =>
|
||||
callbacks.createFile = (data) =>
|
||||
{
|
||||
project.files.create(data.path, data.content)
|
||||
project.zipNeedsUpdate = true
|
||||
@@ -276,10 +276,9 @@ class App
|
||||
{
|
||||
console.log(util.inspect(project.files.describe(), { depth: null, colors: true }))
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
// Delete file
|
||||
socket.on('delete_file', (data) =>
|
||||
callbacks.deleteFile = (data) =>
|
||||
{
|
||||
project.files.delete(data.path)
|
||||
project.zipNeedsUpdate = true
|
||||
@@ -293,19 +292,33 @@ class App
|
||||
{
|
||||
console.log(util.inspect(project.files.describe(), { depth: null, colors: true }))
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
// Disconnect
|
||||
socket.on('disconnect', () =>
|
||||
callbacks.disconnect = () =>
|
||||
{
|
||||
// Delete project
|
||||
this.projects.deleteProject(project.slug)
|
||||
|
||||
// Stop listening
|
||||
socket.off('start_project', callbacks.startProject)
|
||||
socket.off('update_file', callbacks.updateFile)
|
||||
socket.off('create_file', callbacks.createFile)
|
||||
socket.off('delete_file', callbacks.disconnect)
|
||||
socket.off('disconnect', callbacks.disconnect)
|
||||
|
||||
// Debug
|
||||
if(this.config.debug >= 1)
|
||||
{
|
||||
console.log(`${chalk.green.bold('app > socket')} - ${chalk.cyan('disconnect')} - ${chalk.cyan(socket.id)}`)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
// Start listening
|
||||
socket.on('start_project', callbacks.startProject)
|
||||
socket.on('update_file', callbacks.updateFile)
|
||||
socket.on('create_file', callbacks.createFile)
|
||||
socket.on('delete_file', callbacks.deleteFile)
|
||||
socket.on('disconnect', callbacks.disconnect)
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user