🎨 Finish restructuring app
This commit is contained in:
+13
-28
@@ -4,42 +4,27 @@ const Project = require('./project.js')
|
||||
|
||||
class Projects
|
||||
{
|
||||
constructor(_options)
|
||||
constructor(_config)
|
||||
{
|
||||
this.config = _config
|
||||
this.all = {}
|
||||
|
||||
this.setOptions(_options)
|
||||
this.setSocket(_options.socket)
|
||||
this.setSocket()
|
||||
}
|
||||
|
||||
/**
|
||||
* Set options
|
||||
*/
|
||||
setOptions(_options)
|
||||
setSocket()
|
||||
{
|
||||
if(typeof _options.debug === 'undefined')
|
||||
{
|
||||
_options.debug = false
|
||||
}
|
||||
|
||||
// Save
|
||||
this.options = _options
|
||||
}
|
||||
|
||||
setSocket(socket)
|
||||
{
|
||||
// Set up
|
||||
this.originalSocket = socket
|
||||
this.socket = this.originalSocket.of('/projects')
|
||||
// Save original socket and create a channel for projects
|
||||
this.projectsSocket = this.config.socket.of('/projects')
|
||||
|
||||
// Connection event
|
||||
this.socket.on('connection', (socket) =>
|
||||
this.projectsSocket.on('connection', (socket) =>
|
||||
{
|
||||
this.socket.emit('update_projects', this.describe())
|
||||
this.projectsSocket.emit('update_projects', this.describe())
|
||||
|
||||
if(this.options.debug)
|
||||
if(this.config.debug >= 1)
|
||||
{
|
||||
console.log('socket projects'.green.bold + ' - ' + 'connect'.cyan + ' - ' + socket.id.cyan)
|
||||
console.log('projects > socket'.green.bold + ' - ' + 'connection'.cyan + ' - ' + socket.id.cyan)
|
||||
}
|
||||
})
|
||||
}
|
||||
@@ -47,7 +32,7 @@ class Projects
|
||||
createProject(_name)
|
||||
{
|
||||
// Create project
|
||||
const project = new Project({ name: _name, socket: this.originalSocket, debug: this.options.debug })
|
||||
const project = new Project(this.config, { name: _name })
|
||||
let sameNameProject = this.all[ project.slug ]
|
||||
|
||||
// Try to found same name project
|
||||
@@ -75,7 +60,7 @@ class Projects
|
||||
this.all[ project.slug ] = project
|
||||
|
||||
// Emit
|
||||
this.socket.emit('update_projects', this.describe())
|
||||
this.projectsSocket.emit('update_projects', this.describe())
|
||||
|
||||
// Return
|
||||
return project
|
||||
@@ -94,7 +79,7 @@ class Projects
|
||||
project.destructor()
|
||||
|
||||
// Emit
|
||||
this.socket.emit('update_projects', this.describe())
|
||||
this.projectsSocket.emit('update_projects', this.describe())
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user