diff --git a/README.md b/README.md index f97cf3d..5fc902d 100644 --- a/README.md +++ b/README.md @@ -111,6 +111,8 @@ Note: The **=** sign is important here. Replacing the equal sign with a space wi * **websocket_ping_interval**: The period, in seconds, between sending WebSocket ping frames to each client. If a client fails to respond with a pong frame twice in a row, the connection will be closed. Set to 0 to disable sending of WebSocket pings. **(default: 30)** +* **use_stream_tags**: Set to 'true' to enable the use of legacy `` tags instead of `` and ``. You may need this if your client is not up to date with the spec. **(default: false)** + ### Architecture The project itself is divided into 4 main components as of now. @@ -238,7 +240,7 @@ if the *callback=* GET query parameter is supplied. * [http://xmpp.org/extensions/xep-0124.html](http://xmpp.org/extensions/xep-0124.html) * [http://xmpp.org/extensions/xep-0206.html](http://xmpp.org/extensions/xep-0206.html) -* [http://tools.ietf.org/html/draft-moffitt-xmpp-over-websocket-00](http://tools.ietf.org/html/draft-moffitt-xmpp-over-websocket-00) +* [https://tools.ietf.org/html/draft-ietf-xmpp-websocket-10](https://tools.ietf.org/html/draft-ietf-xmpp-websocket-10) ### Dependencies @@ -278,6 +280,7 @@ if the *callback=* GET query parameter is supplied. 4. libpurple (pidgin as a client) 5. [strophe.js websocket client] (https://github.com/superfeedr/strophejs/tree/protocol-ed) [broken link] 6. [node-xmpp] (https://github.com/astro/node-xmpp) + 7. [stanza.io] (https://github.com/otalk/stanza.io) ### Tested using diff --git a/bosh.conf.example.js b/bosh.conf.example.js index 18bd3c0..1b77934 100644 --- a/bosh.conf.example.js +++ b/bosh.conf.example.js @@ -98,5 +98,8 @@ exports.config = { // client. If a client fails to respond with a pong frame twice in a row, // the connection will be closed. // Set to 0 to disable sending of WebSocket pings. - websocket_ping_interval: 30 + websocket_ping_interval: 30, + + // Set to true to use legacy tags instead of and + use_stream_tags: false, }; diff --git a/src/websocket.js b/src/websocket.js index bcf4208..da7e1c3 100644 --- a/src/websocket.js +++ b/src/websocket.js @@ -45,6 +45,7 @@ var STREAM_OPENED = 2; var STREAM_CLOSED = 3; var XML_STREAM_CLOSE = ''; +var XML_CLOSE_TAG = ''; // // Important links: @@ -61,6 +62,7 @@ exports.createServer = function(bosh_server, options, webSocket) { // Config options var ping_interval = options.websocket_ping_interval; + var use_stream_tags = !!options.use_stream_tags; // State information for XMPP streams var sn_state = { }; @@ -104,13 +106,17 @@ exports.createServer = function(bosh_server, options, webSocket) { wsep.on('stream-added', function(sstate) { var to = sstate.to || ''; - var ss_xml = new ltx.Element('stream:stream', { - 'xmlns': 'jabber:client', - 'xmlns:stream': 'http://etherx.jabber.org/streams', + var tagName = use_stream_tags ? 'stream:stream' : 'open'; + var attributes = { + 'xmlns': use_stream_tags ? 'jabber:client' : 'urn:ietf:params:xml:ns:xmpp-framing', 'version': '1.0', 'xml:lang': 'en', 'from': to - }).toString(); + } + if(use_stream_tags) { + attributes['xmlns:stream'] = 'http://etherx.jabber.org/streams' + } + var ss_xml = new ltx.Element(tagName, attributes).toString(); if (sstate.has_open_stream_tag) { ss_xml = ss_xml.replace('/>', '>'); } @@ -125,6 +131,12 @@ exports.createServer = function(bosh_server, options, webSocket) { if (sstate.has_open_stream_tag) { ss_xml = ss_xml.replace('/>', '>'); } + + if(!use_stream_tags) { + ss_xml = ss_xml.replace('