context: function ControllerSpop(commandRouter) {	// This fixed variable will let us refer to 'this' object at deeper scopes	var self = this;	//getting configuration	var config=fs.readJsonSync(__dirname+'/config.json');	var nHost=config['nHost'].value;	var nPort=config['nPort'].value;	// Save a reference to the parent commandRouter	self.commandRouter = commandRouter;	// Each core gets its own set of Spop sockets connected	self.connSpopCommand = libNet.createConnection(nPort, nHost); // Socket to send commands and receive track listings	self.connSpopStatus = libNet.createConnection(nPort, nHost); // Socket to listen for status changes	// Init some command socket variables	self.bSpopCommandGotFirstMessage = false;	self.spopCommandReadyDeferred = libQ.defer(); // Make a promise for when the Spop connection is ready to receive events (basically when it emits 'spop 0.0.1').	self.spopCommandReady = self.spopCommandReadyDeferred.promise;	self.arrayResponseStack = [];	self.sResponseBuffer = '';	// Start a listener for receiving errors	self.connSpopCommand.on('error', function(err) {		console.error('SPOP command error:');		console.error(err);	});	self.connSpopStatus.on('error', function(err) {		console.error('SPOP status error:');		console.error(err);	});	// Start a listener for command socket messages (command responses)	self.connSpopCommand.on('data', function(data) {		self.sResponseBuffer = self.sResponseBuffer.concat(data.toString());		// If the last character in the data chunk is a newline, this is the end of the response		if (data.slice(data.length - 1).toString() === '\n') {			// If this is the first message, then the connection is open			if (!self.bSpopCommandGotFirstMessage) {				self.bSpopCommandGotFirstMessage = true;				try {					self.spopCommandReadyDeferred.resolve();				} catch (error) {					self.pushError(error);				}				// Else this is a command response			} else {				try {					self.arrayResponseStack.shift().resolve(self.sResponseBuffer);				} catch (error) {					self.pushError(error);				}			}			// Reset the response buffer			self.sResponseBuffer = '';		}	});	// Init some status socket variables	self.bSpopStatusGotFirstMessage = false;	self.sStatusBuffer = '';	// Start a listener for status socket messages	self.connSpopStatus.on('data', function(data) {		self.sStatusBuffer = self.sStatusBuffer.concat(data.toString());		// If the last character in the data chunk is a newline, this is the end of the status update		if (data.slice(data.length - 1).toString() === '\n') {			// Put socket back into monitoring mode			self.connSpopStatus.write('idle\n');			// If this is the first message, then the connection is open			if (!self.bSpopStatusGotFirstMessage) {				self.bSpopStatusGotFirstMessage = true;				// Else this is a state update announcement			} else {				var timeStart = Date.now();				var sStatus = self.sStatusBuffer;				self.logStart('Spop announces state update')				.then(function() {					return self.parseState.call(self, sStatus);				})				.then(libFast.bind(self.pushState, self))				.fail(libFast.bind(self.pushError, self))				.done(function() {					return self.logDone(timeStart);				});			}			// Reset the status buffer			self.sStatusBuffer = '';		}	});	self.tracklist = [];	// Start tracklist promise as rejected, so requestors do not wait for it if not immediately available.	// This is okay because no part of Volumio requires a populated tracklist to function.	self.tracklistReadyDeferred = null;	self.tracklistReady = libQ.reject('Tracklist not yet populated.');	// Attempt to load tracklist from database on disk	// TODO make this a relative path	self.sTracklistPath = __dirname+'/db/tracklist';	self.loadTracklistFromDB()	.fail(libFast.bind(self.pushError, self));}
meta: 3465	/local1/tlutelli/issta_data/temp/all_js/javascript/2006_temp/2006/3465/821971c3c9603507fa3c85327d943d033fc5d161/index.js/buggy/app/controllers/spop/index.js