I have a class which required to be init.
class ROS {
static init() {
// do ros initialization
ROS.ros = new ROSLIB.Ros({
url: 'ws://' + ROS.host + ':' + ROS.ws_port.toString()
});
// and so on
}
static topic_publisher(topic_name, msg){
var topic = new ROSLIB.Topic({
ros: ROS.ros,
name: topic_name,
});
topic.publish(msg);
}
}
If I want to publish a message to a topic (call the topic_publisher) I just need to do like this ROS.topic_publisher("x_param', '0.1').
However, in those respected page, there should be a script which already called ROS.init() (at least one from all scripts.js which I imported).
I design the web in which consist of 4 iframes and 1 parent. Let say all of them need to use ROS.topic_publisher("x_param', '0.1').
In the current design, I need to call ROS.init() across all page. It make the server to have 5 ROS clients.
I want to know, is there anyway for me to let the initialization once (in the parent maybe) and let the rest I frame only call ROS.topic_publisher("x_param', '0.1') without re-import or re-initialize the ROS.init().
I also try to use parent.object. So it is become like this:
On parent page:
var obj = ROS.init();
ROS.topic_publisher("x_param', '0.1'); // success
on Iframe page:
var obj = parent.obj;
obj.ROS.topic_publisher("x_param', '0.1'); // error
Any information will be helpful... Thanks!
parent.ROS.topic_publisher? sinceROS.initdoesn't return anythingobjwill just be undefined and pointless ... you can just doROS.init()in the parentparentpage finished first for then loaded theIframe( to make sure the web-socket connection).still not works- you haven't described what happens that makes you say "it doesn't work" - do you get errors? you shouldn't need to callparent.ROS.init- so I hope you aren't