Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Documentation on how to make roslibjs work with bson only mode on rosbridge #345

Open
VorpalBlade opened this issue Oct 4, 2019 · 4 comments

Comments

@VorpalBlade
Copy link

I'm interested in running with BSON only mode on the rosbridge side. However I can't figure out how to make this work, as I get errors like this (and no data passed):

2019-10-04 16:16:52+0200 [-] [ERROR] [1570198612.968579]: [Client 0] Exception in deserialization of BSON

I have added the bson module (I'm using webpack currently to generate the client side javascript, since the ready made browser bundle file did not work for bson).

const bson = require('bson');
const roslib = require('roslib');

It does not seem like roslib picks this up. Nor does it help modifying roslib to have it as a hard dependency in SocketAdapter.js. Any advice on how to get this working would be useful.

@Rayman
Copy link
Contributor

Rayman commented Oct 4, 2019

How do you know "roslib did not pick this up". What error did you get?

Did you get the following message? throw 'Cannot process BSON encoded message without BSON header.';

@VorpalBlade
Copy link
Author

No, I did not get that message. What happened is that I got a message that it managed to connect the web socket (from ros.on('connection', ...). Then nothing (except the errors on the server side from rosbridge_server as described above). If I disable bson_only_mode subscriptions go through and everything works.

This was the behaviour both with and without the bson = require('bson') line or not. As well as when I replaced the optional check in SocketAdapter.js with a hard dependency on bson.

@trusktr
Copy link

trusktr commented Sep 16, 2021

@Rayman I think what @VorpalBlade was talking about is that the SocketAdapter.js file looks for an global variable bson (which is barely documented anywhere) here:

if(typeof bson !== 'undefined'){
BSON = bson().BSON;
}

If that variable exists (presumably from the bson package, one would assume, as it is not documented), then SocketAdapter will use it.

I'm catching errors like 'bson' is not defined now that I'm running ESLint on the source while working on #475.


@VorpalBlade What you would have to do it set bson as a global in Node.js:

global.bson = require('bson');

The version you wrote using const does not create a global variable, therefore roslib does not see it.

@trusktr
Copy link

trusktr commented Sep 18, 2021

Ah, I need to add a shim file for bson in #475. Documenting it would be nice.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants