Prechádzať zdrojové kódy

Websocket support. closes #204

JC Brand 10 rokov pred
rodič
commit
3e9994e01c
2 zmenil súbory, kde vykonal 9 pridanie a 8 odobranie
  1. 8 8
      converse.js
  2. 1 0
      docs/CHANGES.rst

+ 8 - 8
converse.js

@@ -280,6 +280,7 @@
                 'clear': true,
                 'toggle_participants': true
             },
+            websocket_url: undefined,
             xhr_custom_status: false,
             xhr_custom_status_url: '',
             xhr_user_search: false,
@@ -664,11 +665,6 @@
                         // object should never be exposed to production systems.
                         // 'jasmine tests' is an invalid http bind service value,
                         // so we're sure that this is just for tests.
-                        //
-                        // TODO: We might need to consider websockets, which
-                        // probably won't use the 'service' attr. Current
-                        // strophe.js version used by converse.js doesn't support
-                        // websockets.
                         this.callback(this);
                     } else  {
                         this.callback();
@@ -5101,10 +5097,14 @@
                 //
                 // Also, what do we do when the keepalive session values are
                 // expired? Do we try to fall back?
-                if (!this.bosh_service_url) {
-                    throw("Error: you must supply a value for the bosh_service_url");
+                if (!this.bosh_service_url && ! this.websocket_url) {
+                    throw("Error: you must supply a value for the bosh_service_url or websocket_url");
+                }
+                if ('WebSocket' in window || 'MozWebSocket' in window) {
+                    this.connection = new Strophe.Connection(this.websocket_url);
+                } else {
+                    this.connection = new Strophe.Connection(this.bosh_service_url);
                 }
-                this.connection = new Strophe.Connection(this.bosh_service_url);
                 this.setUpXMLLogging();
 
                 if (this.prebind) {

+ 1 - 0
docs/CHANGES.rst

@@ -8,6 +8,7 @@ Changelog
 * Updated Afrikaans translations. [jcbrand]
 * Add responsiveness to CSS. We now use Sass preprocessor for generating CSS. [jcbrand]
 * Don't send out the message carbons IQ stanza on each page load. [jcbrand]
+* #204 Support websocket connections. [jcbrand]
 * #252, 253 Add fullname and jid to contact's tooltip in roster. [gbonvehi]
 * #292 Better support for XEP-0085 Chat State Notifications. [jcbrand]
 * #295 Document "allow_registration". [gbonvehi]