Smack 中的多用户聊天邀请

发布于 2024-12-20 03:51:25 字数 804 浏览 2 评论 0原文

我有以下代码来监听聊天室的邀请:

    Connection.DEBUG_ENABLED = true;
    XMPPConnection connection = new XMPPConnection("jabber.org");
    connection.connect();
    connection.login("username", "password");

    MultiUserChat.addInvitationListener(connection, new InvitationListener() {
        @Override
        public void invitationReceived(Connection arg0, String arg1,
                String arg2, String arg3, String arg4, Message arg5) {
            System.out.println("Invitation Received!");
        }
    });

    System.out.println("Connected, waiting for invitation");
    while(true) {
        Thread.yield();
    }
}

然后我使用另一个帐户使用 pidgin 登录创建一个聊天室,并邀请上述用户。未调用invitationReceived 方法。当我登录时,smack 调试器会收到存在更新,但不会收到其他数据包。但是,如果我使用 pidgin 登录到上述用户,我就会收到邀请。如何让 smack 检测到邀请请求?

I have the following code to listen for invitations to a chatroom:

    Connection.DEBUG_ENABLED = true;
    XMPPConnection connection = new XMPPConnection("jabber.org");
    connection.connect();
    connection.login("username", "password");

    MultiUserChat.addInvitationListener(connection, new InvitationListener() {
        @Override
        public void invitationReceived(Connection arg0, String arg1,
                String arg2, String arg3, String arg4, Message arg5) {
            System.out.println("Invitation Received!");
        }
    });

    System.out.println("Connected, waiting for invitation");
    while(true) {
        Thread.yield();
    }
}

I then use another account to login with pidgin create a chatroom, and invite the above user. The invitationReceived method is not called. The smack debugger receives a presence update when I login, but no other packets. However, if I am logged in to the above user with pidgin, I do receive the invitation. How can I make smack detect the invitation request?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

梦醒时光 2024-12-27 03:51:25

我可能来不及回答这个问题了,但我想在这里分享我的解决方案,我遇到了同样的问题,

首先这取决于您使用的 smack 版本(我推荐最新版本)

其次,用户发送 MUC 邀请和接收邀请的用户应连接到同一服务器才能接收 MUC 邀请。

第三,始终启用 smack 调试器,它将提供有关传入和传出节的信息。

您应该考虑的第四个因素是登录后向 XMPP 服务器发送状态,如下所示,

       connection.setStatus(true,"ONLINE");

public void setStatus(boolean available, String status) throws XMPPException {
        Presence.Type type = available? Type.available: Type.unavailable;
        Presence presence = new Presence(type);
        presence.setStatus(status);
        connection.sendPacket(presence);
    } 

发送状态通知 xmpp 服务器有关用户状态的信息,然后如果您在连接对象上启用了侦听器,则将收到状态信息以及新的邀请,这有效对我来说,希望它也适用于您,如果有任何信息错误,请纠正我。

I might be too late to answer this question ,but i would like to share my solution here, i had same issue ,

First off all it depends what version of smack are you using(i recommended latest version)

Second, user sending MUC invitation and user receiving invitation should be connected to same server in order to receive MUC invitation.

Third always enable smack debugger ,it will give information about incoming and outgoing stanza.

Fourth factor you should consider is to send a presence to XMPP server after login as shown below,

       connection.setStatus(true,"ONLINE");

public void setStatus(boolean available, String status) throws XMPPException {
        Presence.Type type = available? Type.available: Type.unavailable;
        Presence presence = new Presence(type);
        presence.setStatus(status);
        connection.sendPacket(presence);
    } 

sending presence informs xmpp server about user status and then presence information as well as new invitation will be received if you have enabled listener on connection object ,this works for me hope it will works for you also,please correct me if any information is wrong.

流殇 2024-12-27 03:51:25

您可能使用了错误的 pidgin 用户名。您必须使用姓名和电子邮件地址。

You might be using the wrong username from pidgin. You have to use the name followed by the email address.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文