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) {
var calJson = cal.returnCalendar();
console.log(calJson);
logger.info(calJson);
res.json(calJson);
});
@ -119,27 +119,27 @@ app.post('/api/calendar/extend', function(req, res) {
// Events and sockets
busEmitter.on('clientConnected', (socketSet) => {
console.log(socketSet.getClientStatus());
logger.info(socketSet.getClientStatus());
heating_v1.setsocket(socketSet).subscribe();
lighting_v1.setsocket(socketSet).subscribe();
projector_v1.setsocket(socketSet).subscribe();
});
busEmitter.on('clientStatusUpdated', (v) => {
console.log(v);
logger.info(v);
});
logger.info('Configuring WebSocket Listener...');
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.end();
});
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({
httpServer: server, // You should not use autoAcceptConnections for production
@ -160,12 +160,12 @@ wsServer.on('request', function(request) {
if (!originIsAllowed(request.origin)) {
// Make sure we only accept requests from an allowed origin
request.reject();
console.log((new Date()) + ' Connection from origin ' + request.origin + ' rejected.');
logger.info((new Date()) + ' Connection from origin ' + request.origin + ' rejected.');
return;
}
var connection = request.accept('stream', request.origin);
console.log((new Date()) + ' Connection accepted.');
logger.info((new Date()) + ' Connection accepted.');
var sendSocketHandler = (obj) => {
// Logger.info('sendSocket: ' , JSON.stringify(obj));
@ -185,22 +185,22 @@ wsServer.on('request', function(request) {
connection.on('message', function(message) {
if (message.type === 'utf8') {
console.log('Received Message: ' + message.utf8Data);
logger.info('Received Message: ' + message.utf8Data);
connection.sendUTF(message.utf8Data);
} 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.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);
});
});
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);
@ -264,5 +264,5 @@ app.post('/api/v1/extend', function(req, res) {
});
app.listen(3000, function() {
console.log('Express listening on 3000');
logger.info('Express listening on 3000');
});