Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WebSocket Fixes - Revert to Starscream 3.x and invert dependency #1861

Merged
merged 10 commits into from
Jul 6, 2021
Merged
46 changes: 32 additions & 14 deletions Apollo.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,8 @@
9B7BDA9C23FDE94C00ACD198 /* WebSocketTask.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9B7BDA9523FDE94C00ACD198 /* WebSocketTask.swift */; };
9B7BDA9D23FDE94C00ACD198 /* SplitNetworkTransport.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9B7BDA9623FDE94C00ACD198 /* SplitNetworkTransport.swift */; };
9B7BDA9E23FDE94C00ACD198 /* OperationMessage.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9B7BDA9723FDE94C00ACD198 /* OperationMessage.swift */; };
9B7BDA9F23FDE94C00ACD198 /* ApolloWebSocket.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9B7BDA9823FDE94C00ACD198 /* ApolloWebSocket.swift */; };
9B7BDA9F23FDE94C00ACD198 /* WebSocketClient.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9B7BDA9823FDE94C00ACD198 /* WebSocketClient.swift */; };
9B7BDAA023FDE94C00ACD198 /* WebSocketTransport.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9B7BDA9923FDE94C00ACD198 /* WebSocketTransport.swift */; };
9B7BDAAC23FDEA7B00ACD198 /* Starscream in Frameworks */ = {isa = PBXBuildFile; productRef = 9B7BDAAB23FDEA7B00ACD198 /* Starscream */; };
9B7BDAD023FDEBE300ACD198 /* SQLiteSerialization.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9B7BDACD23FDEBE300ACD198 /* SQLiteSerialization.swift */; };
9B7BDAD223FDEBE300ACD198 /* SQLiteNormalizedCache.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9B7BDACF23FDEBE300ACD198 /* SQLiteNormalizedCache.swift */; };
9B7BDAF623FDEE2600ACD198 /* SQLite in Frameworks */ = {isa = PBXBuildFile; productRef = 9B7BDAF523FDEE2600ACD198 /* SQLite */; };
Expand Down Expand Up @@ -244,6 +243,7 @@
DE0586362669957800265760 /* CacheReference.swift in Sources */ = {isa = PBXBuildFile; fileRef = DE664ED92666DF150054DB4F /* CacheReference.swift */; };
DE0586372669958F00265760 /* GraphQLError.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9FC9A9D21E2FD48B0023C4D5 /* GraphQLError.swift */; };
DE0586392669985000265760 /* Dictionary+Helpers.swift in Sources */ = {isa = PBXBuildFile; fileRef = DE0586382669985000265760 /* Dictionary+Helpers.swift */; };
DE3A2816268BCE6700A1BDC8 /* Starscream in Frameworks */ = {isa = PBXBuildFile; productRef = DE3A2815268BCE6700A1BDC8 /* Starscream */; };
DE3C7974260A646300D2F4FF /* dist in Resources */ = {isa = PBXBuildFile; fileRef = DE3C7973260A646300D2F4FF /* dist */; };
DE3C7A94260A6C1000D2F4FF /* ApolloUtils.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 9B68353E2463481A00337AE6 /* ApolloUtils.framework */; };
DE3C7A95260A6C1000D2F4FF /* ApolloUtils.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 9B68353E2463481A00337AE6 /* ApolloUtils.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
Expand All @@ -256,6 +256,7 @@
DE6B156A261505660068D642 /* GraphQLMap.swift in Sources */ = {isa = PBXBuildFile; fileRef = DE6B154A261505450068D642 /* GraphQLMap.swift */; };
DE6B15AF26152BE10068D642 /* DefaultInterceptorProviderIntegrationTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = DE6B15AE26152BE10068D642 /* DefaultInterceptorProviderIntegrationTests.swift */; };
DE6B15B126152BE10068D642 /* Apollo.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 9FC750441D2A532C00458D91 /* Apollo.framework */; };
DE8C84F5268BC42100C54D02 /* DefaultWebSocketClient.swift in Sources */ = {isa = PBXBuildFile; fileRef = DE8C84F4268BC42100C54D02 /* DefaultWebSocketClient.swift */; };
DECD46D0262F64D000924527 /* StarWarsApolloSchemaDownloaderTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = DECD46CF262F64D000924527 /* StarWarsApolloSchemaDownloaderTests.swift */; };
DECD46FB262F659500924527 /* ApolloCodegenLib.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 9B7B6F47233C26D100F32205 /* ApolloCodegenLib.framework */; };
DECD4736262F668500924527 /* UploadAPI.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 9B2DFBB624E1FA0D00ED3AE6 /* UploadAPI.framework */; };
Expand Down Expand Up @@ -699,7 +700,7 @@
9B7BDA9523FDE94C00ACD198 /* WebSocketTask.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = WebSocketTask.swift; sourceTree = "<group>"; };
9B7BDA9623FDE94C00ACD198 /* SplitNetworkTransport.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SplitNetworkTransport.swift; sourceTree = "<group>"; };
9B7BDA9723FDE94C00ACD198 /* OperationMessage.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = OperationMessage.swift; sourceTree = "<group>"; };
9B7BDA9823FDE94C00ACD198 /* ApolloWebSocket.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ApolloWebSocket.swift; sourceTree = "<group>"; };
9B7BDA9823FDE94C00ACD198 /* WebSocketClient.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = WebSocketClient.swift; sourceTree = "<group>"; };
9B7BDA9923FDE94C00ACD198 /* WebSocketTransport.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = WebSocketTransport.swift; sourceTree = "<group>"; };
9B7BDA9A23FDE94C00ACD198 /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
9B7BDAA323FDE98C00ACD198 /* ApolloWebSocket-Project-Release.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; path = "ApolloWebSocket-Project-Release.xcconfig"; sourceTree = "<group>"; };
Expand Down Expand Up @@ -912,6 +913,7 @@
DE6B160B26152D210068D642 /* Project-Debug.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = "Project-Debug.xcconfig"; sourceTree = "<group>"; };
DE6B160C26152D210068D642 /* Workspace-Packaging.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = "Workspace-Packaging.xcconfig"; sourceTree = "<group>"; };
DE6B160D26152D210068D642 /* Workspace-Shared.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = "Workspace-Shared.xcconfig"; sourceTree = "<group>"; };
DE8C84F4268BC42100C54D02 /* DefaultWebSocketClient.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DefaultWebSocketClient.swift; sourceTree = "<group>"; };
DEA34AF6260E821F00F95F86 /* Apollo-Target-AnimalKingdomAPI.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = "Apollo-Target-AnimalKingdomAPI.xcconfig"; sourceTree = "<group>"; };
DECD46CF262F64D000924527 /* StarWarsApolloSchemaDownloaderTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StarWarsApolloSchemaDownloaderTests.swift; sourceTree = "<group>"; };
DECD490B262F81BF00924527 /* ApolloCodegenTestSupport.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = ApolloCodegenTestSupport.framework; sourceTree = BUILT_PRODUCTS_DIR; };
Expand Down Expand Up @@ -965,7 +967,7 @@
buildActionMask = 2147483647;
files = (
9B7BDAFD23FDEE9300ACD198 /* Apollo.framework in Frameworks */,
9B7BDAAC23FDEA7B00ACD198 /* Starscream in Frameworks */,
DE3A2816268BCE6700A1BDC8 /* Starscream in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down Expand Up @@ -1382,7 +1384,8 @@
9B7BDA9323FDE94C00ACD198 /* ApolloWebSocket */ = {
isa = PBXGroup;
children = (
9B7BDA9823FDE94C00ACD198 /* ApolloWebSocket.swift */,
9B7BDA9823FDE94C00ACD198 /* WebSocketClient.swift */,
DE8C84F4268BC42100C54D02 /* DefaultWebSocketClient.swift */,
9B7BDA9723FDE94C00ACD198 /* OperationMessage.swift */,
9B7BDA9623FDE94C00ACD198 /* SplitNetworkTransport.swift */,
9B7BDA9423FDE94C00ACD198 /* WebSocketError.swift */,
Expand Down Expand Up @@ -2182,7 +2185,7 @@
);
name = ApolloWebSocket;
packageProductDependencies = (
9B7BDAAB23FDEA7B00ACD198 /* Starscream */,
DE3A2815268BCE6700A1BDC8 /* Starscream */,
);
productName = ApolloWebSocket;
productReference = 9B7BDA7D23FDE90400ACD198 /* ApolloWebSocket.framework */;
Expand Down Expand Up @@ -2312,6 +2315,7 @@
);
name = Apollo;
packageProductDependencies = (
DE8C84F3268BBF8000C54D02 /* Starscream */,
);
productName = Apollo;
productReference = 9FC750441D2A532C00458D91 /* Apollo.framework */;
Expand Down Expand Up @@ -2518,10 +2522,10 @@
);
mainGroup = 9FC7503A1D2A532C00458D91;
packageReferences = (
9B7BDAAA23FDEA7B00ACD198 /* XCRemoteSwiftPackageReference "Starscream" */,
9B7BDAF423FDEE2600ACD198 /* XCRemoteSwiftPackageReference "SQLite.swift" */,
9B68F04B2413239100E97318 /* XCRemoteSwiftPackageReference "Stencil" */,
9B47515B2575AA4A0001FB87 /* XCRemoteSwiftPackageReference "InflectorKit" */,
DE8C84F2268BBF8000C54D02 /* XCRemoteSwiftPackageReference "Starscream" */,
);
productRefGroup = 9FC750451D2A532C00458D91 /* Products */;
projectDirPath = "";
Expand Down Expand Up @@ -2786,9 +2790,10 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
9B7BDA9F23FDE94C00ACD198 /* ApolloWebSocket.swift in Sources */,
9B7BDA9F23FDE94C00ACD198 /* WebSocketClient.swift in Sources */,
9B7BDAA023FDE94C00ACD198 /* WebSocketTransport.swift in Sources */,
9B7BDA9C23FDE94C00ACD198 /* WebSocketTask.swift in Sources */,
DE8C84F5268BC42100C54D02 /* DefaultWebSocketClient.swift in Sources */,
9B7BDA9B23FDE94C00ACD198 /* WebSocketError.swift in Sources */,
9B7BDA9D23FDE94C00ACD198 /* SplitNetworkTransport.swift in Sources */,
9B7BDA9E23FDE94C00ACD198 /* OperationMessage.swift in Sources */,
Expand Down Expand Up @@ -3807,7 +3812,7 @@
repositoryURL = "https://github.com/daltoniam/Starscream.git";
requirement = {
kind = upToNextMinorVersion;
minimumVersion = 4.0.4;
minimumVersion = 3.1.1;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like there's some kind of reference to the main Starscream repo floating around in here

};
};
9B7BDAF423FDEE2600ACD198 /* XCRemoteSwiftPackageReference "SQLite.swift" */ = {
Expand All @@ -3818,6 +3823,14 @@
minimumVersion = 0.12.2;
};
};
DE8C84F2268BBF8000C54D02 /* XCRemoteSwiftPackageReference "Starscream" */ = {
isa = XCRemoteSwiftPackageReference;
repositoryURL = "https://github.com/apollographql/Starscream.git";
requirement = {
kind = upToNextMinorVersion;
minimumVersion = 3.1.2;
};
};
/* End XCRemoteSwiftPackageReference section */

