diff --git a/Gruntfile.js b/Gruntfile.js index d3e036f16..d538399d9 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -20,7 +20,7 @@ module.exports = function(grunt) { }, browserify: { dist: { - src: ['./tsbuild/RosLibBrowser.js'], + src: ['./tsbuild/RosLib.js'], dest: './build/roslib.js' } }, diff --git a/package.json b/package.json index 71a56dddc..aaea277e3 100644 --- a/package.json +++ b/package.json @@ -4,9 +4,8 @@ "description": "The standard ROS Javascript Library", "version": "1.4.1", "license": "BSD-2-Clause", - "main": "./src/RosLibNode.js", + "main": "./src/RosLib.js", "browser": { - "./src/RosLibNode.js": "./src/RosLib.js", "canvas": "./src/util/shim/canvas.js", "ws": "./src/util/shim/WebSocket.js", "@xmldom/xmldom": "./src/util/shim/@xmldom/xmldom.js", diff --git a/src/RosLib.js b/src/RosLib.js index 0acde4b32..4e91e7fb4 100644 --- a/src/RosLib.js +++ b/src/RosLib.js @@ -22,3 +22,6 @@ var ROSLIB = { }; module.exports = ROSLIB; + +// Add to global namespace for in-browser support (i.e. CDN) +global.ROSLIB = ROSLIB; diff --git a/src/RosLibBrowser.js b/src/RosLibBrowser.js deleted file mode 100644 index f134db6da..000000000 --- a/src/RosLibBrowser.js +++ /dev/null @@ -1 +0,0 @@ -global.ROSLIB = require('./RosLib'); diff --git a/src/RosLibNode.js b/src/RosLibNode.js deleted file mode 100644 index 85d6dc04b..000000000 --- a/src/RosLibNode.js +++ /dev/null @@ -1,13 +0,0 @@ -/** - * @fileOverview ROSLIB Node exclusive extensions - */ - -module.exports = { - ...require('./core'), - ...require('./actionlib'), - ...require('./math'), - ...require('./tf'), - ...require('./urdf'), - Ros: require('./node/RosTCP'), - Topic: require('./node/TopicStream') -}; diff --git a/src/node/RosTCP.js b/src/node/RosTCP.js deleted file mode 100644 index 810fa0e54..000000000 --- a/src/node/RosTCP.js +++ /dev/null @@ -1,63 +0,0 @@ -var Ros = require('../core/Ros'); -var net = require('net'); -var socketAdapter = require('../core/SocketAdapter.js'); -const TopicStream = require('./TopicStream'); - -/** - * Same as core Ros except supports TCP connections. - * @private - */ -class RosTCP extends Ros { - constructor(options) { - options = options || {}; - if (!options.encoding) { - console.error( - 'ROSLib uses utf8 encoding by default. ' + - 'It would be more efficient to use ascii (if possible).' - ); - } - super(options); - this.encoding = options.encoding || 'utf8'; - - if (!this.socket && (options.host || options.port)) { - this.connect({ - host: options.host, - port: options.port - }); - } - } - /** - * Connect to a live socket. - * - * @param {string|number|Object} url - Address and port to connect to (see http://nodejs.org/api/net.html). - * Format: {host: String, port: Int} or (port:Int) or "host:port". - */ - connect(url) { - if ( - typeof url === 'string' && - (url.slice(0, 5) === 'ws://' || url.slice(0, 6) === 'wss://') - ) { - Ros.prototype.connect.call(this, url); - } else { - var events = socketAdapter(this); - this.socket = net - .connect(url) - .on('data', events.onmessage) - .on('close', events.onclose) - .on('error', events.onerror) - .on('connect', events.onopen); - this.socket.setEncoding(this.encoding); - this.socket.setTimeout(0); - - // Little hack for call on connection - this.socket.send = this.socket.write; - // Similarly for close - this.socket.close = this.socket.end; - } - } - Topic(options) { - return new TopicStream({ ros: this, ...options }); - } -} - -module.exports = RosTCP; diff --git a/src/node/TopicStream.js b/src/node/TopicStream.js deleted file mode 100644 index 33c226c33..000000000 --- a/src/node/TopicStream.js +++ /dev/null @@ -1,51 +0,0 @@ -var Topic = require('../core/Topic'); -var DuplexStream = require('stream').Duplex; - -class TopicStream extends Topic { - /** - * Publish a connected ROS topic to a duplex - * stream. This stream can be piped to, which will - * publish to the topic. - * - * @param {Object} options - * @param {boolean} [options.subscribe=true] - The flag to indicate whether to subscribe to the topic and start emitting data or not. - * @param {boolean} [options.publish=true] - The flag to indicate whether to register the stream as a publisher to the topic or not. - * @param {function} [options.transform] - A function to change the data to be published or filter it if false is returned. - */ - toStream(options) { - options = options || { subscribe: true, publish: true }; - - var topic = this; - - var stream = new DuplexStream({ - objectMode: true - }); - stream._read = function () {}; - - // Publish to the topic if someone pipes to stream - stream._write = function (chunk, encoding, callback) { - if (typeof options.transform === 'function') { - chunk = options.transform(chunk); - } - if (chunk === false) { - topic.publish(chunk); - } - callback(); - }; - - if (options.subscribe) { - this.subscribe(function (message) { - stream.push(message); - }); - this.on('unsubscribe', stream.push.bind(stream, null)); - } - - if (options.publish) { - this.advertise(); - } - - return stream; - } -} - -module.exports = TopicStream; diff --git a/test/tcp/check-topics.examples.js b/test/tcp/check-topics.examples.js deleted file mode 100644 index dbc52a684..000000000 --- a/test/tcp/check-topics.examples.js +++ /dev/null @@ -1,24 +0,0 @@ -var expect = require('chai').expect; -var ROSLIB = require('../..'); - -var expectedTopics = [ - // '/turtle1/cmd_vel', '/turtle1/color_sensor', '/turtle1/pose', - // '/turtle2/cmd_vel', '/turtle2/color_sensor', '/turtle2/pose', - '/tf2_web_republisher/status', '/tf2_web_republisher/feedback', - // '/tf2_web_republisher/goal', '/tf2_web_republisher/result', - '/fibonacci/feedback', '/fibonacci/status', '/fibonacci/result' -]; - -describe('Example topics are live', function(done) { - it('getTopics', function(done) { - var ros = new ROSLIB.Ros({ - port: 9090 - }); - ros.getTopics(function(result) { - expectedTopics.forEach(function(topic) { - expect(result.topics).to.contain(topic, 'Couldn\'t find topic: ' + topic); - }); - done(); - }); - }); -}); \ No newline at end of file