Skip to content

Commit 9f160af

Browse files
committed
Add: handle pong closure
1 parent c6d8ea0 commit 9f160af

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

Sources/WebSockets.swift

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ import Foundation
1010

1111
public func websocket(
1212
_ text: ((WebSocketSession, String) -> Void)?,
13-
_ binary: ((WebSocketSession, [UInt8]) -> Void)?) -> ((HttpRequest) -> HttpResponse) {
13+
_ binary: ((WebSocketSession, [UInt8]) -> Void)?,
14+
_ pong: ((WebSocketSession, [UInt8]) -> Void)?) -> ((HttpRequest) -> HttpResponse) {
1415
return { r in
1516
guard r.hasTokenForHeader("upgrade", token: "websocket") else {
1617
return .badRequest(.text("Invalid value of 'Upgrade' header: \(r.headers["upgrade"] ?? "unknown")"))
@@ -90,6 +91,9 @@ public func websocket(
9091
session.writeFrame(ArraySlice(frame.payload), .pong)
9192
}
9293
case .pong:
94+
if let handlePong = pong {
95+
handlePong(session, frame.payload)
96+
}
9397
break
9498
}
9599
}

0 commit comments

Comments
 (0)