我试图用 Java 创建一个多用户聊天。我正在使用 smack 库。这是我创建多用户聊天的代码:
MultiUserChat muc = new MultiUserChat(connection, "roomname@somehost");
muc.create("mynickname");
Form form = muc.getConfigurationForm();
Form submitForm = form.createAnswerForm();
submitForm.setAnswer("muc#roomconfig_roomname", "A nice formatted Room Name");
submitForm.setAnswer("muc#roomconfig_roomdesc", "The description. It should be longer.");
muc.sendConfigurationForm(submitForm);
muc.addMessageListener(mucMessageListener); // mucMessageListener is a PacketListener
然后,我尝试使用 mucMessageListener 捕获上面创建的这个房间发送的消息:
private PacketListener mucMessageListener = new PacketListener() {
public void processPacket(Packet packet) {
if (packet instanceof Message) {
Message message = (Message) packet;
// this is where I got the problem
}
}
}
作为其他部分(不是该多用户聊天所有者的用户)收到的消息,他能否以某种方式获得上面这一行中设置的值:
submitForm.setAnswer("muc#roomconfig_roomname", "A nice formatted Room Name");
你看,仅仅获得房间的 JID 对视图来说并不是很好。我希望我可以有一个值为“格式良好的房间名称”的字符串。
我们怎样才能得到它?