我正在尝试创建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="group1480576001764.846924_XXX@conference.hostname"><x xmlns="http://jabber.org/protocol/muc#user"><invite to="XXXXX@hostname"> <reason>THIS IS GROUP MESSAGE</reason></invite></x></message>
}
func xmppStream(_ sender: XMPPStream!, didReceive message: XMPPMessage!){
<message xmlns="jabber:client" from="group148057strong text6001764.846924_XXXX@conference.hostname" to="XXXX@hostname/33932018081480575881630558" type="groupchat" id="75252205"><x xmlns="http://jabber.org/protocol/muc#user"><status code="104"></status></x> </message>
}
答案 0 :(得分:0)
在您的代码中,有两种不同的Room Name
:
<{p>中的groupxxx
的字符串(格式:&#34;组%@ _%@%@&#34;,currentTimeMills,createdBy,&#34; @ conference.hostname&#34)
格式为roomName@conference.hostname
。
GroupNameString
在配置表单中设置。你在谈论哪一个?
对于#1,该节中的from
,你只需要从jid中取出它。
对于#2,它不会被包含在节中,你必须要求提供房间信息。 http://xmpp.org/extensions/xep-0045.html#disco-roominfo