comparison lightstring.js @ 20:7fcccf59e6ec

Always use two-spaces indent.
author Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
date Thu, 26 Jan 2012 15:04:53 +0100
parents b7bd814333eb
children b7d52bf259e0
comparison
equal deleted inserted replaced
17:b7bd814333eb 20:7fcccf59e6ec
22 */ 22 */
23 var Lightstring = { 23 var Lightstring = {
24 /** 24 /**
25 * @namespace Holds XMPP namespaces. 25 * @namespace Holds XMPP namespaces.
26 */ 26 */
27 NS: { 27 NS: {
28 stream: 'http://etherx.jabber.org/streams', 28 stream: 'http://etherx.jabber.org/streams',
29 jabberClient: 'jabber:client' 29 jabberClient: 'jabber:client'
30 }, 30 },
31 /** 31 /**
32 * @namespace Holds XMPP stanza builders. 32 * @namespace Holds XMPP stanza builders.
33 */ 33 */
34 stanza: { 34 stanza: {
35 stream: { 35 stream: {
36 open: function(aService) { 36 open: function(aService) {
37 //FIXME no ending "/" - node-xmpp-bosh bug 37 //FIXME no ending "/" - node-xmpp-bosh bug
38 return "<stream:stream to='" + aService + "'\ 38 return "<stream:stream to='" + aService + "'\
39 xmlns='" + Lightstring.NS.jabberClient + "'\ 39 xmlns='" + Lightstring.NS.jabberClient + "'\
260 this.socket.addEventListener('error', function(e) { 260 this.socket.addEventListener('error', function(e) {
261 that.emit('error', e.data); 261 that.emit('error', e.data);
262 console.log(e.data); 262 console.log(e.data);
263 }); 263 });
264 this.socket.addEventListener('close', function(e) { 264 this.socket.addEventListener('close', function(e) {
265 that.emit('disconnected', e.data); 265 that.emit('disconnected', e.data);
266 }); 266 });
267 this.socket.addEventListener('message', function(e) { 267 this.socket.addEventListener('message', function(e) {
268 that.emit('XMLInput', e.data); 268 that.emit('XMLInput', e.data);
269 var elm = Lightstring.xml2dom(e.data); 269 var elm = Lightstring.xml2dom(e.data);
270 that.emit('DOMInput', elm); 270 that.emit('DOMInput', elm);
271 that.emit(elm.tagName, elm); 271 that.emit(elm.tagName, elm);
272 272
273 if (elm.tagName === 'iq') 273 if (elm.tagName === 'iq')
274 that.emit(elm.getAttribute('id'), elm); 274 that.emit(elm.getAttribute('id'), elm);
275 }); 275 });
276 }, 276 },
277 /** 277 /**
278 * @function Send a message. 278 * @function Send a message.
279 * @param {String|Object} aStanza The message to send. 279 * @param {String|Object} aStanza The message to send.
293 return; 293 return;
294 } 294 }
295 295
296 296
297 if (elm.tagName === 'iq') { 297 if (elm.tagName === 'iq') {
298 var id = elm.getAttribute('id'); 298 var id = elm.getAttribute('id');
299 if (!id) { 299 if (!id) {
300 elm.setAttribute('id', this.getNewId()); 300 elm.setAttribute('id', this.getNewId());
301 str = Lightstring.dom2xml(elm); 301 str = Lightstring.dom2xml(elm);
302 } 302 }
303 if (aCallback) 303 if (aCallback)
314 }, 314 },
315 /** 315 /**
316 * @function Closes the XMPP stream and the socket. 316 * @function Closes the XMPP stream and the socket.
317 */ 317 */
318 disconnect: function() { 318 disconnect: function() {
319 this.emit('disconnecting'); 319 this.emit('disconnecting');
320 var stream = Lightstring.stanza.stream.close(); 320 var stream = Lightstring.stanza.stream.close();
321 this.send(stream); 321 this.send(stream);
322 this.emit('XMLOutput', stream); 322 this.emit('XMLOutput', stream);
323 this.socket.close(); 323 this.socket.close();
324 }, 324 },
325 /** 325 /**
326 * @function Emits an event. 326 * @function Emits an event.
327 * @param {String} aName The event name. 327 * @param {String} aName The event name.
328 * @param {Function|Array|Object} [aData] Data about the event. 328 * @param {Function|Array|Object} [aData] Data about the event.
329 */ 329 */