我在 Amazon Web Services EC2 云上运行 openfire 服务器,并编写了一个小型的 strophe.js 驱动的 xmpp 客户端来连接服务器并来回发送消息。这很好用。
但是,我还想用这个客户端进行带内注册 (XEP-0077)。为此,我尝试使用 strophe.register.js。
这是我使用的代码:
var tempConn = new Strophe.Connection("http://myAWSDNS.compute.amazonaws.com:7070/http-bind/");
tempConn.register.connect("http://myAWSDNS.us-west-2.compute.amazonaws.com/", function (status) {
if (status === Strophe.Status.REGISTER) {
// fill out the fields
connection.register.fields.username = "juliet";
connection.register.fields.password = "R0m30";
// calling submit will continue the registration process
connection.register.submit();
} else if (status === Strophe.Status.REGISTERED) {
console.log("registered!");
// calling login will authenticate the registered JID.
connection.authenticate();
} else if (status === Strophe.Status.CONFLICT) {
console.log("Contact already existed!");
} else if (status === Strophe.Status.NOTACCEPTABLE) {
console.log("Registration form not properly filled out.")
} else if (status === Strophe.Status.REGIFAIL) {
console.log("The Server does not support In-Band Registration")
} else if (status === Strophe.Status.CONNECTED) {
// do something after successful authentication
} else {
// Do other stuff
}
});
我已经在 openfire 服务器上启用了带内注册(请参阅图像)
但是,我总是得到输出:“服务器不支持带内注册”(即,状态 === Strophe.Status.REGIFAIL。
我已经进入 strophe.register.js 代码,发现它尝试在 中找到 register-tag <stream:features>
,但找不到,然后将状态设置为 REGIFAIL。
var register, mechanisms;
register = bodyWrap.getElementsByTagName("register");
mechanisms = bodyWrap.getElementsByTagName("mechanism");
if (register.length === 0) {
that._changeConnectStatus(Strophe.Status.REGIFAIL, null);
return;
这是我获得的包含流特征的 xml:
<body xmlns="http://jabber.org/protocol/httpbind" xmlns:stream="http://etherx.jabber.org/streams" from="win-lv4k7bsupjo" authid="747df9ee" sid="747df9ee" secure="true" requests="2" inactivity="30" polling="5" wait="60" hold="1" ack="913534085" maxpause="300" ver="1.6"><stream:features><mechanisms xmlns="urn:ietf:params:xml:ns:xmpp-sasl"><mechanism>DIGEST-MD5</mechanism><mechanism>PLAIN</mechanism><mechanism>ANONYMOUS</mechanism><mechanism>CRAM-MD5</mechanism></mechanisms><compression xmlns="http://jabber.org/features/compress"><method>zlib</method></compression><bind xmlns="urn:ietf:params:xml:ns:xmpp-bind"/><session xmlns="urn:ietf:params:xml:ns:xmpp-session"/></stream:features></body>
如您所见,它包含一堆机制,但没有注册部分。
所以,我的问题是:如果我已经启用了带内注册,为什么它不包含注册标签?以及如何设置它以包含这个注册标签,以便我可以进行带内注册?
任何帮助都将不胜感激!
谢谢,
此致,
克里斯
答案1
您是否尝试过在 Strophe.Connection 中包含 http://,完整 URL +“:7070/http-bind/”
例如 Strophe.Connection("http://myAWSDNS.compute.amazonaws.com:7070/http-bind/“)
并在 strophe.register 中注释掉
/* 如果(register.length === 0){ that._changeConnectStatus(Strophe.Status.REGIFAIL,null); 返回; } 其他*/ this.enabled = true;
对我有用。
问候,Marinus