xmppify 0.0.12
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +29 -0
- data/Rakefile +1 -0
- data/app/assets/javascripts/xmpp/index.js +0 -0
- data/app/assets/javascripts/xmpp/scripts/checkplayer.js +12 -0
- data/app/assets/javascripts/xmpp/scripts/crossdomain.xml +7 -0
- data/app/assets/javascripts/xmpp/scripts/flXHR.js +2 -0
- data/app/assets/javascripts/xmpp/scripts/flXHR.swf +0 -0
- data/app/assets/javascripts/xmpp/scripts/flXHR.vbs +44 -0
- data/app/assets/javascripts/xmpp/scripts/flensed.js +12 -0
- data/app/assets/javascripts/xmpp/scripts/strophe.flxhr.js +31 -0
- data/app/assets/javascripts/xmpp/scripts/strophe.js +3538 -0
- data/app/assets/javascripts/xmpp/scripts/swfobject.js +5 -0
- data/app/assets/javascripts/xmpp/scripts/updateplayer.swf +0 -0
- data/app/assets/javascripts/xmpp/scripts/xmpp.js.coffee +386 -0
- data/app/assets/javascripts/xmpp/strophejs-plugins/LICENSE.txt +19 -0
- data/app/assets/javascripts/xmpp/strophejs-plugins/README.markdown +95 -0
- data/app/assets/javascripts/xmpp/strophejs-plugins/archive/README.markdown +14 -0
- data/app/assets/javascripts/xmpp/strophejs-plugins/archive/iso8601_support.js +32 -0
- data/app/assets/javascripts/xmpp/strophejs-plugins/archive/strophe.archive.js +88 -0
- data/app/assets/javascripts/xmpp/strophejs-plugins/caps/README.markdown +53 -0
- data/app/assets/javascripts/xmpp/strophejs-plugins/caps/sha1.js +202 -0
- data/app/assets/javascripts/xmpp/strophejs-plugins/caps/strophe.CAPS.coffee +153 -0
- data/app/assets/javascripts/xmpp/strophejs-plugins/caps/strophe.CAPS.js +88 -0
- data/app/assets/javascripts/xmpp/strophejs-plugins/caps/strophe.caps.jsonly.js +240 -0
- data/app/assets/javascripts/xmpp/strophejs-plugins/chatstates/strophe.chatstates.js +80 -0
- data/app/assets/javascripts/xmpp/strophejs-plugins/cmds/README.markdown +47 -0
- data/app/assets/javascripts/xmpp/strophejs-plugins/cmds/spec/GetUrlComamndSpec.js +66 -0
- data/app/assets/javascripts/xmpp/strophejs-plugins/cmds/spec/strophe.cmds.spec.coffee +145 -0
- data/app/assets/javascripts/xmpp/strophejs-plugins/cmds/spec/support/jasmine.json +16 -0
- data/app/assets/javascripts/xmpp/strophejs-plugins/cmds/src/strophe.cmds.coffee +265 -0
- data/app/assets/javascripts/xmpp/strophejs-plugins/cmds/src/strophe.cmds.js +403 -0
- data/app/assets/javascripts/xmpp/strophejs-plugins/dataforms/README.markdown +82 -0
- data/app/assets/javascripts/xmpp/strophejs-plugins/dataforms/spec/strophe.x.coffee +715 -0
- data/app/assets/javascripts/xmpp/strophejs-plugins/dataforms/src/strophe.x.coffee +443 -0
- data/app/assets/javascripts/xmpp/strophejs-plugins/dataforms/src/strophe.x.js +854 -0
- data/app/assets/javascripts/xmpp/strophejs-plugins/disco/.gitignore +1 -0
- data/app/assets/javascripts/xmpp/strophejs-plugins/disco/README.markdown +0 -0
- data/app/assets/javascripts/xmpp/strophejs-plugins/disco/convert.js +13 -0
- data/app/assets/javascripts/xmpp/strophejs-plugins/disco/jasmine.json +11 -0
- data/app/assets/javascripts/xmpp/strophejs-plugins/disco/lib/strophe.disco.js +137 -0
- data/app/assets/javascripts/xmpp/strophejs-plugins/disco/public/javascript/strophe.disco.js +137 -0
- data/app/assets/javascripts/xmpp/strophejs-plugins/disco/spec/01_querying_information.xml +6 -0
- data/app/assets/javascripts/xmpp/strophejs-plugins/disco/spec/02_result_set_for_information_request.xml +22 -0
- data/app/assets/javascripts/xmpp/strophejs-plugins/disco/spec/03_target_entity_does_not_exist.xml +10 -0
- data/app/assets/javascripts/xmpp/strophejs-plugins/disco/spec/04_service_unavailable.xml +11 -0
- data/app/assets/javascripts/xmpp/strophejs-plugins/disco/spec/09_querying_specific_jid_and_node_combination.xml +7 -0
- data/app/assets/javascripts/xmpp/strophejs-plugins/disco/spec/10_jid_and_node_result.xml +12 -0
- data/app/assets/javascripts/xmpp/strophejs-plugins/disco/spec/11_requesting_all_items.xml +6 -0
- data/app/assets/javascripts/xmpp/strophejs-plugins/disco/spec/12_result_set_for_all_items.xml +23 -0
- data/app/assets/javascripts/xmpp/strophejs-plugins/disco/spec/13_empty_result_set.xml +7 -0
- data/app/assets/javascripts/xmpp/strophejs-plugins/disco/spec/17_service_returns_nodes.xml +16 -0
- data/app/assets/javascripts/xmpp/strophejs-plugins/disco/spec/18_requesting_further_nodes.xml +7 -0
- data/app/assets/javascripts/xmpp/strophejs-plugins/disco/spec/24_jid_and_node_error.xml +11 -0
- data/app/assets/javascripts/xmpp/strophejs-plugins/disco/spec/DiscoNodeSpec.js +50 -0
- data/app/assets/javascripts/xmpp/strophejs-plugins/disco/spec/SpecHelper.js +51 -0
- data/app/assets/javascripts/xmpp/strophejs-plugins/disco/spec/Stanzas.js +0 -0
- data/app/assets/javascripts/xmpp/strophejs-plugins/disco/spec/strophe.disco.spec.helper.js +54 -0
- data/app/assets/javascripts/xmpp/strophejs-plugins/disco/spec/strophe.disco.spec.js +0 -0
- data/app/assets/javascripts/xmpp/strophejs-plugins/disco/spec/support/jasmine.json +13 -0
- data/app/assets/javascripts/xmpp/strophejs-plugins/disco/strophe.disco.js +232 -0
- data/app/assets/javascripts/xmpp/strophejs-plugins/epic/public/javascript/jquery.epic.js +61 -0
- data/app/assets/javascripts/xmpp/strophejs-plugins/epic/spec/SpecHelper.js +9 -0
- data/app/assets/javascripts/xmpp/strophejs-plugins/epic/spec/jquery.epic.js +39 -0
- data/app/assets/javascripts/xmpp/strophejs-plugins/epic/spec/support/jasmine.json +22 -0
- data/app/assets/javascripts/xmpp/strophejs-plugins/iexdomain/iexdomain.js +36 -0
- data/app/assets/javascripts/xmpp/strophejs-plugins/joap/README.markdown +117 -0
- data/app/assets/javascripts/xmpp/strophejs-plugins/joap/buster.js +23 -0
- data/app/assets/javascripts/xmpp/strophejs-plugins/joap/jid.coffee +64 -0
- data/app/assets/javascripts/xmpp/strophejs-plugins/joap/jid.js +92 -0
- data/app/assets/javascripts/xmpp/strophejs-plugins/joap/spec/browserSetup.coffee +1 -0
- data/app/assets/javascripts/xmpp/strophejs-plugins/joap/spec/jid.spec.coffee +96 -0
- data/app/assets/javascripts/xmpp/strophejs-plugins/joap/spec/strophe.joap.spec.coffee +461 -0
- data/app/assets/javascripts/xmpp/strophejs-plugins/joap/strophe.joap.coffee +304 -0
- data/app/assets/javascripts/xmpp/strophejs-plugins/joap/strophe.joap.js +522 -0
- data/app/assets/javascripts/xmpp/strophejs-plugins/mam/LICENSE.txt +19 -0
- data/app/assets/javascripts/xmpp/strophejs-plugins/mam/README.markdown +52 -0
- data/app/assets/javascripts/xmpp/strophejs-plugins/mam/strophe.mam.js +62 -0
- data/app/assets/javascripts/xmpp/strophejs-plugins/muc/LICENSE.txt +20 -0
- data/app/assets/javascripts/xmpp/strophejs-plugins/muc/strophe.muc.js +1003 -0
- data/app/assets/javascripts/xmpp/strophejs-plugins/ping/README.markdown +28 -0
- data/app/assets/javascripts/xmpp/strophejs-plugins/ping/strophe.ping.js +68 -0
- data/app/assets/javascripts/xmpp/strophejs-plugins/private/README.markdown +16 -0
- data/app/assets/javascripts/xmpp/strophejs-plugins/private/strophe.private.js +192 -0
- data/app/assets/javascripts/xmpp/strophejs-plugins/pubsub/strophe.pubsub.js +555 -0
- data/app/assets/javascripts/xmpp/strophejs-plugins/receipts/strophe.receipts.js +155 -0
- data/app/assets/javascripts/xmpp/strophejs-plugins/register/README.markdown +44 -0
- data/app/assets/javascripts/xmpp/strophejs-plugins/register/strophe.register.js +431 -0
- data/app/assets/javascripts/xmpp/strophejs-plugins/roster/public/javascript/strophe.roster.js +40 -0
- data/app/assets/javascripts/xmpp/strophejs-plugins/roster/spec/strophe.roster.spec.js +65 -0
- data/app/assets/javascripts/xmpp/strophejs-plugins/roster/spec/support/jasmine.json +15 -0
- data/app/assets/javascripts/xmpp/strophejs-plugins/roster/strophe.roster.js +438 -0
- data/app/assets/javascripts/xmpp/strophejs-plugins/rpc/.gitignore +6 -0
- data/app/assets/javascripts/xmpp/strophejs-plugins/rpc/README.md +113 -0
- data/app/assets/javascripts/xmpp/strophejs-plugins/rpc/buster.js +11 -0
- data/app/assets/javascripts/xmpp/strophejs-plugins/rpc/lib/strophe.js +4198 -0
- data/app/assets/javascripts/xmpp/strophejs-plugins/rpc/spec/strophe.rpc.spec.helper.js +38 -0
- data/app/assets/javascripts/xmpp/strophejs-plugins/rpc/spec/strophe.rpc.spec.js +262 -0
- data/app/assets/javascripts/xmpp/strophejs-plugins/rpc/strophe.rpc.js +464 -0
- data/app/assets/javascripts/xmpp/strophejs-plugins/rsm/strophe.rsm.js +52 -0
- data/app/assets/javascripts/xmpp/strophejs-plugins/serverdate/strophe.serverdate.js +58 -0
- data/app/assets/javascripts/xmpp/strophejs-plugins/vcard/examples/index.html +17 -0
- data/app/assets/javascripts/xmpp/strophejs-plugins/vcard/examples/strophevcard.js +0 -0
- data/app/assets/javascripts/xmpp/strophejs-plugins/vcard/strophe.vcard.coffee +44 -0
- data/app/assets/javascripts/xmpp/strophejs-plugins/vcard/strophe.vcard.js +66 -0
- data/app/assets/stylesheets/xmpp/index.css +0 -0
- data/app/controllers/omniauth_callbacks_controller.rb +15 -0
- data/app/controllers/ruby_bosh.rb +221 -0
- data/app/models/identity.rb +3 -0
- data/app/models/user.rb +40 -0
- data/bin/rails +8 -0
- data/db/migrate/20140329065635_create_users.rb +10 -0
- data/db/migrate/20140329070238_create_identities.rb +11 -0
- data/lib/xmppify/version.rb +3 -0
- data/lib/xmppify.rb +6 -0
- data/xmppify.gemspec +23 -0
- metadata +197 -0
@@ -0,0 +1 @@
|
|
1
|
+
.monitor
|
File without changes
|
@@ -0,0 +1,13 @@
|
|
1
|
+
var fs = require('fs'), sys = require('sys');
|
2
|
+
|
3
|
+
if (process.argv.length !== 3) {
|
4
|
+
sys.puts(process.argv[1] + " file.xml");
|
5
|
+
}
|
6
|
+
fs.readFile(process.argv[2],'ascii', function(err, x) {
|
7
|
+
sys.puts('var stanza = "";');
|
8
|
+
x.split('\n').forEach(function(line) {
|
9
|
+
sys.puts('stanza += "' + line + '";');
|
10
|
+
});
|
11
|
+
});
|
12
|
+
|
13
|
+
|
@@ -0,0 +1,137 @@
|
|
1
|
+
(function(Strophe,$) {
|
2
|
+
var DiscoNode = function(disco,cfg) {
|
3
|
+
this.disco = disco;
|
4
|
+
$.extend(this, cfg);
|
5
|
+
};
|
6
|
+
|
7
|
+
DiscoNode.prototype.parseRequest = function(iq) {
|
8
|
+
if (iq.tree) { return $(Strophe.serialize(iq.tree())); }
|
9
|
+
return $(iq);
|
10
|
+
};
|
11
|
+
|
12
|
+
DiscoNode.prototype.fromTo= function(iq) {
|
13
|
+
var to = iq.attr('from'), id = iq.attr('id'), res;
|
14
|
+
return $iq({to: to, type: 'result', id: id});
|
15
|
+
};
|
16
|
+
|
17
|
+
DiscoNode.prototype.addFirstChild = function(req,res) {
|
18
|
+
var child = req.find('> *:eq(0)'), childAttr = {};
|
19
|
+
if (child.length === 0) { return ; }
|
20
|
+
if (child.attr('xmlns')) { childAttr.xmlns = child.attr('xmlns'); }
|
21
|
+
if (child.attr('node')) { childAttr.node = child.attr('node'); }
|
22
|
+
if ($.isEmptyObject(childAttr)) { res.c(child[0].tagName); }
|
23
|
+
else { res.c(child[0].tagName, childAttr); }
|
24
|
+
};
|
25
|
+
|
26
|
+
DiscoNode.prototype.reply = function(iq) {
|
27
|
+
var req = this.parseRequest(iq);
|
28
|
+
var res = this.fromTo(req);
|
29
|
+
this.addFirstChild(req,res);
|
30
|
+
this.addContent(req,res);
|
31
|
+
return res;
|
32
|
+
};
|
33
|
+
|
34
|
+
/// DISCO_INFO
|
35
|
+
DiscoInfoNode = function() { DiscoNode.apply(this,arguments); };
|
36
|
+
DiscoInfoNode.prototype = new DiscoNode();
|
37
|
+
DiscoInfoNode.prototype.addContent = function(req,res) {
|
38
|
+
var nodes = this.features || this.disco.features;
|
39
|
+
var identity = this.identity || this.disco.identity;
|
40
|
+
res.c('identity', identity).up();
|
41
|
+
$.each(nodes, function(node){
|
42
|
+
res.c('feature', { 'var' : node}).up();
|
43
|
+
});
|
44
|
+
};
|
45
|
+
|
46
|
+
/// DISCO_ITEMS
|
47
|
+
DiscoItemsNode = function() { DiscoNode.apply(this,arguments); };
|
48
|
+
DiscoItemsNode.prototype = new DiscoNode();
|
49
|
+
DiscoItemsNode.prototype.addContent = function(req,res) {
|
50
|
+
var items = this.items || this.disco.items;
|
51
|
+
$.each(items, function(i,item){
|
52
|
+
if(!item.jid) { item.jid = this.disco._conn.jid; }
|
53
|
+
res.c('item', item).up();
|
54
|
+
}.bind(this));
|
55
|
+
|
56
|
+
};
|
57
|
+
|
58
|
+
/// NODE_NOT_FOUND
|
59
|
+
DiscoNodeNotFound = function() { DiscoNode.apply(this,arguments); };
|
60
|
+
DiscoNodeNotFound.prototype = new DiscoNode();
|
61
|
+
DiscoNodeNotFound.prototype.addContent = function(req,res) {
|
62
|
+
res.c('error', { type: 'cancel'});
|
63
|
+
res.c('item-not-found', { xmlns: 'urn:ietf:params:xml:ns:xmpp-stanzas' });
|
64
|
+
};
|
65
|
+
|
66
|
+
|
67
|
+
function noop(stanza) {
|
68
|
+
if (console) { console.log(stanza); }
|
69
|
+
}
|
70
|
+
Strophe.Disco = {
|
71
|
+
DiscoNode: DiscoNode,
|
72
|
+
DiscoInfoNode: DiscoInfoNode,
|
73
|
+
DiscoNodeNotFound: DiscoNodeNotFound,
|
74
|
+
noop: noop
|
75
|
+
};
|
76
|
+
})(Strophe, jQuery);
|
77
|
+
|
78
|
+
(function(Strophe,$) {
|
79
|
+
var INFO = Strophe.NS.DISCO_INFO;
|
80
|
+
var ITEMS = Strophe.NS.DISCO_ITEMS;
|
81
|
+
|
82
|
+
var DiscoNode = Strophe.Disco.DiscoNode;
|
83
|
+
var DiscoInfoNode = Strophe.Disco.DiscoInfoNode;
|
84
|
+
var DiscoNodeNotFound = Strophe.Disco.DiscoNodeNotFound;
|
85
|
+
var noop = Strophe.Disco.noop;
|
86
|
+
|
87
|
+
function request(conn, type, args) {
|
88
|
+
var to = args[0], node = args[1], cb = args[2], err = args[3],
|
89
|
+
q = { xmlns: type };
|
90
|
+
if(typeof node === 'function') { err = cb; cb = node; node = undefined; }
|
91
|
+
if(node) { q.node = node; }
|
92
|
+
var iq = $iq({to: to, 'type': 'get'}).c('query',q);
|
93
|
+
conn.sendIQ(iq, cb || noop, err || noop);
|
94
|
+
}
|
95
|
+
|
96
|
+
function reply(iq) {
|
97
|
+
var node = $('query',iq).attr('node') || $('query',iq).attr('xmlns');
|
98
|
+
var nodeImpl = this.features[node] || new DiscoNodeNotFound();
|
99
|
+
if($.isPlainObject(nodeImpl)) {
|
100
|
+
var xmlns = $('query',iq).attr('xmlns');
|
101
|
+
var ctr = xmlns === INFO ? DiscoInfoNode : DiscoItemsNode;
|
102
|
+
nodeImpl = new ctr(this,nodeImpl);
|
103
|
+
}
|
104
|
+
this._conn.send(nodeImpl.reply(iq));
|
105
|
+
return true;
|
106
|
+
}
|
107
|
+
|
108
|
+
var disco = {
|
109
|
+
_conn: null,
|
110
|
+
init: function(conn) {
|
111
|
+
this.jid = conn.jid;
|
112
|
+
this.features = {};
|
113
|
+
this.identity = { name: 'strophe' };
|
114
|
+
this.features[INFO] = new DiscoInfoNode(this);
|
115
|
+
this.features[ITEMS] = new DiscoItemsNode(this);
|
116
|
+
this._conn = conn;
|
117
|
+
},
|
118
|
+
statusChanged: function(status) {
|
119
|
+
if (status === Strophe.Status.CONNECTED) {
|
120
|
+
this._conn.addHandler(reply.bind(this), INFO, 'iq', 'get');
|
121
|
+
this._conn.addHandler(reply.bind(this), ITEMS, 'iq', 'get');
|
122
|
+
}
|
123
|
+
},
|
124
|
+
info: function(to, node, callback) {
|
125
|
+
request(this._conn, INFO, arguments);
|
126
|
+
},
|
127
|
+
items: function(to, node, callback) {
|
128
|
+
request(this._conn, ITEMS, arguments);
|
129
|
+
},
|
130
|
+
addNode: function(node, args) {
|
131
|
+
if(this.features[node]) { throw node + ' exists'; }
|
132
|
+
this.features[node] = args;
|
133
|
+
}
|
134
|
+
|
135
|
+
};
|
136
|
+
Strophe.addConnectionPlugin('disco', disco);
|
137
|
+
})(Strophe,jQuery);
|
@@ -0,0 +1,137 @@
|
|
1
|
+
(function(Strophe,$) {
|
2
|
+
var DiscoNode = function(disco,cfg) {
|
3
|
+
this.disco = disco;
|
4
|
+
$.extend(this, cfg);
|
5
|
+
};
|
6
|
+
|
7
|
+
DiscoNode.prototype.parseRequest = function(iq) {
|
8
|
+
if (iq.tree) { return $(Strophe.serialize(iq.tree())); }
|
9
|
+
return $(iq);
|
10
|
+
};
|
11
|
+
|
12
|
+
DiscoNode.prototype.fromTo= function(iq) {
|
13
|
+
var to = iq.attr('from'), id = iq.attr('id'), res;
|
14
|
+
return $iq({to: to, type: 'result', id: id});
|
15
|
+
};
|
16
|
+
|
17
|
+
DiscoNode.prototype.addFirstChild = function(req,res) {
|
18
|
+
var child = req.find('> *:eq(0)'), childAttr = {};
|
19
|
+
if (child.length === 0) { return ; }
|
20
|
+
if (child.attr('xmlns')) { childAttr.xmlns = child.attr('xmlns'); }
|
21
|
+
if (child.attr('node')) { childAttr.node = child.attr('node'); }
|
22
|
+
if ($.isEmptyObject(childAttr)) { res.c(child[0].tagName); }
|
23
|
+
else { res.c(child[0].tagName, childAttr); }
|
24
|
+
};
|
25
|
+
|
26
|
+
DiscoNode.prototype.reply = function(iq) {
|
27
|
+
var req = this.parseRequest(iq);
|
28
|
+
var res = this.fromTo(req);
|
29
|
+
this.addFirstChild(req,res);
|
30
|
+
this.addContent(req,res);
|
31
|
+
return res;
|
32
|
+
};
|
33
|
+
|
34
|
+
/// DISCO_INFO
|
35
|
+
DiscoInfoNode = function() { DiscoNode.apply(this,arguments); };
|
36
|
+
DiscoInfoNode.prototype = new DiscoNode();
|
37
|
+
DiscoInfoNode.prototype.addContent = function(req,res) {
|
38
|
+
var nodes = this.features || this.disco.features;
|
39
|
+
var identity = this.identity || this.disco.identity;
|
40
|
+
res.c('identity', identity).up();
|
41
|
+
$.each(nodes, function(node){
|
42
|
+
res.c('feature', { 'var' : node}).up();
|
43
|
+
});
|
44
|
+
};
|
45
|
+
|
46
|
+
/// DISCO_ITEMS
|
47
|
+
DiscoItemsNode = function() { DiscoNode.apply(this,arguments); };
|
48
|
+
DiscoItemsNode.prototype = new DiscoNode();
|
49
|
+
DiscoItemsNode.prototype.addContent = function(req,res) {
|
50
|
+
var items = this.items || this.disco.items;
|
51
|
+
$.each(items, function(i,item){
|
52
|
+
if(!item.jid) { item.jid = this.disco._conn.jid; }
|
53
|
+
res.c('item', item).up();
|
54
|
+
}.bind(this));
|
55
|
+
|
56
|
+
};
|
57
|
+
|
58
|
+
/// NODE_NOT_FOUND
|
59
|
+
DiscoNodeNotFound = function() { DiscoNode.apply(this,arguments); };
|
60
|
+
DiscoNodeNotFound.prototype = new DiscoNode();
|
61
|
+
DiscoNodeNotFound.prototype.addContent = function(req,res) {
|
62
|
+
res.c('error', { type: 'cancel'});
|
63
|
+
res.c('item-not-found', { xmlns: 'urn:ietf:params:xml:ns:xmpp-stanzas' });
|
64
|
+
};
|
65
|
+
|
66
|
+
|
67
|
+
function noop(stanza) {
|
68
|
+
if (console) { console.log(stanza); }
|
69
|
+
}
|
70
|
+
Strophe.Disco = {
|
71
|
+
DiscoNode: DiscoNode,
|
72
|
+
DiscoInfoNode: DiscoInfoNode,
|
73
|
+
DiscoNodeNotFound: DiscoNodeNotFound,
|
74
|
+
noop: noop
|
75
|
+
};
|
76
|
+
})(Strophe, jQuery);
|
77
|
+
|
78
|
+
(function(Strophe,$) {
|
79
|
+
var INFO = Strophe.NS.DISCO_INFO;
|
80
|
+
var ITEMS = Strophe.NS.DISCO_ITEMS;
|
81
|
+
|
82
|
+
var DiscoNode = Strophe.Disco.DiscoNode;
|
83
|
+
var DiscoInfoNode = Strophe.Disco.DiscoInfoNode;
|
84
|
+
var DiscoNodeNotFound = Strophe.Disco.DiscoNodeNotFound;
|
85
|
+
var noop = Strophe.Disco.noop;
|
86
|
+
|
87
|
+
function request(conn, type, args) {
|
88
|
+
var to = args[0], node = args[1], cb = args[2], err = args[3],
|
89
|
+
q = { xmlns: type };
|
90
|
+
if(typeof node === 'function') { err = cb; cb = node; node = undefined; }
|
91
|
+
if(node) { q.node = node; }
|
92
|
+
var iq = $iq({to: to, 'type': 'get'}).c('query',q);
|
93
|
+
conn.sendIQ(iq, cb || noop, err || noop);
|
94
|
+
}
|
95
|
+
|
96
|
+
function reply(iq) {
|
97
|
+
var node = $('query',iq).attr('node') || $('query',iq).attr('xmlns');
|
98
|
+
var nodeImpl = this.features[node] || new DiscoNodeNotFound();
|
99
|
+
if($.isPlainObject(nodeImpl)) {
|
100
|
+
var xmlns = $('query',iq).attr('xmlns');
|
101
|
+
var ctr = xmlns === INFO ? DiscoInfoNode : DiscoItemsNode;
|
102
|
+
nodeImpl = new ctr(this,nodeImpl);
|
103
|
+
}
|
104
|
+
this._conn.send(nodeImpl.reply(iq));
|
105
|
+
return true;
|
106
|
+
}
|
107
|
+
|
108
|
+
var disco = {
|
109
|
+
_conn: null,
|
110
|
+
init: function(conn) {
|
111
|
+
this.jid = conn.jid;
|
112
|
+
this.features = {};
|
113
|
+
this.identity = { name: 'strophe' };
|
114
|
+
this.features[INFO] = new DiscoInfoNode(this);
|
115
|
+
this.features[ITEMS] = new DiscoItemsNode(this);
|
116
|
+
this._conn = conn;
|
117
|
+
},
|
118
|
+
statusChanged: function(status) {
|
119
|
+
if (status === Strophe.Status.CONNECTED) {
|
120
|
+
this._conn.addHandler(reply.bind(this), INFO, 'iq', 'get');
|
121
|
+
this._conn.addHandler(reply.bind(this), ITEMS, 'iq', 'get');
|
122
|
+
}
|
123
|
+
},
|
124
|
+
info: function(to, node, callback) {
|
125
|
+
request(this._conn, INFO, arguments);
|
126
|
+
},
|
127
|
+
items: function(to, node, callback) {
|
128
|
+
request(this._conn, ITEMS, arguments);
|
129
|
+
},
|
130
|
+
addNode: function(node, args) {
|
131
|
+
if(this.features[node]) { throw node + ' exists'; }
|
132
|
+
this.features[node] = args;
|
133
|
+
}
|
134
|
+
|
135
|
+
};
|
136
|
+
Strophe.addConnectionPlugin('disco', disco);
|
137
|
+
})(Strophe,jQuery);
|
@@ -0,0 +1,22 @@
|
|
1
|
+
<iq type='result'
|
2
|
+
from='plays.shakespeare.lit'
|
3
|
+
to='romeo@montague.net/orchard'
|
4
|
+
id='info1'>
|
5
|
+
<query xmlns='http://jabber.org/protocol/disco#info'>
|
6
|
+
<identity
|
7
|
+
category='conference'
|
8
|
+
type='text'
|
9
|
+
name='Play-Specific Chatrooms'/>
|
10
|
+
<identity
|
11
|
+
category='directory'
|
12
|
+
type='chatroom'
|
13
|
+
name='Play-Specific Chatrooms'/>
|
14
|
+
<feature var='http://jabber.org/protocol/disco#info'/>
|
15
|
+
<feature var='http://jabber.org/protocol/disco#items'/>
|
16
|
+
<feature var='http://jabber.org/protocol/muc'/>
|
17
|
+
<feature var='jabber:iq:register'/>
|
18
|
+
<feature var='jabber:iq:search'/>
|
19
|
+
<feature var='jabber:iq:time'/>
|
20
|
+
<feature var='jabber:iq:version'/>
|
21
|
+
</query>
|
22
|
+
</iq>
|
data/app/assets/javascripts/xmpp/strophejs-plugins/disco/spec/03_target_entity_does_not_exist.xml
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
<iq type='error'
|
2
|
+
from='plays.shakespeare.lit'
|
3
|
+
to='romeo@montague.net/orchard'
|
4
|
+
id='info1'>
|
5
|
+
<query xmlns='http://jabber.org/protocol/disco#info'/>
|
6
|
+
<error type='cancel'>
|
7
|
+
<item-not-found xmlns='urn:ietf:params:xml:ns:xmpp-stanzas'/>
|
8
|
+
</error>
|
9
|
+
</iq>
|
10
|
+
|
@@ -0,0 +1,11 @@
|
|
1
|
+
<iq type='error'
|
2
|
+
from='plays.shakespeare.lit'
|
3
|
+
to='romeo@montague.net/orchard'
|
4
|
+
id='info1'>
|
5
|
+
<query xmlns='http://jabber.org/protocol/disco#info'/>
|
6
|
+
<error type='cancel'>
|
7
|
+
<service-unavailable xmlns='urn:ietf:params:xml:ns:xmpp-stanzas'/>
|
8
|
+
</error>
|
9
|
+
</iq>
|
10
|
+
|
11
|
+
|
@@ -0,0 +1,12 @@
|
|
1
|
+
<iq type='result'
|
2
|
+
from='mim.shakespeare.lit'
|
3
|
+
to='romeo@montague.net/orchard'
|
4
|
+
id='info3'>
|
5
|
+
<query xmlns='http://jabber.org/protocol/disco#info'
|
6
|
+
node='http://jabber.org/protocol/commands'>
|
7
|
+
<identity
|
8
|
+
category='automation'
|
9
|
+
type='command-list'/>
|
10
|
+
</query>
|
11
|
+
</iq>
|
12
|
+
|
@@ -0,0 +1,23 @@
|
|
1
|
+
<iq type='result'
|
2
|
+
from='shakespeare.lit'
|
3
|
+
to='romeo@montague.net/orchard'
|
4
|
+
id='items1'>
|
5
|
+
<query xmlns='http://jabber.org/protocol/disco#items'>
|
6
|
+
<item jid='people.shakespeare.lit'
|
7
|
+
name='Directory of Characters'/>
|
8
|
+
<item jid='plays.shakespeare.lit'
|
9
|
+
name='Play-Specific Chatrooms'/>
|
10
|
+
<item jid='mim.shakespeare.lit'
|
11
|
+
name='Gateway to Marlowe IM'/>
|
12
|
+
<item jid='words.shakespeare.lit'
|
13
|
+
name='Shakespearean Lexicon'/>
|
14
|
+
<item jid='globe.shakespeare.lit'
|
15
|
+
name='Calendar of Performances'/>
|
16
|
+
<item jid='headlines.shakespeare.lit'
|
17
|
+
name='Latest Shakespearean News'/>
|
18
|
+
<item jid='catalog.shakespeare.lit'
|
19
|
+
name='Buy Shakespeare Stuff!'/>
|
20
|
+
<item jid='en2fr.shakespeare.lit'
|
21
|
+
name='French Translation Service'/>
|
22
|
+
</query>
|
23
|
+
</iq>
|
@@ -0,0 +1,16 @@
|
|
1
|
+
<iq type='result'
|
2
|
+
from='catalog.shakespeare.lit'
|
3
|
+
to='romeo@montague.net/orchard'
|
4
|
+
id='items2'>
|
5
|
+
<query xmlns='http://jabber.org/protocol/disco#items'>
|
6
|
+
<item jid='catalog.shakespeare.lit'
|
7
|
+
node='books'
|
8
|
+
name='Books by and about Shakespeare'/>
|
9
|
+
<item jid='catalog.shakespeare.lit'
|
10
|
+
node='clothing'
|
11
|
+
name='Wear your literary taste with pride'/>
|
12
|
+
<item jid='catalog.shakespeare.lit'
|
13
|
+
node='music'
|
14
|
+
name='Music from the time of Shakespeare'/>
|
15
|
+
</query>
|
16
|
+
</iq>
|
@@ -0,0 +1,11 @@
|
|
1
|
+
<iq type='error'
|
2
|
+
from='mim.shakespeare.lit'
|
3
|
+
to='romeo@montague.net/orchard'
|
4
|
+
id='info3'>
|
5
|
+
<query xmlns='http://jabber.org/protocol/disco#info'
|
6
|
+
node='http://jabber.org/protocol/commands'/>
|
7
|
+
<error type='cancel'>
|
8
|
+
<not-allowed xmlns='urn:ietf:params:xml:ns:xmpp-stanzas'/>
|
9
|
+
</error>
|
10
|
+
</iq>
|
11
|
+
|
@@ -0,0 +1,50 @@
|
|
1
|
+
|
2
|
+
xdescribe("DiscoNode", function() {
|
3
|
+
var node, DiscoNode = Strophe.DiscoNode, iq, c = mockConnection();
|
4
|
+
beforeEach(function() {
|
5
|
+
node = new DiscoNode();
|
6
|
+
iq = {to: 'n@d/r2', from: 'n@d/r1', type: 'get', id: 'abc'};
|
7
|
+
});
|
8
|
+
|
9
|
+
it("#reply switches from and to, changes type to 'result'", function() {
|
10
|
+
var req = $iq(iq), res = reply(node,req);
|
11
|
+
expect(res.attr('to')).toEqual(iq.from);
|
12
|
+
expect(res.attr('id')).toEqual(iq.id);
|
13
|
+
expect(res.attr('type')).toEqual('result');
|
14
|
+
});
|
15
|
+
|
16
|
+
it("#reply includes first child only in response", function() {
|
17
|
+
var req = $iq(iq).c('query', { xmlns: Strophe.NS.DISCO_INFO });
|
18
|
+
expect(reply(node,req).find('query').attr('xmlns')).toEqual(Strophe.NS.DISCO_INFO);
|
19
|
+
expect(reply(node,req.c('another')).find('another').length).toEqual(0);
|
20
|
+
});
|
21
|
+
|
22
|
+
it("#reply calls addContent(req,res) which can add elements", function() {
|
23
|
+
var req = $iq(iq).c('query', { xmlns: Strophe.NS.DISCO_INFO });
|
24
|
+
node.addContent = jasmine.createSpy('addContent').andCallFake(function(req,res) {
|
25
|
+
res.c('another');
|
26
|
+
});
|
27
|
+
expect(reply(node,req).find('another').length).toEqual(1);
|
28
|
+
expect(node.addContent).toHaveBeenCalled();
|
29
|
+
});
|
30
|
+
|
31
|
+
it("#info: this is how checking for response should look like", function() {
|
32
|
+
// c.disco.add(Strophe.NS.DISCO_INFO);
|
33
|
+
var req = $iq(iq).c('query', { xmlns: Strophe.NS.DISCO_INFO});
|
34
|
+
spyon(c,'send',function(res) {
|
35
|
+
expect(res.find('identity').attr('name')).toEqual('strophe');
|
36
|
+
expect(res.find('feature:eq(0)').attr('var')).toEqual(Strophe.NS.DISCO_INFO);
|
37
|
+
expect(res.find('feature:eq(1)').attr('var')).toEqual(Strophe.NS.DISCO_ITEMS);
|
38
|
+
});
|
39
|
+
receive(c,req);
|
40
|
+
});
|
41
|
+
|
42
|
+
xit("#lala - should fail", function() {
|
43
|
+
var req = $msg();
|
44
|
+
spyon(c,'send',function(res) {
|
45
|
+
expect(res.find('feature:eq(1)').attr('var')).toEqual(Strophe.NS.DISCO_ITEMS);
|
46
|
+
});
|
47
|
+
receive(c,req);
|
48
|
+
});
|
49
|
+
});
|
50
|
+
|
@@ -0,0 +1,51 @@
|
|
1
|
+
$.s = function(builder) {
|
2
|
+
return $(Strophe.serialize(builder.tree()));
|
3
|
+
};
|
4
|
+
|
5
|
+
logStanza = function(s) {
|
6
|
+
if (s.length && s.length === 1) { s = s[0]; }
|
7
|
+
if (s.tree) { s = s.tree(); }
|
8
|
+
console.log(Strophe.serialize(s));
|
9
|
+
};
|
10
|
+
reply = function(node,req) {
|
11
|
+
return str(node.reply(req));
|
12
|
+
};
|
13
|
+
str = function(builder) {
|
14
|
+
if (builder.tree) {
|
15
|
+
return $(Strophe.serialize(builder.tree()));
|
16
|
+
}
|
17
|
+
return $(Strophe.serialize(builder));
|
18
|
+
};
|
19
|
+
|
20
|
+
var mockConnection = function() {
|
21
|
+
var c = new Strophe.Connection();
|
22
|
+
c.authenticated = true;
|
23
|
+
c.jid = 'n@d/r2';
|
24
|
+
c._processRequest = function() {};
|
25
|
+
c._changeConnectStatus(Strophe.Status.CONNECTED);
|
26
|
+
return c;
|
27
|
+
};
|
28
|
+
|
29
|
+
var spyon = function(obj,method, cb) {
|
30
|
+
spyOn(obj,method).andCallFake(function(res) {
|
31
|
+
res = str(res);
|
32
|
+
cb.call(this,res);
|
33
|
+
});
|
34
|
+
};
|
35
|
+
var receive = function(c,req) {
|
36
|
+
c._dataRecv(createRequest(req));
|
37
|
+
expect(c.send).toHaveBeenCalled();
|
38
|
+
};
|
39
|
+
|
40
|
+
|
41
|
+
var createRequest = function(iq) {
|
42
|
+
iq = typeof iq.tree == "function" ? iq.tree() : iq;
|
43
|
+
var req = new Strophe.Request(iq, function() {});
|
44
|
+
req.getResponse = function() {
|
45
|
+
var env = new Strophe.Builder('env', {type: 'mock'}).tree();
|
46
|
+
env.appendChild(iq);
|
47
|
+
return env;
|
48
|
+
};
|
49
|
+
return req;
|
50
|
+
};
|
51
|
+
|
File without changes
|
@@ -0,0 +1,54 @@
|
|
1
|
+
var helper = (function() {
|
2
|
+
function logStanza(s) {
|
3
|
+
if (s.length && s.length === 1) { s = s[0]; }
|
4
|
+
if (s.tree) { s = s.tree(); }
|
5
|
+
console.log(Strophe.serialize(s));
|
6
|
+
}
|
7
|
+
|
8
|
+
function str(builder) {
|
9
|
+
if (builder.tree) {
|
10
|
+
return $(Strophe.serialize(builder.tree()));
|
11
|
+
}
|
12
|
+
return $(Strophe.serialize(builder));
|
13
|
+
}
|
14
|
+
function receive(c,req) {
|
15
|
+
c._dataRecv(createRequest(req));
|
16
|
+
expect(c.send).toHaveBeenCalled();
|
17
|
+
}
|
18
|
+
|
19
|
+
function spyon (obj,method, cb) {
|
20
|
+
spyOn(obj,method).andCallFake(function(res) {
|
21
|
+
res = str(res);
|
22
|
+
cb.call(this,res);
|
23
|
+
});
|
24
|
+
}
|
25
|
+
|
26
|
+
function mockConnection() {
|
27
|
+
var c = new Strophe.Connection();
|
28
|
+
c.authenticated = true;
|
29
|
+
c.jid = 'n@d/r2';
|
30
|
+
c._processRequest = function() {};
|
31
|
+
c._changeConnectStatus(Strophe.Status.CONNECTED);
|
32
|
+
return c;
|
33
|
+
}
|
34
|
+
|
35
|
+
function createRequest(iq) {
|
36
|
+
iq = typeof iq.tree == "function" ? iq.tree() : iq;
|
37
|
+
var req = new Strophe.Request(iq, function() {});
|
38
|
+
req.getResponse = function() {
|
39
|
+
var env = new Strophe.Builder('env', {type: 'mock'}).tree();
|
40
|
+
env.appendChild(iq);
|
41
|
+
return env;
|
42
|
+
};
|
43
|
+
return req;
|
44
|
+
}
|
45
|
+
|
46
|
+
return {
|
47
|
+
createRequest: createRequest,
|
48
|
+
mockConnection: mockConnection,
|
49
|
+
receive: receive,
|
50
|
+
spyon: spyon,
|
51
|
+
str: str
|
52
|
+
};
|
53
|
+
})();
|
54
|
+
|
File without changes
|