Mercurial > eldonilo > barbecue
comparison script2.js @ 9:d3b37bbb2b88 default tip master
Support multiple participants.
author | Emmanuel Gil Peyrot <linkmauve@linkmauve.fr> |
---|---|
date | Thu, 02 Feb 2012 16:37:28 +0100 |
parents | 7b2ca4d5af6d |
children |
comparison
equal
deleted
inserted
replaced
8:7b2ca4d5af6d | 9:d3b37bbb2b88 |
---|---|
259 "</sxe>" + | 259 "</sxe>" + |
260 "</message>"; | 260 "</message>"; |
261 conn.send(message); | 261 conn.send(message); |
262 }; | 262 }; |
263 | 263 |
264 var sendState = function(sid) { | 264 var sendState = function(sid, from) { |
265 var doc = documents[sid]; | 265 var doc = documents[sid]; |
266 var initialState = doc.createState([]).map(function(element) { | 266 var initialState = doc.createState([]).map(function(element) { |
267 return Lightstring.DOM2XML(element); | 267 return Lightstring.DOM2XML(element); |
268 }).join(''); | 268 }).join(''); |
269 if (conn.jid.full in doc.participants) { // participant | 269 if (conn.jid.full in doc.participants) { // participant |
281 "</sxe>" + | 281 "</sxe>" + |
282 "</message>"; | 282 "</message>"; |
283 conn.send(message); | 283 conn.send(message); |
284 } else { // host | 284 } else { // host |
285 for (var jid in doc.participants) { | 285 for (var jid in doc.participants) { |
286 if (from == jid) | |
287 continue; | |
286 var type = doc.participants[jid]; | 288 var type = doc.participants[jid]; |
287 var message = "<message to='" + jid + "'" + | 289 var message = "<message to='" + jid + "'" + |
288 " type='" + type + "'>" + | 290 " type='" + type + "'>" + |
289 "<sxe xmlns='" + Lightstring.ns['sxe'] + "'" + | 291 "<sxe xmlns='" + Lightstring.ns['sxe'] + "'" + |
290 " id='" + Lightstring.newId('sxe') + "'" + | 292 " id='" + Lightstring.newId('sxe') + "'" + |
349 break; | 351 break; |
350 case 'state': | 352 case 'state': |
351 var elements = payload.children; | 353 var elements = payload.children; |
352 doc.empty(); | 354 doc.empty(); |
353 doc.processState(from, elements); | 355 doc.processState(from, elements); |
356 if (doc.host === conn.jid.full) | |
357 sendState(sid, from); | |
354 break; | 358 break; |
355 default: | 359 default: |
356 var elements = sxe.children; | 360 var elements = sxe.children; |
357 doc.processState(from, elements); | 361 doc.processState(from, elements); |
358 } | 362 } |