Skip to content

Instantly share code, notes, and snippets.

@MickaelCruzDB
Created May 3, 2023 14:02
Show Gist options
  • Save MickaelCruzDB/3487d8aeb536a1e87ddb4be3611f2c11 to your computer and use it in GitHub Desktop.
Save MickaelCruzDB/3487d8aeb536a1e87ddb4be3611f2c11 to your computer and use it in GitHub Desktop.
func routes(_ app: Application) throws {
var webSocketClients = [WebSocket]()
app.webSocket("commands") { request, ws in
ws.send("Connection OK")
webSocketClients.append(ws)
ws.onText { ws, string in
for client in webSocketClients {
client.send(string + " : OK")
}
}
ws.onClose.whenComplete { result in
switch result {
case .success():
print("Closed")
case .failure(let error):
print("Failed to close connection \(error)")
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment