Mercurial > eldonilo > lightstring
comparison lightstring.js @ 89:55548845b177
typos
author | Sonny Piers <sonny.piers@gmail.com> |
---|---|
date | Wed, 29 Feb 2012 17:48:05 +0100 |
parents | d9804e206393 |
children | b211a00efa7f |
comparison
equal
deleted
inserted
replaced
88:595be4a8584f | 89:55548845b177 |
---|---|
172 //if (this.protocol !== 'xmpp') | 172 //if (this.protocol !== 'xmpp') |
173 //return; //TODO: error | 173 //return; //TODO: error |
174 | 174 |
175 var stream = Lightstring.stanzas.stream.open(Conn.jid.domain); | 175 var stream = Lightstring.stanzas.stream.open(Conn.jid.domain); |
176 //FIXME: Use Lightstring.Connection.send (problem with parsing steam); | 176 //FIXME: Use Lightstring.Connection.send (problem with parsing steam); |
177 Conn.socket.send(stream); | 177 this.send(stream); |
178 var stanza = { | 178 var stanza = { |
179 XML: stream | 179 XML: stream |
180 }; | 180 }; |
181 Conn.emit('output', stanza); | 181 Conn.emit('output', stanza); |
182 }); | 182 }); |
202 //FIXME SASL mechanisms and XMPP features can be both in a stream:features | 202 //FIXME SASL mechanisms and XMPP features can be both in a stream:features |
203 if (name === 'features') { | 203 if (name === 'features') { |
204 //SASL mechanisms | 204 //SASL mechanisms |
205 if (stanza.DOM.firstChild.localName === 'mechanisms') { | 205 if (stanza.DOM.firstChild.localName === 'mechanisms') { |
206 stanza.mechanisms = []; | 206 stanza.mechanisms = []; |
207 var nodes = stanza.DOM.querySelectorAll('mechanism'); | 207 var nodes = stanza.DOM.getElementsByTagName('mechanism'); |
208 for (var i = 0; i < nodes.length; i++) | 208 for (var i = 0; i < nodes.length; i++) |
209 stanza.mechanisms.push(nodes[i].textContent); | 209 stanza.mechanisms.push(nodes[i].textContent); |
210 Conn.emit('mechanisms', stanza); | 210 Conn.emit('mechanisms', stanza); |
211 } | 211 } |
212 //XMPP features | 212 //XMPP features |
229 else if (name === 'iq') { | 229 else if (name === 'iq') { |
230 var payload = stanza.DOM.firstChild; | 230 var payload = stanza.DOM.firstChild; |
231 if (payload) | 231 if (payload) |
232 Conn.emit('iq/' + payload.namespaceURI + ':' + payload.localName, stanza); | 232 Conn.emit('iq/' + payload.namespaceURI + ':' + payload.localName, stanza); |
233 | 233 |
234 var id = stanza.DOM.getAttributeNS(null, 'id'); | 234 var id = stanza.DOM.getAttribute('id'); |
235 if (!(id && id in Conn.callbacks)) | 235 if (!(id && id in Conn.callbacks)) |
236 return; | 236 return; |
237 | 237 |
238 var type = stanza.DOM.getAttributeNS(null, 'type'); | 238 var type = stanza.DOM.getAttribute('type'); |
239 if (type !== 'result' && type !== 'error') | 239 if (type !== 'result' && type !== 'error') |
240 return; //TODO: warning | 240 return; //TODO: warning |
241 | 241 |
242 var callback = Conn.callbacks[id]; | 242 var callback = Conn.callbacks[id]; |
243 if (type === 'result' && callback.success) | 243 if (type === 'result' && callback.success) |
266 | 266 |
267 if (!stanza) | 267 if (!stanza) |
268 return; | 268 return; |
269 | 269 |
270 if (stanza.DOM.tagName === 'iq') { | 270 if (stanza.DOM.tagName === 'iq') { |
271 var type = stanza.DOM.getAttributeNS(null, 'type'); | 271 var type = stanza.DOM.getAttribute('type'); |
272 if (type !== 'get' || type !== 'set') | 272 if (type !== 'get' || type !== 'set') |
273 ; //TODO: error | 273 ; //TODO: error |
274 | 274 |
275 var callback = {success: aSuccess, error: aError}; | 275 var callback = {success: aSuccess, error: aError}; |
276 | 276 |
277 var id = stanza.DOM.getAttributeNS(null, 'id'); | 277 var id = stanza.DOM.getAttribute('id'); |
278 if (!id) { | 278 if (!id) { |
279 var id = Lightstring.newId('sendiq:'); | 279 var id = Lightstring.newId('sendiq:'); |
280 stanza.DOM.setAttributeNS(null, 'id', id); | 280 stanza.DOM.setAttribute('id', id); |
281 } | 281 } |
282 | 282 |
283 this.callbacks[id] = callback; | 283 this.callbacks[id] = callback; |
284 | 284 |
285 } | 285 } |
341 emit: function(aName, aData) { | 341 emit: function(aName, aData) { |
342 var handlers = this.handlers[aName]; | 342 var handlers = this.handlers[aName]; |
343 if (!handlers) | 343 if (!handlers) |
344 return; | 344 return; |
345 | 345 |
346 //No data events | 346 //Non-data events |
347 if(!aData) { | 347 if(!aData) { |
348 for (var i = 0; i < handlers.length; i++) | 348 for (var i = 0; i < handlers.length; i++) |
349 handlers[i].call(this, aData); | 349 handlers[i].call(this, aData); |
350 | 350 |
351 return; | 351 return; |
369 if (ret) | 369 if (ret) |
370 return; | 370 return; |
371 } | 371 } |
372 | 372 |
373 if (aData && aData.DOM) { | 373 if (aData && aData.DOM) { |
374 var type = aData.DOM.getAttributeNS(null, 'type'); | 374 var type = aData.DOM.getAttribute('type'); |
375 if (type !== 'get' && type !== 'set') | 375 if (type !== 'get' && type !== 'set') |
376 return; | 376 return; |
377 | 377 |
378 var from = aData.DOM.getAttributeNS(null, 'from'); | 378 var from = aData.DOM.getAttribute('from'); |
379 var id = aData.DOM.getAttributeNS(null, 'id'); | 379 var id = aData.DOM.getAttribute('id'); |
380 this.send(Lightstring.stanzas.errors.iq(from, id, 'cancel', 'service-unavailable')); | 380 this.send(Lightstring.stanzas.errors.iq(from, id, 'cancel', 'service-unavailable')); |
381 } | 381 } |
382 }, | 382 }, |
383 /** | 383 /** |
384 * @function Register an event handler. | 384 * @function Register an event handler. |