xmpp.js

changeset 15
b328899c936a
parent 14
aaad945d10ba
child 16
74a24eb1fb44
equal deleted inserted replaced
14:aaad945d10ba 15:b328899c936a
60 attr["xmlns:"+namespaces[i][0]] = namespaces[i][1]; 60 attr["xmlns:"+namespaces[i][0]] = namespaces[i][1];
61 if(!stanza) 61 if(!stanza)
62 { 62 {
63 if(stream.opened) 63 if(stream.opened)
64 stanza = xmpp.stanza(tagname, attr); 64 stanza = xmpp.stanza(tagname, attr);
65 /* else if(tagname == "stream") */
66 else if(tagname == "stream" && uri == xmpp.xmlns.streams) 65 else if(tagname == "stream" && uri == xmpp.xmlns.streams)
67 { 66 {
68 stream.opened = true; 67 stream.opened = true;
69 callbacks.opened(attr); 68 callbacks.opened(attr);
70 } 69 }
115 xmpp.Connection = function (host, port) 114 xmpp.Connection = function (host, port)
116 { 115 {
117 this.host = host || "localhost"; 116 this.host = host || "localhost";
118 this.port = port || 5347; 117 this.port = port || 5347;
119 118
120 /** this.socket = tcp.createConnection();
121 this.socket.close() **/
122
123 this.stream = new xmpp.Stream({ 119 this.stream = new xmpp.Stream({
124 opened: recontext(this, this._stream_opened), 120 opened: recontext(this, this._stream_opened),
125 stanza: recontext(this, this._handle_stanza), 121 stanza: recontext(this, this._handle_stanza),
126 closed: recontext(this, this._stream_closed) 122 closed: recontext(this, this._stream_closed)
127 }); 123 });
137 this.jid = jid; 133 this.jid = jid;
138 this.password = pass; 134 this.password = pass;
139 this.connect_callback = callback; 135 this.connect_callback = callback;
140 136
141 var conn = this; 137 var conn = this;
138
139 // Note that tcp.createConnection also initiates the connection.
140 // This doesn't appear to create problems with adding listeners
141 // afterward, but should be kept in mind should any arise.
142 this.socket = tcp.createConnection(this.port, this.host) 142 this.socket = tcp.createConnection(this.port, this.host)
143
143 this.socket.addListener("connect", recontext(this, conn._socket_connected)); 144 this.socket.addListener("connect", recontext(this, conn._socket_connected));
144 this.socket.addListener("disconnect", recontext(this, conn._socket_disconnected)); 145 this.socket.addListener("disconnect", recontext(this, conn._socket_disconnected));
145 this.socket.addListener("data", recontext(this, conn._socket_received)); 146 this.socket.addListener("data", recontext(this, conn._socket_received));
146 147
147 this.handlers = []; 148 this.handlers = [];
148 149
149 // Connect TCP socket
150 // this.socket.connect(this.port, this.host);
151
152 this._setStatus(xmpp.Status.CONNECTING); 150 this._setStatus(xmpp.Status.CONNECTING);
153 }, 151 },
154 152
155 send: function (data) 153 send: function (data)
156 { 154 {
314 }; 312 };
315 313
316 xmpp.StanzaBuilder.prototype = { 314 xmpp.StanzaBuilder.prototype = {
317 s: function (name, attr) 315 s: function (name, attr)
318 { 316 {
317 // This function was created because c() doesn't seem to work for adding
318 // multiple children on the same level with each other. This is just a
319 // quick fix mostly to get chatstates working.
319 var s = new xmpp.StanzaBuilder(name, attr); 320 var s = new xmpp.StanzaBuilder(name, attr);
320 var parent = this; 321 var parent = this;
321 parent.tags.push(s); 322 parent.tags.push(s);
322 parent.children.push(s); 323 parent.children.push(s);
323 this.last_node.push(s); 324 this.last_node.push(s);

mercurial