/
reader_websocket.js
55 lines (50 loc) · 2.25 KB
/
reader_websocket.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
/******************************************************************************
* (c) 2005-2015 Copyright, Real-Time Innovations. All rights reserved. *
* No duplications, whole or partial, manual or electronic, may be made *
* without express written permission. Any such copies, or revisions thereof, *
* must display this notice unaltered. *
* This code contains trade secrets of Real-Time Innovations, Inc. *
******************************************************************************/
var http = require('http');
var fs = require('fs');
var rti = require('rticonnextdds-connector');
var connector = new rti.Connector("MyParticipantLibrary::Zero",__dirname + "/../ShapeExample.xml");
var input = connector.getInput("MySubscriber::MySquareReader");
var server = http.createServer(function (req, res) {
if (req.url=="/simple") {
fs.readFile(__dirname + "/indexShape.html", function(error, data) {
res.writeHead(200, { 'Content-Type': 'text/html' });
res.end(data, 'utf-8');
});
} else if (req.url=="/chart") {
fs.readFile(__dirname + '/indexChart.html', function(error, data) {
res.writeHead(200, { 'Content-Type': 'text/html' });
res.end(data, 'utf-8');
});
} else if (req.url == "/earth") {
fs.readFile(__dirname + '/indexEarth.html', function(error, data) {
res.writeHead(200, { 'Content-Type': 'text/html' });
res.end(data, 'utf-8');
});
} else {
res.writeHead(200, {'Content-Type': 'text/html'});
res.write("Click <a href='simple'>simple</a>, <a href='chart'>D3 chart</a> or <a href='earth'>earth</a>");
res.end();
}
}).listen(7400, "127.0.0.1");
console.log('Server running at http://127.0.0.1:7400/');
var io = require('socket.io').listen(server);
connector.on('on_data_available',
function() {
console.log('on_dat');
input.take();
console.log(input.samples.getLength());
for (i=1; i <= input.samples.getLength(); i++) {
if (input.infos.isValid(i)) {
console.log('is valid');
var jsonObj = input.samples.getJSON(i);
console.log(JSON.stringify(jsonObj));
io.sockets.emit('shape', jsonObj);
}
}
});