Mercurial > eldonilo > barbecue
annotate script2.js @ 7:853dcbe8f06f
Make barbecue work with latest Lightstring.
author | Emmanuel Gil Peyrot <linkmauve@linkmauve.fr> |
---|---|
date | Thu, 02 Feb 2012 12:11:33 +0100 |
parents | 24aa8dccb170 |
children | 7b2ca4d5af6d |
rev | line source |
---|---|
5 | 1 'use strict'; |
2 | |
3 /** Copyright (c) 2012 Emmanuel Gil Peyrot <linkmauve@linkmauve.fr> | |
4 * | |
5 * Permission is hereby granted, free of charge, to any person obtaining a copy | |
6 * of this software and associated documentation files (the "Software"), to | |
7 * deal in the Software without restriction, including without limitation the | |
8 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or | |
9 * sell copies of the Software, and to permit persons to whom the Software is | |
10 * furnished to do so, subject to the following conditions: | |
11 * | |
12 * The above copyright notice and this permission notice shall be included in | |
13 * all copies or substantial portions of the Software. | |
14 * | |
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | |
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | |
18 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | |
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS | |
21 * IN THE SOFTWARE. | |
22 */ | |
23 | |
24 var conn = new Lightstring.Connection(SERVICE); | |
25 var roster = {}; | |
26 var documents = {}; | |
27 | |
7
853dcbe8f06f
Make barbecue work with latest Lightstring.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
6
diff
changeset
|
28 Lightstring.plugins['jingle'] = { |
853dcbe8f06f
Make barbecue work with latest Lightstring.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
6
diff
changeset
|
29 namespaces: { |
853dcbe8f06f
Make barbecue work with latest Lightstring.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
6
diff
changeset
|
30 jingle: 'urn:xmpp:jingle:1', |
853dcbe8f06f
Make barbecue work with latest Lightstring.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
6
diff
changeset
|
31 jingle_transports_sxe: 'urn:xmpp:jingle:transports:sxe', |
853dcbe8f06f
Make barbecue work with latest Lightstring.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
6
diff
changeset
|
32 jingle_apps_xhtml: 'urn:xmpp:jingle:apps:xhtml' |
5 | 33 } |
34 }; | |
7
853dcbe8f06f
Make barbecue work with latest Lightstring.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
6
diff
changeset
|
35 Lightstring.ns['sxe'] = 'urn:xmpp:sxe:0'; |
5 | 36 |
7
853dcbe8f06f
Make barbecue work with latest Lightstring.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
6
diff
changeset
|
37 conn.on('iq/' + Lightstring.ns['disco#info'] + ':query', function(stanza) { |
5 | 38 if (stanza.DOM.getAttributeNS(null, 'type') !== 'get') |
39 return; | |
40 | |
41 var query = stanza.DOM.firstChild; | |
42 if (query.getAttributeNS(null, 'node')) { | |
43 var response = "<iq to='" + stanza.DOM.getAttributeNS(null, 'from') + "'" + | |
44 " id='" + stanza.DOM.getAttributeNS(null, 'id') + "'" + | |
45 " type='error'/>"; //TODO: precise the error. | |
46 conn.send(response); | |
47 return; | |
48 } | |
49 | |
7
853dcbe8f06f
Make barbecue work with latest Lightstring.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
6
diff
changeset
|
50 var features = [Lightstring.ns['sxe'], Lightstring.ns['jingle_transports_sxe']]; //TODO: put that elsewhere. |
5 | 51 |
52 var response = "<iq to='" + stanza.DOM.getAttributeNS(null, 'from') + "'" + | |
53 " id='" + stanza.DOM.getAttributeNS(null, 'id') + "'" + | |
54 " type='result'>" + | |
7
853dcbe8f06f
Make barbecue work with latest Lightstring.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
6
diff
changeset
|
55 "<query xmlns='" + Lightstring.ns['disco#info'] + "'>" + |
5 | 56 "<identity category='client' type='browser'/>"; |
57 features.forEach(function(f) { | |
58 response += "<feature var='" + f + "'/>"; | |
59 }); | |
60 response += "</query>" + | |
61 "</iq>"; | |
62 | |
63 conn.send(response); | |
64 }); | |
65 | |
66 conn.on('presence', function(stanza) { | |
67 var from = new Lightstring.JID(stanza.DOM.getAttributeNS(null, 'from')); | |
68 if (!from.equals(conn.jid)) { | |
69 var type = stanza.DOM.getAttributeNS(null, 'type'); | |
70 if (!type) | |
7
853dcbe8f06f
Make barbecue work with latest Lightstring.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
6
diff
changeset
|
71 conn.disco.info(from, undefined, function(stanza) { |
853dcbe8f06f
Make barbecue work with latest Lightstring.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
6
diff
changeset
|
72 roster[from.full] = {identities: stanza.identities, features: stanza.features}; |
853dcbe8f06f
Make barbecue work with latest Lightstring.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
6
diff
changeset
|
73 }, function(stanza) { |
853dcbe8f06f
Make barbecue work with latest Lightstring.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
6
diff
changeset
|
74 console.log(from + ' doesn’t handle disco#info.'); |
853dcbe8f06f
Make barbecue work with latest Lightstring.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
6
diff
changeset
|
75 roster[from.full] = {}; |
5 | 76 }); |
77 else if (type === 'unavailable') | |
78 delete roster[from.full]; | |
79 } | |
80 }); | |
81 | |
82 var host = function(sid, name) { | |
83 if (!sid) | |
84 sid = String(Math.random()); | |
85 | |
86 documents[sid] = new Document(conn.jid.full, name, conn.jid.full, 'document'); | |
87 | |
88 for (var jid in roster) { | |
89 var contact = roster[jid]; | |
7
853dcbe8f06f
Make barbecue work with latest Lightstring.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
6
diff
changeset
|
90 if ((contact.features.indexOf(Lightstring.ns['sxe']) !== -1) && (contact.features.indexOf(Lightstring.ns['jingle_transports_sxe']) !== -1)) |
5 | 91 initiate(jid, sid); |
92 } | |
93 } | |
94 | |
95 var initiate = function(jid, sid) { | |
96 var initiate = "<iq to='" + jid + "' type='set'>" + | |
7
853dcbe8f06f
Make barbecue work with latest Lightstring.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
6
diff
changeset
|
97 "<jingle xmlns='" + Lightstring.ns.jingle.main + "'" + |
5 | 98 " action='session-initiate'" + |
99 " initiator='" + documents[sid].initiator + "'" + | |
100 " sid='" + sid + "'>" + | |
101 "<content creator='initiator' name='" + documents[sid].name + "'>" + | |
7
853dcbe8f06f
Make barbecue work with latest Lightstring.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
6
diff
changeset
|
102 "<description xmlns='" + Lightstring.ns['jingle_apps_xhtml'] + "'/>" + |
853dcbe8f06f
Make barbecue work with latest Lightstring.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
6
diff
changeset
|
103 "<transport xmlns='" + Lightstring.ns['jingle_transports_sxe'] + "'>" + |
5 | 104 "<host>" + documents[sid].host + "</host>" + |
105 "</transport>" + | |
106 "</content>" + | |
107 "</jingle>" + | |
108 "</iq>"; | |
109 conn.send(initiate); | |
110 }; | |
111 | |
112 var accept = function(sid) { | |
6
24aa8dccb170
Make XMPP actually work.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
5
diff
changeset
|
113 var doc = documents[sid]; |
24aa8dccb170
Make XMPP actually work.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
5
diff
changeset
|
114 doc.empty(); |
24aa8dccb170
Make XMPP actually work.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
5
diff
changeset
|
115 var accept = "<iq to='" + doc.initiator + "' type='set'>" + |
7
853dcbe8f06f
Make barbecue work with latest Lightstring.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
6
diff
changeset
|
116 "<jingle xmlns='" + Lightstring.ns.jingle.main + "'" + |
5 | 117 " action='session-accept'" + |
6
24aa8dccb170
Make XMPP actually work.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
5
diff
changeset
|
118 " initiator='" + doc.initiator + "'" + |
5 | 119 " sid='" + sid + "'>" + |
120 "<content creator='initiator' name='" + documents[sid].name + "'>" + | |
7
853dcbe8f06f
Make barbecue work with latest Lightstring.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
6
diff
changeset
|
121 "<description xmlns='" + Lightstring.ns['jingle_apps_xhtml'] + "'/>" + |
853dcbe8f06f
Make barbecue work with latest Lightstring.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
6
diff
changeset
|
122 "<transport xmlns='" + Lightstring.ns['jingle_transports_sxe'] + "'>" + |
6
24aa8dccb170
Make XMPP actually work.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
5
diff
changeset
|
123 "<host>" + doc.host + "</host>" + |
5 | 124 "</transport>" + |
125 "</content>" + | |
126 "</jingle>" + | |
127 "</iq>"; | |
128 conn.send(accept, function(stanza) { | |
129 if (stanza.DOM.getAttributeNS(null, 'type') === 'result') | |
130 connect(sid); | |
131 else | |
132 terminate('TODO'); //XXX | |
133 }); | |
134 }; | |
135 | |
136 var terminate = function(sid, reason) { | |
137 if (!(sid in documents)) | |
138 return console.log('BIG WARNING!!!'); | |
139 | |
140 var terminate = "<iq to='" + documents[sid].initiator + "' type='set'>" + | |
7
853dcbe8f06f
Make barbecue work with latest Lightstring.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
6
diff
changeset
|
141 "<jingle xmlns='" + Lightstring.ns.jingle.main + "'" + |
5 | 142 " action='session-terminate'" + |
143 " host='" + documents[sid].host + "'" + | |
144 " initiator='" + documents[sid].initiator + "'" + | |
145 " sid='" + sid + "'>" + | |
146 "<reason>" + | |
147 "<" + reason + "/>" + | |
148 "</reason>" + | |
149 "</jingle>" + | |
150 "</iq>"; | |
151 delete documents[sid]; | |
152 conn.send(terminate); | |
153 }; | |
154 | |
7
853dcbe8f06f
Make barbecue work with latest Lightstring.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
6
diff
changeset
|
155 conn.on('iq/' + Lightstring.ns.jingle + ':jingle', function(stanza) { |
5 | 156 conn.send("<iq to='" + stanza.DOM.getAttributeNS(null, 'from') + "'" + |
157 " id='" + stanza.DOM.getAttributeNS(null, 'id') + "'" + | |
158 " type='result'/>"); | |
159 | |
160 var jingle = stanza.DOM.firstChild; | |
161 var action = jingle.getAttributeNS(null, 'action'); | |
162 var initiator = jingle.getAttributeNS(null, 'initiator'); | |
163 var sid = jingle.getAttributeNS(null, 'sid'); | |
164 | |
165 var payload = jingle.firstChild; //TODO: what if they are multiple? | |
166 | |
167 //TODO: verify that the payload is really what we want. | |
168 //TODO: use the reason even with content as payload. | |
169 if (action === 'session-initiate') { | |
170 var content = payload; | |
171 var creator = content.getAttributeNS(null, 'creator'); | |
172 var name = content.getAttributeNS(null, 'name'); | |
173 | |
174 if (documents[sid]) | |
175 return terminate(sid, 'alternative-session'); //TODO: The XEP: “and wishes to use that [previous] session instead” | |
176 | |
177 var description = content.getElementsByTagName('description')[0]; //TODO: supporte multiple applications. | |
7
853dcbe8f06f
Make barbecue work with latest Lightstring.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
6
diff
changeset
|
178 if (description.namespaceURI !== Lightstring.ns['jingle_apps_xhtml']) |
5 | 179 return terminate(sid, 'unsupported-applications'); |
180 | |
181 var transport = content.getElementsByTagName('transport')[0]; //TODO: supporte multiple transports. | |
7
853dcbe8f06f
Make barbecue work with latest Lightstring.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
6
diff
changeset
|
182 if (transport.namespaceURI !== Lightstring.ns['jingle_transports_sxe']) |
5 | 183 return terminate(sid, 'unsupported-transports'); |
184 | |
185 var host = transport.textContent; //TODO: verify the presence of the host element. | |
186 | |
187 documents[sid] = new Document(initiator, name, host, 'document'); | |
188 | |
189 if (confirm('Do you accept?')) | |
190 accept(sid); | |
191 else | |
192 terminate(sid, 'decline'); | |
193 | |
194 } else if (action === 'session-accept') { | |
195 var content = payload; | |
196 var creator = content.getAttributeNS(null, 'creator'); | |
197 var name = content.getAttributeNS(null, 'name'); | |
198 | |
199 alert('Accepted! \\o/'); | |
200 | |
201 var description = content.getElementsByTagName('description')[0]; //TODO: supporte multiple applications. | |
7
853dcbe8f06f
Make barbecue work with latest Lightstring.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
6
diff
changeset
|
202 if (description.namespaceURI !== Lightstring.ns['jingle_apps_xhtml']) |
5 | 203 return terminate(sid, 'unsupported-applications'); |
204 | |
205 var transport = content.getElementsByTagName('transport')[0]; //TODO: supporte multiple transports. | |
7
853dcbe8f06f
Make barbecue work with latest Lightstring.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
6
diff
changeset
|
206 if (transport.namespaceURI !== Lightstring.ns['jingle_transports_sxe']) |
5 | 207 return terminate(sid, 'unsupported-transports'); |
208 | |
209 var host = transport.textContent; //TODO: verify the presence of the host element. | |
210 | |
211 var doc = documents[sid]; | |
212 if (doc.initiator !== initiator || | |
213 doc.name !== name || | |
214 doc.host !== host) | |
215 return terminate(sid, 'unknown-error'); //XXX | |
216 | |
217 } else if (action === 'session-terminate') { | |
218 var reason = payload; | |
219 | |
220 //TODO: verify they are what the should be. | |
221 var element = reason.firstChild; | |
222 var text = element.nextSibling; | |
223 | |
224 alert('Terminated, reason: ' + element.localName + (text? ' (' + text.textContent + ')': '')); | |
225 | |
226 delete documents[sid]; | |
227 } | |
228 }); | |
229 | |
230 var connect = function(sid) { | |
231 var host = documents[sid].host; | |
232 var identities = roster[host].identities; | |
233 var type = 'chat'; | |
234 identities.forEach(function(identity) { | |
235 if (identity.category === 'conference') | |
236 type = 'groupchat'; | |
237 }); | |
238 var message = "<message to='" + host + "'" + | |
239 " type='" + type + "'>" + | |
7
853dcbe8f06f
Make barbecue work with latest Lightstring.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
6
diff
changeset
|
240 "<sxe xmlns='" + Lightstring.ns['sxe'] + "'" + |
5 | 241 " id='" + Lightstring.newId('sxe') + "'" + |
242 " session='" + sid + "'>" + | |
243 "<connect/>" + | |
244 "</sxe>" + | |
245 "</message>"; | |
246 conn.send(message); | |
247 }; | |
248 | |
7
853dcbe8f06f
Make barbecue work with latest Lightstring.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
6
diff
changeset
|
249 conn.on('message/' + Lightstring.ns['sxe'] + ':sxe', function(stanza) { |
5 | 250 var from = stanza.DOM.getAttributeNS(null, 'from'); |
251 var type = 'chat'; //TODO: always? | |
252 var sxe = stanza.DOM.firstChild; //TODO: there can be multiple payloads. | |
253 var id = sxe.getAttributeNS(null, 'id'); | |
254 var sid = sxe.getAttributeNS(null, 'session'); | |
255 | |
256 var doc = documents[sid]; | |
257 if (!doc) { | |
258 conn.send("<message to='" + from + "' type='error'/>"); //XXX | |
259 return; | |
260 } | |
261 | |
262 var payload = sxe.firstChild; //TODO: really? | |
263 switch (payload.localName) { | |
264 case 'connect': | |
265 var message = "<message to='" + from + "'" + | |
266 " type='" + type + "'>" + | |
7
853dcbe8f06f
Make barbecue work with latest Lightstring.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
6
diff
changeset
|
267 "<sxe xmlns='" + Lightstring.ns['sxe'] + "'" + |
5 | 268 " id='" + Lightstring.newId('sxe') + "'" + |
269 " session='" + sid + "'>" + | |
270 "<state-offer>" + | |
7
853dcbe8f06f
Make barbecue work with latest Lightstring.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
6
diff
changeset
|
271 "<description xmlns='" + Lightstring.ns['jingle_apps_xhtml'] + "'/>" + |
5 | 272 "</state-offer>" + |
273 "</sxe>" + | |
274 "</message>"; | |
275 conn.send(message); | |
276 break; | |
277 case 'state-offer': | |
278 var description = payload.firstChild; | |
7
853dcbe8f06f
Make barbecue work with latest Lightstring.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
6
diff
changeset
|
279 if (description.namespaceURI !== Lightstring.ns['jingle_apps_xhtml']) |
5 | 280 return terminate(sid, 'unsupported-applications'); |
281 | |
282 var accept = false; | |
283 if (from === doc.host || from === doc.initiator) | |
284 accept = true; | |
285 | |
286 //TODO: refuse if proposed multiple times. | |
287 | |
288 var message = "<message to='" + from + "'" + | |
289 " type='" + type + "'>" + | |
7
853dcbe8f06f
Make barbecue work with latest Lightstring.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
6
diff
changeset
|
290 "<sxe xmlns='" + Lightstring.ns['sxe'] + "'" + |
5 | 291 " id='" + Lightstring.newId('sxe') + "'" + |
292 " session='" + sid + "'>" + | |
293 "<" + (accept? 'accept': 'refuse') + "-state/>" + | |
294 "</sxe>" + | |
295 "</message>"; | |
296 conn.send(message); | |
297 break; | |
298 case 'accept-state': | |
7
853dcbe8f06f
Make barbecue work with latest Lightstring.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
6
diff
changeset
|
299 console.log(doc); |
853dcbe8f06f
Make barbecue work with latest Lightstring.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
6
diff
changeset
|
300 var initialState = doc.createState([]); |
853dcbe8f06f
Make barbecue work with latest Lightstring.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
6
diff
changeset
|
301 console.log(initialState); |
853dcbe8f06f
Make barbecue work with latest Lightstring.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
6
diff
changeset
|
302 initialState = initialState.map(function(element) { |
6
24aa8dccb170
Make XMPP actually work.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
5
diff
changeset
|
303 return Lightstring.DOM2XML(element); |
24aa8dccb170
Make XMPP actually work.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
5
diff
changeset
|
304 }).join(''); |
7
853dcbe8f06f
Make barbecue work with latest Lightstring.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
6
diff
changeset
|
305 console.log(initialState); |
5 | 306 var message = "<message to='" + from + "'" + |
307 " type='" + type + "'>" + | |
7
853dcbe8f06f
Make barbecue work with latest Lightstring.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
6
diff
changeset
|
308 "<sxe xmlns='" + Lightstring.ns['sxe'] + "'" + |
5 | 309 " id='" + Lightstring.newId('sxe') + "'" + |
310 " session='" + sid + "'>" + | |
311 "<state>" + | |
312 "<document-begin prolog='" + doc.prolog + "'/>" + | |
6
24aa8dccb170
Make XMPP actually work.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
5
diff
changeset
|
313 initialState + |
5 | 314 "<document-end last-sender='' last-id=''/>" + |
315 "</state>" + | |
316 "</sxe>" + | |
317 "</message>"; | |
318 conn.send(message); | |
319 break; | |
320 case 'refuse-state': | |
321 terminate(sid, 'decline'); | |
322 break; | |
323 case 'state': | |
324 var elements = payload.children; | |
325 doc.processState(from, elements); | |
326 break; | |
327 default: | |
328 var elements = sxe.children; | |
329 doc.processState(from, elements); | |
330 } | |
331 }); | |
332 | |
333 (function() { | |
334 var events = ['connected', 'conn-error', 'connecting', 'disconnected', 'disconnecting']; | |
335 var state = document.getElementById('state'); | |
336 events.forEach(function(e) { | |
337 conn.on(e, function() { | |
338 state.innerHTML = e; | |
7
853dcbe8f06f
Make barbecue work with latest Lightstring.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
6
diff
changeset
|
339 return false; |
5 | 340 }); |
341 }); | |
342 })(); | |
343 | |
344 conn.on('error', function(a) { | |
345 alert(a); | |
346 }); | |
347 | |
348 document.getElementById('host').addEventListener('click', function() { | |
349 host(Lightstring.newId('sess'), 'My First XHTML Document'); | |
350 }, false); | |
351 | |
7
853dcbe8f06f
Make barbecue work with latest Lightstring.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
6
diff
changeset
|
352 conn.on('output', function(stanza) { |
853dcbe8f06f
Make barbecue work with latest Lightstring.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
6
diff
changeset
|
353 console.log('out:', stanza.DOM || stanza.XML); |
853dcbe8f06f
Make barbecue work with latest Lightstring.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
6
diff
changeset
|
354 }); |
853dcbe8f06f
Make barbecue work with latest Lightstring.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
6
diff
changeset
|
355 conn.on('input', function(stanza) { |
853dcbe8f06f
Make barbecue work with latest Lightstring.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
6
diff
changeset
|
356 console.log('in:', stanza.DOM || stanza.XML); |
5 | 357 }); |
358 | |
7
853dcbe8f06f
Make barbecue work with latest Lightstring.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
6
diff
changeset
|
359 conn.on('connected', function() { |
853dcbe8f06f
Make barbecue work with latest Lightstring.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
6
diff
changeset
|
360 conn.presence.send(conn); |
853dcbe8f06f
Make barbecue work with latest Lightstring.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
6
diff
changeset
|
361 return true; |
853dcbe8f06f
Make barbecue work with latest Lightstring.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
6
diff
changeset
|
362 }); |
5 | 363 |
7
853dcbe8f06f
Make barbecue work with latest Lightstring.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
6
diff
changeset
|
364 conn.load('DIGEST-MD5'); |
853dcbe8f06f
Make barbecue work with latest Lightstring.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
6
diff
changeset
|
365 conn.load('presence'); |
853dcbe8f06f
Make barbecue work with latest Lightstring.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
6
diff
changeset
|
366 conn.load('disco'); |
853dcbe8f06f
Make barbecue work with latest Lightstring.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
6
diff
changeset
|
367 conn.load('jingle'); |
853dcbe8f06f
Make barbecue work with latest Lightstring.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
6
diff
changeset
|
368 conn.disco.addFeatures(Lightstring.ns['jingle_transports_sxe'], Lightstring.ns['sxe']); |
853dcbe8f06f
Make barbecue work with latest Lightstring.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
6
diff
changeset
|
369 conn.connect(JID + '/' + prompt('Resource?'), PASSWORD); |