Changes for Azure

This commit is contained in:
Martin Donnelly 2016-05-13 15:36:10 +01:00
parent 014d0fceee
commit b92f1a7231

24
app.js
View File

@ -105,7 +105,7 @@ app.get('/start', function(request, response) {
app.get('/api/calendar', function(req, res) { app.get('/api/calendar', function(req, res) {
var calJson = cal.returnCalendar(); var calJson = cal.returnCalendar();
console.log(calJson); logger.info(calJson);
res.json(calJson); res.json(calJson);
}); });
@ -119,27 +119,27 @@ app.post('/api/calendar/extend', function(req, res) {
// Events and sockets // Events and sockets
busEmitter.on('clientConnected', (socketSet) => { busEmitter.on('clientConnected', (socketSet) => {
console.log(socketSet.getClientStatus()); logger.info(socketSet.getClientStatus());
heating_v1.setsocket(socketSet).subscribe(); heating_v1.setsocket(socketSet).subscribe();
lighting_v1.setsocket(socketSet).subscribe(); lighting_v1.setsocket(socketSet).subscribe();
projector_v1.setsocket(socketSet).subscribe(); projector_v1.setsocket(socketSet).subscribe();
}); });
busEmitter.on('clientStatusUpdated', (v) => { busEmitter.on('clientStatusUpdated', (v) => {
console.log(v); logger.info(v);
}); });
logger.info('Configuring WebSocket Listener...'); logger.info('Configuring WebSocket Listener...');
var server = http.createServer(function(request, response) { var server = http.createServer(function(request, response) {
console.log((new Date()) + ' Received request for ' + request.url); logger.info((new Date()) + ' Received request for ' + request.url);
response.writeHead(404); response.writeHead(404);
response.end(); response.end();
}); });
server.listen(3001, function() { server.listen(3001, function() {
console.log((new Date()) + ' Server is listening on port 8080'); logger.info((new Date()) + ' Server is listening on port 3001');
}); });
var wsServer = new WebSocketServer({ var wsServer = new WebSocketServer({
httpServer: server, // You should not use autoAcceptConnections for production httpServer: server, // You should not use autoAcceptConnections for production
@ -160,12 +160,12 @@ wsServer.on('request', function(request) {
if (!originIsAllowed(request.origin)) { if (!originIsAllowed(request.origin)) {
// Make sure we only accept requests from an allowed origin // Make sure we only accept requests from an allowed origin
request.reject(); request.reject();
console.log((new Date()) + ' Connection from origin ' + request.origin + ' rejected.'); logger.info((new Date()) + ' Connection from origin ' + request.origin + ' rejected.');
return; return;
} }
var connection = request.accept('stream', request.origin); var connection = request.accept('stream', request.origin);
console.log((new Date()) + ' Connection accepted.'); logger.info((new Date()) + ' Connection accepted.');
var sendSocketHandler = (obj) => { var sendSocketHandler = (obj) => {
// Logger.info('sendSocket: ' , JSON.stringify(obj)); // Logger.info('sendSocket: ' , JSON.stringify(obj));
@ -185,22 +185,22 @@ wsServer.on('request', function(request) {
connection.on('message', function(message) { connection.on('message', function(message) {
if (message.type === 'utf8') { if (message.type === 'utf8') {
console.log('Received Message: ' + message.utf8Data); logger.info('Received Message: ' + message.utf8Data);
connection.sendUTF(message.utf8Data); connection.sendUTF(message.utf8Data);
} else if (message.type === 'binary') { } else if (message.type === 'binary') {
console.log('Received Binary Message of ' + message.binaryData.length + ' bytes'); logger.info('Received Binary Message of ' + message.binaryData.length + ' bytes');
connection.sendBytes(message.binaryData); connection.sendBytes(message.binaryData);
} }
}); });
connection.on('close', function(reasonCode, description) { connection.on('close', function(reasonCode, description) {
console.log((new Date()) + ' Peer ' + connection.remoteAddress + ' disconnected.'); logger.info((new Date()) + ' Peer ' + connection.remoteAddress + ' disconnected.');
busEmitter.removeListener('sendSocket', sendSocketHandler); busEmitter.removeListener('sendSocket', sendSocketHandler);
}); });
}); });
mqttConnect.connectWS(function() { mqttConnect.connectWS(function() {
console.log('Ready to plug in sockets...'); logger.info('Ready to plug in sockets...');
}); });
app.post('/api/v1/lighting/off', lighting_v1.turnoff); app.post('/api/v1/lighting/off', lighting_v1.turnoff);
@ -264,5 +264,5 @@ app.post('/api/v1/extend', function(req, res) {
}); });
app.listen(3000, function() { app.listen(3000, function() {
console.log('Express listening on 3000'); logger.info('Express listening on 3000');
}); });