diff script2.js @ 6:24aa8dccb170

Make XMPP actually work.
author Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
date Tue, 31 Jan 2012 15:59:28 +0100
parents 03ef53b969bd
children 853dcbe8f06f
line wrap: on
line diff
--- a/script2.js
+++ b/script2.js
@@ -109,15 +109,17 @@ var initiate = function(jid, sid) {
 };
 
 var accept = function(sid) {
-  var accept = "<iq to='" + documents[sid].initiator + "' type='set'>" +
+  var doc = documents[sid];
+  doc.empty();
+  var accept = "<iq to='" + doc.initiator + "' type='set'>" +
                  "<jingle xmlns='" + Lightstring.NS.jingle.main + "'" +
                         " action='session-accept'" +
-                        " initiator='" + documents[sid].initiator + "'" +
+                        " initiator='" + doc.initiator + "'" +
                         " sid='" + sid + "'>" +
                    "<content creator='initiator' name='" + documents[sid].name + "'>" +
                      "<description xmlns='" + Lightstring.NS.jingle.apps.xhtml + "'/>" +
                      "<transport xmlns='" + Lightstring.NS.jingle.transports.sxe + "'>" +
-                       "<host>" + documents[sid].host + "</host>" +
+                       "<host>" + doc.host + "</host>" +
                      "</transport>" +
                    "</content>" +
                  "</jingle>" +
@@ -293,6 +295,9 @@ conn.on('message/' + Lightstring.NS.sxe 
       conn.send(message);
       break;
     case 'accept-state':
+      var initialState = doc.createState([]).map(function(element) {
+        return Lightstring.DOM2XML(element);
+      }).join('');
       var message = "<message to='" + from + "'" +
                             " type='" + type + "'>" +
                       "<sxe xmlns='" + Lightstring.NS.sxe + "'" +
@@ -300,7 +305,7 @@ conn.on('message/' + Lightstring.NS.sxe 
                           " session='" + sid + "'>" +
                         "<state>" +
                           "<document-begin prolog='" + doc.prolog + "'/>" +
-                          //TODO: support non-empty documents.
+                           initialState +
                           "<document-end last-sender='' last-id=''/>" +
                         "</state>" +
                       "</sxe>" +