comparison lightstring.js @ 92:b211a00efa7f

Various implementation improvements.
author Sonny Piers <sonny.piers@gmail.com>
date Thu, 05 Apr 2012 17:36:43 +0200
parents 55548845b177
children 11e38a9bfe38
comparison
equal deleted inserted replaced
91:c5240333ea4c 92:b211a00efa7f
31 * @namespace Holds XMPP stanza builders. 31 * @namespace Holds XMPP stanza builders.
32 */ 32 */
33 stanzas: { 33 stanzas: {
34 stream: { 34 stream: {
35 open: function(aService) { 35 open: function(aService) {
36 //WORKAROUND: no ending "/" - node-xmpp-bosh bug
37 return "<stream:stream to='" + aService + "'" + 36 return "<stream:stream to='" + aService + "'" +
38 " xmlns='" + Lightstring.ns['jabber_client'] + "'" + 37 " xmlns='" + Lightstring.ns['jabber_client'] + "'" +
39 " xmlns:stream='" + Lightstring.ns['streams'] + "'" + 38 " xmlns:stream='" + Lightstring.ns['streams'] + "'" +
40 " version='1.0'/>"; 39 " version='1.0'>";
41 }, 40 },
42 close: function() { 41 close: function() {
43 return "</stream:stream>"; 42 return "</stream:stream>";
44 } 43 }
45 }, 44 },
154 // Standard 153 // Standard
155 if (typeof(WebSocket) === 'function') 154 if (typeof(WebSocket) === 'function')
156 this.socket = new WebSocket(this.service, 'xmpp'); 155 this.socket = new WebSocket(this.service, 'xmpp');
157 // Safari 156 // Safari
158 else if (typeof(WebSocket) === 'object') 157 else if (typeof(WebSocket) === 'object')
159 this.socket = new WebSocket(this.service); 158 this.socket = new WebSocket(this.service, 'xmpp');
160 // Old Gecko 159 // Old Gecko
161 else if (typeof(MozWebSocket) === 'function') { 160 else if (typeof(MozWebSocket) === 'function') {
162 this.socket = new MozWebSocket(this.service, 'xmpp'); 161 this.socket = new MozWebSocket(this.service, 'xmpp');
163 } 162 }
164 // No known WebSocket support 163 // No known WebSocket support
171 //FIXME: Opera/Safari WebSocket implementation doesn't support sub-protocol mechanism. 170 //FIXME: Opera/Safari WebSocket implementation doesn't support sub-protocol mechanism.
172 //if (this.protocol !== 'xmpp') 171 //if (this.protocol !== 'xmpp')
173 //return; //TODO: error 172 //return; //TODO: error
174 173
175 var stream = Lightstring.stanzas.stream.open(Conn.jid.domain); 174 var stream = Lightstring.stanzas.stream.open(Conn.jid.domain);
176 //FIXME: Use Lightstring.Connection.send (problem with parsing steam);
177 this.send(stream); 175 this.send(stream);
178 var stanza = { 176 var stanza = {
179 XML: stream 177 XML: stream
180 }; 178 };
181 Conn.emit('output', stanza); 179 Conn.emit('output', stanza);
297 * @function Closes the XMPP stream and the socket. 295 * @function Closes the XMPP stream and the socket.
298 */ 296 */
299 disconnect: function() { 297 disconnect: function() {
300 this.emit('disconnecting'); 298 this.emit('disconnecting');
301 var stream = Lightstring.stanzas.stream.close(); 299 var stream = Lightstring.stanzas.stream.close();
302 this.send(stream); 300 this.socket.send(stream);
303 this.emit('XMLOutput', stream); 301 this.emit('XMLOutput', stream);
304 this.socket.close(); 302 this.socket.close();
305 }, 303 },
306 load: function() { 304 load: function() {
307 for (var i = 0; i < arguments.length; i++) { 305 for (var i = 0; i < arguments.length; i++) {