2011-07-07 11 views
0

XMPPサーバーに接続するのにGWT-Stropheを使用しています。状況は順調で、XMPPサーバーに接続して他のユーザーにメッセージを送信することができます。メッセージの受信に問題があります。私はStrophe echobotの例をコピーしようとしていますが、メッセージが受信されたときにHandler内のコードが実行されません。ここでGWT-Stropheを使用するGWT XMPPクライアント

は私がハンドラを接続し、登録するために使用していたコードです:

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("[email protected]", "password", callback); 

答えて

1

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

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

あなたの行を変更し

、それが正常に動作する必要があります。

0

gwt-stropheの接続方法をここに投稿できますか(接続に成功した場合)? より良い解決策が見つかった場合は、ここに投稿してください。私はGWT互換モジュールをgwt-strophe(gwt.xmlとすべてのソースを含む)から作成し、私のGWTプロジェクトで使用しました。コンパイル中にエラーは発生しませんでしたが、私のウィジェットを呼び出すと「未定義のConnection 'Connection'を読み取ることができません」というメッセージが表示されます。 window.Stropheオブジェクトが P.S.が定義されていないため、一部のコード検査の後、私は、ランタイム実行中にスローされた詩句オブジェクトが初期化されている

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

エラーが見つかりませんでした私はここにコメントを追加する方法を見つけていないので、このスレッドで質問するために "答え"を作成しました... GWTから私のopenfireサーバーへの接続が必要です。

関連する問題