Connect data

This commit is contained in:
brunosimon
2016-06-05 01:14:23 +02:00
parent b61ddb5967
commit c8d111cf5c
10 changed files with 261 additions and 164 deletions
+40 -14
View File
@@ -36,16 +36,16 @@ class App
// Set up
this.projects = new Projects()
// // Tests
// Tests
// var project = this.projects.create_project( 'test' )
// project.create_folder( 'toto' )
// project.get_folder( 'toto//tutu/tete', true )
// project.create_file( 'coucou/coco.txt', 'content 0' )
// project.update_file( 'toto/tutu/tete/tutu.txt', 'content 1' )
// project.update_file( 'toto/tata/lorem.txt', 'content 2' )
// project.update_file( 'toto/tata/ipsum.txt', 'content 3' )
// project.delete_folder( 'toto/tutu', true )
// project.delete_file( 'toto/tata/ipsum.txt' )
// project.create_folder( './toto' )
// project.get_folder( './toto//tutu/tete', true )
// project.create_file( './coucou/coco.txt', 'content 0' )
// project.create_file( './test-1.txt', 'content 1' )
// project.update_file( './toto/tata/lorem.txt', 'content 2' )
// project.update_file( './toto/tata/ipsum.txt', 'content 3' )
// project.delete_folder( './toto/tutu', true )
// project.delete_file( './toto/tata/ipsum.txt' )
// console.log( util.inspect( project, { depth: null, colors: true } ) )
}
@@ -108,51 +108,77 @@ class App
set_socket()
{
// Set up
this.io = socket_io.listen( this.server )
this.sockets = {}
this.sockets.main = socket_io.listen( this.server )
this.sockets.app = this.sockets.main.of( '/app' )
this.sockets.site = this.sockets.main.of( '/site' )
let project = null
// Connection event
this.io.on( 'connection', ( socket ) =>
this.sockets.app.on( 'connection', ( socket ) =>
{
console.log( 'socket'.green.bold + ' - ' + 'connect'.cyan + ' - ' + socket.id.cyan )
let project = null
console.log( 'socket app'.green.bold + ' - ' + 'connect'.cyan + ' - ' + socket.id.cyan )
socket.on( 'start_project', ( data ) =>
{
project = this.projects.create_project( data.slug )
console.log( util.inspect( project, { depth: null, colors: true } ) )
} )
socket.on( 'update_file', ( data ) =>
{
project.update_file( data.path, data.content )
this.sockets.site.emit( 'update_project', project )
console.log( util.inspect( project, { depth: null, colors: true } ) )
} )
socket.on( 'create_file', ( data ) =>
{
project.create_file( data.path, data.content )
this.sockets.site.emit( 'update_project', project )
console.log( util.inspect( project, { depth: null, colors: true } ) )
} )
socket.on( 'delete_file', ( data ) =>
{
project.delete_file( data.path )
this.sockets.site.emit( 'update_project', project )
console.log( util.inspect( project, { depth: null, colors: true } ) )
} )
socket.on( 'create_folder', ( data ) =>
{
project.create_folder( data.path, data.content )
this.sockets.site.emit( 'update_project', project )
console.log( util.inspect( project, { depth: null, colors: true } ) )
} )
socket.on( 'delete_folder', ( data ) =>
{
project.delete_folder( data.path )
this.sockets.site.emit( 'update_project', project )
console.log( util.inspect( project, { depth: null, colors: true } ) )
} )
} )
this.sockets.site.on( 'connection', ( socket ) =>
{
console.log( 'socket site'.green.bold + ' - ' + 'connect'.cyan + ' - ' + socket.id.cyan )
socket.emit( 'update_project', project )
} )
}
}