Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Strophe.connection.sendPresence not there #6

Open
robcross1977 opened this issue Jan 17, 2018 · 0 comments
Open

Strophe.connection.sendPresence not there #6

robcross1977 opened this issue Jan 17, 2018 · 0 comments

Comments

@robcross1977
Copy link

robcross1977 commented Jan 17, 2018

I tried to make my own branch and do a pull request but I am not authorized apparently. Just paste this code above sendIQ please:

/** Function: sendPresence
* Helper function to send presence stanzas. The main benefit is for
* sending presence stanzas for which you expect a responding presence
* stanza with the same id (for example when leaving a chat room).
*
* Parameters:
* (XMLElement) elem - The stanza to send.
* (Function) callback - The callback function for a successful request.
* (Function) errback - The callback function for a failed or timed
* out request. On timeout, the stanza will be null.
* (Integer) timeout - The time specified in milliseconds for a
* timeout to occur.
*
* Returns:
* The id used to send the presence.
*/
sendPresence: function(elem, callback, errback, timeout) {
var timeoutHandler = null;
var that = this;
if (typeof(elem.tree) === "function") {
elem = elem.tree();
}
var id = elem.getAttribute('id');
if (!id) { // inject id if not found
id = this.getUniqueId("sendPresence");
elem.setAttribute("id", id);
}

    if (typeof callback === "function" || typeof errback === "function") {
        var handler = this.addHandler(function (stanza) {
            // remove timeout handler if there is one
            if (timeoutHandler) {
                that.deleteTimedHandler(timeoutHandler);
            }
            var type = stanza.getAttribute('type');
            if (type === 'error') {
                if (errback) {
                    errback(stanza);
                }
            } else if (callback) {
                callback(stanza);
            }
        }, null, 'presence', null, id);

        // if timeout specified, set up a timeout handler.
        if (timeout) {
            timeoutHandler = this.addTimedHandler(timeout, function () {
                // get rid of normal handler
                that.deleteHandler(handler);
                // call errback on timeout with null stanza
                if (errback) {
                    errback(null);
                }
                return false;
            });
        }
    }
    this.send(elem);
    return id;
},
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant