Commit e746ae7395aae64ef5af554c57c0c2f20d90a1bd

Authored by Eric Fernandez
1 parent cfc5bd0036
Exists in master

console log

Showing 1 changed file with 1 additions and 7 deletions   Show diff stats
1 const express = require('express');
2 const app = express();
3
4 const WebSocketClient = require('ws'); 1 const WebSocketClient = require('ws');
5 const config = require('./config/config.json'); 2 const config = require('./config/config.json');
6 const data = require('./data/index')(config.bo); 3 const data = require('./data/index')(config.bo);
7 4
8 app.listen(config.port);
9 app.use(express.json({limit: '50mb'}));
10
11 const client = new WebSocketClient(config.urlHO); 5 const client = new WebSocketClient(config.urlHO);
12 6
13 client.on('open', function open() { 7 client.on('open', function open() {
14 console.log('conection to socket ho is open'); 8 console.log('conection to socket ho is open');
15 9
16 client.send(JSON.stringify({ gln: config.gln, action: 'gln'})); 10 client.send(JSON.stringify({ gln: config.gln, action: 'gln'}));
17 11
18 client.on('message', function incoming(message) { 12 client.on('message', function incoming(message) {
19 13
20 message = JSON.parse(message.toString('utf8')); 14 message = JSON.parse(message.toString('utf8'));
21 15
22 switch (message.action) { 16 switch (message.action) {
23 case 'getEntity': 17 case 'getEntity':
24 18
25 data.getEntity(message).then(function(message) { 19 data.getEntity(message).then(function(message) {
26 20
27 client.send(JSON.stringify(message)); 21 client.send(JSON.stringify(message));
28 }); 22 });
29 break; 23 break;
30 default: 24 default:
31 break; 25 break;
32 } 26 }
33 }); 27 });
34 }); 28 });
35 29
36 console.log('Sevice open port ' + config.port); 30 console.log('Sevice connected to wsServer: ' + config.urlHO);
37 31