Goal: configure xmpp room to restrict access to members only, then add members. using xmppframework in swift4
there is some documentation on the xmppframework github but it is generally in objective c and aimed at people that know what they're doing
I am creating a little program that logs into my xmpp server4, then joins a room, and starts posting alerts based on my staff productivity. I have created the room, and it has a history, and i can post to the room fine. I want to restrict the room so that only certain users can join
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()
}
I now need to configure the room, i believe i am required to use
xmppRoom.configureRoom(usingOptions:XMLElement )
as a beginner programmer, I have no idea how to proceed, so I'm looking for an example configuration of a room, restricted to members, in which I can add or remove members as required.
Here is the detail of XMPP-MUC , and to restricting room for members only you can use this XEP-0045.
For restricting a room you may use following delegate.
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)
}