MUCManager.swift 908 B

123456789101112131415161718192021222324252627282930313233343536
  1. //
  2. // MUCManager.swift
  3. // Chat (iOS)
  4. //
  5. // Created by Sergey Tarasov on 17.08.2022.
  6. //
  7. import Foundation
  8. import XMPPFramework
  9. import XMPPFrameworkSwift
  10. class MUCManager: NSObject {
  11. var muc: XMPPMUCLight
  12. var rooms: [Room] = []
  13. override init() {
  14. self.muc = XMPPMUCLight()
  15. super.init()
  16. self.muc.activate(StreamManager.shared.stream)
  17. self.muc.addDelegate(self, delegateQueue: .main)
  18. }
  19. func fetchRooms() {
  20. _ = self.muc.discoverRooms(forServiceNamed: "chat.msg.sharix-app.org")
  21. }
  22. }
  23. extension MUCManager: XMPPMUCLightDelegate {
  24. func xmppMUCLight(_ sender: XMPPMUCLight, didDiscoverRooms rooms: [DDXMLElement], forServiceNamed serviceName: String) {
  25. debugPrint(rooms)
  26. self.rooms = rooms.map({ Room(jidString: $0.attributeStringValue(forName: "jid") ?? "", name: $0.attributeStringValue(forName: "name") ?? "") })
  27. }
  28. }