Schafkopf-Server/Sources/App/Model/ClientConnection.swift

19 lines
388 B
Swift
Raw Normal View History

2021-11-30 20:56:04 +01:00
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)
}
}