123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354 |
- //
- // 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")
- }
- }
|