Created
May 3, 2023 14:02
-
-
Save MickaelCruzDB/3487d8aeb536a1e87ddb4be3611f2c11 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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