Merge Request #5
← To merge requests
efernandez/websocketbo:
master
→
master
Commits (1)
Showing
1 changed file
Show diff stats
index.js
1 | const WebSocketClient = require('ws'); | 1 | const WebSocketClient = require('ws'); |
2 | const config = require('./config/config.json'); | 2 | const config = require('./config/config.json'); |
3 | const data = require('./data/index')(config.bo); | 3 | const data = require('./data/index')(config.bo); |
4 | 4 | ||
5 | const client = new WebSocketClient(config.urlHO); | 5 | const client = new WebSocketClient(config.urlHO); |
6 | 6 | ||
7 | client.on('open', function open() { | 7 | client.on('open', function open() { |
8 | console.log('conection to socket ho is open'); | 8 | console.log('conection to socket ho is open'); |
9 | 9 | ||
10 | client.send(JSON.stringify({ gln: config.gln, action: 'gln'})); | 10 | client.send(JSON.stringify({ gln: config.gln, action: 'gln'})); |
11 | 11 | ||
12 | client.on('message', function incoming(message) { | 12 | client.on('message', function incoming(message) { |
13 | 13 | ||
14 | message = JSON.parse(message.toString('utf8')); | 14 | message = JSON.parse(message.toString('utf8')); |
15 | 15 | ||
16 | switch (message.action) { | 16 | switch (message.action) { |
17 | case 'getEntity': | 17 | case 'getEntity': |
18 | 18 | ||
19 | data.getEntity(message).then(function(message) { | 19 | data.getEntity(message).then(function(message) { |
20 | 20 | ||
21 | client.send(JSON.stringify(message)); | 21 | client.send(JSON.stringify(message)); |
22 | }); | 22 | }); |
23 | break; | 23 | break; |
24 | default: | 24 | default: |
25 | break; | 25 | break; |
26 | } | 26 | } |
27 | }); | 27 | }); |
28 | }); | 28 | }); |
29 | 29 | ||
30 | client.on('error', function(e) { | ||
31 | console.log(e); | ||
32 | }) | ||
33 | |||
30 | console.log('Sevice connected to wsServer: ' + config.urlHO); | 34 | console.log('Sevice connected to wsServer: ' + config.urlHO); |
31 | 35 |