-
Notifications
You must be signed in to change notification settings - Fork 169
Replace NWWebsocket with URLSessionWebSocketTask #442
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
base: master
Are you sure you want to change the base?
Conversation
…ocket-swift into nwwebsocket-fork
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. If you'd like this issue to stay open please leave a comment indicating how this issue is affecting you. Thank you. |
This issue still exists |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR replaces the legacy NWWebSocket client with a wrapper around URLSessionWebSocketTask. Key changes include updating test cases and mocks from NWWebSocket to WebSocketClient, modifying production code to use URLSessionWebSocketTask-based connection handling, and removing the NWWebSocket dependency from Package.swift.
Reviewed Changes
Copilot reviewed 12 out of 12 changed files in this pull request and generated 2 comments.
Show a summary per file
File | Description |
---|---|
Tests/Unit/Services/WebSocketClientTests.swift | Updates tests to work with the new WebSocketClient and URLSessionWebSocketTask API |
Tests/Unit/Services/Server/WebSocketServerConnection.swift | Minor adjustments in connection handling with NWConnection |
Tests/Unit/Services/Server/NWWebSocketServer.swift | Replaces NWWebSocket with URLSessionWebSocketTask-based logic; note a potential naming typo |
Tests/Unit/Protocols/PusherConnectionDelegateTests.swift | Updates disconnect code to use URLSessionWebSocketTask.CloseCode |
Tests/Helpers/Mocks.swift | Replaces NWWebSocket with WebSocketClient in mocks |
Sources/Services/WebSocketClient.swift | Implements the new client using URLSessionWebSocketTask and updates related documentation |
Sources/Services/PusherConnection.swift | Updates socket property type and references to use WebSocketClient |
Sources/PusherSwift.swift | Updates connection initialization to use the WebSocketClient |
Sources/Protocols/WebSocketConnection.swift | Defines protocol methods with the new closeCode type |
Sources/Extensions/PusherConnection+WebsocketDelegate.swift | Changes delegate methods to work with URLSessionWebSocketTask.CloseCode |
Package.swift | Removes NWWebSocket dependency |
Comments suppressed due to low confidence (1)
Sources/Services/WebSocketClient.swift:27
- The doc comment still refers to NWWebSocket; update it to reflect that this initializer now creates a WebSocketClient instance using URLSessionWebSocketTask.
/// Creates a `NWWebSocket` instance which connects to a socket `url`.
if Self.receivedPongTimestamps.count == Self.expectedReceivedPongsCount { | ||
Self.pingsWithIntervalExpectation?.fulfill() | ||
} | ||
Self.receivedPongTimestamps.append(Date()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nitpick] Consider appending the Date timestamp before checking the received count to ensure the condition accurately reflects the number of pong responses received.
if Self.receivedPongTimestamps.count == Self.expectedReceivedPongsCount { | |
Self.pingsWithIntervalExpectation?.fulfill() | |
} | |
Self.receivedPongTimestamps.append(Date()) | |
Self.receivedPongTimestamps.append(Date()) | |
if Self.receivedPongTimestamps.count == Self.expectedReceivedPongsCount { | |
Self.pingsWithIntervalExpectation?.fulfill() | |
} |
Copilot uses AI. Check for mistakes.
Hey @theolampert Thanks for opening the PR 🙌 I did some research, and found this part in a Pusher blog post where it's mentioned we couldn't use
Although, from my limited understanding, the client code in NWWebSocket, is NOT really sending any custom codes and is using the
|
Hey @aonemd I never saw that blog post but that explains better why there was custom handling, we haven't noticed anything strange with reconnection but the reasons to not use |
This removes the
NWWebsocket
client and replaces it with a wrapper around the newer, higher-levelURLSessionWebSocketTask
. There's still a bit of cleanup to do in this branch, and I'm unsure if it's something you'll want to accept, but I am opening a draft for feedback.