xmppify 0.0.12

Sign up to get free protection for your applications and to get access to all the features.
Files changed (120) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +17 -0
  3. data/Gemfile +4 -0
  4. data/LICENSE.txt +22 -0
  5. data/README.md +29 -0
  6. data/Rakefile +1 -0
  7. data/app/assets/javascripts/xmpp/index.js +0 -0
  8. data/app/assets/javascripts/xmpp/scripts/checkplayer.js +12 -0
  9. data/app/assets/javascripts/xmpp/scripts/crossdomain.xml +7 -0
  10. data/app/assets/javascripts/xmpp/scripts/flXHR.js +2 -0
  11. data/app/assets/javascripts/xmpp/scripts/flXHR.swf +0 -0
  12. data/app/assets/javascripts/xmpp/scripts/flXHR.vbs +44 -0
  13. data/app/assets/javascripts/xmpp/scripts/flensed.js +12 -0
  14. data/app/assets/javascripts/xmpp/scripts/strophe.flxhr.js +31 -0
  15. data/app/assets/javascripts/xmpp/scripts/strophe.js +3538 -0
  16. data/app/assets/javascripts/xmpp/scripts/swfobject.js +5 -0
  17. data/app/assets/javascripts/xmpp/scripts/updateplayer.swf +0 -0
  18. data/app/assets/javascripts/xmpp/scripts/xmpp.js.coffee +386 -0
  19. data/app/assets/javascripts/xmpp/strophejs-plugins/LICENSE.txt +19 -0
  20. data/app/assets/javascripts/xmpp/strophejs-plugins/README.markdown +95 -0
  21. data/app/assets/javascripts/xmpp/strophejs-plugins/archive/README.markdown +14 -0
  22. data/app/assets/javascripts/xmpp/strophejs-plugins/archive/iso8601_support.js +32 -0
  23. data/app/assets/javascripts/xmpp/strophejs-plugins/archive/strophe.archive.js +88 -0
  24. data/app/assets/javascripts/xmpp/strophejs-plugins/caps/README.markdown +53 -0
  25. data/app/assets/javascripts/xmpp/strophejs-plugins/caps/sha1.js +202 -0
  26. data/app/assets/javascripts/xmpp/strophejs-plugins/caps/strophe.CAPS.coffee +153 -0
  27. data/app/assets/javascripts/xmpp/strophejs-plugins/caps/strophe.CAPS.js +88 -0
  28. data/app/assets/javascripts/xmpp/strophejs-plugins/caps/strophe.caps.jsonly.js +240 -0
  29. data/app/assets/javascripts/xmpp/strophejs-plugins/chatstates/strophe.chatstates.js +80 -0
  30. data/app/assets/javascripts/xmpp/strophejs-plugins/cmds/README.markdown +47 -0
  31. data/app/assets/javascripts/xmpp/strophejs-plugins/cmds/spec/GetUrlComamndSpec.js +66 -0
  32. data/app/assets/javascripts/xmpp/strophejs-plugins/cmds/spec/strophe.cmds.spec.coffee +145 -0
  33. data/app/assets/javascripts/xmpp/strophejs-plugins/cmds/spec/support/jasmine.json +16 -0
  34. data/app/assets/javascripts/xmpp/strophejs-plugins/cmds/src/strophe.cmds.coffee +265 -0
  35. data/app/assets/javascripts/xmpp/strophejs-plugins/cmds/src/strophe.cmds.js +403 -0
  36. data/app/assets/javascripts/xmpp/strophejs-plugins/dataforms/README.markdown +82 -0
  37. data/app/assets/javascripts/xmpp/strophejs-plugins/dataforms/spec/strophe.x.coffee +715 -0
  38. data/app/assets/javascripts/xmpp/strophejs-plugins/dataforms/src/strophe.x.coffee +443 -0
  39. data/app/assets/javascripts/xmpp/strophejs-plugins/dataforms/src/strophe.x.js +854 -0
  40. data/app/assets/javascripts/xmpp/strophejs-plugins/disco/.gitignore +1 -0
  41. data/app/assets/javascripts/xmpp/strophejs-plugins/disco/README.markdown +0 -0
  42. data/app/assets/javascripts/xmpp/strophejs-plugins/disco/convert.js +13 -0
  43. data/app/assets/javascripts/xmpp/strophejs-plugins/disco/jasmine.json +11 -0
  44. data/app/assets/javascripts/xmpp/strophejs-plugins/disco/lib/strophe.disco.js +137 -0
  45. data/app/assets/javascripts/xmpp/strophejs-plugins/disco/public/javascript/strophe.disco.js +137 -0
  46. data/app/assets/javascripts/xmpp/strophejs-plugins/disco/spec/01_querying_information.xml +6 -0
  47. data/app/assets/javascripts/xmpp/strophejs-plugins/disco/spec/02_result_set_for_information_request.xml +22 -0
  48. data/app/assets/javascripts/xmpp/strophejs-plugins/disco/spec/03_target_entity_does_not_exist.xml +10 -0
  49. data/app/assets/javascripts/xmpp/strophejs-plugins/disco/spec/04_service_unavailable.xml +11 -0
  50. data/app/assets/javascripts/xmpp/strophejs-plugins/disco/spec/09_querying_specific_jid_and_node_combination.xml +7 -0
  51. data/app/assets/javascripts/xmpp/strophejs-plugins/disco/spec/10_jid_and_node_result.xml +12 -0
  52. data/app/assets/javascripts/xmpp/strophejs-plugins/disco/spec/11_requesting_all_items.xml +6 -0
  53. data/app/assets/javascripts/xmpp/strophejs-plugins/disco/spec/12_result_set_for_all_items.xml +23 -0
  54. data/app/assets/javascripts/xmpp/strophejs-plugins/disco/spec/13_empty_result_set.xml +7 -0
  55. data/app/assets/javascripts/xmpp/strophejs-plugins/disco/spec/17_service_returns_nodes.xml +16 -0
  56. data/app/assets/javascripts/xmpp/strophejs-plugins/disco/spec/18_requesting_further_nodes.xml +7 -0
  57. data/app/assets/javascripts/xmpp/strophejs-plugins/disco/spec/24_jid_and_node_error.xml +11 -0
  58. data/app/assets/javascripts/xmpp/strophejs-plugins/disco/spec/DiscoNodeSpec.js +50 -0
  59. data/app/assets/javascripts/xmpp/strophejs-plugins/disco/spec/SpecHelper.js +51 -0
  60. data/app/assets/javascripts/xmpp/strophejs-plugins/disco/spec/Stanzas.js +0 -0
  61. data/app/assets/javascripts/xmpp/strophejs-plugins/disco/spec/strophe.disco.spec.helper.js +54 -0
  62. data/app/assets/javascripts/xmpp/strophejs-plugins/disco/spec/strophe.disco.spec.js +0 -0
  63. data/app/assets/javascripts/xmpp/strophejs-plugins/disco/spec/support/jasmine.json +13 -0
  64. data/app/assets/javascripts/xmpp/strophejs-plugins/disco/strophe.disco.js +232 -0
  65. data/app/assets/javascripts/xmpp/strophejs-plugins/epic/public/javascript/jquery.epic.js +61 -0
  66. data/app/assets/javascripts/xmpp/strophejs-plugins/epic/spec/SpecHelper.js +9 -0
  67. data/app/assets/javascripts/xmpp/strophejs-plugins/epic/spec/jquery.epic.js +39 -0
  68. data/app/assets/javascripts/xmpp/strophejs-plugins/epic/spec/support/jasmine.json +22 -0
  69. data/app/assets/javascripts/xmpp/strophejs-plugins/iexdomain/iexdomain.js +36 -0
  70. data/app/assets/javascripts/xmpp/strophejs-plugins/joap/README.markdown +117 -0
  71. data/app/assets/javascripts/xmpp/strophejs-plugins/joap/buster.js +23 -0
  72. data/app/assets/javascripts/xmpp/strophejs-plugins/joap/jid.coffee +64 -0
  73. data/app/assets/javascripts/xmpp/strophejs-plugins/joap/jid.js +92 -0
  74. data/app/assets/javascripts/xmpp/strophejs-plugins/joap/spec/browserSetup.coffee +1 -0
  75. data/app/assets/javascripts/xmpp/strophejs-plugins/joap/spec/jid.spec.coffee +96 -0
  76. data/app/assets/javascripts/xmpp/strophejs-plugins/joap/spec/strophe.joap.spec.coffee +461 -0
  77. data/app/assets/javascripts/xmpp/strophejs-plugins/joap/strophe.joap.coffee +304 -0
  78. data/app/assets/javascripts/xmpp/strophejs-plugins/joap/strophe.joap.js +522 -0
  79. data/app/assets/javascripts/xmpp/strophejs-plugins/mam/LICENSE.txt +19 -0
  80. data/app/assets/javascripts/xmpp/strophejs-plugins/mam/README.markdown +52 -0
  81. data/app/assets/javascripts/xmpp/strophejs-plugins/mam/strophe.mam.js +62 -0
  82. data/app/assets/javascripts/xmpp/strophejs-plugins/muc/LICENSE.txt +20 -0
  83. data/app/assets/javascripts/xmpp/strophejs-plugins/muc/strophe.muc.js +1003 -0
  84. data/app/assets/javascripts/xmpp/strophejs-plugins/ping/README.markdown +28 -0
  85. data/app/assets/javascripts/xmpp/strophejs-plugins/ping/strophe.ping.js +68 -0
  86. data/app/assets/javascripts/xmpp/strophejs-plugins/private/README.markdown +16 -0
  87. data/app/assets/javascripts/xmpp/strophejs-plugins/private/strophe.private.js +192 -0
  88. data/app/assets/javascripts/xmpp/strophejs-plugins/pubsub/strophe.pubsub.js +555 -0
  89. data/app/assets/javascripts/xmpp/strophejs-plugins/receipts/strophe.receipts.js +155 -0
  90. data/app/assets/javascripts/xmpp/strophejs-plugins/register/README.markdown +44 -0
  91. data/app/assets/javascripts/xmpp/strophejs-plugins/register/strophe.register.js +431 -0
  92. data/app/assets/javascripts/xmpp/strophejs-plugins/roster/public/javascript/strophe.roster.js +40 -0
  93. data/app/assets/javascripts/xmpp/strophejs-plugins/roster/spec/strophe.roster.spec.js +65 -0
  94. data/app/assets/javascripts/xmpp/strophejs-plugins/roster/spec/support/jasmine.json +15 -0
  95. data/app/assets/javascripts/xmpp/strophejs-plugins/roster/strophe.roster.js +438 -0
  96. data/app/assets/javascripts/xmpp/strophejs-plugins/rpc/.gitignore +6 -0
  97. data/app/assets/javascripts/xmpp/strophejs-plugins/rpc/README.md +113 -0
  98. data/app/assets/javascripts/xmpp/strophejs-plugins/rpc/buster.js +11 -0
  99. data/app/assets/javascripts/xmpp/strophejs-plugins/rpc/lib/strophe.js +4198 -0
  100. data/app/assets/javascripts/xmpp/strophejs-plugins/rpc/spec/strophe.rpc.spec.helper.js +38 -0
  101. data/app/assets/javascripts/xmpp/strophejs-plugins/rpc/spec/strophe.rpc.spec.js +262 -0
  102. data/app/assets/javascripts/xmpp/strophejs-plugins/rpc/strophe.rpc.js +464 -0
  103. data/app/assets/javascripts/xmpp/strophejs-plugins/rsm/strophe.rsm.js +52 -0
  104. data/app/assets/javascripts/xmpp/strophejs-plugins/serverdate/strophe.serverdate.js +58 -0
  105. data/app/assets/javascripts/xmpp/strophejs-plugins/vcard/examples/index.html +17 -0
  106. data/app/assets/javascripts/xmpp/strophejs-plugins/vcard/examples/strophevcard.js +0 -0
  107. data/app/assets/javascripts/xmpp/strophejs-plugins/vcard/strophe.vcard.coffee +44 -0
  108. data/app/assets/javascripts/xmpp/strophejs-plugins/vcard/strophe.vcard.js +66 -0
  109. data/app/assets/stylesheets/xmpp/index.css +0 -0
  110. data/app/controllers/omniauth_callbacks_controller.rb +15 -0
  111. data/app/controllers/ruby_bosh.rb +221 -0
  112. data/app/models/identity.rb +3 -0
  113. data/app/models/user.rb +40 -0
  114. data/bin/rails +8 -0
  115. data/db/migrate/20140329065635_create_users.rb +10 -0
  116. data/db/migrate/20140329070238_create_identities.rb +11 -0
  117. data/lib/xmppify/version.rb +3 -0
  118. data/lib/xmppify.rb +6 -0
  119. data/xmppify.gemspec +23 -0
  120. metadata +197 -0
