【问题标题】:Invitation Listener not working smack 4.2邀请侦听器无法正常工作 4.2
【发布时间】:2017-06-08 02:58:21
【问题描述】:

我可以成功创建群聊室 XMPP(smack)。我已经添加了 邀请听众,但从未打电话。有人知道怎么做吗?

使用:

  1. XMPP
  2. Smack 4.2
  3. Openfire 服务器

发送邀请码:

 muc.invite(userId +"@" +XMPP.getInstance().HOST + "/Smack", "Meet me in this excellent room");

邀请监听代码:

         MultiUserChatManager manager = MultiUserChatManager.getInstanceFor(connection);
            manager.addInvitationListener(new InvitationListener() {
                @Override
                public void invitationReceived(XMPPConnection xmppConnection, MultiUserChat muc, String inviter, String reason, String password, Message message) {
                    try {
                        muc.join(nickname);
                    } catch (SmackException.NoResponseException e) {
                        e.printStackTrace();
                    } catch (XMPPException.XMPPErrorException e) {
                        e.printStackTrace();
                    } catch (SmackException.NotConnectedException e) {
                        e.printStackTrace();
                    }
                }
            });

【问题讨论】:

    标签: android openfire smack multiuserchat


    【解决方案1】:

    您可能对RESOURCE 有疑问。

    当您向某个JID 发送邀请时,您可以省略resource 部分,否则消息将仅发送到指定的resource

    JID 由以下方式组成:

    user@serverdomain/resource
    

    通过此邀请,您仅邀请使用“Smack”作为资源的用户。 资源AbstractXMPPConnection对象或登录阶段配置

    XMPPTCPConnectionConfiguration.builder()
                    .setServiceName(serverName)
                    .setHost(server)
                    .setPort(port)
                    .setResource( RESOURCE_IDENTIFIER)
                    .build();
    connection = new XMPPTCPConnection(config);
    
    connection.login(username, password, RESOURCE_IDENTIFIER);
    

    所以,很可能,您声明为您的资源标识符(只是一个任意字符串)不是“Smack”而是“Spark”或其他东西或保留默认值。

    只需省略资源部分(或用正确的部分修复,但我建议省略)

     muc.invite(userId +"@" +XMPP.getInstance().HOST, "Meet me in this excellent room");
    

    当然,userId 必须存在并且 HOST 是有效的

    【讨论】:

    • 非常感谢亲爱的 MrPk 。现在代码正在运行。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-03-14
    • 2021-01-31
    • 1970-01-01
    • 2023-03-18
    • 1970-01-01
    相关资源
    最近更新 更多