Skip to content

Strophe.connection.sendPresence not there #6

@robcross1977

Description

@robcross1977

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;
},

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions