gpt4 book ai didi

ios - 创建XMPPRoom时如何设置和获取roomName(组名)?

转载 作者:行者123 更新时间:2023-11-30 12:51:23 25 4
gpt4 key购买 nike

我正在尝试创建 XMPPRoom,但无法设置房间名称,并且收到的节格式不包含房间名称,请帮我解决后端可以看到房间名称的问题。

这是我创建 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>
}

最佳答案

在您的代码中,有两个不同的房间名称:

  1. groupxxx

    字符串(格式:“group%@_%@%@”,currentTimeMills,createdBy,“@conference.hostname”)

格式为roomName@conference.hostname

  • GroupNameString 在配置表单中设置。
  • 你说的是哪一个?

    对于 #1,它位于 from 节中,您只需将其从 jid 中取出即可。

    对于#2,它不会包含在节中,您必须请求房间信息。 http://xmpp.org/extensions/xep-0045.html#disco-roominfo

    关于ios - 创建XMPPRoom时如何设置和获取roomName(组名)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40904678/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com