// // StreamManager.swift // Chat (iOS) // // Created by Sergey Tarasov on 17.08.2022. // import Foundation import XMPPFramework import XMPPFrameworkSwift final class StreamManager: NSObject { static let shared = StreamManager() var stream: XMPPStream var delegate: XMPPStreamDelegate? var password: String override init() { self.stream = XMPPStream() self.password = "" super.init() self.stream.addDelegate(self, delegateQueue: DispatchQueue.main) } func setupStream(with login: String, password: String) { self.stream.hostName = "msg.sharix-app.org" self.stream.hostPort = 5222 self.stream.myJID = XMPPJID(string: login) self.stream.startTLSPolicy = XMPPStreamStartTLSPolicy.allowed self.password = password } func connect() { if !self.stream.isDisconnected { return } try! self.stream.connect(withTimeout: XMPPStreamTimeoutNone) } } extension StreamManager: XMPPStreamDelegate { func xmppStreamDidConnect(_ stream: XMPPStream) { print("Stream: Connected") try! stream.authenticate(withPassword: self.password) } func xmppStreamDidAuthenticate(_ sender: XMPPStream) { self.stream.send(XMPPPresence()) print("Stream: Authenticated") } }