File tree Expand file tree Collapse file tree 2 files changed +9
-2
lines changed
Expand file tree Collapse file tree 2 files changed +9
-2
lines changed Original file line number Diff line number Diff line change @@ -180,7 +180,10 @@ public func demoServer(_ publicDir: String) -> HttpServer {
180180 session. writeText ( text)
181181 } , { ( session, binary) in
182182 session. writeBinary ( binary)
183- } )
183+ } , { ( session, pong) in
184+ // Got a pong frame
185+ }
186+ )
184187
185188 server. notFoundHandler = { r in
186189 return . movedPermanently( " https://github.com/404 " )
Original file line number Diff line number Diff line change @@ -10,7 +10,8 @@ import Foundation
1010
1111public 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 }
You can’t perform that action at this time.
0 commit comments