0

GWT-Stropheを使用して XMPP サーバーに接続しています。順調に進んでおり、XMPP サーバーに接続して他のユーザーにメッセージを送信できます。メッセージの受信に問題があります。Strophe echobot の例をコピーしようとしていますが、メッセージを受信したときに Handler のコードが実行されません。

ハンドラーを接続して登録するために使用しているコードは次のとおりです。

connection = new Connection("http://localhost/proxy/");
handler = new Handler<Element>() {

    @Override
    public boolean handle(Element element) {
        GWT.log("Handling...");
        GWT.log(element.toString());

        String to = element.getAttribute("to");
        String from = element.getAttribute("from");
        String type = element.getAttribute("type");

        NodeList<com.google.gwt.dom.client.Element> elems = element.getElementsByTagName("body");

        if ((type == null ? "chat" == null : type.equals("chat")) && elems.getLength() > 0) {
            Element body = (Element) elems.getItem(0);

            GWT.log("ECHOBOT: I got a message from " + from + ": " + body.getText());
            String[][] attributes = {{"to", from}, {"from", to}, {"type", "chat"}};    
            Builder reply = Builder.$msg(attributes).cnode(body.copy());    
            connection.send(reply.tree());

            GWT.log("ECHOBOT: I sent " + from + ": " + body.getText());
        }    
        return true;
    }
};

StatusCallback callback = new Connection.StatusCallback() {

    @Override
    public void statusChanged(Status status, String reason) {

        if (status == Status.CONNECTING) {
            GWT.log("Strophe is connecting.");
        } else if (status == Status.CONNFAIL) {
            GWT.log("Strophe failed to connect.");
        } else if (status == Status.DISCONNECTING) {
            GWT.log("Strophe is disconnecting.");
        } else if (status == Status.DISCONNECTED) {
            GWT.log("Strophe is disconnected.");
        } else if (status == Status.CONNECTED) {
            GWT.log("Strophe is connected.");
            connection.addHandler(null, null, "message", null, null, handler);
            Builder pres = Builder.$pres(null);
            connection.send(pres);

            GWT.log("ECHOBOT: Send a message to " + connection.getJid() + " to talk to me.");
        }

    }
};

connection.connect("me@myserver.com", "password", callback);
4

2 に答える 2

1

回線を変更する

connection.addHandler(null, null, "message", null, null, handler);

connection.addHandler(null, "message", null, null, null, handler);

そしてそれはうまくいくはずです。

于 2012-02-28T04:24:08.497 に答える
0

gwt-strophe の接続方法をここに投稿できますか (接続に成功した場合)。または、より良い解決策を見つけた場合は、ここに投稿してください。gwt-strophe (gwt.xml とすべてのソースを含む) から GWT 互換モジュールを作成し、GWT プロジェクトで使用しました。コンパイル中にエラーはありませんでしたが、ウィジェットを呼び出すと、「未定義のプロパティ「接続」を読み取れません」と表示されます。いくつかのコード検査の後、Strophe オブジェクトが初期化されている場所が見つかりませんでした

private native JavaScriptObject connection(String boshService) /*-{
    var connection = new $wnd.Strophe.Connection(boshService);
    return connection;
}-*/;

window.Strophe オブジェクトが未定義であるため、ランタイム実行中にエラーがスローされました ps ここでコメントを追加する方法が見つからなかったので、このスレッドで質問するために「回答」を作成しました...必要なのは、GWT から自分の openfire への接続だけですサーバ

于 2012-03-21T05:10:57.327 に答える