🎨 Finish restructuring app
This commit is contained in:
+13
-27
@@ -6,51 +6,37 @@ const Files = require('./files.js')
|
||||
|
||||
class Project
|
||||
{
|
||||
constructor(_options)
|
||||
constructor(_config, _options)
|
||||
{
|
||||
this.setOptions(_options)
|
||||
this.config = _config
|
||||
|
||||
this.setName(_options.name)
|
||||
this.setSocket(_options.socket)
|
||||
this.setSocket()
|
||||
|
||||
this.files = new Files({ socket: this.socket })
|
||||
this.files = new Files(this.config, { projectSocket: this.projectSocket })
|
||||
this.date = new Date()
|
||||
}
|
||||
|
||||
/**
|
||||
* Set options
|
||||
*/
|
||||
setOptions(_options)
|
||||
{
|
||||
if(typeof _options.debug === 'undefined')
|
||||
{
|
||||
_options.debug = false
|
||||
}
|
||||
|
||||
// Save
|
||||
this.options = _options
|
||||
}
|
||||
|
||||
setName(_name)
|
||||
{
|
||||
this.name = _name
|
||||
this.slug = slug(this.name, { lower: true })
|
||||
}
|
||||
|
||||
setSocket(socket)
|
||||
setSocket()
|
||||
{
|
||||
// Set up
|
||||
this.originalSocket = socket
|
||||
this.socket = this.originalSocket.of('/project/' + this.slug)
|
||||
// Save original socket and create a channel for this specific project
|
||||
this.projectSocket = this.config.socket.of('/project/' + this.slug)
|
||||
|
||||
// Connection event
|
||||
this.socket.on('connection', (socket) =>
|
||||
this.projectSocket.on('connection', (socket) =>
|
||||
{
|
||||
this.socket.emit('update_project', this.describe())
|
||||
this.projectSocket.emit('update_project', this.describe())
|
||||
|
||||
// Debug
|
||||
if(this.options.debug)
|
||||
if(this.config.debug >= 1)
|
||||
{
|
||||
console.log('socket projects'.green.bold + ' - ' + 'connect'.cyan + ' - ' + socket.id.cyan)
|
||||
console.log('project > socket'.green.bold + ' - ' + 'connection'.cyan + ' - ' + socket.id.cyan)
|
||||
}
|
||||
})
|
||||
}
|
||||
@@ -69,7 +55,7 @@ class Project
|
||||
|
||||
destructor()
|
||||
{
|
||||
this.socket.emit('destruct')
|
||||
this.projectSocket.emit('destruct')
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user