Sesame-Server/Sources/App/routes.swift
2022-01-23 20:49:06 +01:00

32 lines
789 B
Swift
Executable File

import Vapor
var connection: WebSocket?
func routes(_ app: Application) throws {
app.get { req in
return "It works!"
}
/**
Start a new websocket connection for the client to receive table updates from the server
- Returns: Nothing
- Note: The first (and only) message from the client over the connection must be a valid session token.
*/
app.webSocket("listen") { req, socket in
socket.onBinary { socket, data in
print("\(data)")
}
socket.onText { socket, text in
print(text)
}
_ = socket.onClose.always { result in
connection = nil
print("Socket closed")
}
connection = socket
print("Socket connected")
}
}