# HG changeset patch # User Emmanuel Gil Peyrot # Date 1328181093 -3600 # Node ID 853dcbe8f06f40823eb2c1375ce6ee770663a275 # Parent 24aa8dccb1701f9972c91893151c49103a17d34f Make barbecue work with latest Lightstring. diff --git a/index.xhtml b/index.xhtml --- a/index.xhtml +++ b/index.xhtml @@ -9,9 +9,9 @@ + - diff --git a/script2.js b/script2.js --- a/script2.js +++ b/script2.js @@ -25,18 +25,16 @@ var conn = new Lightstring.Connection(SE var roster = {}; var documents = {}; -Lightstring.NS.sxe = 'urn:xmpp:sxe:0'; -Lightstring.NS.jingle = { - main: 'urn:xmpp:jingle:1', - transports: { - sxe: 'urn:xmpp:jingle:transports:sxe' - }, - apps: { - xhtml: 'urn:xmpp:jingle:apps:xhtml' +Lightstring.plugins['jingle'] = { + namespaces: { + jingle: 'urn:xmpp:jingle:1', + jingle_transports_sxe: 'urn:xmpp:jingle:transports:sxe', + jingle_apps_xhtml: 'urn:xmpp:jingle:apps:xhtml' } }; +Lightstring.ns['sxe'] = 'urn:xmpp:sxe:0'; -conn.on('iq/' + Lightstring.NS['disco#info'] + ':query', function(stanza) { +conn.on('iq/' + Lightstring.ns['disco#info'] + ':query', function(stanza) { if (stanza.DOM.getAttributeNS(null, 'type') !== 'get') return; @@ -49,12 +47,12 @@ conn.on('iq/' + Lightstring.NS['disco#in return; } - var features = [Lightstring.NS.sxe, Lightstring.NS.jingle.transports.sxe]; //TODO: put that elsewhere. + var features = [Lightstring.ns['sxe'], Lightstring.ns['jingle_transports_sxe']]; //TODO: put that elsewhere. var response = "" + - "" + + "" + ""; features.forEach(function(f) { response += ""; @@ -70,8 +68,11 @@ conn.on('presence', function(stanza) { if (!from.equals(conn.jid)) { var type = stanza.DOM.getAttributeNS(null, 'type'); if (!type) - Lightstring.discoInfo(conn, from, undefined, function(aData) { - roster[from.full] = aData; + conn.disco.info(from, undefined, function(stanza) { + roster[from.full] = {identities: stanza.identities, features: stanza.features}; + }, function(stanza) { + console.log(from + ' doesn’t handle disco#info.'); + roster[from.full] = {}; }); else if (type === 'unavailable') delete roster[from.full]; @@ -86,20 +87,20 @@ var host = function(sid, name) { for (var jid in roster) { var contact = roster[jid]; - if ((contact.features.indexOf(Lightstring.NS.sxe) !== -1) && (contact.features.indexOf(Lightstring.NS.jingle.transports.sxe) !== -1)) + if ((contact.features.indexOf(Lightstring.ns['sxe']) !== -1) && (contact.features.indexOf(Lightstring.ns['jingle_transports_sxe']) !== -1)) initiate(jid, sid); } } var initiate = function(jid, sid) { var initiate = "" + - "" + "" + - "" + - "" + + "" + + "" + "" + documents[sid].host + "" + "" + "" + @@ -112,13 +113,13 @@ var accept = function(sid) { var doc = documents[sid]; doc.empty(); var accept = "" + - "" + "" + - "" + - "" + + "" + + "" + "" + doc.host + "" + "" + "" + @@ -137,7 +138,7 @@ var terminate = function(sid, reason) { return console.log('BIG WARNING!!!'); var terminate = "" + - ""); @@ -174,11 +175,11 @@ conn.on('iq/' + Lightstring.NS.jingle.ma return terminate(sid, 'alternative-session'); //TODO: The XEP: “and wishes to use that [previous] session instead” var description = content.getElementsByTagName('description')[0]; //TODO: supporte multiple applications. - if (description.namespaceURI !== Lightstring.NS.jingle.apps.xhtml) + if (description.namespaceURI !== Lightstring.ns['jingle_apps_xhtml']) return terminate(sid, 'unsupported-applications'); var transport = content.getElementsByTagName('transport')[0]; //TODO: supporte multiple transports. - if (transport.namespaceURI !== Lightstring.NS.jingle.transports.sxe) + if (transport.namespaceURI !== Lightstring.ns['jingle_transports_sxe']) return terminate(sid, 'unsupported-transports'); var host = transport.textContent; //TODO: verify the presence of the host element. @@ -198,11 +199,11 @@ conn.on('iq/' + Lightstring.NS.jingle.ma alert('Accepted! \\o/'); var description = content.getElementsByTagName('description')[0]; //TODO: supporte multiple applications. - if (description.namespaceURI !== Lightstring.NS.jingle.apps.xhtml) + if (description.namespaceURI !== Lightstring.ns['jingle_apps_xhtml']) return terminate(sid, 'unsupported-applications'); var transport = content.getElementsByTagName('transport')[0]; //TODO: supporte multiple transports. - if (transport.namespaceURI !== Lightstring.NS.jingle.transports.sxe) + if (transport.namespaceURI !== Lightstring.ns['jingle_transports_sxe']) return terminate(sid, 'unsupported-transports'); var host = transport.textContent; //TODO: verify the presence of the host element. @@ -236,7 +237,7 @@ var connect = function(sid) { }); var message = "" + - "" + "" + @@ -245,7 +246,7 @@ var connect = function(sid) { conn.send(message); }; -conn.on('message/' + Lightstring.NS.sxe + ':sxe', function(stanza) { +conn.on('message/' + Lightstring.ns['sxe'] + ':sxe', function(stanza) { var from = stanza.DOM.getAttributeNS(null, 'from'); var type = 'chat'; //TODO: always? var sxe = stanza.DOM.firstChild; //TODO: there can be multiple payloads. @@ -263,11 +264,11 @@ conn.on('message/' + Lightstring.NS.sxe case 'connect': var message = "" + - "" + "" + - "" + + "" + "" + "" + ""; @@ -275,7 +276,7 @@ conn.on('message/' + Lightstring.NS.sxe break; case 'state-offer': var description = payload.firstChild; - if (description.namespaceURI !== Lightstring.NS.jingle.apps.xhtml) + if (description.namespaceURI !== Lightstring.ns['jingle_apps_xhtml']) return terminate(sid, 'unsupported-applications'); var accept = false; @@ -286,7 +287,7 @@ conn.on('message/' + Lightstring.NS.sxe var message = "" + - "" + "<" + (accept? 'accept': 'refuse') + "-state/>" + @@ -295,12 +296,16 @@ conn.on('message/' + Lightstring.NS.sxe conn.send(message); break; case 'accept-state': - var initialState = doc.createState([]).map(function(element) { + console.log(doc); + var initialState = doc.createState([]); + console.log(initialState); + initialState = initialState.map(function(element) { return Lightstring.DOM2XML(element); }).join(''); + console.log(initialState); var message = "" + - "" + "" + @@ -331,6 +336,7 @@ conn.on('message/' + Lightstring.NS.sxe events.forEach(function(e) { conn.on(e, function() { state.innerHTML = e; + return false; }); }); })(); @@ -343,17 +349,21 @@ document.getElementById('host').addEvent host(Lightstring.newId('sess'), 'My First XHTML Document'); }, false); -conn.on('connected', function() { - conn.on('output', function(stanza) { - console.log('out:', stanza.DOM); - }); - conn.on('input', function(stanza) { - console.log('in:', stanza.DOM); - }); - - Lightstring.presence(conn); +conn.on('output', function(stanza) { + console.log('out:', stanza.DOM || stanza.XML); +}); +conn.on('input', function(stanza) { + console.log('in:', stanza.DOM || stanza.XML); }); -conn.connect(JID + '/' + prompt('Resource?'), PASSWORD); +conn.on('connected', function() { + conn.presence.send(conn); + return true; +}); -register_feature_not_implemented.call(conn); +conn.load('DIGEST-MD5'); +conn.load('presence'); +conn.load('disco'); +conn.load('jingle'); +conn.disco.addFeatures(Lightstring.ns['jingle_transports_sxe'], Lightstring.ns['sxe']); +conn.connect(JID + '/' + prompt('Resource?'), PASSWORD);