Migrate from rosbridge 1.0 to 2.0
Hello guys, I have a project where I used rosbridge 1.0 and (so) ROS Groovy. I have to move my project to Hydro, so I need of rosbridge 2.0. How can I edit this js code to migrate to rosbridge 2.0?
var ros = ros || {};
var Connection = function(url) {
this.handlers = new Array();
if (typeof WebSocket == 'undefined') {
WebSocket = MozWebSocket;
}
this.socket = new WebSocket(url);
this.onmessage = null;
var ths = this;
this.socket.onmessage = function(e) {
if(ths.onmessage) {
try {
ths.onmessage(e);
} catch(err) {
ros_debug(err);
}
}
var call = '';
try {
eval('call = ' + e.data);
} catch(err) {
return;
}
for (var i in ths.handlers[call.receiver]) {
var handler = ths.handlers[call.receiver][i]
handler(call.msg);
}
}
this.magicServices = new Array('/rosbridge/topics','/rosbridge/services','/rosbridge/typeStringFromTopic','/rosbridge/typeStringFromService','/rosbridge/msgClassFromTypeString','/rosbridge/reqClassFromTypeString','/rosbridge/rspClassFromTypeString','/rosbridge/classFromTopic','/rosbridge/classesFromService');
}
Connection.prototype.callService = function(service, json, callback) {
this.handlers[service] = new Array(callback);
var call = '{"receiver":"' + service + '"';
call += ',"msg":' + json + '}';
this.socket.send(call);
}
Connection.prototype.publish = function(topic, typeStr, json) {
typeStr.replace(/^\//,'');
var call = '{"receiver":"' + topic + '"';
call += ',"msg":' + json;
call += ',"type":"' + typeStr + '"}';
this.socket.send(call);
}
Connection.prototype.addHandler = function(topic, func) {
if (!(topic in this.handlers)) {
this.handlers[topic] = new Array();
}
this.handlers[topic].push(func);
}
Connection.prototype.setOnError = function(func) {
this.socket.onerror = func;
}
Connection.prototype.setOnClose = function(func) {
this.socket.onclose = func;
}
Connection.prototype.setOnOpen = function(func) {
this.socket.onopen = func;
}
Connection.prototype.setOnMessage = function(func) {
this.onmessage = func;
}
ros.Connection = Connection;
In fact, when I type rosrun rosbridge_server rosbridge_websocket, it gives me this error
[ERROR] [WallTime: 1399303416.415417] [Client 0] Received a rosbridge v1.0 message. Please refer to rosbridge.org for the correct format of rosbridge v2.0 messages. Original message was: {"receiver":"/rosjs/services","msg":[]}
[ERROR] [WallTime: 1399303416.415678] [Client 0] Received a rosbridge v1.0 message. Please refer to rosbridge.org for the correct format of rosbridge v2.0 messages. Original message was: {"receiver":"/rosjs/topics","msg":[]}
That rosjs appears in this code: h t t p://pastebin.com/eSYAEaNd (I haven`t enough karma for pub links) (I put here because is long)
Thanks guys