Commit 90bc7ff5 authored by Leo Iannacone's avatar Leo Iannacone

update to socket.io v1.x

parent acfabe9c
......@@ -19,7 +19,7 @@ var http = require('http'),
var app = module.exports = express(),
server = http.createServer(app),
io = require('socket.io').listen(server, config.socket),
io = require('socket.io')(server),
env = process.env.NODE_ENV || 'development';
if ('development' == env) {
......
......@@ -17,9 +17,6 @@ var config = {};
config.host = 'localhost';
config.port = 3000;
config.socket = {};
config.socket.log = false;
config.debomatic = {};
config.debomatic.path = '/srv/debomatic-amd64';
config.debomatic.jsonfile = '/var/log/debomatic-json.log';
......
......@@ -75,46 +75,41 @@ function __get_files_list(dir, onlyDirectories, callback) {
}
function __watch_path_onsocket(event_name, socket, data, watch_path, updater) {
socket.get('watchers', function (err, socket_watchers) {
if (!socket_watchers) {
// init socket watchers
socket_watchers = {};
}
try {
var watcher = socket_watchers[event_name];
if (watcher)
watcher.close();
fs.stat(watch_path, function (err, stats) {
if (err) {
__errors_handler('__watch_path_onsocket:fs.stat', err, socket);
return;
}
if (stats.isDirectory()) {
watcher = fs.watch(watch_path, {
persistent: true
}, function (event, fileName) {
if (event == 'rename')
updater(event_name, socket, data);
});
} else if (stats.isFile()) {
watcher = new Tail(watch_path);
watcher.on('line', function (new_content, tailInfo) {
data.file.new_content = new_content + '\n';
var socket_watchers = socket.watchers || {};
try {
var watcher = socket_watchers[event_name];
if (watcher)
watcher.close();
fs.stat(watch_path, function (err, stats) {
if (err) {
__errors_handler('__watch_path_onsocket:fs.stat', err, socket);
return;
}
if (stats.isDirectory()) {
watcher = fs.watch(watch_path, {
persistent: true
}, function (event, fileName) {
if (event == 'rename')
updater(event_name, socket, data);
});
watcher.on('error', function (msg) {
socket.emit(config.events.error, msg);
});
}
socket_watchers[event_name] = watcher;
socket.set('watchers', socket_watchers);
});
} catch (err) {
__errors_handler('__watch_path_onsocket <- ' + arguments.callee.caller.name, err, socket);
return;
}
});
});
} else if (stats.isFile()) {
watcher = new Tail(watch_path);
watcher.on('line', function (new_content, tailInfo) {
data.file.new_content = new_content + '\n';
updater(event_name, socket, data);
});
watcher.on('error', function (msg) {
socket.emit(config.events.error, msg);
});
}
socket_watchers[event_name] = watcher;
socket.watchers = socket_watchers;
});
} catch (err) {
__errors_handler('__watch_path_onsocket <- ' + arguments.callee.caller.name, err, socket);
return;
}
}
function __generic_handler_watcher(event_name, socket, data, watch_path, callback) {
......
......@@ -8,7 +8,7 @@
"serve-static": "*",
"errorhandler ": "*",
"ejs": ">= 0.0.1",
"socket.io": "0.*",
"socket.io": "1.*",
"tail": "*"
},
"scripts": {
......
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