X-Git-Url: https://git.r.bdr.sh/rbdr/cologne/blobdiff_plain/c315b8c3c28373aeb28889cf4b09041d98cd5320..97a7ece70e89b973468b62e1775a33762a37258e:/lib/loggers/socket.js?ds=sidebyside diff --git a/lib/loggers/socket.js b/lib/loggers/socket.js index 739c5b3..7066274 100644 --- a/lib/loggers/socket.js +++ b/lib/loggers/socket.js @@ -1,55 +1,37 @@ -(function (global) { - var Module, Class; - - // Load up dependencies - if (typeof require === 'function') { - var Ne = require('neon'); - Module = Ne.Module; - Class = Ne.Class; - } else { - Module = global.Module; - Class = global.Class; - } - - var Cobalt = {}; - Module(Cobalt, 'Logger')({}); +if (typeof require === 'function') { + var ioClient = require('socket.io-client'); +} - Cobalt.Logger.Socket = Class(Cobalt.Logger, 'Socket')({ - prototype : { - serverUrl : '/', +Class(Cobalt.Logger, 'Socket')({ + prototype : { + serverUrl : '/', - init : function (config) { - var logger = this; - logger.socketIo = io; + init : function (config) { + var logger = this; - if (config) { - for (property in config) { - logger[property] = config[property]; - } + if (config) { + for (property in config) { + logger[property] = config[property]; } + } - logger._socket = logger.socketIo.connect(logger.serverUrl); - }, + if (!logger.socketIo) { + logger.socketIo = ioClient; + } - log : function () { - var i, messageArray = []; + logger._socket = logger.socketIo.connect(logger.serverUrl); + }, - for (i = 0; i < arguments.length; i++) { - messageArray.push(arguments[i]); - } + log : function () { + var i, messageArray = []; + for (i = 0; i < arguments.length; i++) { + messageArray.push(arguments[i]); + } + + if (this._socket) { this._socket.emit('log', messageArray); } } - }); - - if (Cobalt.Logger.Socket.__objectSpy) { - Cobalt.Logger.Socket.__objectSpy.destroy(); - } - - if (typeof require === 'function') { - global.Socket = Cobalt.Logger.Socket; - } else { - global.Cobalt.Logger.Socket = Cobalt.Logger.Socket; } -}(typeof window !== 'undefined' ? window : (typeof exports !== 'undefined' ? exports : self))); +});