Метод делегата XMPP подключен не стреляет - PullRequest
0 голосов
/ 25 апреля 2018

Я возиться с xmpp и вижу, что метод подключенного делегата никогда не срабатывает.

У меня работает сервер openfire, где я могу войти в систему. У меня также работает Spark, где я могу войти.

В настоящее время методы делегата запускаются в этом порядке.

1. xmppStreamWillConnect
2. socketDidConnect
3. xmppStreamDidStartNegotiation

Ничего не происходит после этого момента.

Кто-нибудь знает, почему это происходит?

Вот моя связь ..

let jId = XMPPJID(string: "admin@127.0.0.1")
 ChatManager(jID: jId!, host: "127.0.0.1", password: "openfire")

Тогда внутри менеджера чата ..

import Foundation

import XMPPFrameworkSwift

открытый финальный класс ChatManager: NSObject {

var stream: XMPPStream!
var jID: XMPPJID
let host: String
let port: UInt16
let password: String

init(jID: XMPPJID, host: String, port: UInt16 = 32876, password: String) {

    self.jID = jID
    self.host = host
    self.port = port
    self.password = password

    // Setup the XMPPStream
    stream = XMPPStream()

    stream.hostName = self.host
    stream.hostPort = self.port
    stream.myJID = self.jID
    stream.startTLSPolicy = .allowed

    super.init()

    stream.addDelegate(self, delegateQueue: DispatchQueue.main)

    connect()
}

private func connect(){
    if !self.stream.isDisconnected {
    }

    let timeoutInterval: TimeInterval = 5.0
    do {
        try stream.connect(withTimeout: XMPPStreamTimeoutNone)
    } catch {}

}

}

расширение ChatManager: XMPPStreamDelegate {

public func xmppStreamDidSecure(_ sender: XMPPStream) {
    print("Secured...")
}

public func xmppStreamDidStartNegotiation(_ sender: XMPPStream) {
    print("Negotiation Started..")

}

public func xmppStream(_ sender: XMPPStream, willSecureWithSettings settings: NSMutableDictionary) {
    print("Will secure...")
    print("Settings: \(settings)")
}

public func xmppStream(_ sender: XMPPStream, didReceive trust: SecTrust, completionHandler: @escaping (Bool) -> Void) {
    print("Recieved trust")
}

public func xmppStreamWillConnect(_ sender: XMPPStream) {
    print("Attempting to connect...")
}

public func xmppStreamDidConnect(_ sender: XMPPStream) {
    print("Connected")
    try! stream.authenticate(withPassword: password)
}

public func xmppStreamConnectDidTimeout(_ sender: XMPPStream) {
    print("Connection timeout")
}

public func xmppStreamWasTold(toAbortConnect sender: XMPPStream) {
    print("Abortion connect")
}

public func xmppStreamDidAuthenticate(_ sender: XMPPStream) {
    print("Stream: Authenticated")
}

public func xmppStream(_ sender: XMPPStream, didNotAuthenticate error: DDXMLElement) {
    print("Stream: Not Authenticated")
}

public func xmppStream(_ sender: XMPPStream, socketDidConnect socket: GCDAsyncSocket) {
    print("Connected socket")
}

}

Консольный вывод

...