Improved socket connection for node_helper.

This commit is contained in:
Michael Teeuw 2016-03-30 16:25:24 +02:00
parent 59b339aba5
commit b243d25399
6 changed files with 55 additions and 107 deletions

View file

@ -1,27 +1,3 @@
if (typeof window === 'undefined') {
// Only perfom this part if is isn't running in the browser.
// Load socket client
var io = require('socket.io-client');
// Load config
var fs = require('fs');
var config = {};
var defaults = require(__dirname + '/defaults.js');
var configFilename = __dirname + '/../config/config.js';
try {
fs.accessSync(configFilename, fs.R_OK);
var c = require(configFilename);
config = Object.assign(defaults, c);
} catch (e) {
config = defaults;
}
}
var MMSocket = function(moduleName) {
var self = this;
@ -35,6 +11,7 @@ var MMSocket = function(moduleName) {
// Private Methods
var socketBase = (typeof window === 'undefined') ? 'http://localhost:'+config.port : '';
socket = io(socketBase + '/' + self.moduleName);
console.log(socketBase + '/' + self.moduleName);
var notificationCallback = function() {};
@ -76,8 +53,4 @@ var MMSocket = function(moduleName) {
}
sendNotification(notification, payload);
};
};
if (typeof module !== 'undefined') {
module.exports = MMSocket;
}
};