diff --git a/Libraries/strophe.disco.js b/Libraries/strophe.disco.js new file mode 100644 index 000000000..eb3f9139d --- /dev/null +++ b/Libraries/strophe.disco.js @@ -0,0 +1,232 @@ +/* + Copyright 2010, François de Metz +*/ + +/** + * Disco Strophe Plugin + * Implement http://xmpp.org/extensions/xep-0030.html + * TODO: manage node hierarchies, and node on info request + */ +Strophe.addConnectionPlugin('disco', +{ + _connection: null, + _identities : [], + _features : [], + _items : [], + /** Function: init + * Plugin init + * + * Parameters: + * (Strophe.Connection) conn - Strophe connection + */ + init: function(conn) + { + this._connection = conn; + this._identities = []; + this._features = []; + this._items = []; + // disco info + conn.addHandler(this._onDiscoInfo.bind(this), Strophe.NS.DISCO_INFO, 'iq', 'get', null, null); + // disco items + conn.addHandler(this._onDiscoItems.bind(this), Strophe.NS.DISCO_ITEMS, 'iq', 'get', null, null); + }, + /** Function: addIdentity + * See http://xmpp.org/registrar/disco-categories.html + * Parameters: + * (String) category - category of identity (like client, automation, etc ...) + * (String) type - type of identity (like pc, web, bot , etc ...) + * (String) name - name of identity in natural language + * (String) lang - lang of name parameter + * + * Returns: + * Boolean + */ + addIdentity: function(category, type, name, lang) + { + for (var i=0; i * Dual licensed under the MIT and GPL Licenses */ @@ -22,7 +22,8 @@ "strophe": "Libraries/strophe", "strophe.muc": "Libraries/strophe.muc", "strophe.roster": "Libraries/strophe.roster", - "strophe.vcard": "Libraries/strophe.vcard" + "strophe.vcard": "Libraries/strophe.vcard", + "strophe.disco": "Libraries/strophe.disco" }, // define module dependencies for modules not using define @@ -38,22 +39,11 @@ //module value. exports: 'Backbone' }, - - 'underscore': { - exports: '_' - }, - - 'strophe.muc': { - deps: ['strophe', 'jquery'] - }, - - 'strophe.roster': { - deps: ['strophe', 'jquery'] - }, - - 'strophe.vcard': { - deps: ['strophe', 'jquery'] - } + 'underscore': { exports: '_' }, + 'strophe.muc': { deps: ['strophe', 'jquery'] }, + 'strophe.roster': { deps: ['strophe', 'jquery'] }, + 'strophe.vcard': { deps: ['strophe', 'jquery'] }, + 'strophe.disco': { deps: ['strophe', 'jquery'] } } }); @@ -63,7 +53,8 @@ "sjcl", "strophe.muc", "strophe.roster", - "strophe.vcard" + "strophe.vcard", + "strophe.disco" ], function() { // Use Mustache style syntax for variable interpolation _.templateSettings = { @@ -82,7 +73,6 @@ root.converse = factory(jQuery, _, console || {log: function(){}}); } }(this, function ($, _, console) { - var converse = {}; converse.msg_counter = 0; @@ -744,7 +734,7 @@ $available_chatrooms.find('dt').hide(); } for (i=0; i elements and add option values options.each(function(){ - options_list.push(that.option_template({ - 'value': $(this).val(), + options_list.push(that.option_template({'value': $(this).val(), 'text': $(this).text() })); }); @@ -1854,6 +1848,41 @@ } }); + converse.ServiceDiscovery = Backbone.Model.extend({ + initialize: function () { + converse.connection.disco.info(converse.domain, null, this.onInfo, this.onError); + converse.connection.disco.items(converse.domain, null, $.proxy(this.onItems, this), $.proxy(this.onError, this)); + }, + + onItems: function (stanza) { + var that = this; + $(stanza).find('query item').each(function () { + converse.connection.disco.info($(this).attr('jid'), null, that.onInfo, that.onError); + }); + }, + + onInfo: function (stanza) { + var $stanza = $(stanza); + if ($(stanza).find('identity[category=conference][type=text]').length < 1) { + // This isn't an IM server component + return; + } + $stanza.find('feature').each(function (idx, feature) { + if ($(this).attr('var') == 'http://jabber.org/protocol/muc') { + // This component supports MUC + converse.muc_domain = $stanza.attr('from'); + // XXX: It would probably make sense to refactor a + // controlbox to be a Collection of Panel objects + converse.chatboxesview.views.controlbox.addRoomsPanel(); + } + }); + }, + + onError: function (stanza) { + console.log("Error while doing service discovery"); + } + }); + converse.LoginPanel = Backbone.View.extend({ tagName: 'div', id: "login-dialog", @@ -1868,7 +1897,7 @@ '' + '' + '' + - '' + + '' + ''), bosh_url_input: _.template( @@ -1985,13 +2014,13 @@ converse.onConnected = function (connection) { this.connection = connection; - - this.animate = true; // Use animations this.connection.xmlInput = function (body) { console.log(body); }; this.connection.xmlOutput = function (body) { console.log(body); }; this.bare_jid = Strophe.getBareJidFromJid(this.connection.jid); this.domain = Strophe.getDomainFromJid(this.connection.jid); - this.muc_domain = 'conference.' + this.domain; + + // Sevice discovery + this.disco = new this.ServiceDiscovery(); // Set up the roster this.roster = new this.RosterItems(); diff --git a/main.js b/main.js index 63ee12427..b2d5b3940 100644 --- a/main.js +++ b/main.js @@ -1,5 +1,6 @@ require(["jquery", "converse"], function($, converse) { converse.initialize({ + animate: true, bosh_service_url: 'https://bind.opkode.im', prebind: false, xhr_user_search: false,