/* Begin XCSwiftPackageProductDependency section */
Expand All @@ -3831,11 +3844,6 @@
package = 9B68F04B2413239100E97318 /* XCRemoteSwiftPackageReference "Stencil" */;
productName = Stencil;
};
9B7BDAAB23FDEA7B00ACD198 /* Starscream */ = {
isa = XCSwiftPackageProductDependency;
package = 9B7BDAAA23FDEA7B00ACD198 /* XCRemoteSwiftPackageReference "Starscream" */;
productName = Starscream;
};
9B7BDAF523FDEE2600ACD198 /* SQLite */ = {
isa = XCSwiftPackageProductDependency;
package = 9B7BDAF423FDEE2600ACD198 /* XCRemoteSwiftPackageReference "SQLite.swift" */;
Expand All @@ -3851,6 +3859,16 @@
package = 9B7BDAF423FDEE2600ACD198 /* XCRemoteSwiftPackageReference "SQLite.swift" */;
productName = SQLite;
};
DE3A2815268BCE6700A1BDC8 /* Starscream */ = {
isa = XCSwiftPackageProductDependency;
package = DE8C84F2268BBF8000C54D02 /* XCRemoteSwiftPackageReference "Starscream" */;
productName = Starscream;
};
DE8C84F3268BBF8000C54D02 /* Starscream */ = {
isa = XCSwiftPackageProductDependency;
package = DE8C84F2268BBF8000C54D02 /* XCRemoteSwiftPackageReference "Starscream" */;
productName = Starscream;
};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also not clear on why this has been added like three times

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not clear on that either... XCProject files still have some weird bugs with their SPM integrations sometimes. I'm not too worried about it though. Not sure if there is anything we can do to fix that...

