Mercurial > eldonilo > barbecue
diff 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 |
line wrap: on
line diff
--- 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 = "<iq to='" + stanza.DOM.getAttributeNS(null, 'from') + "'" + " id='" + stanza.DOM.getAttributeNS(null, 'id') + "'" + " type='result'>" + - "<query xmlns='" + Lightstring.NS['disco#info'] + "'>" + + "<query xmlns='" + Lightstring.ns['disco#info'] + "'>" + "<identity category='client' type='browser'/>"; features.forEach(function(f) { response += "<feature var='" + f + "'/>"; @@ -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 = "<iq to='" + jid + "' type='set'>" + - "<jingle xmlns='" + Lightstring.NS.jingle.main + "'" + + "<jingle xmlns='" + Lightstring.ns.jingle.main + "'" + " action='session-initiate'" + " initiator='" + documents[sid].initiator + "'" + " sid='" + sid + "'>" + "<content creator='initiator' name='" + documents[sid].name + "'>" + - "<description xmlns='" + Lightstring.NS.jingle.apps.xhtml + "'/>" + - "<transport xmlns='" + Lightstring.NS.jingle.transports.sxe + "'>" + + "<description xmlns='" + Lightstring.ns['jingle_apps_xhtml'] + "'/>" + + "<transport xmlns='" + Lightstring.ns['jingle_transports_sxe'] + "'>" + "<host>" + documents[sid].host + "</host>" + "</transport>" + "</content>" + @@ -112,13 +113,13 @@ var accept = function(sid) { var doc = documents[sid]; doc.empty(); var accept = "<iq to='" + doc.initiator + "' type='set'>" + - "<jingle xmlns='" + Lightstring.NS.jingle.main + "'" + + "<jingle xmlns='" + Lightstring.ns.jingle.main + "'" + " action='session-accept'" + " 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 + "'>" + + "<description xmlns='" + Lightstring.ns['jingle_apps_xhtml'] + "'/>" + + "<transport xmlns='" + Lightstring.ns['jingle_transports_sxe'] + "'>" + "<host>" + doc.host + "</host>" + "</transport>" + "</content>" + @@ -137,7 +138,7 @@ var terminate = function(sid, reason) { return console.log('BIG WARNING!!!'); var terminate = "<iq to='" + documents[sid].initiator + "' type='set'>" + - "<jingle xmlns='" + Lightstring.NS.jingle.main + "'" + + "<jingle xmlns='" + Lightstring.ns.jingle.main + "'" + " action='session-terminate'" + " host='" + documents[sid].host + "'" + " initiator='" + documents[sid].initiator + "'" + @@ -151,7 +152,7 @@ var terminate = function(sid, reason) { conn.send(terminate); }; -conn.on('iq/' + Lightstring.NS.jingle.main + ':jingle', function(stanza) { +conn.on('iq/' + Lightstring.ns.jingle + ':jingle', function(stanza) { conn.send("<iq to='" + stanza.DOM.getAttributeNS(null, 'from') + "'" + " id='" + stanza.DOM.getAttributeNS(null, 'id') + "'" + " type='result'/>"); @@ -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 = "<message to='" + host + "'" + " type='" + type + "'>" + - "<sxe xmlns='" + Lightstring.NS.sxe + "'" + + "<sxe xmlns='" + Lightstring.ns['sxe'] + "'" + " id='" + Lightstring.newId('sxe') + "'" + " session='" + sid + "'>" + "<connect/>" + @@ -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 = "<message to='" + from + "'" + " type='" + type + "'>" + - "<sxe xmlns='" + Lightstring.NS.sxe + "'" + + "<sxe xmlns='" + Lightstring.ns['sxe'] + "'" + " id='" + Lightstring.newId('sxe') + "'" + " session='" + sid + "'>" + "<state-offer>" + - "<description xmlns='" + Lightstring.NS.jingle.apps.xhtml + "'/>" + + "<description xmlns='" + Lightstring.ns['jingle_apps_xhtml'] + "'/>" + "</state-offer>" + "</sxe>" + "</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 = "<message to='" + from + "'" + " type='" + type + "'>" + - "<sxe xmlns='" + Lightstring.NS.sxe + "'" + + "<sxe xmlns='" + Lightstring.ns['sxe'] + "'" + " id='" + Lightstring.newId('sxe') + "'" + " session='" + sid + "'>" + "<" + (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 = "<message to='" + from + "'" + " type='" + type + "'>" + - "<sxe xmlns='" + Lightstring.NS.sxe + "'" + + "<sxe xmlns='" + Lightstring.ns['sxe'] + "'" + " id='" + Lightstring.newId('sxe') + "'" + " session='" + sid + "'>" + "<state>" + @@ -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);