19 lines
388 B
Swift
19 lines
388 B
Swift
|
import Foundation
|
||
|
import WebSocketKit
|
||
|
|
||
|
private let encoder = JSONEncoder()
|
||
|
|
||
|
enum ClientMessageType: String {
|
||
|
|
||
|
case tableInfo = "t"
|
||
|
}
|
||
|
|
||
|
extension WebSocket {
|
||
|
|
||
|
func send<T>(_ type: ClientMessageType, data: T) where T: Encodable {
|
||
|
let json = try! encoder.encode(data)
|
||
|
let string = String(data: json, encoding: .utf8)!
|
||
|
self.send(type.rawValue + string)
|
||
|
}
|
||
|
}
|