DECD4870262F7A6E00924527 /* InflectorKit */ = {
isa = XCSwiftPackageProductDependency;
package = 9B47515B2575AA4A0001FB87 /* XCRemoteSwiftPackageReference "InflectorKit" */;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,11 @@
},
{
"package": "Starscream",
"repositoryURL": "https://github.com/daltoniam/Starscream.git",
"repositoryURL": "https://github.com/apollographql/Starscream.git",
"state": {
"branch": null,
"revision": "df8d82047f6654d8e4b655d1b1525c64e1059d21",
"version": "4.0.4"
"revision": "4c985380c92920be5f75c14577e5c2e3615f2337",
"version": "3.1.2"
}
},
{
Expand Down
6 changes: 3 additions & 3 deletions Package.resolved
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,11 @@
},
{
"package": "Starscream",
"repositoryURL": "https://github.com/daltoniam/Starscream",
"repositoryURL": "https://github.com/apollographql/Starscream",
"state": {
"branch": null,
"revision": "df8d82047f6654d8e4b655d1b1525c64e1059d21",
"version": "4.0.4"
"revision": "4c985380c92920be5f75c14577e5c2e3615f2337",
"version": "3.1.2"
}
},
{
Expand Down
4 changes: 2 additions & 2 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ let package = Package(
url: "https://github.com/stephencelis/SQLite.swift.git",
.upToNextMinor(from: "0.12.2")),
.package(
url: "https://github.com/daltoniam/Starscream",
.upToNextMinor(from: "4.0.4")),
url: "https://github.com/apollographql/Starscream",
calvincestari marked this conversation as resolved.
Show resolved Hide resolved
.upToNextMinor(from: "3.1.2")),
.package(
url: "https://github.com/stencilproject/Stencil.git",
.upToNextMinor(from: "0.14.0")),
Expand Down
42 changes: 10 additions & 32 deletions Sources/ApolloTestSupport/MockWebSocket.swift
Original file line number Diff line number Diff line change
@@ -1,57 +1,35 @@
import Starscream
import Foundation
@testable import ApolloWebSocket

