如何在创建XMPPRoom时设置并获取roomName(组名)?
问题描述:
我想创建XMPPRoom哪里无法设置房间名称,也收到节格式不包含房间名称,请帮我解决这个问题,在后端能够看到roomName。如何在创建XMPPRoom时设置并获取roomName(组名)?
这里是我的代码来创建xmppRoom。
func createGroupChat(){
// membersToInvite = members
let xmppRoomMemoryStorage = XMPPRoomMemoryStorage()
let currentTimeMills = self.currentTimeMillis()
let createdBy = (appDelegate.xmppStream?.myJID.user)! as String
let jidString = String(format: "group%@_%@%@",currentTimeMills,createdBy,"@conference.hostname")
let xmppJid = XMPPJID(string: jidString)
let xmppRoom = XMPPRoom.init(roomStorage: xmppRoomMemoryStorage, jid: xmppJid)
xmppRoom?.activate(appDelegate.xmppStream)
xmppRoom?.addDelegate(self, delegateQueue: DispatchQueue.main)
xmppRoom?.join(usingNickname: appDelegate.xmppStream?.myJID.full(), history: nil)
}
func xmppRoomDidCreate(_ sender: XMPPRoom!) {
print(sender)
}
func xmppRoomDidJoin(_ sender: XMPPRoom!) {
sender.fetchConfigurationForm()
for JID in selectedParticipantsAry {
sender.editPrivileges([XMPPRoom.item(withAffiliation: "member", jid: XMPPJID(string: JID as! String))])
sender.inviteUser(XMPPJID(string: JID as! String), withMessage: "THIS IS GROUP MESSAGE")
}
}
func xmppRoom(_ sender: XMPPRoom!, didFetchConfigurationForm configForm: DDXMLElement!)
{
let newConfig: DDXMLElement = configForm.copy() as! DDXMLElement
let fields = newConfig.elements(forName: "field")
for field in fields {
let vars = field.attribute(forName: "var")
// Make Room Persistent
if (vars?.stringValue == "muc#roomconfig_persistentroom") {
field.removeChild(at: 0)
field.addChild(DDXMLElement(name: "value", stringValue : "1"))
}else if (vars?.stringValue == "muc#roomconfig_roomname"){
field.removeChild(at: 0)
field.addChild(DDXMLElement(name: "value", stringValue : "GroupNameString"))
}
}
sender.configureRoom(usingOptions: newConfig)
}
func xmppStream(_ sender: XMPPStream!, didSend message: XMPPMessage!){
<message to="[email protected]"><x xmlns="http://jabber.org/protocol/muc#user"><invite to="[email protected]"> <reason>THIS IS GROUP MESSAGE</reason></invite></x></message>
}
func xmppStream(_ sender: XMPPStream!, didReceive message: XMPPMessage!){
<message xmlns="jabber:client" from="group148057strong [email protected]" to="[email protected]/33932018081480575881630558" type="groupchat" id="75252205"><x xmlns="http://jabber.org/protocol/muc#user"><status code="104"></status></x> </message>
}
答
在代码中,有两种不同的Room Name
:
-
groupxxx
在字符串(格式为: “一群%@ _%@%@”,currentTimeMills,createdBy” @ conference.hostname“)
-
GroupNameString
在配置表单中设置。
你在说什么?
对于#1,这是在from
节,你只需要从jid中取出。
对于#2,它不会包含在节中,您必须要求提供房间信息。 http://xmpp.org/extensions/xep-0045.html#disco-roominfo
感谢您的回复,我正在谈论#2。我可以如何请求房间信息? – Bucket
@Bucket检查我发送的链接,你需要发送一个查询房间信息。 – dichen
谢谢,我在这里请求查询,但不是运气。 – Bucket