metajack / strophejs

The Strophe.js repository has moved to https://github.com/strophe/strophejs
http://strophe.im/strophejs
MIT License
810 stars 160 forks source link

Websocket Support #95

Closed Gordin closed 10 years ago

Gordin commented 12 years ago

Like the title says, I implemented WebSocket support in StropheJS. By Websocket support I mean the latest draft-moffitt-xmpp-over-websocket-01 from here: http://tools.ietf.org/html/draft-moffitt-xmpp-over-websocket-01

What I''ve done specifically: core.js is now split up into three different files:

While implementing support for Websockets I tried to leave as much existing code unchanged as possible to still be able to merge patches from other branches that do not suppert Websockets (or at least make it very easy to merge these manually). Also I tried to make the Websocket code use as much of the already existing handlers as possible. What I basically did is wrap stanzas in an empty <body> tag and then (where possible) put it through the same handlers that are used for all types of connections (which currently if of course only BOSH). The framework that StropheJS uses is mostly unchanged, many functions are just split up in a part that is needed for both protocols and a part that depends on the current protocol object. In theory implementing other new protocols would be possible without touching core.js (Not that there are much other protocols one could use...). Also, this branch is API-compatible to the current version of StropheJS. Wether Websockets or BOSH is used is determined by the URL you create a connection with (URLs starting with ws:// will use Websocket protocol, everything else will fall back to BOSH). This can be decided on a per-connection level and BOSH and Websocket connection can both be open at the same time. Of course trying to "attach" a Websocket connection will fail as there is no real equivalent for what you would do in BOSH, I just left that in core to not brake the API (yet).

I tested this branch against websocket plugins for ejabberd and Prosody and with the Websocket-over-XMPP proxies node-xmpp-bosh and WXG and it seems to be stable. Everything I added is also fully commented and the code of websocket.js and bosh.js is structured the same way for easy comparison.

I'd really like to have this merged into StropheJS, so if there are any issues with this branch that need fixing I will of course do that.

primalmotion commented 12 years ago

man this is huge :) I'm going to test this right now

primalmotion commented 12 years ago

works as described. I use it with Archipel through StropheCappuccino, I didn't have to change anything, it works out of box. Awesome work.

Gordin commented 12 years ago

@primalmotion Thanks :) But just to clarify... with "didn't have to change anything" do you mean that you were still using BOSH or did you actually use Websockets? ^^

primalmotion commented 12 years ago

Both are working seamlessly. By "didn't change anything" I mean in strophecappuccino. So that means that the API is unchanged, and this is cool :)

Antoine Mercadal

On 7 sept. 2012, at 09:25, Gordin notifications@github.com wrote:

@primalmotion Thanks :) But just to clarify... with "didn't have to change anything" do you mean that you were still using BOSH or did you actually use Websockets? ^^

— Reply to this email directly or view it on GitHub.

flosse commented 11 years ago

@Gordin great work! Are there any examples how to use it with ejabberd? Which version of ejabberd do you use and which websocket plugin?

Gordin commented 11 years ago

@flosse I'm using it with the latest ejabberd package (2.1.11 on archlinux) and I'm using this fork of the websocket plugin https://github.com/mweibel/ejabberd-websockets/tree/experimental-websocket-final ("experimental-websocket-final" branch). I didn't follow the development of the ejabberd websocket plugin though, so it might eventually work with the original ejabberd-websockets repo. (probably not, hasn't been updated in a year...) Also, I think I had to alter the compilation script for the plugin to make it build. If you just wanna test if it works I would really recommend to just use a websocket-proxy like node-xmpp-bosh or using a different server with websocket plugins that are actually being maintained by someone... Config looks like this: In the listening Ports section: {5288, ejabberd_websocket, [{request_handlers, [{["ws-xmpp"], mod_websocket}]}]}, URL to connect to would be ws://hostname:5288/ws-xmpp in modules: {mod_websocket, []}, That should be it, if you managed to actually build the plugin ^^

flosse commented 11 years ago

@Gordin

That should be it, if you managed to actually build the plugin ^^

actually that the problem :( But using node-xmpp-bosh works fine. So thanks again for your work. Hopefully @metajack will merge your branch soon!

mweibel commented 11 years ago

@Gordin I don't mind anymore about the way how to do websockets. If people like more your way of doing it, np for me :)

Regarding the websockets plugin: I didn't update the stuff anymore because I thought there will be soon a release of a newer ejabberd with websockets included. As this doesn't seem to happen until now, you might want to try MongooseIM (or just their mod_websocket) which uses cowboy's websocket impl.

ajacksified commented 11 years ago

fwiw, I'm running this Websocket support branch together with Candy against a Prosody server. Works great!