Quellcodebibliothek Statistik Leitseite products/Sources/formale Sprachen/C/Threema/Threema/Core/ThreemaCalls/   (Social Medium ©)  Datei vom 26.9.2026 mit Größe 2 kB image not shown  

Quelle  VoIPIceServerSource.swift   Sprache: JAVA

 

import Foundation
import ThreemaFramework

let MIN_SPARE_VALIDITY: TimeInterval = 3600

struct TurnServerInfo {
    var turnURLs: [String]
    var turnURLsDualStack: [String]
    var turnUsername: String
    var turnPassword: String
    var expirationDate: Date
}

enum TurnServerError: Error {
    case badServerData
}

enum VoIPIceServerSource {
    private static var cachedTurnServers: TurnServerInfo?
    
    static func prefetchIceServers() {
        obtainIceServers(dualStack: false) { _ in
            // ignored
        }
    }
    
    static func obtainIceServers(
        dualStack: Bool,
        completion: @escaping (Swift.Result<RTCIceServer, Error>) -> Void
    ) {
        if cachedTurnServers != nil {
            let minExpiration = Date().addingTimeInterval(MIN_SPARE_VALIDITY)
            if cachedTurnServers!.expirationDate > minExpiration {
                completion(.success(makeIceServers(dualStack: dualStack, turnServerInfo: cachedTurnServers!)))
                return
            }
        }
        
        // No unexpired TURN server info in cache; must fetch
        ServerAPIConnector()
            .obtainTurnServers(with: MyIdentityStore.shared()) { (response: [AnyHashable: Any]?) in
                guard let expiration = response?["expiration"] as? TimeInterval,
                      let turnURLs = response?["turnUrls"] as? [String],
                      let turnURLsDualStack = response?["turnUrlsDualStack"] as? [String],
                      let turnUsername = response?["turnUsername"] as? String,
                      let turnPassword = response?["turnPassword"] as? String else {
                    completion(.failure(TurnServerError.badServerData))
                    return
                }
            
                let expirationDate = Date().addingTimeInterval(expiration)
                cachedTurnServers = TurnServerInfo(
                    turnURLs: turnURLs,
                    turnURLsDualStack: turnURLsDualStack,
                    turnUsername: turnUsername,
                    turnPassword: turnPassword,
                    expirationDate: expirationDate
                )
                completion(.success(makeIceServers(dualStack: dualStack, turnServerInfo: cachedTurnServers!)))
            } onError: { (e: Error?) in
                completion(.failure(e!))
            }
    }
    
    private static func makeIceServers(dualStack: Bool, turnServerInfo: TurnServerInfo) -> RTCIceServer {
        let urls = dualStack ? turnServerInfo.turnURLsDualStack : turnServerInfo.turnURLs
        return RTCIceServer(
            urlStrings: urls,
            username: turnServerInfo.turnUsername,
            credential: turnServerInfo.turnPassword,
            tlsCertPolicy: .secure
        )
    }
}

Messung
CHZG
821009692

¤ Dauer der Verarbeitung: 0.1 Sekunden  (vorverarbeitet am  2026-11-04) ¤

*© Formatika GbR, Deutschland






Wurzel

Suchen

PVS Prover

Isabelle Prover


Cephes Mathematical Library

Vienna Development Method

Haftungshinweis

Die Informationen auf dieser Webseite wurden nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit, noch Qualität der bereit gestellten Informationen zugesichert.

Bemerkung:

Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.