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

Refactor websocket implementation directly into ApolloWebSocket #1906

Merged
merged 14 commits into from
Aug 16, 2021

Conversation

AnthonyMDev
Copy link
Contributor

Due to dependency management conflicts in #1903, it has become easier for us to maintain our WebSockets as part of the ApolloWebSockets target instead of an external dependency on a forked version of Starscream.

This PR moves over the Starscream implementation directly into our target. I did a bit of refactoring and clean up to make the Starscream code make sense as a more integrated part of our websocket stack and to fix warnings for deprecated usage of unsafe Swift APIs.

Sources/ApolloWebSocket/Compression.swift Outdated Show resolved Hide resolved
Sources/ApolloWebSocket/WebSocketError.swift Show resolved Hide resolved
Sources/ApolloWebSocket/WebSocketTransport.swift Outdated Show resolved Hide resolved
@@ -22,7 +21,7 @@ class StarWarsSubscriptionTests: XCTestCase {
connectionStartedExpectation = self.expectation(description: "Web socket connected")

webSocketTransport = WebSocketTransport(
websocket: DefaultWebSocket(
websocket: WebSocket(
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we not still want to abstract this out for when we offer URLSessionWebSocket compatibility in the future?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It is still injected, you just need something that conforms to the WebSocketClient protocol. Just changed the name of the "Default" one to remove "Default".

I decided to hold off on moving the non-abstract parts of this into Apollo target until we do the networking layer refactor, because the API is going to likely change so drastically at that point anyways.

Copy link
Contributor

Choose a reason for hiding this comment

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

OK sounds like a plan

@calvincestari
Copy link
Member

This is nitpicking but it might be better to keep the Starscream files in their own sub-folder. If ApolloWebSocket grows in number of files it would be good to be able to isolate Starscream contributions.

@designatednerd
Copy link
Contributor

Agreed on throwing the Starscream files into a folder for clarity.

@AnthonyMDev
Copy link
Contributor Author

I don’t think we should be naming the folder starscream. I don’t know why we are even moving them into a sub folder. I have already modified the starscream code modestly, and it’s now directly integrated as part of Apollo.

@designatednerd
Copy link
Contributor

@AnthonyMDev I disagree - we're taking it over, but I think it's really worth keeping "what is stuff we developed in-house" and "what is stuff we adopted from Starscream" very clearly delinated.

@AnthonyMDev
Copy link
Contributor Author

I’m very okay with acknowledging the contributions of Starscream that we are deriving from, but going forward, this is no longer “Starscream” code. We have responsibility and ownership over the future or it. And it’s not included using any abstractions or DI or via a separate package dependency.

@AnthonyMDev
Copy link
Contributor Author

@designatednerd Alright I hear you, but I’m not clear what actual value we get out of doing that.

I guess I expect that as this library evolves, the lines between the two are going to get blurred even more. When we implement native Apple Websockets, we will still likely be using part of the Starscream derived code, but it will become even more heavily modified.

I just don’t see the benefit of separation here. It feels like we are creating an artificial abstraction.

Once we move the protocols and the WebSocketTransport into the base Apollo target (when we refactor the networking layer prior to 1.0), this Starscream derived code is going to become basically the entire target anyways.

@AnthonyMDev
Copy link
Contributor Author

I’d be more inclined to accept a folder for “DefaultImplementation” or something. But I don’t think that it should be associated with Starscream in the project structure.

@designatednerd
Copy link
Contributor

I'm good with DefaultImplementation as well if that works for @calvincestari - much more concerned with separating out this existing implementation from any we create in the future.

@calvincestari calvincestari merged commit c046b27 into main Aug 16, 2021
@calvincestari calvincestari deleted the web-socket-refactor branch August 16, 2021 22:00
@calvincestari calvincestari added include-in-changelog Indicates that changes from a PR should be noted in the changelog for their release. 2021-08 labels Aug 16, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
include-in-changelog Indicates that changes from a PR should be noted in the changelog for their release.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants