# HG changeset patch # User Sonny Piers # Date 1339522969 -7200 # Node ID 6ec16b3e9cfcd22d954b0558d5ce5e0fad999581 # Parent 11e38a9bfe3894b5f83122a93022323e9740ec74 improvements on the websocket transport diff --git a/websocket.js b/websocket.js --- a/websocket.js +++ b/websocket.js @@ -5,7 +5,7 @@ this.service = aService; }; Lightstring.WebSocketConnection.prototype = new EventEmitter(); - Lightstring.WebSocketConnection.prototype.connect = function() { + Lightstring.WebSocketConnection.prototype.open = function() { // Standard if (typeof(WebSocket) === 'function') this.socket = new WebSocket(this.service, 'xmpp'); @@ -19,25 +19,33 @@ else return; //TODO: error - var Conn = this; + var that = this; this.socket.addEventListener('open', function() { - //FIXME: Opera/Safari WebSocket implementation doesn't support sub-protocol mechanism. - //if (this.protocol !== 'xmpp') - //return; //TODO: error - Conn.emit('open') + //FIXME: Opera/Safari WebSocket implementation doesn't support sub-protocol mechanism. + //if (this.protocol !== 'xmpp') + //return; //TODO: error + that.emit('open'); + + var stream = Lightstring.stanzas.stream.open(that.jid.domain); + this.socket.send(stream); + var stanza = { + XML: stream + }; + that.emit('out', stanza); }); this.socket.addEventListener('error', function(e) { - Conn.emit('disconnecting', e.data); + that.emit('disconnecting', e.data); //TODO: error }); this.socket.addEventListener('close', function(e) { - Conn.emit('disconnected', e.data); + that.emit('disconnected', e.data); }); this.socket.addEventListener('message', function(e) { - Conn.emit('stanza', e.data); + that.emit('in', e.data); }); - }, + }; Lightstring.WebSocketConnection.prototype.send = function(aStanza) { this.socket.send(aStanza); - } + that.emit('out', aStanza); + }; })(); \ No newline at end of file