@@ -0,0 +1,265 @@
1
+ CMD = "http://jabber.org/protocol/commands"
2
+
3
+ create = (node, callback=Strophe.Disco.noop) ->
4
+ switch node
5
+ when "getUrls" then new CommandNode item: "url", node: "getUrls", name: "Retrieve Urls", callback: callback
6
+ when "setUrls" then new CommandNode item: "url", node: "setUrls", name: "Sets Urls", callback: callback
7
+ else throw "Strophe.Commands has no implementation for: #{node}"
8
+
9
+ createExecIQ = (opt) ->
10
+
11
+ iq = $iq { to: opt.jid, type: "set" }
12
+
13
+ cfg =
14
+ xmlns: CMD,
15
+ node: opt.node,
16
+
17
+ cfg.action = opt.action or "execute"
18
+ cfg.sessionid = opt.sid if opt.sid
19
+
20
+ iq.c "command", cfg
21
+
22
+ if $.isArray opt.data
23
+ iq.c(opt.item[0].item).t(item).up() for i,item of opt.data
24
+
25
+ else if opt.form
26
+ iq.cnode opt.form.toXML()
27
+ iq
28
+
29
+ # we have to overrite reply, because we pass in the callback fn form
30
+ # node requests handler, we can only send a response
31
+ # once our cmd callback has returned
32
+ Strophe.Disco.DiscoNode::reply = (iq, fn) ->
33
+ req = @parseRequest(iq)
34
+ res = @fromTo(req)
35
+ @fn = fn
36
+ @addFirstChild req, res
37
+ @addContent req, res
38
+ res
39
+
40
+ class RemoteCommand
41
+
42
+ constructor: (@conn, @jid, @node) ->
43
+ @executeAction = "execute"
44
+ @actions = []
45
+ @sessionid = null
46
+ @data = null
47
+ @form = null
48
+ @resonseForm = null
49
+ @status = null
50
+ @error = null
51
+
52
+ _parseResult: (res) ->
53
+ cmd = ($ res).find "command"
54
+ @sessionid = cmd.attr "sessionid"
55
+ @status = cmd.attr "status"
56
+ @_parseActions cmd
57
+ @_parseResultForm cmd
58
+ @_parseError res
59
+
60
+ _parseActions: (cmd) ->
61
+ actions = cmd.find "actions"
62
+ if actions.length > 0
63
+ @executeAction = actions.attr "execute"
64
+ @actions = (a.nodeName for a in actions.children())
65
+
66
+ _parseResultForm:(cmd) ->
67
+ x = cmd.find "x"
68
+ if x.length > 0
69
+ @form = Strophe.x.Form.fromXML x
70
+ else
71
+ @form = null
72
+
73
+ _parseError: (res) ->
74
+ res = $ res
75
+ err = res.find "error"
76
+ if err.length > 0
77
+ @error =
78
+ code: err.attr "code"
79
+ type: err.attr "type"
80
+ conditions: ( e.nodeName for e in err.children())
81
+ else
82
+ @error = null
83
+
84
+ _parseSubmitFormFromHTML: (html) ->
85
+ form = Strophe.x.Form.fromHTML html
86
+ form.type = "submit"
87
+ for f in form.fields
88
+ f.options = []
89
+ f.required = false
90
+ form
91
+
92
+ _createFn: (action, div, opt) ->
93
+
94
+ close = -> div.dialog "close"
95
+ switch action.toLowerCase()
96
+
97
+ when "next" then =>
98
+ close()
99
+ opt.responseForm = @_parseSubmitFormFromHTML div
100
+ @next opt
101
+
102
+ when "prev" then =>
103
+ close()
104
+ @prev opt
105
+
106
+ when "complete" then =>
107
+ close()
108
+ opt.responseForm = @_parseSubmitFormFromHTML div
109
+ @complete opt
110
+
111
+ when "cancel" then =>
112
+ close()
113
+ @cancel opt
114
+
115
+ else =>
116
+
117
+ openDialog: (opt) =>
118
+
119
+ throw new Error "jQuery dialog is not available" unless $.fn.dialog
120
+
121
+ if @form
122
+ actions = {}
123
+ div = $ @form.toHTML()
124
+ actions[a] = @_createFn a, div, opt for a in @actions
125
+
126
+ div.find("h1").remove()
127
+ div.dialog
128
+ autoOpen: true
129
+ modal: true
130
+ title: @form.title
131
+ buttons: actions
132
+
133
+ onSuccess: (res, cmd) ->
134
+
135
+ onError: (res, cmd) ->
136
+ if console and cmd.error
137
+ console.error """could not exectute command.
138
+ Error:
139
+ Type: #{ cmd.error.type },
140
+ Code: #{ cmd.error.code },"
141
+ Conditions: #{ cmd.error.conditions.join ',' }"""
142
+
143
+ _exec: (opt) ->
144
+ if opt.gui is true
145
+ opt.success = (res, cmd) ->
146
+ cmd.openDialog opt
147
+
148
+ @conn.cmds.execute @jid, @node,
149
+ success: (res) =>
150
+ @_parseResult res
151
+ if opt.success
152
+ opt.success res, @
153
+ else
154
+ @onSuccess res, @
155
+ error: (res) =>
156
+ @_parseResult res
157
+ if opt.error
158
+ opt.error res, @
159
+ else
160
+ @onError res, @
161
+ sid: @sessionid
162
+ action: @executeAction
163
+ form: @responseForm
164
+
165
+ execute: (opt) -> @_exec opt
166
+
167
+ next: (opt) ->
168
+ @responseForm = opt.responseForm if opt.responseForm
169
+ @executeAction = "next"
170
+ @_exec opt
171
+
172
+ prev: (opt)->
173
+ @executeAction = "prev"
174
+ @_exec opt
175
+
176
+ complete: (opt) ->
177
+ @responseForm = opt.responseForm if opt.responseForm
178
+ @executeAction = "complete"
179
+ @_exec opt
180
+
181
+ cancel: (opt)->
182
+ @executeAction = "cancel"
183
+ @_exec opt
184
+
185
+ isValidAction: (action) -> (action in @actions)
186
+
187
+ toIQ: -> createExecIQ { @jid, @node, @action, @sessionid, @data }
188
+
189
+ class CommandNode extends Strophe.Disco.DiscoNode
190
+
191
+ constructor: (cfg) -> @[k] = v for k,v of cfg
192
+
193
+ send: -> $iq {}
194
+
195
+ callback: (onSucces, onError) -> @onSuccess {}
196
+
197
+ addContent: (req, res) ->
198
+ @req = req
199
+ @res = res
200
+ @callback.call @, @onSuccess.bind(@), @onError.bind(@)
201
+
202
+ onError: ->
203
+ res.attrs status: "error"
204
+ @fn.call @, res
205
+
206
+ onSuccess: (obj) ->
207
+ res = @res
208
+ item = @item
209
+ res.attrs status: "completed"
210
+ res.c(item).t(entry).up() for i, entry of obj if $.isArray(obj)
211
+ @fn.call @, res
212
+
213
+ Strophe.Commands =
214
+ CommandNode: CommandNode
215
+ RemoteCommand: RemoteCommand
216
+ create: create
217
+
218
+ Strophe.addConnectionPlugin "cmds", do ->
219
+
220
+ conn = cmds = null
221
+
222
+ init = (c) ->
223
+ conn = c
224
+ Strophe.addNamespace "COMMANDS", CMD
225
+ cmds = conn.disco.features[CMD] = { items: [] }
226
+
227
+ add = (item) ->
228
+ throw "command needs a node" unless item.node
229
+ item.jid = conn.jid unless item.jid
230
+ cmds.items.push new CommandNode item
231
+
232
+ reply = (iq) ->
233
+ node = ($ "command", iq).attr("node")
234
+ n = $.grep(cmds.items, (n) -> n.node is node)
235
+ if n.length is 0
236
+ nodeImpl = new DiscoNodeNotFound
237
+ conn.send nodeImpl.reply iq
238
+ else
239
+ nodeImpl = n[0]
240
+ nodeImpl.reply(iq, (res) => conn.send res)
241
+ true
242
+
243
+ statusChanged = (status, condition) ->
244
+ conn.addHandler reply.bind(@), CMD, "iq", "set" if status is Strophe.Status.CONNECTED
245
+
246
+ execute = (jid, node, opt={}) ->
247
+
248
+ iq = createExecIQ
249
+ jid: jid
250
+ node: node
251
+ action: opt.action
252
+ sid: opt.sid
253
+ data: opt.data
254
+ form: opt.form
255
+ item: $.grep(cmds.items, (n) -> n.node is node)
256
+
257
+ noop = Strophe.Disco.noop
258
+ conn.sendIQ iq, opt.success or noop, opt.error or noop
259
+
260
+ # public API
261
+ init: init
262
+ statusChanged: statusChanged
263
+ add: add
264
+ execute:execute
265
+ exec:execute
@@ -0,0 +1,403 @@
1
+ (function() {
2
+ var CMD, CommandNode, RemoteCommand, create, createExecIQ;
3
+ var __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; }, __indexOf = Array.prototype.indexOf || function(item) {
4
+ for (var i = 0, l = this.length; i < l; i++) {
5
+ if (this[i] === item) return i;
6
+ }
7
+ return -1;
8
+ }, __hasProp = Object.prototype.hasOwnProperty, __extends = function(child, parent) {
9
+ for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; }
10
+ function ctor() { this.constructor = child; }
11
+ ctor.prototype = parent.prototype;
12
+ child.prototype = new ctor;
13
+ child.__super__ = parent.prototype;
14
+ return child;
15
+ };
16
+ CMD = "http://jabber.org/protocol/commands";
17
+ create = function(node, callback) {
18
+ if (callback == null) {
19
+ callback = Strophe.Disco.noop;
20
+ }
21
+ switch (node) {
22
+ case "getUrls":
23
+ return new CommandNode({
24
+ item: "url",
25
+ node: "getUrls",
26
+ name: "Retrieve Urls",
27
+ callback: callback
28
+ });
29
+ case "setUrls":
30
+ return new CommandNode({
31
+ item: "url",
32
+ node: "setUrls",
33
+ name: "Sets Urls",
34
+ callback: callback
35
+ });
36
+ default:
37
+ throw "Strophe.Commands has no implementation for: " + node;
38
+ }
39
+ };
40
+ createExecIQ = function(opt) {
41
+ var cfg, i, iq, item, _ref;
42
+ iq = $iq({
43
+ to: opt.jid,
44
+ type: "set"
45
+ });
46
+ cfg = {
47
+ xmlns: CMD,
48
+ node: opt.node
49
+ };
50
+ cfg.action = opt.action || "execute";
51
+ if (opt.sid) {
52
+ cfg.sessionid = opt.sid;
53
+ }
54
+ iq.c("command", cfg);
55
+ if ($.isArray(opt.data)) {
56
+ _ref = opt.data;
57
+ for (i in _ref) {
58
+ item = _ref[i];
59
+ iq.c(opt.item[0].item).t(item).up();
60
+ }
61
+ } else if (opt.form) {
62
+ iq.cnode(opt.form.toXML());
63
+ }
64
+ return iq;
65
+ };
66
+ Strophe.Disco.DiscoNode.prototype.reply = function(iq, fn) {
67
+ var req, res;
68
+ req = this.parseRequest(iq);
69
+ res = this.fromTo(req);
70
+ this.fn = fn;
71
+ this.addFirstChild(req, res);
72
+ this.addContent(req, res);
73
+ return res;
74
+ };
75
+ RemoteCommand = (function() {
76
+ function RemoteCommand(conn, jid, node) {
77
+ this.conn = conn;
78
+ this.jid = jid;
79
+ this.node = node;
80
+ this.openDialog = __bind(this.openDialog, this);
81
+ this.executeAction = "execute";
82
+ this.actions = [];
83
+ this.sessionid = null;
84
+ this.data = null;
85
+ this.form = null;
86
+ this.resonseForm = null;
87
+ this.status = null;
88
+ this.error = null;
89
+ }
90
+ RemoteCommand.prototype._parseResult = function(res) {
91
+ var cmd;
92
+ cmd = ($(res)).find("command");
93
+ this.sessionid = cmd.attr("sessionid");
94
+ this.status = cmd.attr("status");
95
+ this._parseActions(cmd);
96
+ this._parseResultForm(cmd);
97
+ return this._parseError(res);
98
+ };
99
+ RemoteCommand.prototype._parseActions = function(cmd) {
100
+ var a, actions;
101
+ actions = cmd.find("actions");
102
+ if (actions.length > 0) {
103
+ this.executeAction = actions.attr("execute");
104
+ return this.actions = (function() {
105
+ var _i, _len, _ref, _results;
106
+ _ref = actions.children();
107
+ _results = [];
108
+ for (_i = 0, _len = _ref.length; _i < _len; _i++) {
109
+ a = _ref[_i];
110
+ _results.push(a.nodeName);
111
+ }
112
+ return _results;
113
+ })();
114
+ }
115
+ };
116
+ RemoteCommand.prototype._parseResultForm = function(cmd) {
117
+ var x;
118
+ x = cmd.find("x");
119
+ if (x.length > 0) {
120
+ return this.form = Strophe.x.Form.fromXML(x);
121
+ } else {
122
+ return this.form = null;
123
+ }
124
+ };
125
+ RemoteCommand.prototype._parseError = function(res) {
126
+ var e, err;
127
+ res = $(res);
128
+ err = res.find("error");
129
+ if (err.length > 0) {
130
+ return this.error = {
131
+ code: err.attr("code"),
132
+ type: err.attr("type"),
133
+ conditions: (function() {
134
+ var _i, _len, _ref, _results;
135
+ _ref = err.children();
136
+ _results = [];
137
+ for (_i = 0, _len = _ref.length; _i < _len; _i++) {
138
+ e = _ref[_i];
139
+ _results.push(e.nodeName);
140
+ }
141
+ return _results;
142
+ })()
143
+ };
144
+ } else {
145
+ return this.error = null;
146
+ }
147
+ };
148
+ RemoteCommand.prototype._parseSubmitFormFromHTML = function(html) {
149
+ var f, form, _i, _len, _ref;
150
+ form = Strophe.x.Form.fromHTML(html);
151
+ form.type = "submit";
152
+ _ref = form.fields;
153
+ for (_i = 0, _len = _ref.length; _i < _len; _i++) {
154
+ f = _ref[_i];
155
+ f.options = [];
156
+ f.required = false;
157
+ }
158
+ return form;
159
+ };
160
+ RemoteCommand.prototype._createFn = function(action, div, opt) {
161
+ var close;
162
+ close = function() {
163
+ return div.dialog("close");
164
+ };
165
+ switch (action.toLowerCase()) {
166
+ case "next":
167
+ return __bind(function() {
168
+ close();
169
+ opt.responseForm = this._parseSubmitFormFromHTML(div);
170
+ return this.next(opt);
171
+ }, this);
172
+ case "prev":
173
+ return __bind(function() {
174
+ close();
175
+ return this.prev(opt);
176
+ }, this);
177
+ case "complete":
178
+ return __bind(function() {
179
+ close();
180
+ opt.responseForm = this._parseSubmitFormFromHTML(div);
181
+ return this.complete(opt);
182
+ }, this);
183
+ case "cancel":
184
+ return __bind(function() {
185
+ close();
186
+ return this.cancel(opt);
187
+ }, this);
188
+ default:
189
+ return __bind(function() {}, this);
190
+ }
191
+ };
192
+ RemoteCommand.prototype.openDialog = function(opt) {
193
+ var a, actions, div, _i, _len, _ref;
194
+ if (!$.fn.dialog) {
195
+ throw new Error("jQuery dialog is not available");
196
+ }
197
+ if (this.form) {
198
+ actions = {};
199
+ div = $(this.form.toHTML());
200
+ _ref = this.actions;
201
+ for (_i = 0, _len = _ref.length; _i < _len; _i++) {
202
+ a = _ref[_i];
203
+ actions[a] = this._createFn(a, div, opt);
204
+ }
205
+ div.find("h1").remove();
206
+ return div.dialog({
207
+ autoOpen: true,
208
+ modal: true,
209
+ title: this.form.title,
210
+ buttons: actions
211
+ });
212
+ }
213
+ };
214
+ RemoteCommand.prototype.onSuccess = function(res, cmd) {};
215
+ RemoteCommand.prototype.onError = function(res, cmd) {
216
+ if (console && cmd.error) {
217
+ return console.error("could not exectute command.\nError:\n Type: " + cmd.error.type + ",\n Code: " + cmd.error.code + ",\"\n Conditions: " + (cmd.error.conditions.join(',')));
218
+ }
219
+ };
220
+ RemoteCommand.prototype._exec = function(opt) {
221
+ if (opt.gui === true) {
222
+ opt.success = function(res, cmd) {
223
+ return cmd.openDialog(opt);
224
+ };
225
+ }
226
+ return this.conn.cmds.execute(this.jid, this.node, {
227
+ success: __bind(function(res) {
228
+ this._parseResult(res);
229
+ if (opt.success) {
230
+ return opt.success(res, this);
231
+ } else {
232
+ return this.onSuccess(res, this);
233
+ }
234
+ }, this),
235
+ error: __bind(function(res) {
236
+ this._parseResult(res);
237
+ if (opt.error) {
238
+ return opt.error(res, this);
239
+ } else {
240
+ return this.onError(res, this);
241
+ }
242
+ }, this),
243
+ sid: this.sessionid,
244
+ action: this.executeAction,
245
+ form: this.responseForm
246
+ });
247
+ };
248
+ RemoteCommand.prototype.execute = function(opt) {
249
+ return this._exec(opt);
250
+ };
251
+ RemoteCommand.prototype.next = function(opt) {
252
+ if (opt.responseForm) {
253
+ this.responseForm = opt.responseForm;
254
+ }
255
+ this.executeAction = "next";
256
+ return this._exec(opt);
257
+ };
258
+ RemoteCommand.prototype.prev = function(opt) {
259
+ this.executeAction = "prev";
260
+ return this._exec(opt);
261
+ };
262
+ RemoteCommand.prototype.complete = function(opt) {
263
+ if (opt.responseForm) {
264
+ this.responseForm = opt.responseForm;
265
+ }
266
+ this.executeAction = "complete";
267
+ return this._exec(opt);
268
+ };
269
+ RemoteCommand.prototype.cancel = function(opt) {
270
+ this.executeAction = "cancel";
271
+ return this._exec(opt);
272
+ };
273
+ RemoteCommand.prototype.isValidAction = function(action) {
274
+ return __indexOf.call(this.actions, action) >= 0;
275
+ };
276
+ RemoteCommand.prototype.toIQ = function() {
277
+ return createExecIQ({
278
+ jid: this.jid,
279
+ node: this.node,
280
+ action: this.action,
281
+ sessionid: this.sessionid,
282
+ data: this.data
283
+ });
284
+ };
285
+ return RemoteCommand;
286
+ })();
287
+ CommandNode = (function() {
288
+ __extends(CommandNode, Strophe.Disco.DiscoNode);
289
+ function CommandNode(cfg) {
290
+ var k, v;
291
+ for (k in cfg) {
292
+ v = cfg[k];
293
+ this[k] = v;
294
+ }
295
+ }
296
+ CommandNode.prototype.send = function() {
297
+ return $iq({});
298
+ };
299
+ CommandNode.prototype.callback = function(onSucces, onError) {
300
+ return this.onSuccess({});
301
+ };
302
+ CommandNode.prototype.addContent = function(req, res) {
303
+ this.req = req;
304
+ this.res = res;
305
+ return this.callback.call(this, this.onSuccess.bind(this), this.onError.bind(this));
306
+ };
307
+ CommandNode.prototype.onError = function() {
308
+ res.attrs({
309
+ status: "error"
310
+ });
311
+ return this.fn.call(this, res);
312
+ };
313
+ CommandNode.prototype.onSuccess = function(obj) {
314
+ var entry, i, item, res;
315
+ res = this.res;
316
+ item = this.item;
317
+ res.attrs({
318
+ status: "completed"
319
+ });
320
+ if ($.isArray(obj)) {
321
+ for (i in obj) {
322
+ entry = obj[i];
323
+ res.c(item).t(entry).up();
324
+ }
325
+ }
326
+ return this.fn.call(this, res);
327
+ };
328
+ return CommandNode;
329
+ })();
330
+ Strophe.Commands = {
331
+ CommandNode: CommandNode,
332
+ RemoteCommand: RemoteCommand,
333
+ create: create
334
+ };
335
+ Strophe.addConnectionPlugin("cmds", (function() {
336
+ var add, cmds, conn, execute, init, reply, statusChanged;
337
+ conn = cmds = null;
338
+ init = function(c) {
339
+ conn = c;
340
+ Strophe.addNamespace("COMMANDS", CMD);
341
+ return cmds = conn.disco.features[CMD] = {
342
+ items: []
343
+ };
344
+ };
345
+ add = function(item) {
346
+ if (!item.node) {
347
+ throw "command needs a node";
348
+ }
349
+ if (!item.jid) {
350
+ item.jid = conn.jid;
351
+ }
352
+ return cmds.items.push(new CommandNode(item));
353
+ };
354
+ reply = function(iq) {
355
+ var n, node, nodeImpl;
356
+ node = ($("command", iq)).attr("node");
357
+ n = $.grep(cmds.items, function(n) {
358
+ return n.node === node;
359
+ });
360
+ if (n.length === 0) {
361
+ nodeImpl = new DiscoNodeNotFound;
362
+ conn.send(nodeImpl.reply(iq));
363
+ } else {
364
+ nodeImpl = n[0];
365
+ nodeImpl.reply(iq, __bind(function(res) {
366
+ return conn.send(res);
367
+ }, this));
368
+ }
369
+ return true;
370
+ };
371
+ statusChanged = function(status, condition) {
372
+ if (status === Strophe.Status.CONNECTED) {
373
+ return conn.addHandler(reply.bind(this), CMD, "iq", "set");
374
+ }
375
+ };
376
+ execute = function(jid, node, opt) {
377
+ var iq, noop;
378
+ if (opt == null) {
379
+ opt = {};
380
+ }
381
+ iq = createExecIQ({
382
+ jid: jid,
383
+ node: node,
384
+ action: opt.action,
385
+ sid: opt.sid,
386
+ data: opt.data,
387
+ form: opt.form,
388
+ item: $.grep(cmds.items, function(n) {
389
+ return n.node === node;
390
+ })
391
+ });
392
+ noop = Strophe.Disco.noop;
393
+ return conn.sendIQ(iq, opt.success || noop, opt.error || noop);
394
+ };
395
+ return {
396
+ init: init,
397
+ statusChanged: statusChanged,
398
+ add: add,
399
+ execute: execute,
400
+ exec: execute
401
+ };
402
+ })());
403
+ }).call(this);