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