comparison lightstring.js @ 16:6707f450549e

fix several problems
author Sonny Piers <sonny.piers@gmail.com>
date Mon, 16 Jan 2012 16:55:40 +0100
parents 9aeb0750b9d1
children b7bd814333eb
comparison
equal deleted inserted replaced
15:521962f10743 16:6707f450549e
118 } 118 }
119 119
120 var that = this; 120 var that = this;
121 this.socket.addEventListener('open', function() { 121 this.socket.addEventListener('open', function() {
122 if (this.protocol !== 'xmpp') 122 if (this.protocol !== 'xmpp')
123 throw 'Lightstring: The server located at '+ that.service + ' is not XMPP aware.'; 123 console.error('Lightstring: The server located at '+ that.service + ' doesn\'t seems to be XMPP aware.');
124 124
125 var stream = Lightstring.stanza.stream.open(that.host); 125 var stream = Lightstring.stanza.stream.open(that.host);
126 126
127 that.socket.send(stream); 127 that.socket.send(stream);
128 that.emit('XMLOutput', stream); 128 that.emit('XMLOutput', stream);
157 else if (aStanza instanceof Element) { 157 else if (aStanza instanceof Element) {
158 var elm = aStanza; 158 var elm = aStanza;
159 var str = this.dom2xml(elm); 159 var str = this.dom2xml(elm);
160 } 160 }
161 else { 161 else {
162 that.emit('error', 'Unsupported data type.'); 162 this.emit('error', 'Unsupported data type.');
163 return;
163 } 164 }
164 165
165 166
166 if (elm.tagName === 'iq') { 167 if (elm.tagName === 'iq') {
167 var id = elm.getAttribute('id'); 168 var id = elm.getAttribute('id');
171 } 172 }
172 if (aCallback) 173 if (aCallback)
173 this.on(elm.getAttribute('id'), aCallback); 174 this.on(elm.getAttribute('id'), aCallback);
174 } 175 }
175 else if (aCallback) { 176 else if (aCallback) {
176 that.emit('warning', 'Callback can\'t be called with non-iq stanza.'); 177 this.emit('warning', 'Callback can\'t be called with non-iq stanza.');
177 } 178 }
178 179
179 180
180 this.socket.send(str); 181 this.socket.send(str);
181 this.emit('XMLOutput', str); 182 this.emit('XMLOutput', str);
275 }); 276 });
276 } 277 }
277 }); 278 });
278 this.on('success', function(stanza, that) { 279 this.on('success', function(stanza, that) {
279 that.send( 280 that.send(
280 "<stream:stream to='" + that.domain + "'\ 281 "<stream:stream to='" + that.host + "'\
281 xmlns='jabber:client'\ 282 xmlns='jabber:client'\
282 xmlns:stream='http://etherx.jabber.org/streams'\ 283 xmlns:stream='http://etherx.jabber.org/streams'\
283 version='1.0' />" 284 version='1.0' />"
284 ); 285 );
285 }); 286 });
322 host = matches[2]; 323 host = matches[2];
323 break; 324 break;
324 } 325 }
325 } 326 }
326 327
327 var digest_uri = 'xmpp/' + that.domain; 328 var digest_uri = 'xmpp/' + that.host;
328 if (host !== null) { 329 if (host !== null) {
329 digest_uri = digest_uri + '/' + host; 330 digest_uri = digest_uri + '/' + host;
330 } 331 }
331 var A1 = MD5.hash(that.node + 332 var A1 = MD5.hash(that.node +
332 ':' + realm + ':' + that.password) + 333 ':' + realm + ':' + that.password) +