Commit c7008c40 authored by Leo Iannacone's avatar Leo Iannacone

renamed send.js in client.js - moved socket handler completly to client - created Client class

parent 0e689cb9
......@@ -8,7 +8,7 @@ var express = require('express')
, fs = require('fs')
, path = require('path')
, config = require('./lib/config.js')
, send = require('./lib/send.js')
, client = require('./lib/client.js')
, utils = require('./lib/utils.js')
var app = module.exports = express.createServer();
......@@ -40,37 +40,13 @@ app.get('/', routes.index);
app.get(config.routes.distribution, routes.distribution)
io.sockets.on('connection', function(socket) {
send.distributions(socket);
// send distribution packages
socket.on('get_distribution_packages', function (data) {
if (! utils.check_data_distribution(data))
return
send.distribution_packages(socket, data);
})
socket.on('get_package_files_list', function(data) {
if (! utils.check_data_package(data))
return
send.package_files_list(socket, data)
})
socket.on('get_file', function (data){
if (! utils.check_data_file(data))
return
send.file(socket, data)
})
client(socket)
});
io.sockets.on('disconnect', function(socket){
});
fs.watch(config.debomatic.path, { persistent: true }, function (event, fileName) {
send.distributions(io.sockets);
});
var server = app.listen(config.port, function(){
console.log("Express server listening on port %d in %s mode", app.address().port, app.settings.env);
});
......@@ -97,6 +97,12 @@ function __send_file (event_name, socket, data) {
});
}
function __send_distributions(event_name, socket, data) {
__get_files_list(config.debomatic.path, true, function(distros){
socket.emit(event_name, distros);
});
}
function __watch_path_onsocket(event_name, socket, data, watch_path, updater) {
name = "watcher-" + event_name
socket.get(name, function (err, watcher) {
......@@ -137,33 +143,57 @@ function __file_newcontent(event_name, socket, data) {
socket.emit(event_name, data)
}
sender = {
function __handler_get_distributions (socket, data) {
event_name = 'distributions'
__watch_path_onsocket(event_name,socket, data, config.debomatic.path, __send_distributions)
__send_distributions(event_name, socket, data)
}
distributions: function(socket) {
__get_files_list(config.debomatic.path, true, function(distros){
socket.emit('distributions', distros);
});
},
package_files_list: function(socket, data) {
event_name = 'package_files_list'
package_path = utils.get_package_path(data)
__watch_path_onsocket(event_name, socket, data, package_path, __send_package_files_list)
__send_package_files_list(event_name, socket, data)
},
distribution_packages: function(socket, data) {
event_name = 'distribution_packages'
distribution_path = path.join(config.debomatic.path, data.distribution.name, 'pool')
__watch_path_onsocket(event_name, socket, data, distribution_path, __send_distribution_packages)
__send_distribution_packages(event_name, socket, data)
},
function __handler_get_package_files_list (socket, data) {
event_name = 'package_files_list'
package_path = utils.get_package_path(data)
__watch_path_onsocket(event_name, socket, data, package_path, __send_package_files_list)
__send_package_files_list(event_name, socket, data)
}
function __handler_get_distribution_packages (socket, data) {
event_name = 'distribution_packages'
distribution_path = path.join(config.debomatic.path, data.distribution.name, 'pool')
__watch_path_onsocket(event_name, socket, data, distribution_path, __send_distribution_packages)
__send_distribution_packages(event_name, socket, data)
}
function __handler_get_file (socket, data) {
file_path = utils.get_file_path(data)
__watch_path_onsocket('file_newcontent', socket, data, file_path, __file_newcontent)
__send_file('file', socket, data)
}
Client = function (socket) {
__handler_get_distributions(socket);
// send distribution packages
socket.on('get_distribution_packages', function (data) {
if (! utils.check_data_distribution(data))
return
__handler_get_distribution_packages(socket, data);
})
socket.on('get_package_files_list', function(data) {
if (! utils.check_data_package(data))
return
__handler_get_package_files_list(socket, data)
})
file: function(socket, data) {
file_path = utils.get_file_path(data)
__watch_path_onsocket('file_newcontent', socket, data, file_path, __file_newcontent)
__send_file('file', socket, data)
},
socket.on('get_file', function (data){
if (! utils.check_data_file(data))
return
__handler_get_file(socket, data)
})
return {
}
}
module.exports = sender
module.exports = Client
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment