12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576 |
- //
- // KMWebsocketManager.swift
- // PDF Master DMG
- //
- // Created by wanjun on 2023/6/29.
- //
- import Cocoa
- enum KMWebsocketEvent : Int {
- case KMWebsocketEventPaySuccess = 0
- case KMWebsocketEventPayFail
- }
- class KMWebsocketManager: NSObject {
-
- static let defaultManager = KMWebsocketManager()
-
- var websocket: KMWebsocket?
- var content: [String : String] = [:]
-
- override init() {
- super.init()
-
- self.websocket = KMWebsocket()
- self.websocket?.delegate = self
- }
-
- //MARK: Private Methods
-
- //MARK: Public Methods
- func connect() -> Void {
- #if VERSION_DMG
- let endPoint: String = ""
- #endif
- self.websocket?.connect(endPoint: endPoint)
- }
-
- func disconnect() -> Void {
- self.websocket?.disconnect()
- }
- }
- extension KMWebsocketManager: KMWebsocketDelegate {
- func websocketDidConnect() {
-
- }
-
- func websocketDidDisconnect() {
-
- }
-
- func websocketDidError(error: Error) {
- self.disconnect()
- }
-
- func websocketDidReceive(content: String) {
- DispatchQueue.main.async {
- let data: Data = content.data(using: .utf8)!
- let content: [String : String] = try! JSONSerialization.jsonObject(with: data, options: JSONSerialization.ReadingOptions.mutableContainers) as! [String : String]
- self.content = content
- let event: String = content["event"]!
-
- if event == "pay_success" {
-
- } else if event == "pay_fail" {
-
- }
- }
- }
-
- func webSocketDidReceiveData(data: Data) {
-
- }
- }
|