Skip to content

Commit

Permalink
Merge pull request #2 from foxglove/jhurliman/remove-png
Browse files Browse the repository at this point in the history
Remove pngparse dependency, merge in upstream roslibjs changes
  • Loading branch information
jhurliman committed May 27, 2021
2 parents 364a19d + 6904cfd commit 1c29f89
Show file tree
Hide file tree
Showing 18 changed files with 1,263 additions and 1,516 deletions.
6 changes: 0 additions & 6 deletions .github/dependabot.yml

This file was deleted.

2 changes: 1 addition & 1 deletion .npmignore
Expand Up @@ -2,6 +2,6 @@ test
examples
Gruntfile.js
.gitignore
.travis.yml
.github
bower.json
*.md
17 changes: 0 additions & 17 deletions .travis.yml

This file was deleted.

23 changes: 11 additions & 12 deletions CONTRIBUTING.md
@@ -1,24 +1,23 @@
roslibjs Build Setup
====================
# roslibjs Build Setup

[Grunt](http://gruntjs.com/) is used for building, including concatenating, minimizing, documenting, linting, and testing.

### Install Grunt and its Dependencies
## Install Grunt and its Dependencies

1. Install [Node.js](http://nodejs.org/) for your environment
2. Install the build task runner, [Grunt](http://gruntjs.com/)

```sh
$ [sudo] npm install -g grunt
```
```bash
$ [sudo] npm install -g grunt
```
3. Install the dependencies and build dependencies

```sh
$ cd /path/to/roslibjs/
$ [sudo] npm install
```
```bash
$ cd /path/to/roslibjs/
$ [sudo] npm install
```

### Build with Grunt
## Build with Grunt

Before proceeding, please confirm you have installed the dependencies above.

Expand All @@ -27,7 +26,7 @@ To run the build tasks:
1. `cd /path/to/roslibjs/`
2. `grunt build`

`grunt build` will concatenate and minimize the files under src and replace roslib.js and roslib.min.js in the build directory. It will also run the linter and test cases. This is what [Travis CI](https://travis-ci.org/RobotWebTools/roslibjs) runs when a Pull Request is submitted.
`grunt build` will concatenate and minimize the files under src and replace roslib.js and roslib.min.js in the build directory. It will also run the linter and test cases. This is what [GH Actions](https://github.com/RobotWebTools/roslibjs/actions) runs when a Pull Request is submitted.

`grunt dev` will watch for any changes to any of the src/ files and automatically concatenate and minimize the files. This is ideal for those developing as you should only have to run `grunt dev` once.

Expand Down
18 changes: 10 additions & 8 deletions Dockerfile
@@ -1,16 +1,18 @@
FROM ros:kinetic-ros-core
ARG ROS_DISTRO=melodic
FROM ros:$ROS_DISTRO-ros-core

ARG CI=true
ENV CI=$CI

ENV ROS_DISTRO=kinetic
# Dependencies for rosbridge
RUN apt update && apt-get install -y xvfb firefox git wget ros-$ROS_DISTRO-rosbridge-server ros-$ROS_DISTRO-tf2-web-republisher ros-$ROS_DISTRO-common-tutorials ros-$ROS_DISTRO-rospy-tutorials ros-$ROS_DISTRO-actionlib-tutorials
RUN apt update && apt-get install -y firefox git wget ros-$ROS_DISTRO-rosbridge-server ros-$ROS_DISTRO-tf2-web-republisher ros-$ROS_DISTRO-common-tutorials ros-$ROS_DISTRO-rospy-tutorials ros-$ROS_DISTRO-actionlib-tutorials

# Install nvm, Node.js and node-gyp
ENV NODE_VERSION v10.15.0
RUN wget -qO- https://raw.githubusercontent.com/creationix/nvm/v0.33.2/install.sh | bash \
ARG NODE_VERSION=14
RUN wget -qO- https://raw.githubusercontent.com/nvm-sh/nvm/v0.38.0/install.sh | bash \
&& . $HOME/.nvm/nvm.sh \
&& nvm install $NODE_VERSION && nvm alias default $NODE_VERSION \
&& npm install -g node-gyp

RUN echo "source /opt/ros/kinetic/setup.bash" >> $HOME/.bashrc
ENV PATH /bin/versions/node/$NODE_VERSION/bin:$PATH

RUN echo "source /opt/ros/$ROS_DISTRO/setup.bash" >> $HOME/.bashrc
ENV PATH=/bin/versions/node/$NODE_VERSION/bin:$PATH
21 changes: 16 additions & 5 deletions Gruntfile.js
Expand Up @@ -31,11 +31,19 @@ module.exports = function(grunt) {
]
},
karma: {
build: {
configFile: './test/karma.conf.js',
options: {
singleRun: true,
browsers: ['Firefox']
}
browsers: process.env.CI ? ['FirefoxHeadless'] : ['Firefox']
},
test: {
configFile: './test/karma.conf.js',
},
examples: {
configFile: './test/examples/karma.conf.js',
},
workersocket: {
configFile: './test/workersocket/karma.conf.js',
},
},
mochaTest: {
options: {
Expand Down Expand Up @@ -103,7 +111,10 @@ module.exports = function(grunt) {
});

grunt.registerTask('dev', ['browserify', 'watch']);
grunt.registerTask('test', ['jshint', 'mochaTest:test', 'browserify', 'karma']);
grunt.registerTask('test', ['jshint', 'mochaTest:test', 'karma:test']);
grunt.registerTask('test-examples', ['mochaTest:examples', 'karma:examples']);
grunt.registerTask('test-tcp', ['mochaTest:tcp']);
grunt.registerTask('test-workersocket', ['karma:workersocket']);
grunt.registerTask('build', ['browserify', 'uglify']);
grunt.registerTask('build_and_watch', ['watch']);
grunt.registerTask('doc', ['clean', 'jsdoc']);
Expand Down
40 changes: 26 additions & 14 deletions README.md
@@ -1,45 +1,57 @@
roslibjs [![Build Status](https://api.travis-ci.org/RobotWebTools/roslibjs.png)](https://travis-ci.org/RobotWebTools/roslibjs)
========
# roslibjs

[![CI](https://github.com/RobotWebTools/roslibjs/actions/workflows/main.yml/badge.svg)](https://github.com/RobotWebTools/roslibjs/actions/workflows/main.yml)

## The Standard ROS JavaScript Library

#### The Standard ROS JavaScript Library
For full documentation, see [the ROS wiki](http://wiki.ros.org/roslibjs) or check out some [working demos](http://robotwebtools.org/demos.html).

[JSDoc](http://robotwebtools.org/jsdoc/roslibjs/current/) can be found on the Robot Web Tools website.

This project is released as part of the [Robot Web Tools](http://robotwebtools.org/) effort.

### Usage
## Usage

Pre-built files can be found in either [roslib.js](build/roslib.js) or [roslib.min.js](build/roslib.min.js).

Alternatively, you can use the current release via the Robot Web Tools CDN: ([full](https://static.robotwebtools.org/roslibjs/current/roslib.js)) | ([min](https://static.robotwebtools.org/roslibjs/current/roslib.min.js))

### Troubleshooting
## Troubleshooting

1. Check that connection is established. You can listen to error and
connection events to report them to console. See
examples/simple.html for a complete example:

ros.on('error', function(error) { console.log( error ); });
ros.on('connection', function() { console.log('Connection made!'); });
```js
ros.on('error', function(error) { console.log( error ); });
ros.on('connection', function() { console.log('Connection made!'); });
```

1. Check that you have the websocket server is running on
2. Check that you have the websocket server is running on
port 9090. Something like this should do:

netstat -a | grep 9090
```bash
netstat -a | grep 9090
```

### Dependencies
## Dependencies

roslibjs has a number of dependencies. You will need to run:

`npm install`
```bash
npm install
```

Depending on your build environment.

### Build
## Build

Checkout [CONTRIBUTING.md](CONTRIBUTING.md) for details on building.

### License
## License

roslibjs is released with a BSD license. For full terms and conditions, see the [LICENSE](LICENSE) file.

### Authors
## Authors

See the [AUTHORS.md](AUTHORS.md) file for a full list of contributors.
28 changes: 0 additions & 28 deletions bower.json

This file was deleted.

48 changes: 23 additions & 25 deletions package.json
Expand Up @@ -2,45 +2,42 @@
"name": "roslib",
"homepage": "https://www.robotwebtools.org",
"description": "The standard ROS Javascript Library",
"version": "1.1.0",
"version": "1.1.1",
"license": "BSD-2-Clause",
"main": "./build/roslib.js",
"browser": {
"./src/RosLibNode.js": "./src/RosLib.js",
"canvas": "./src/util/shim/canvas.js",
"ws": "./src/util/shim/WebSocket.js",
"xmldom": "./src/util/shim/xmldom.js",
"./src/util/decompressPng.js": "./src/util/shim/decompressPng.js"
"xmldom": "./src/util/shim/xmldom.js"
},
"devDependencies": {
"chai": "*",
"grunt": "^1.0.1",
"grunt-browserify": "^5.0.0",
"grunt-browserify": "^6.0.0",
"grunt-cli": "^1.2.0",
"grunt-contrib-clean": "^1.0.0",
"grunt-contrib-jshint": "^1.0.0",
"grunt-contrib-uglify": "^1.0.1",
"grunt-contrib-clean": "^2.0.0",
"grunt-contrib-jshint": "^3.0.0",
"grunt-contrib-uglify": "^5.0.0",
"grunt-contrib-watch": "^1.0.0",
"grunt-jsdoc": "^2.1.0",
"grunt-karma": "^2.0.0",
"grunt-mocha-test": "^0.12.7",
"karma": "^3.1.4",
"grunt-karma": "^4.0.0",
"grunt-mocha-test": "^0.13.0",
"karma": "^6.3.0",
"karma-chai": "^0.1.0",
"chai": "*",
"karma-firefox-launcher": "^1.0.0",
"karma-mocha": "^1.1.1",
"load-grunt-tasks": "^3.3.0",
"mocha": "^2.3.3",
"time-grunt": "^1.0.0"
"karma-firefox-launcher": "^2.1.0",
"karma-mocha": "^2.0.0",
"load-grunt-tasks": "^5.1.0",
"mocha": "^8.3.0",
"time-grunt": "^2.0.0"
},
"dependencies": {
"cbor-js": "^0.1.0",
"eventemitter2": "^6.4.0",
"object-assign": "^4.0.1",
"pngparse": "^2.0.1",
"ws": "^7.2.1",
"xmldom": "^0.1.19",
"cbor-js": "^0.1.0",
"socket.io": "^4.0.0",
"webworkify": "^1.5.0",
"socket.io": "2.2.0"
"ws": "^7.2.1",
"xmldom": "^0.6.0"
},
"directories": {
"example": "examples",
Expand All @@ -51,10 +48,11 @@
},
"scripts": {
"prepack": "grunt build",
"build": "grunt build",
"test": "grunt test",
"test-examples": "grunt mochaTest:examples && xvfb-run -a karma start test/examples/karma.conf.js",
"test-workersocket": "grunt uglify && xvfb-run -a karma start test/workersocket/karma.conf.js",
"test-tcp": "grunt mochaTest:tcp"
"test-examples": "grunt test-examples",
"test-workersocket": "grunt test-workersocket",
"test-tcp": "grunt test-tcp"
},
"repository": {
"type": "git",
Expand Down
27 changes: 18 additions & 9 deletions src/core/Ros.js
Expand Up @@ -32,11 +32,13 @@ var EventEmitter2 = require('eventemitter2').EventEmitter2;
*/
function Ros(options) {
options = options || {};
var that = this;
this.socket = null;
this.idCounter = 0;
this.isConnected = false;
this.transportLibrary = options.transportLibrary || 'websocket';
this.transportOptions = options.transportOptions || {};
this._sendFunc = function(msg) { that.sendEncodedMessage(msg); };

if (typeof options.groovyCompatibility === 'undefined') {
this.groovyCompatibility = true;
Expand Down Expand Up @@ -120,14 +122,9 @@ Ros.prototype.authenticate = function(mac, client, dest, rand, t, level, end) {
this.callOnConnection(auth);
};

/**
* Sends the message over the WebSocket, but queues the message up if not yet
* connected.
*/
Ros.prototype.callOnConnection = function(message) {
var that = this;
var messageJson = JSON.stringify(message);
Ros.prototype.sendEncodedMessage= function(messageEncoded) {
var emitter = null;
var that = this;
if (this.transportLibrary === 'socket.io') {
emitter = function(msg){that.socket.emit('operation', msg);};
} else {
Expand All @@ -136,10 +133,22 @@ Ros.prototype.callOnConnection = function(message) {

if (!this.isConnected) {
that.once('connection', function() {
emitter(messageJson);
emitter(messageEncoded);
});
} else {
emitter(messageJson);
emitter(messageEncoded);
}
};

/**
* Sends the message over the WebSocket, but queues the message up if not yet
* connected.
*/
Ros.prototype.callOnConnection = function(message) {
if (this.transportOptions.encoder) {
this.transportOptions.encoder(message, this._sendFunc);
} else {
this._sendFunc(JSON.stringify(message));
}
};

Expand Down

0 comments on commit 1c29f89

Please sign in to comment.