# HG changeset patch # User Emmanuel Gil Peyrot # Date 1328031882 -3600 # Node ID 3dfb596cf66901650300737b56d7caad53685816 # Parent 136df1708856141c2793a5cd5dea641b0c1261ce Add a plugin loader. diff --git a/lightstring.js b/lightstring.js --- a/lightstring.js +++ b/lightstring.js @@ -24,20 +24,20 @@ var Lightstring = { /** * @namespace Holds XMPP namespaces. */ - NS: { + ns: { stream: 'http://etherx.jabber.org/streams', jabberClient: 'jabber:client' }, /** * @namespace Holds XMPP stanza builders. */ - stanza: { + stanzas: { stream: { open: function(aService) { //FIXME no ending "/" - node-xmpp-bosh bug return ""; }, close: function() { @@ -45,6 +45,7 @@ var Lightstring = { } } }, + plugins: {}, /** * @private */ @@ -279,7 +280,7 @@ Lightstring.Connection.prototype = { this.socket.addEventListener('open', function() { //TODO: if (this.protocol !== 'xmpp') - var stream = Lightstring.stanza.stream.open(that.jid.domain); + var stream = Lightstring.stanzas.stream.open(that.jid.domain); //TODO: Use Lightstring.Connection.send (problem with parsing steam); that.socket.send(stream); var stanza = { @@ -376,11 +377,32 @@ Lightstring.Connection.prototype = { */ disconnect: function() { this.emit('disconnecting'); - var stream = Lightstring.stanza.stream.close(); + var stream = Lightstring.stanzas.stream.close(); this.send(stream); this.emit('XMLOutput', stream); this.socket.close(); }, + load: function() { + for (var i = 0; i < arguments.length; i++) { + var name = arguments[i]; + if (!(name in Lightstring.plugins)) + continue; //TODO: throw an error? + + var plugin = Lightstring.plugins[name]; + + for (var ns in plugin.namespaces) + Lightstring.ns[ns] = plugin.namespaces[ns]; + + for (var stanza in plugin.stanzas) + Lightstring.stanzas[stanza] = plugin.stanzas[stanza]; + + for (var handler in plugin.handlers) + this.on(handler, plugin.handlers[handler]); + + for (var method in plugin.methods) + this.methods[method] = plugin.methods[method]; + } + }, /** * @function Emits an event. * @param {String} aName The event name.