candy-chat / candy

JavaScript-based multi-user chat client for XMPP.
http://candy-chat.github.io/candy
MIT License
1.32k stars 370 forks source link

Loading Strophe plugins (latest version of Strophe auto initializes) #414

Open OpenSiteMobile opened 9 years ago

OpenSiteMobile commented 9 years ago

Hi Guys,

While playing around with the latest version of Strophe and it's plug-ins, I came across this. The lines:

self.addHandler(_connection.disco._onDiscoInfo.bind(_connection.disco), Strophe.NS.DISCO_INFO, 'iq', 'get');
self.addHandler(_connection.disco._onDiscoItems.bind(_connection.disco), Strophe.NS.DISCO_ITEMS, 'iq', 'get');
self.addHandler(_connection.caps._delegateCapabilities.bind(_connection.caps), Strophe.NS.CAPS);

...in the "self.registerEventHandlers" functions of candy.core.js, are not needed. The latest version (at least) self-registers these plug-ins.

So, just an FYI for anyone upgrading Strophe and it's plug-ins.

benlangfeld commented 9 years ago

If these are not necessary for the current version of Strophe that we're using, perhaps you'd be prepared to submit a pull request to that effect?

benlangfeld commented 9 years ago

I'm actually not convinced that we use the disco plugin at all. We do use caps, however.

mweibel commented 9 years ago

@benlangfeld AFAIR the caps plugin uses disco

OpenSiteMobile commented 9 years ago

Hi. Sorry about the delay getting back. As it turns out, the way Candy Chat is doing it now is ok (or better). The plugins now self register, but if you call _connection.reset() like Candy Chat does before each call to _connection.connect(), the reset function wipes out the loaded Strophe plugin handlers.

So just be aware of the problem if/when you move towards the latest version of Strophe. I noted the problem in the GitHub Strophe Issue tracker, but have no idea what the best way to work around or resolve the issue will be.

mweibel commented 9 years ago

That's probably why we added those event registers because the registerEventHandlers is called after the reset & there's also a hook for the plugins where they can register for event hooks after the reset.