Преглед на файлове

Add support for stream features to converse-disco

JC Brand преди 7 години
родител
ревизия
4cfade2843
променени са 1 файла, в които са добавени 32 реда и са изтрити 0 реда
  1. 32 0
      src/converse-disco.js

+ 32 - 0
src/converse-disco.js

@@ -217,8 +217,30 @@
                 return this;
                 return this;
             }
             }
 
 
+            function initStreamFeatures () {
+                _converse.stream_features = new Backbone.Collection();
+                _converse.stream_features.browserStorage = new Backbone.BrowserStorage[_converse.storage](
+                    b64_sha1(`converse.stream-features-${_converse.bare_jid}`)
+                );
+                _converse.stream_features.fetch({
+                    success (collection) {
+                        if (collection.length === 0) {
+                            _.forEach(
+                                _converse.connection.features.childNodes,
+                                (feature) => {
+                                    _converse.stream_features.create({
+                                        'name': feature.nodeName,
+                                        'xmlns': feature.getAttribute('xmlns')
+                                    });
+                                });
+                        }
+                    }
+                });
+            }
+
             function initializeDisco () {
             function initializeDisco () {
                 addClientFeatures();
                 addClientFeatures();
+                initStreamFeatures();
                 _converse.connection.addHandler(onDiscoInfoRequest, Strophe.NS.DISCO_INFO, 'iq', 'get', null, null);
                 _converse.connection.addHandler(onDiscoInfoRequest, Strophe.NS.DISCO_INFO, 'iq', 'get', null, null);
 
 
                 _converse.disco_entities = new _converse.DiscoEntities();
                 _converse.disco_entities = new _converse.DiscoEntities();
@@ -231,6 +253,7 @@
                         // If we don't have an entity for our own XMPP server,
                         // If we don't have an entity for our own XMPP server,
                         // create one.
                         // create one.
                         _converse.disco_entities.create({'jid': _converse.domain});
                         _converse.disco_entities.create({'jid': _converse.domain});
+                        initStreamFeatures();
                     }
                     }
                     _converse.emit('discoInitialized');
                     _converse.emit('discoInitialized');
                 }).catch(_.partial(_converse.log, _, Strophe.LogLevel.FATAL));
                 }).catch(_.partial(_converse.log, _, Strophe.LogLevel.FATAL));
@@ -291,6 +314,15 @@
                  * @namespace
                  * @namespace
                  */
                  */
                 'disco': {
                 'disco': {
+                    'stream': {
+                        'getFeature': function (name, xmlns) {
+                            if (_.isNil(name) || _.isNil(xmlns)) {
+                                throw new Error("name and xmlns need to be provided when calling disco.stream.getFeature");
+                            }
+                            return _converse.stream_features.findWhere({'name': name, 'xmlns': xmlns});
+                        }
+                    },
+
                     /**
                     /**
                      * The "own" grouping
                      * The "own" grouping
                      * @namespace
                      * @namespace