public class MockWebSocket: ApolloWebSocketClient {
public class MockWebSocket: WebSocketClient {

public var callbackQueue: DispatchQueue = DispatchQueue.main

// A dummy web socket since we can't just return the client
var webSocketForDelegate: WebSocket
public var request: URLRequest
public var callbackQueue: DispatchQueue = DispatchQueue.main
public var delegate: WebSocketClientDelegate? = nil
public var isConnected: Bool = false

public required init(request: URLRequest,
certPinner: CertificatePinning? = FoundationSecurity(),
compressionHandler: CompressionHandler? = nil) {
self.webSocketForDelegate = WebSocket(request: request)
public required init(request: URLRequest) {
self.request = request
}

public init(request: URLRequest) {
self.request = request
self.webSocketForDelegate = WebSocket(request: request)
}

open func reportDidConnect() {
callbackQueue.async {
self.delegate?.didReceive(event: .connected([:]), client: self.webSocketForDelegate)
self.delegate?.websocketDidConnect(socket: self)
}
}

open func write(string: String, completion: (() -> ())?) {
open func write(string: String) {
callbackQueue.async {
self.delegate?.didReceive(event: .text(string), client: self.webSocketForDelegate)
self.delegate?.websocketDidReceiveMessage(socket: self, text: string)
}
}

open func write(stringData: Data, completion: (() -> ())?) {
}

open func write(data: Data, completion: (() -> ())?) {
}

open func write(ping: Data, completion: (() -> ())?) {
}

open func write(pong: Data, completion: (() -> ())?) {
}

public func disconnect(closeCode: UInt16) {

public func disconnect() {
}

public var delegate: WebSocketDelegate? = nil
public var isConnected: Bool = false

public func connect() {
}
}
52 changes: 0 additions & 52 deletions Sources/ApolloWebSocket/ApolloWebSocket.swift

This file was deleted.

70 changes: 70 additions & 0 deletions Sources/ApolloWebSocket/DefaultWebSocketClient.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
import Starscream
import Foundation

/// Included default implementation of a `WebSocketClient`, based on `Starscream`'s `WebSocket`.
public class DefaultWebSocket: WebSocketClient, Starscream.WebSocketDelegate {
calvincestari marked this conversation as resolved.
Show resolved Hide resolved

/// The websocket protocols supported by this websocket client implementation.
static private let wsProtocols = ["graphql-ws"]

/// The underlying `Starscream` websocket used by this websocket client.
private let underlyingWebsocket: Starscream.WebSocket

public var request: URLRequest {
get { underlyingWebsocket.request }
set { underlyingWebsocket.request = newValue }
}

public weak var delegate: WebSocketClientDelegate?

public var callbackQueue: DispatchQueue {
get { underlyingWebsocket.callbackQueue }
set { underlyingWebsocket.callbackQueue = newValue }
}

/// Required initializer
///
/// - Parameters:
/// - request: The URLRequest to use on connection.
/// - certPinner: [optional] The object providing information about certificate pinning. Should default to Starscream's `FoundationSecurity`.
/// - compressionHandler: [optional] The object helping with any compression handling. Should default to nil.
required public init(request: URLRequest) {
self.underlyingWebsocket = Starscream.WebSocket(
request: request,
protocols: Self.wsProtocols,
stream: FoundationStream())
self.underlyingWebsocket.delegate = self
}

public func connect() {
self.underlyingWebsocket.connect()
}

public func disconnect() {
self.underlyingWebsocket.disconnect()
}

public func write(ping: Data, completion: (() -> Void)?) {
self.underlyingWebsocket.write(ping: ping, completion: completion)
}

public func write(string: String) {
self.underlyingWebsocket.write(string: string)
}

public func websocketDidConnect(socket: Starscream.WebSocketClient) {
self.delegate?.websocketDidConnect(socket: self)
}

public func websocketDidDisconnect(socket: Starscream.WebSocketClient, error: Error?) {
self.delegate?.websocketDidDisconnect(socket: self, error: error)
}

public func websocketDidReceiveMessage(socket: Starscream.WebSocketClient, text: String) {
self.delegate?.websocketDidReceiveMessage(socket: self, text: text)
}

public func websocketDidReceiveData(socket: Starscream.WebSocketClient, data: Data) {
self.delegate?.websocketDidReceiveData(socket: self, data: data)
}
}
Loading