LoginSignup
20
19

More than 5 years have passed since last update.

QiMessaging JavaScript 開発環境の確認

Last updated at Posted at 2015-03-14

はじめに

まずは Version 1.0 から

適当な Webサーバに配置した HTMLを表示し、そのページ内から QiMessaging JavaScriptを使用して Pepperに接続します。

こんな HTMLを用意します。Pepper(192.168.3.23)に接続して、ALTextSpeechで「Hello!」と言わせるだけです。

index_v1.html
<!DOCTYPE html>
<html lang="ja">
  <head>
    <meta charset="utf-8">
    <title>qimessaging javascript v1.0</title>

    <script src="libs/qimessaging/1.0/qimessaging.js"></script>
    <script>
window.onload = function() {
  var session = new QiSession("192.168.3.23");

  session.socket().on('connect', function() {
    console.log("connected!");
  });

  session.service("ALTextToSpeech").done(function(tts) {
    tts.say("Hello!");
  }).fail(function(error) {
    console.log("Error!");
  });
}
    </script>
  </head>

  <body>
v1.0
  </body>
</html>

ページ表示後、Pepperが「Hello」と言いましたので、まあ動いているようです。

[Warning] This version of QiMessaging is now deprecated. Please consider upgrading with help from the documentation. (qimessaging.js, line 1)
[Log] connected! (index_v1.html, line 13)

ただ、JavaScriptコンソールの表示を見ると、「 This version of QiMessaging is now deprecated. 」と言われています。

qimessaging.jsの先頭行に入っているようです。

libs/qimessaging/1.0/qimessaging.js
console.warn("This version of QiMessaging is now deprecated. Please consider upgrading with help from the documentation.");
/*
**  Copyright (C) Aldebaran Robotics
**  See COPYING for the license
**
**  Author(s):
**   - Laurent LEC    <llec@aldebaran-robotics.com>
**
*/

次に Version 2 を

Ver 2も試してみます。
ざっとソースを見たところ、QiSessionのコンストラクタのパラメータから違うようです。

libs/qimessaging/1.0/qimessaging.js
function QiSession(host, resource)
libs/qimessaging/2/qimessaging.js
function QiSession(connected, disconnected, host)

処理はあまり気にしなくても大丈夫そうな印象でしたので、とりあえず以下の状態で確認してみます。

index_v2.html
<!DOCTYPE html>
<html lang="ja">
  <head>
    <meta charset="utf-8">
    <title>qimessaging javascript v2</title>

    <script src="libs/qimessaging/2/qimessaging.js"></script>
    <script>
window.onload = function() {
  var session = new QiSession(true, true, "192.168.3.23");
}
    </script>
  </head>

  <body>
v2
  </body>
</html>

Webサーバから取得して表示

JavaScriptコンソールに以下の内容が表示されました。

[Error] XMLHttpRequest cannot load http://192.168.3.23/libs/qimessaging/2/socket.io/1/?t=1426313694819. Origin http://localhost is not allowed by Access-Control-Allow-Origin. (index_v2.html, line 0)

「Access-Control-Allow-Origin」と、クロスドメイン関連のエラーっぽいです。まあ、そう言われればそうなのですが、Ver 1.0はなぜ動いたのでしょうか。

ローカルファイルをそのまま表示

js をファイルシステム上のフルパスで指定し、そのままブラウザで開きます。

index_v2.html
<script src="/Library/WebServer/Documents/pepper/libs/qimessaging/2/qimessaging.js"></script>

JavaScriptコンソールには以下の内容が表示されました。

[Error] Failed to load resource: the server responded with a status of 404 (Not Found) (1, line 0)

Pepper側にアクセスはしていますが、Ver 2のファイルはないようです。パーミッション的にここにコピーするわけにはいかないようです。

$ pwd
/var/log/nginx

$ tail -f access_log
192.168.3.235 - - [14/Mar/2015:16:01:36 +0900] "GET /libs/qimessaging/2/socket.io/1/?t=1426316495939 HTTP/1.1" 404 143 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_2) AppleWebKit/600.3.18 (KHTML, like Gecko) Version/8.0.3 Safari/600.3.18"
$ pwd
/var/www/libs/qimessaging

$ ls -la
total 12
drwxr-xr-x 3 root root 4096 Oct 23 22:43 .
drwxr-xr-x 3 root root 4096 Oct 23 22:43 ..
drwxr-xr-x 2 root root 4096 Oct 23 22:43 1.0

/var/www/apps/等のコピーできる場所にコピーしたら動かせるだろうかとも思いましたが、

$ pwd
/var/www

$ ls -la
total 24
drwxr-xr-x 6 root root 4096 Oct 23 22:43 .
drwxr-xr-x 7 root root 4096 Nov 19 16:33 ..
lrwxrwxrwx 1 root root   42 Oct 23 22:43 apps -> /home/nao/.local/share/PackageManager/apps
drwxr-xr-x 3 root root 4096 Oct 23 22:43 libs
drwxr-xr-x 2 root root 4096 Oct 23 22:48 localhost
drwxr-xr-x 6 root root 4096 Oct 23 22:43 oldrobotwebpage
drwxr-xr-x 8 root root 4096 Oct 23 22:29 robotsgate

どうも ver 1.0では nginxが何やらリクエストを処理しているようで、そのまま ver 2の jsをコピーするだけでは動かないような感じがします。

/etc/nginx/nginx.conf
        location ^~ /libs/qimessaging/1.0/socket.io/ {
            rewrite /libs/qimessaging/1.0/socket.io/(.*) /socket.io/$1 break;
            proxy_pass http://127.0.0.1:8002;
            proxy_http_version 1.1;
            proxy_set_header Upgrade $http_upgrade;
            proxy_set_header Connection "upgrade";
            proxy_set_header Host $host;
        }

結論

結局 Ver 2は動かせてはいませんが、今のところ Pepper側も対応していないようですし、Ver 1.0を使うしかないようです。github版では deprecated と示されるのが気になりますが。

感想

  • Ver 2ってどういう位置づけなんですかね。そのうち置き換わっていくのでしょうか?
  • 新しい Pepperが届いた方は、ぜひバージョンを教えてください。たぶん 1.0だと思いますけど。
  • ちなみに私は先日の 300台の販売では、表参道店の抽選に外れ、オンライン予約では 10:10にアクセスし、抽選にも入れませんでした(悲
20
19
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
20
19