CNLiveCommonManager.swift 2.14 KB
//
//  CNLiveCommonManager.swift
//  metaCode
//
//  Created by zx on 2023/11/29.
//

import Foundation
import CNLiveRequestBastKit

typealias getTimeWithResultBlock = (_ networkTimestamp:Double) -> Void

class CNLiveCommonManager: NSObject{
    
    //单例类
    static let shared = CNLiveCommonManager()
   
    /// 跳转播放器
    /// @param playURL 播放URL
    /// @param coverImage 封面图
    /// @param coverImageUrl 封面图url
    func skipPlayerVCWithPlayURL(playURL:URL,coverImage:UIImage?,coverImageUrl:String?){
        let vc = CNLivePlayerViewController()
        vc.setPlayUrl(playUrl: playURL, isLive: false)
        vc.coverImageUrl = coverImageUrl
        navigationViewController().pushViewController(vc, animated: pushAnimated)
//        currentViewController()?.navigationController?.pushViewController(vc, animated: pushAnimated)
    }
    
    /**
     获取网络时间
     */
    func postGetTimeWithResult(resultBlock:@escaping getTimeWithResultBlock){
        
        CNLiveNetworking.setAllowRequestDefaultArgument(true)
        CNLiveNetworking.setupShowDataResult(false)
        CNLiveNetworking.setupDSRequest(true)
        let custom_param = NSMutableDictionary()
        custom_param.setValue(CNLiveEnvironmentManager.shared.appId_wjj, forKey: "appId")
        custom_param.setValue(CNLiveEnvironmentManager.shared.appKey_wjj, forKey: "appKey")
        CNLiveNetworking.setupCustomParam(custom_param as? [String : String])
        CNLiveNetworking.requestNetwork(with: .GET, urlString: APPBaseWjjBUrl+"/Api/Index3/get_time", param: nil, cacheType: .networkOnly) { task, result, error in
            if error == nil{
                let res = (result as! NSDictionary)
                let allKeys = res.allKeys as NSArray
                var networkTimestamp:Double = 0
                if allKeys.contains("time"){
                    networkTimestamp = (res["time"] as! NSString).doubleValue
                }
                resultBlock(networkTimestamp)
            }else{
                let date = Date()
                let timestamp = date.timeIntervalSince1970
                resultBlock(timestamp)
            }
        }
    }
}