目标:配置xmpp空间以限制仅限成员访问,然后添加成员。在swift4中使用xmppframework
有一些关于xmppframework github的文档,但它通常是客观的c,针对那些知道他们正在做什么的人
我正在创建一个小程序,它登录到我的xmpp server4,然后加入一个房间,并根据我的员工生产力开始发布警报。 我创造了房间,它有历史,我可以很好地张贴到房间。 我想限制房间,以便只有某些用户可以加入
func xmppStreamDidAuthenticate(_ sender: XMPPStream) {
self.xmppStream.send(XMPPPresence())
print("Connected, and Authenticated")
// Join Room
let roomStorage: XMPPRoomMemoryStorage = XMPPRoomMemoryStorage()
let roomJID = XMPPJID(string: "chatalerts@muc.im.taudy.com") ??
XMPPJID(string: "chatalerts@muc.im.taudy.com")
let xmppRoom: XMPPRoom = XMPPRoom(roomStroage: roomStorage, jid: roomJID!,
dispatchQueue: DispatchQueue.main)
xmppRoom.fetchConfigurationForm()
}
我现在需要配置房间,我相信我需要使用
xmppRoom.configureRoom(usingOptions:XMLElement )
作为初学程序员,我不知道如何继续,所以我正在寻找一个房间的示例配置,仅限于成员,我可以根据需要添加或删除成员。
答案 0 :(得分:0)
这是XMPP-MUC的详细信息,要限制会员的空间,您只能使用此XEP-0045。
要限制房间,您可以使用以下代表。
func xmppRoom(_ sender: XMPPRoom, didFetchConfigurationForm configForm: DDXMLElement) {
print("XMPPManager xmppRoom didFetch ConfigurationForm : \(configForm)")
let newForm = configForm.copy() as! DDXMLElement
let groupName = "Your Room Name"
for field in newForm.elements(forName: "field")
{
if let _var = field.attributeStringValue(forName: "var")
{
switch _var
{
case "muc#roomconfig_persistentroom":
field.removeChild(at: 0)
field.addChild(DDXMLElement(name: "value", stringValue: "1"))
case "muc#roomconfig_roomname":
field.removeChild(at: 0)
field.addChild(DDXMLElement(name : "value", stringValue :groupName))
case "muc#roomconfig_publicroom":
field.removeChild(at: 0)
field.addChild(DDXMLElement(name: "value", stringValue: "1"))
case "muc#roomconfig_whois":
field.removeChild(at: 0)
field.insertChild(DDXMLElement(name: "value", stringValue: "anyone"), at: 0)
case "muc#roomconfig_allow_subscription":
field.removeChild(at: 0)
field.addChild(DDXMLElement(name: "value", stringValue: "1"))
// Here goes your value. in your case you have to send 1.
case "muc#roomconfig_membersonly":
field.removeChild(at: 0)
field.addChild(DDXMLElement(name: "value", stringValue: "1"))
case "muc#roomconfig_getmemberlist":
field.removeChild(at: 0)
field.addChild(DDXMLElement(name: "value", stringValue: "moderator"))
field.addChild(DDXMLElement(name: "value", stringValue: "participant"))
field.addChild(DDXMLElement(name: "value", stringValue: "visitor"))
case "muc#roomconfig_moderatedroom":
field.removeChild(at: 0)
field.addChild(DDXMLElement(name: "value", stringValue: "1"))
case "public_list":
field.removeChild(at: 0)
field.addChild(DDXMLElement(name: "value", stringValue: "1"))
case "muc#roomconfig_allowinvites":
field.removeChild(at: 0)
field.addChild(DDXMLElement(name: "value", stringValue: "1"))
case "muc#roomconfig_changesubject":
field.removeChild(at: 0)
field.addChild(DDXMLElement(name: "value", stringValue: "true"))
// other configures
default:
break
}
}
}
sender.configureRoom(usingOptions: newForm)
}