无法使用stropher.js连接XMPP服务器



当我使用stropher.js连接到XMPP服务器时,它给出连接状态为1 =当前正在建立连接

此状态有什么问题。

代码如下用于连接。

它返回我连接状态。

$(document).ready(function () {
$('#login_dialog').dialog({
    autoOpen: true,
    draggable: false,
    modal: true,
    title: 'Connect to XMPP',
    buttons: {
        "Connect": function () {
            $(document).trigger('connect', {
                jid: $('#jid').val(),
                password: $('#password').val()
            });                
            $('#password').val('');
            $(this).dialog('close');
        }
    }
});
});
$(document).bind('connect', function (ev, data) {
    var conn = new Strophe.Connection("http://127.0.0.1:5280/http-bind");
    //"http://bosh.metajack.im:5280/xmpp-httpbind");
        conn.connect(data.jid, data.password, function (status) {           
    if (status === Strophe.Status.CONNECTED) {          
        $(document).trigger('connected');
    } else if (status === Strophe.Status.DISCONNECTED) {
        Hello.log("Status DISCONNECTED.");
        $(document).trigger('disconnected');
    }
});
 Hello.connection = conn;
});
 $(document).bind('connected', function () {
    // inform the user
    Hello.log("Connection established.");
   Hello.connection.addHandler(Hello.handle_pong, null, "iq", null, "ping1");
   var domain = Strophe.getDomainFromJid(Hello.connection.jid);
   Hello.send_ping(domain);
 });
 $(document).bind('disconnected', function () {
   Hello.log("Connection terminated.");
   // remove dead connection object
  Hello.connection = null;
});

我正在使用电话间隙。

谢谢

您在Stroph.Connection处的代码是错误的。首先,您验证将URL参数传递给Stroph.connnection("URL")是否有效。

$(document).bind('connect', function (ev, data) {
    var conn = new Strophe.Connection("http://example.com:7070/http-bind");
    //"http://bosh.metajack.im:5280/xmpp-httpbind");
  • 在上面的代码中, 7070 用于OpenFire上HTTP绑定连接的无安全端口。
  • 如果您的问题未解决,请提供您在PhoneGap应用程序中使用的XMPP服务器。

最新更新