Skip to content

Commit

Permalink
fix: Add peer closed WebSocket handling introduced in StarScream 4.0.…
Browse files Browse the repository at this point in the history
…5. According to RFC 6455

RFC 6455 7.1.5 says:
   If _The WebSocket
   Connection is Closed_ and no Close control frame was received by the
   endpoint (such as could occur if the underlying transport connection
   is lost), _The WebSocket Connection Close Code_ is considered to be
   1006
  • Loading branch information
Fedos committed Sep 28, 2023
1 parent 9c6104e commit 814bb47
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ let package = Package(
.package(url: "https://github.com/apple/swift-argument-parser", from: "1.0.0"),
.package(url: "https://github.com/apple/swift-format", from: "508.0.0"),
.package(url: "https://github.com/apple/swift-log.git", from: "1.0.0"),
.package(url: "https://github.com/daltoniam/Starscream.git", exact: "4.0.4"),
.package(url: "https://github.com/daltoniam/Starscream.git", from: "4.0.0"),
.package(url: "https://github.com/dominicegginton/Spinner", from: "2.0.0"),
.package(url: "https://github.com/JohnSundell/Files", from: "4.0.0"),
.package(url: "https://github.com/jpsim/Yams.git", from: "5.0.0"),
Expand Down
7 changes: 5 additions & 2 deletions Sources/GraphQLWebSocket/Client.swift
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public class GraphQLWebSocket: WebSocketDelegate {
case connecting

/// WebSocket has opened.
case opened(socket: WebSocket)
case opened(socket: WebSocketClient)

/// Open WebSocket connection has been acknowledged
case acknowledged(payload: [String: AnyCodable]?)
Expand Down Expand Up @@ -143,7 +143,7 @@ public class GraphQLWebSocket: WebSocketDelegate {

// MARK: - Internals

public func didReceive(event: WebSocketEvent, client: WebSocket) {
public func didReceive(event: WebSocketEvent, client: WebSocketClient) {
self.config.logger.debug("Received a new message from the server!")

switch event {
Expand Down Expand Up @@ -219,6 +219,9 @@ public class GraphQLWebSocket: WebSocketDelegate {
self.close(code: closeCode)
break

case .peerClosed:
self.close(code: 1006)
break
}
}

Expand Down

0 comments on commit 814bb47

Please sign in to comment.