diff --git a/pep/strophe.pep.coffee b/pep/strophe.pep.coffee index 26848d9..44ca4e6 100644 --- a/pep/strophe.pep.coffee +++ b/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 diff --git a/pep/strophe.pep.js b/pep/strophe.pep.js index 6fd0edd..cf5a59d 100644 --- a/pep/strophe.pep.js +++ b/pep/strophe.pep.js @@ -1,3 +1,4 @@ +// Generated by CoffeeScript 1.3.3 (function() { Strophe.addConnectionPlugin('pep', (function() { @@ -5,8 +6,12 @@ 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,