-
Notifications
You must be signed in to change notification settings - Fork 161
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
Howdy Jack #3
base: master
Are you sure you want to change the base?
Howdy Jack #3
Conversation
…h an object rather than passing 'null' for several positional arguments. Reverse compatibility was maintained.
I like this a lot. The only thing I am considering is whether to take it even farther. I think it was a mistake to use the return value of a handle to determine whether it is a one time or permanent handler. I've been thinking about deprecating addHandler and instead using a pair of functions (like addOnetimeHandler/addHandler), but I wasn't sure how to make it backwards compatible. This could solve the problem. What do you think about making the two arg version use the new semantics? Or do you think that would be too confusing? If so, do you have alternate suggestions for naming these new functions? |
Hi Jack, glad you liked the concept. I agree that deprecating the existing I've seen backbone.js do this. While they don't require jQuery they detect for it and add some convenience methods if you have it. Essentially, if jQuery is present, you could allow jquery selector strings as an option. Using the echobot example from your post about jquery and strophe you could potentially allow something like this:
This would streamline the process of identifying a muc invitation. As an example, without this option if I'm writing a muc plugin I have to do first add a handler that looks like this (using my object argument syntax):
Then in my
Otherwise I could just do:
Then my handler would only get triggered if it has an |
I think this would be good as a plugin perhaps. I've been intending to add XPath support for some time, but the browser's built in XPath won't work and there are no lightweight XPath implementations in JavaScript. Joe Hildebrand and I started work on one, but it is still unfinished. |
I suppose it could just be a plugin. Anyways, on the original issue. I'm for deprecating |
I would argue against taking advantage of jQuery in Strophe core because of reduced portability of code between applications. Same thing goes for plugins. I prefer to keep my plugins generic and use jQuery selectors in the application layer if necessary. Built-in XPath support would be great though. I'be been meaning to look at http://coderepos.org/share/wiki/JavaScript-XPath for use in Strophe, but haven't had the time yet. |
The XPath library we are working on is here: http://bitbucket.org/hildjj/curlypath |
…as argument to the AUTHFAIL event. This caters for servers implementing case metajack#3 in the XMPP spec in the following section: http://xmpp.org/internet-drafts/draft-saintandre-rfc3920bis-08.html#bind-clientsubmit-error-conflict
…as argument to the AUTHFAIL event. This caters for servers implementing case metajack#3 in the XMPP spec in the following section: http://xmpp.org/internet-drafts/draft-saintandre-rfc3920bis-08.html#bind-clientsubmit-error-conflict
Thumbs up for all three ideas, simplifying how to pass arguments to addHandler, adding two different methods for permanent and one time handlers and built-in xpath. |
What about specifying handler type in it's options? |
Hi everyone, I am having problem on message that have invite in it. Chat.connection.addHandler(Chat.on_message,null, "message", "groupchat"); //for group message but what to put for invite message? |
@goors If you are referring to those invites http://xmpp.org/extensions/xep-0045.html#registrar-querytypes-invite var on_invite = function(x) {
if (x.getElementsByTagName("invite").length) {
return Chat.on_message(x);
} else {
return true;
};
Chat.connection.addHandler(on_invite, null, "message"); You should use the https://github.com/strophe/strophejs repo btw, this one is obsolete |
Will this handler Chat.connection.addHandler(on_invite, null, "message"); handle chat and group_chat type also? |
It will be called on all messages but only those with an invite tag will reach Chat.on_message |
I've made a relatively minor, reverse-compatible tweak to how the
addHandler()
function works. Rather than having to pass positional arguments for 'ns', 'name', 'type', etc. You can now pass just two arguments. The handler function and a simple object literal that defines the other values you wish to filter by.For example, rather than this:
You can now do this:
For me, this solves the problem of having to check the docs each time to see which order to pass in the refining arguments. Also, this approach opens up the possibility of really expanding the matching capabilities of that
addHandler()
function. Potentially, it could be expanded to support more fine-grained matching of a stanza's children, etc.Not sure if you're interested in messing with this API. But the way I wrote it, it maintains backward compatibility. So all existing code should still work, unmodified.
Anyways, just figured I'd do a pull request in case you liked my change.
Thanks for Strophe and your Pro XMPP book! Cheers @HenrikJoreteg