xmpp4js connect code

探讨如何调整JabberWeb客户端通过JabberHttpBind连接Openfire时的超时设置,目标是在首次测试连接时能即时返回,并在连接建立后将消息等待超时时间设为60秒。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

<body xmlns="http://jabber.org/protocol/httpbind" wait="60" to="127.0.0.1" route="xmpp:127.0.0.1:7070" ver="1.6" xml:lang="en" xmlns:xmpp="urn:xmpp:xbosh" xmpp:version="1.0" rid="2778"></body>

在Jabber Web客户端连接JabberHttpBind时,wait=60的设定导致Openfire等待了60s返回,
Web段的超市也是60s.理想的状态是第一次测试连接的时候立即返回,连接建立后消息的等待超时时间为60s.

XMPP4JS + JabberHttpBind 1.1 + Openfire 3.6.3
问题可能出在对协议处理的不一致
Strophe.Connection = function (service) { /* The path to the httpbind service. */ this.service = service; /* The connected JID. */ this.jid = ""; /* request id for body tags */ this.rid = Math.floor(Math.random() * 4294967295); /* The current session ID. */ this.sid = null; this.streamId = null; // SASL this.do_session = false; this.do_bind = false; // handler lists this.timedHandlers = []; this.handlers = []; this.removeTimeds = []; this.removeHandlers = []; this.addTimeds = []; this.addHandlers = []; this._idleTimeout = null; this._disconnectTimeout = null; this.authenticated = false; this.disconnecting = false; this.connected = false; this.errors = 0; this.paused = false; // default BOSH window this.window = 5; this._data = []; this._requests = []; this._uniqueId = Math.round(Math.random() * 10000); this._sasl_success_handler = null; this._sasl_failure_handler = null; this._sasl_challenge_handler = null; // setup onIdle callback every 1/10th of a second this._idleTimeout = setTimeout(this._onIdle.bind(this), 100); }; Strophe.Connection.prototype = { /** Function: reset * Reset the connection. * * This function should be called after a connection is disconnected * before that connection is reused. */ reset: function () { this.rid = Math.floor(Math.random() * 4294967295); this.sid = null; this.streamId = null; // SASL this.do_session = false; this.do_bind = false; // handler lists this.timedHandlers = []; this.handlers = []; this.removeTimeds = []; this.removeHandlers = []; this.addTimeds = []; this.addHandlers = []; this.authenticated = false; this.disconnecting = false; this.connected = false; this.errors = 0; this._requests = []; this._uniqueId = Math.round(Math.random()*10000); }, /** Function: pause * Pause the request manager. * * This will prevent Strophe from sending any more requests to the * server. This is very useful for temporarily pausing while a lot * of send() calls are happening quickly. This causes Strophe to * send the data in a single request, saving many request trips. */ pause: function () { this.paused = true; }, /** Function: resume * Resume the request manager. * * This resumes after pause() has been called. */ resume: function () { this.paused = false; }, /** Function: getUniqueId * Generate a unique ID for use in <iq/> elements. * * All <iq/> stanzas are required to have unique id attributes. This * function makes creating these easy. Each connection instance has * a counter which starts from zero, and the value of this counter * plus a colon followed by the suffix becomes the unique id. If no * suffix is supplied, the counter is used as the unique id. * * Suffixes are used to make debugging easier when reading the stream * data, and their use is recommended. The counter resets to 0 for * every new connection for the same reason. For connections to the * same server that authenticate the same way, all the ids should be * the same, which makes it easy to see changes. This is useful for * automated testing as well. * * Parameters: * (String) suffix - A optional suffix to append to the id. * * Returns: * A unique string to be used for the id attribute. */ getUniqueId: function (suffix) { if (typeof(suffix) == "string" || typeof(suffix) == "number") { return ++this._uniqueId + ":" + suffix; } else { return ++this._uniqueId + ""; } }, /** Function: connect * Starts the connection process. * * As the connection process proceeds, the user supplied callback will * be triggered multiple times with status updates. The callback * should take two arguments - the status code and the error condition. * * The status code will be one of the values in the Strophe.Status * constants. The error condition will be one of the conditions * defined in RFC 3920 or the condition 'strophe-parsererror'. * * Please see XEP 124 for a more detailed explanation of the optional * parameters below. * * Parameters: * (String) jid - The user's JID. This may be a bare JID, * or a full JID. If a node is not supplied, SASL ANONYMOUS * authentication will be attempted. * (String) pass - The user's password. * (Function) callback The connect callback function. * (Integer) wait - The optional HTTPBIND wait value. This is the * time the server will wait before returning an empty result for * a request. The default setting of 60 seconds is recommended. * Other settings will require tweaks to the Strophe.TIMEOUT value. * (Integer) hold - The optional HTTPBIND hold value. This is the * number of connections the server will hold at one time. This * should almost always be set to 1 (the default). * (Integer) wind - The optional HTTBIND window value. This is the * allowed range of request ids that are valid. The default is 5. */ connect: function (jid, pass, callback, wait, hold, wind) { this.jid = jid; this.pass = pass; this.connect_callback = callback; this.disconnecting = false; this.connected = false; this.authenticated = false; this.errors = 0; if (!wait) wait = 60; if (!hold) hold = 1; if (wind) this.window = wind; // parse jid for domain and resource this.domain = Strophe.getDomainFromJid(this.jid); // build the body tag var body = this._buildBody().attrs({ to: this.domain, "xml:lang": "en", wait: wait, hold: hold, window: this.window, content: "text/xml; charset=utf-8", ver: "1.6", "xmpp:version": "1.0", "xmlns:xmpp": Strophe.NS.BOSH }); this.connect_callback(Strophe.Status.CONNECTING, null); this._requests.push( new Strophe.Request(body.toString(), this._onRequestStateChange.bind(this) .prependArg(this._connect_cb.bind(this)), body.tree().getAttribute("rid"))); this._throttledRequestHandler(); },
最新发布
08-08
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值