comparison lightstring.js @ 34:6ce66fba0242

Merging.
author Sonny Piers <sonny.piers@gmail.com>
date Sat, 28 Jan 2012 04:39:03 +0100
parents 1e6d2ca2daae 88d24231bf24
children 6773e5bc2ca0
comparison
equal deleted inserted replaced
29:1e6d2ca2daae 34:6ce66fba0242
84 alert(e); 84 alert(e);
85 } 85 }
86 finally { 86 finally {
87 return XML; 87 return XML;
88 }; 88 };
89 } 89 },
90 /**
91 * @function Get an unique identifier.
92 * @param {String} [aString] Prefix to put before the identifier.
93 * @return {String} Identifier.
94 */
95 newId: (function() {
96 var id = 1024;
97 return function(prefix) {
98 if (typeof prefix === 'string')
99 return prefix + id++;
100 return '' + id++;
101 };
102 })()
90 }; 103 };
91 104
92 /** 105 /**
93 * @constructor Creates a new Lightstring connection 106 * @constructor Creates a new Lightstring connection
94 * @param {String} [aService] The Websocket service URL. 107 * @param {String} [aService] The Websocket service URL.
96 */ 109 */
97 Lightstring.Connection = function(aService) { 110 Lightstring.Connection = function(aService) {
98 if (aService) 111 if (aService)
99 this.service = aService; 112 this.service = aService;
100 this.handlers = {}; 113 this.handlers = {};
101 this.iqid = 1024;
102 this.getNewId = function() {
103 this.iqid++;
104 return 'sendiq:' + this.iqid;
105 };
106 this.on('stream:features', function(stanza, that) { 114 this.on('stream:features', function(stanza, that) {
107 var nodes = stanza.DOM.querySelectorAll('mechanism'); 115 var nodes = stanza.DOM.querySelectorAll('mechanism');
108 //SASL/Auth features 116 //SASL/Auth features
109 if (nodes.length > 0) { 117 if (nodes.length > 0) {
110 that.emit('mechanisms', stanza); 118 that.emit('mechanisms', stanza);
319 327
320 if (stanza.DOM.tagName === 'iq') { 328 if (stanza.DOM.tagName === 'iq') {
321 var id = stanza.DOM.getAttribute('id'); 329 var id = stanza.DOM.getAttribute('id');
322 //TODO: This should be done by a plugin 330 //TODO: This should be done by a plugin
323 if (!id) { 331 if (!id) {
324 alert(Lightstring.DOM2XML(stanza.DOM)); 332 stanza.DOM.setAttribute('id', Lightstring.newId('sendiq:'));
325 stanza.DOM.setAttribute('id', this.getNewId());
326 } 333 }
327 if (aCallback) 334 if (aCallback)
328 this.on(stanza.DOM.getAttribute('id'), aCallback); 335 this.on(stanza.DOM.getAttribute('id'), aCallback);
329 } 336 }
330 else if (aCallback) { 337 else if (aCallback) {