Mercurial > eldonilo > lightstring
comparison lightstring.js @ 72:5dbf93cef55d
Various fixes.
author | Emmanuel Gil Peyrot <linkmauve@linkmauve.fr> |
---|---|
date | Thu, 02 Feb 2012 02:28:18 +0100 |
parents | f12c759e4097 |
children | 0b8e7ca19f83 |
comparison
equal
deleted
inserted
replaced
71:f12c759e4097 | 72:5dbf93cef55d |
---|---|
22 * @namespace Holds XMPP namespaces. | 22 * @namespace Holds XMPP namespaces. |
23 * @description http://xmpp.org/xmpp-protocols/protocol-namespaces | 23 * @description http://xmpp.org/xmpp-protocols/protocol-namespaces |
24 */ | 24 */ |
25 ns: { | 25 ns: { |
26 streams: 'http://etherx.jabber.org/streams', | 26 streams: 'http://etherx.jabber.org/streams', |
27 jabber_client: 'jabber:client' | 27 jabber_client: 'jabber:client', |
28 xmpp_stanzas: 'urn:ietf:params:xml:ns:xmpp-stanzas' | |
28 }, | 29 }, |
29 /** | 30 /** |
30 * @namespace Holds XMPP stanza builders. | 31 * @namespace Holds XMPP stanza builders. |
31 */ | 32 */ |
32 stanzas: { | 33 stanzas: { |
148 if (!this.jid.bare) | 149 if (!this.jid.bare) |
149 return; //TODO: error | 150 return; //TODO: error |
150 if (!this.service) | 151 if (!this.service) |
151 return; //TODO: error | 152 return; //TODO: error |
152 | 153 |
153 if(typeof(WebSocket) === "function") { | 154 if (typeof(WebSocket) === "function") { |
154 this.socket = new WebSocket(this.service, 'xmpp'); | 155 this.socket = new WebSocket(this.service, 'xmpp'); |
155 } | 156 } |
156 else if(typeof(MozWebSocket) === "function") { | 157 else if (typeof(MozWebSocket) === "function") { |
157 this.socket = new MozWebSocket(this.service, 'xmpp'); | 158 this.socket = new MozWebSocket(this.service, 'xmpp'); |
158 } | 159 } |
159 else { | 160 else { |
160 return; //TODO: error | 161 return; //TODO: error |
161 } | 162 } |
184 var stanza = new Lightstring.Stanza(e.data); | 185 var stanza = new Lightstring.Stanza(e.data); |
185 | 186 |
186 //FIXME: node-xmpp-bosh sends a self-closing stream:stream tag; it is wrong! | 187 //FIXME: node-xmpp-bosh sends a self-closing stream:stream tag; it is wrong! |
187 Conn.emit('input', stanza); | 188 Conn.emit('input', stanza); |
188 | 189 |
189 if(!stanza.DOM) | 190 if (!stanza.DOM) |
190 return; | 191 return; |
191 | 192 |
192 var name = stanza.DOM.localName; | 193 var name = stanza.DOM.localName; |
193 | 194 |
194 //Authentication | 195 //Authentication |
238 else if (type === 'error' && callback.error) | 239 else if (type === 'error' && callback.error) |
239 callback.error(stanza); | 240 callback.error(stanza); |
240 | 241 |
241 delete Conn.callbacks[id]; | 242 delete Conn.callbacks[id]; |
242 } | 243 } |
244 | |
245 else if (name === 'presence' || name === 'message') { | |
246 Conn.emit(name, stanza); | |
247 } | |
243 }); | 248 }); |
244 }, | 249 }, |
245 /** | 250 /** |
246 * @function Send a message. | 251 * @function Send a message. |
247 * @param {String|Object} aStanza The message to send. | 252 * @param {String|Object} aStanza The message to send. |
251 if (!(aStanza instanceof Lightstring.Stanza)) | 256 if (!(aStanza instanceof Lightstring.Stanza)) |
252 var stanza = new Lightstring.Stanza(aStanza); | 257 var stanza = new Lightstring.Stanza(aStanza); |
253 else | 258 else |
254 var stanza = aStanza; | 259 var stanza = aStanza; |
255 | 260 |
256 if(!stanza) | 261 if (!stanza) |
257 return; | 262 return; |
258 | 263 |
259 if (stanza.DOM.tagName === 'iq') { | 264 if (stanza.DOM.tagName === 'iq') { |
260 var type = stanza.DOM.getAttributeNS(null, 'type'); | 265 var type = stanza.DOM.getAttributeNS(null, 'type'); |
261 if (type !== 'get' || type !== 'set') | 266 if (type !== 'get' || type !== 'set') |
311 this.on(handler, plugin.handlers[handler]); | 316 this.on(handler, plugin.handlers[handler]); |
312 | 317 |
313 //Methods | 318 //Methods |
314 this[name] = {}; | 319 this[name] = {}; |
315 for (var method in plugin.methods) | 320 for (var method in plugin.methods) |
316 this[name][method].bind(this); | 321 this[name][method] = plugin.methods[method].bind(this); |
317 | 322 |
318 if (plugin.init) | 323 if (plugin.init) |
319 plugin.init(); | 324 plugin.init(); |
320 } | 325 } |
321 }, | 326 }, |
345 if (ret) | 350 if (ret) |
346 return; | 351 return; |
347 } | 352 } |
348 | 353 |
349 if (aData && aData.DOM) { | 354 if (aData && aData.DOM) { |
355 var type = aData.DOM.getAttributeNS(null, 'type'); | |
356 if (type !== 'get' && type !== 'set') | |
357 return; | |
358 | |
350 var from = aData.DOM.getAttributeNS(null, 'from'); | 359 var from = aData.DOM.getAttributeNS(null, 'from'); |
351 var id = aData.DOM.getAttributeNS(null, 'id'); | 360 var id = aData.DOM.getAttributeNS(null, 'id'); |
352 this.send(Lightstring.stanzas.errors.iq(from, id, 'cancel', 'service-unavailable')); | 361 this.send(Lightstring.stanzas.errors.iq(from, id, 'cancel', 'service-unavailable')); |
353 } | 362 } |
354 }, | 363 }, |