Openfire Android PubSub订阅请求批准

时间:2017-05-29 06:26:47

标签: android xmpp publish-subscribe openfire smack

我是Openfire的新手,因此我对pubsub功能有疑问。实际上,我已经使用 setAccessModel 创建了一个节点作为 authorize ,如下所示。

PubSubManager mgr = new PubSubManager(xmpp.getConnection());
try {
    LeafNode leaf = mgr.createNode("testNode");
    ConfigureForm form = new ConfigureForm(DataForm.Type.submit);
    form.setAccessModel(AccessModel.authorize);
    form.setDeliverPayloads(true);
    form.setNotifyRetract(true);
    form.setPersistentItems(true);
    form.setPublishModel(PublishModel.open);
    leaf.sendConfigurationForm(form);
} catch (SmackException.NoResponseException e) {
        e.printStackTrace();
} catch (XMPPException.XMPPErrorException e) {
        e.printStackTrace();
} catch (SmackException.NotConnectedException e) {
        e.printStackTrace();
}

我的问题是,当有人想订阅上述节点时,该节点的所有者如何处理订阅请求?订阅部分如下:

PubSubManager mgr = new PubSubManager(xmpp.getConnection());

// Get the node
LeafNode node = null;
try {
     node = mgr.getNode("testNode");
     node.addItemEventListener(new ItemEventCoordinator());
     node.subscribe(senderUser+"@desi.loc");
    } catch (SmackException.NoResponseException e) {
        e.printStackTrace();
    } catch (XMPPException.XMPPErrorException e) {
        e.printStackTrace();
    } catch (SmackException.NotConnectedException e) {
        e.printStackTrace();
    }

class ItemEventCoordinator  implements ItemEventListener {
    @Override
    public void handlePublishedItems(ItemPublishEvent items) {
        final ItemPublishEvent itemstemp=items;
        runOnUiThread(new Runnable() {
            @Override
            public void run() {
                //stuff that updates ui
                    dspySub.setText("Item: " + itemstemp.getItems());
            }
        });
    }
}

当我设置form.setAccessModel(AccessModel。打开)时,每件事情都可以。用户可以轻松发布和订阅,但是当其AccessModel被授权时,所有者不会听,或者可能是我不知道如何使用上面的代码处理所有者方的订阅请求。请指导我。

1 个答案:

答案 0 :(得分:0)

Jawad,我刚回答了另一个关于收听订阅请求的问题。请看一下:

How can i listen incoming subscription request in smack openfire android

我真的希望它可以帮助你。

祝你好运!

PS:对不起,但我没有足够的声誉做评论:(