Mercurial > eldonilo > lightstring
comparison transports/bosh.js @ 106:c06ec02217ee
many changes
author | Sonny Piers <sonny@fastmail.net> |
---|---|
date | Tue, 26 Jun 2012 12:02:14 +0200 |
parents | 3e124209821a |
children | 5cb4733c5189 |
comparison
equal
deleted
inserted
replaced
105:fb50311997b5 | 106:c06ec02217ee |
---|---|
52 // else | 52 // else |
53 // body.cnode(children); | 53 // body.cnode(children); |
54 // } | 54 // } |
55 // } | 55 // } |
56 | 56 |
57 var body = '<body rid="' + this.rid++ + '" xmlns="http://jabber.org/protocol/httpbind"/>'; | 57 var body = new Lightstring.Stanza('<body rid="' + this.rid++ + '" xmlns="http://jabber.org/protocol/httpbind"/>'); |
58 var body = Lightstring.XML2DOM(body); | |
59 | 58 |
60 //sid | 59 //sid |
61 if (this.sid) | 60 if (this.sid) |
62 body.setAttribute('sid', this.sid); | 61 body.el.setAttribute('sid', this.sid); |
63 | 62 |
64 //attributes on body | 63 //attributes on body |
65 for (var i in attrs) | 64 for (var i in attrs) |
66 body.setAttribute(i, attrs[i]); | 65 body.el.setAttribute(i, attrs[i]); |
67 | 66 |
68 //children | 67 //children |
69 for (var i in children) | 68 for (var i in children) |
70 body.appendChild(children[i]); | 69 body.el.appendChild(children[i]); |
71 | 70 |
72 | 71 |
73 | 72 |
74 var retry = aRetry || 0; | 73 var retry = aRetry || 0; |
75 | 74 |
97 } | 96 } |
98 that.currentRequests--; | 97 that.currentRequests--; |
99 | 98 |
100 var body = this.response; | 99 var body = this.response; |
101 that.emit('rawin', body); | 100 that.emit('rawin', body); |
102 var bodyEl = Lightstring.XML2DOM(body); | 101 var bodyEl = Lightstring.parse(body); |
103 that.processResponse(bodyEl) | 102 that.processResponse(bodyEl) |
104 if (aOnSuccess) | 103 if (aOnSuccess) |
105 aOnSuccess(bodyEl); | 104 aOnSuccess(bodyEl); |
106 | 105 |
107 }, false); | 106 }, false); |
115 // if (aOnError) | 114 // if (aOnError) |
116 // aOnError(error); | 115 // aOnError(error); |
117 // } | 116 // } |
118 // }); | 117 // }); |
119 // this.emit('rawout', body.toString()); | 118 // this.emit('rawout', body.toString()); |
120 | 119 if (body.children) { |
121 for(var i = 0; i < body.children.length; i++) { | 120 for(var i = 0; i < body.children.length; i++) { |
122 var child = body.children[i]; | 121 var child = body.children[i]; |
123 that.emit('out', child); | 122 that.emit('out', child); |
124 } | 123 } |
125 this.emit('rawout', Lightstring.DOM2XML(body)) | 124 } |
126 | 125 this.emit('rawout', body); |
127 req.send(Lightstring.DOM2XML(body)); | 126 |
127 req.send(Lightstring.serialize(body)); | |
128 this.currentRequests++; | 128 this.currentRequests++; |
129 }; | 129 }; |
130 Lightstring.BOSHConnection.prototype.send = function(aData) { | 130 Lightstring.BOSHConnection.prototype.send = function(aData) { |
131 if (!aData) { | 131 if (!aData) { |
132 var el = ''; | 132 var el = ''; |
133 } | 133 } |
134 | 134 |
135 else if(typeof aData == 'string') { | 135 else if(typeof aData == 'string') { |
136 try { | 136 try { |
137 var el = Lightstring.XML2DOM(aData); | 137 var el = Lightstring.parse(aData); |
138 } | 138 } |
139 catch(e) { | 139 catch(e) { |
140 console.log(e); | 140 console.log(e); |
141 console.log(aData); | 141 console.log(aData); |
142 } | 142 } |