Browse files

fix for #71 - not tested

  • Loading branch information...
1 parent c0671f7 commit 3c0bdf3de1f9b0468a86071568937d99084615f1 @flosse flosse committed Jun 9, 2012
Showing with 39 additions and 6 deletions.
  1. +18 −3 pep/strophe.pep.coffee
  2. +21 −3 pep/strophe.pep.js
View
21 pep/strophe.pep.coffee
@@ -1,7 +1,7 @@
# This plugin is distributed under the terms of the MIT licence.
# Please see the LICENCE file for details.
#
-# Copyright (c) Markus Kohlhase, 2011
+# Copyright (c) Markus Kohlhase, 2011 - 2012
# A Strophe plugin for ( http://xmpp.org/extensions/xep-0115.html )
@@ -36,8 +36,23 @@ Strophe.addConnectionPlugin 'pep', (->
conn.caps.removeFeature "#{node}+notify"
conn.caps.sendPres()
- publish = (node, items, callback ) ->
- conn.pubsub.publish node, items, callback
+ # Publish and item to the given pubsub node.
+ # Parameters:
+ # (String) node - The name of the pubsub node.
+ # (Array) items - The list of items to be published.
+ # (Function) callback - Used to determine if node creation was sucessful.
+ publish = (node, items, callback) ->
+
+ # there are some problems with the pubsub plugin (see #71),
+ # so just build the iq stanza manually
+ iqid = conn.getUniqueId "pubsubpublishnode"
+ conn.addHandler callback, null, 'iq', null, iqid, null
+ conn.send $iq({from:conn.jid,type:'set', id:iqid})
+ .c('pubsub', { xmlns:Strophe.NS.PUBSUB })
+ .c('publish', { node:node, jid:conn.jid })
+ .list('item', items)
+ .tree()
+ iqid
# Public API
init: init
View
24 pep/strophe.pep.js
@@ -1,12 +1,17 @@
+// Generated by CoffeeScript 1.3.3
(function() {
Strophe.addConnectionPlugin('pep', (function() {
var conn, init, publish, subscribe, unsubscribe;
conn = null;
init = function(c) {
conn = c;
- if (conn.caps === void 0) throw new Error("caps plugin required!");
- if (conn.pubsub === void 0) throw new Error("pubsub plugin required!");
+ if (conn.caps === void 0) {
+ throw new Error("caps plugin required!");
+ }
+ if (conn.pubsub === void 0) {
+ throw new Error("pubsub plugin required!");
+ }
};
subscribe = function(node, handler) {
conn.caps.addFeature(node);
@@ -20,7 +25,20 @@
return conn.caps.sendPres();
};
publish = function(node, items, callback) {
- return conn.pubsub.publish(node, items, callback);
+ var iqid;
+ iqid = conn.getUniqueId("pubsubpublishnode");
+ conn.addHandler(callback, null, 'iq', null, iqid, null);
+ conn.send($iq({
+ from: conn.jid,
+ type: 'set',
+ id: iqid
+ }).c('pubsub', {
+ xmlns: Strophe.NS.PUBSUB
+ }).c('publish', {
+ node: node,
+ jid: conn.jid
+ }).list('item', items).tree());
+ return iqid;
};
return {
init: init,

0 comments on commit 3c0bdf3

Please sign in to comment.