Skip to content

Commit e8d725c

Browse files
authored
Websocket Ping (#27)
* Add ping endpoint. * Formatting. * Update Xcode in actions.
1 parent 5db7e9f commit e8d725c

4 files changed

Lines changed: 32 additions & 22 deletions

File tree

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ jobs:
2525
name: macOS
2626
runs-on: firebreak
2727
env:
28-
DEVELOPER_DIR: /Applications/Xcode_14.1.app/Contents/Developer
28+
DEVELOPER_DIR: /Applications/Xcode_14.2.app/Contents/Developer
2929
timeout-minutes: 10
3030
steps:
3131
- uses: actions/checkout@v3

.github/workflows/release.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ jobs:
99
name: Upload Release Artifact
1010
runs-on: firebreak
1111
env:
12-
DEVELOPER_DIR: /Applications/Xcode_14.1.app/Contents/Developer
12+
DEVELOPER_DIR: /Applications/Xcode_14.2.app/Contents/Developer
1313
steps:
1414
- name: Checkout
1515
uses: actions/checkout@v3

Package.resolved

Lines changed: 20 additions & 20 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Sources/WebSocket.swift

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,16 @@ func createWebSocketRoutes(for app: Application) throws {
8686
socket.send(string)
8787
}
8888
}
89+
90+
app.webSocket("websocket", "ping", ":count") { request, socket in
91+
var remainingPings = request.parameters["count", as: Int.self] ?? 1
92+
socket.onPing { _ in
93+
remainingPings -= 1
94+
if remainingPings == 0 {
95+
_ = socket.close()
96+
}
97+
}
98+
}
8999
}
90100

91101
struct WebSocketOptions: Decodable {

0 commit comments

Comments
 (0)