问题描述
我想在本地测试我的Javascript应用程序.
I would like to test my Javascript application locally.
因此,我想在我的带有QiMessaging的JavaScript应用程序与虚拟机器人之间建立连接.
Therefore i would like to establish a connection between my JavaScript Application with QiMessaging to a virtual robot.
以前有人做过吗?
这有可能吗?
作为虚拟机器人,我在Windows 10系统上尝试了naoqi-bin.exe和opennao vm.
As virtual robot I tried naoqi-bin.exe and opennao vm on my windows 10 system.
通过连接到虚拟机器人无法正常工作,它可以与真正的机器人(Pepper)正常工作.
It works fine with a real Robot (Pepper) by connecting to a virtual robot didnt work.
这是我的尝试:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"/>
</head>
<body>
<script src="libs/qimessaging/1.0/qimessaging.js"></script>
<script type="text/javascript">
var robot_address = '127.0.0.1'
var session = new QiSession(robot_address);
session.socket().on('connect', function () {
console.log('QiSession connected!');
// now you can start using your QiSession
}).on('disconnect', function () {
console.log('QiSession disconnected!');
});
</script>
</body>
</html>
结果:
浏览器控制台显示:
result:
Broweser Console shows:
跨源请求被阻止:同源策略禁止阅读 远程资源位于 http://127.0.0.1/libs/qimessaging/1.0/socket.io/1/?t=1557305266224 Reson:原因:缺少CORS标头"Access-Control-Allow-Origin"
Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at http://127.0.0.1/libs/qimessaging/1.0/socket.io/1/?t=1557305266224 Reson: Reason: CORS header 'Access-Control-Allow-Origin' missing
qimessaging 2.0:
代码:
qimessaging 2.0:
code:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"/>
</head>
<body>
<script src="libs/qi/2/qi.js"></script>
<script type="text/javascript">
var robot_address = '127.0.0.1'
QiSession(function (session) {
console.log("connected!");
// you can now use your QiSession
}, function () {
console.log("disconnected");
},
robot_address);
</script>
</body>
</html>
结果:
与qimessaging 1.0相同
result:
same as with qimessaging 1.0
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"/>
</head>
<body>
<script src="js/robotutils.js"></script>
<script type="text/javascript">
RobotUtils.robotIp = "127.0.0.1"
RobotUtils.onService(function (ALDialog) {
console.log("Connected the service.")
}, function () {
console.log("Failed to get the service.")
})
</script>
</body>
</html>
结果:
" http://127.0.0.1/libs/qimessaging/2/qimessaging.js " 即使其MIME类型("text/html")无效,也已加载 JavaScript MIME类型.
The script from "http://127.0.0.1/libs/qimessaging/2/qimessaging.js" was loaded even though its MIME type ("text/html") is not a valid JavaScript MIME type.
with源的加载失败 " http://127.0.0.1/libs/qimessaging/2/qimessaging.js".
Loading failed for the with source "http://127.0.0.1/libs/qimessaging/2/qimessaging.js".
所以我的解释是虚拟机器人无法提供所需的文件,或者我在这里丢失了某些东西吗?
So my interpretationis that the virtual robot does not serve the required files or am i missing something here?
推荐答案
好吧,我在 aldebaran论坛
对不起,但是无法在虚拟环境中正常使用javascript机器人,只有一个真实的机器人(在真实的机器人上有一个服务器监听某个端口以进行js通讯没有为虚拟机器人运行的此类服务器.
Sorry, but qimessaging javascript won't work with a virtualrobot, only with a real robot (on a real robot there's a serverlistening to a certain port for qimessaging js communication, there'sno such server running for a virtual robot).
[...]
这篇关于通过QiMessaging JavaScript连接到虚拟机器人的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!