Skip to content

Commit

Permalink
Migrate native WebSocket client to NWWebSocket library
Browse files Browse the repository at this point in the history
- Remove 'WebSocket.swift' (and related source files).
- Add dependency in 'Cartfile' and 'Package.swift' to NWWebSocket (maintained by Pusher).
- Update SDK and example apps to use NWWebSocket library.
  • Loading branch information
danielrbrowne committed Oct 16, 2020
1 parent 372ae42 commit 3d1bc1c
Show file tree
Hide file tree
Showing 13 changed files with 26 additions and 515 deletions.
1 change: 1 addition & 0 deletions Cartfile
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
github "ashleymills/Reachability.swift" ~> 5.0.0
github "jedisct1/swift-sodium" == 0.8.0
github "pusher/NWWebSocket" ~> 0.2.1
1 change: 1 addition & 0 deletions Cartfile.resolved
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
github "ashleymills/Reachability.swift" "v5.0.0"
github "jedisct1/swift-sodium" "0.8.0"
github "pusher/NWWebSocket" "0.2.1"
2 changes: 2 additions & 0 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,14 @@ let package = Package(
],
dependencies: [
.package(url: "https://github.com/ashleymills/Reachability.swift.git", .upToNextMajor(from: "5.0.0")),
.package(url: "https://github.com/pusher/NWWebSocket.git", .upToNextMajor(from: "0.2.1")),
],
targets: [
.target(
name: "PusherSwift",
dependencies: [
"Reachability",
"NWWebSocket",
],
path: "Sources",
exclude: ["PusherSwiftWithEncryption-Only"]
Expand Down
20 changes: 2 additions & 18 deletions PusherSwift.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,10 @@
33C40CB91C1DFC9C008A54E3 /* PusherSwift.h in Headers */ = {isa = PBXBuildFile; fileRef = 33831CD61A9CFFF200B124F1 /* PusherSwift.h */; settings = {ATTRIBUTES = (Public, ); }; };
53140355250A8F7600F3D7BF /* PusherChannelsProtocolCloseCode.swift in Sources */ = {isa = PBXBuildFile; fileRef = 53140354250A8F7600F3D7BF /* PusherChannelsProtocolCloseCode.swift */; };
53140356250A8F7600F3D7BF /* PusherChannelsProtocolCloseCode.swift in Sources */ = {isa = PBXBuildFile; fileRef = 53140354250A8F7600F3D7BF /* PusherChannelsProtocolCloseCode.swift */; };
53140358250B8A9F00F3D7BF /* WebSocket.swift in Sources */ = {isa = PBXBuildFile; fileRef = 53140357250B8A9F00F3D7BF /* WebSocket.swift */; };
53140359250B8A9F00F3D7BF /* WebSocket.swift in Sources */ = {isa = PBXBuildFile; fileRef = 53140357250B8A9F00F3D7BF /* WebSocket.swift */; };
536F96B8252C841000D2C2F4 /* WebSocketTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 536F96B7252C841000D2C2F4 /* WebSocketTests.swift */; };
536F96B9252C841000D2C2F4 /* WebSocketTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 536F96B7252C841000D2C2F4 /* WebSocketTests.swift */; };
539D9AFC2507F67300B5765A /* PusherLogger.swift in Sources */ = {isa = PBXBuildFile; fileRef = 539D9AFB2507F67300B5765A /* PusherLogger.swift */; };
539D9AFE2507F68400B5765A /* Constants.swift in Sources */ = {isa = PBXBuildFile; fileRef = 539D9AFD2507F68400B5765A /* Constants.swift */; };
539D9AFF2507F69400B5765A /* Constants.swift in Sources */ = {isa = PBXBuildFile; fileRef = 539D9AFD2507F68400B5765A /* Constants.swift */; };
539D9B002507F69B00B5765A /* PusherLogger.swift in Sources */ = {isa = PBXBuildFile; fileRef = 539D9AFB2507F67300B5765A /* PusherLogger.swift */; };
539D9B05250913B300B5765A /* WebSocketConnection.swift in Sources */ = {isa = PBXBuildFile; fileRef = 539D9B04250913B300B5765A /* WebSocketConnection.swift */; };
539D9B06250913B300B5765A /* WebSocketConnection.swift in Sources */ = {isa = PBXBuildFile; fileRef = 539D9B04250913B300B5765A /* WebSocketConnection.swift */; };
736E53F5242A378B0052CC1B /* String+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 736E53F3242A35D90052CC1B /* String+Extensions.swift */; };
736E53F7242A45AC0052CC1B /* XCTest+Assertions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 736E53F6242A45AC0052CC1B /* XCTest+Assertions.swift */; };
73D8A1E72435E5F3001FDE05 /* PusherDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 33BA541F1D9035BD00CD853B /* PusherDelegate.swift */; };
Expand Down Expand Up @@ -148,11 +142,8 @@
33BB99671D21226C00B25C2A /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; name = Info.plist; path = ../Tests/Info.plist; sourceTree = "<group>"; };
33C1FD6E1D81BFC300921AD7 /* ObjectiveC.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ObjectiveC.swift; sourceTree = "<group>"; };
53140354250A8F7600F3D7BF /* PusherChannelsProtocolCloseCode.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PusherChannelsProtocolCloseCode.swift; sourceTree = "<group>"; };
53140357250B8A9F00F3D7BF /* WebSocket.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WebSocket.swift; sourceTree = "<group>"; };
536F96B7252C841000D2C2F4 /* WebSocketTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WebSocketTests.swift; sourceTree = "<group>"; };
539D9AFB2507F67300B5765A /* PusherLogger.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PusherLogger.swift; sourceTree = "<group>"; };
539D9AFD2507F68400B5765A /* Constants.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Constants.swift; sourceTree = "<group>"; };
539D9B04250913B300B5765A /* WebSocketConnection.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WebSocketConnection.swift; sourceTree = "<group>"; };
736E53F3242A35D90052CC1B /* String+Extensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "String+Extensions.swift"; sourceTree = "<group>"; };
736E53F6242A45AC0052CC1B /* XCTest+Assertions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "XCTest+Assertions.swift"; sourceTree = "<group>"; };
73D8A1FE2435E5F3001FDE05 /* PusherSwiftWithEncryption.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = PusherSwiftWithEncryption.framework; sourceTree = BUILT_PRODUCTS_DIR; };
Expand Down Expand Up @@ -275,7 +266,6 @@
3390D1E71F054D1E00E1944D /* Authorizer.swift */,
3390D1E51F054D0400E1944D /* AuthRequestBuilderProtocol.swift */,
33BA541F1D9035BD00CD853B /* PusherDelegate.swift */,
539D9B04250913B300B5765A /* WebSocketConnection.swift */,
);
path = Protocols;
sourceTree = "<group>";
Expand All @@ -292,7 +282,6 @@
E2B21F06243F5B860049A35B /* PusherEvent.swift */,
3389F5751CAEDE2800563F49 /* PusherGlobalChannel.swift */,
3389F56D1CAEDDD800563F49 /* PusherPresenceChannel.swift */,
53140357250B8A9F00F3D7BF /* WebSocket.swift */,
);
path = Models;
sourceTree = "<group>";
Expand Down Expand Up @@ -408,7 +397,6 @@
3342F3BB1D808AC500C0296E /* ClientEventTests.swift */,
33BB99611D21226C00B25C2A /* PresenceChannelTests.swift */,
33BB99621D21226C00B25C2A /* PusherChannelTests.swift */,
536F96B7252C841000D2C2F4 /* WebSocketTests.swift */,
);
path = Models;
sourceTree = "<group>";
Expand Down Expand Up @@ -651,6 +639,7 @@
);
inputPaths = (
Reachability,
NWWebSocket,
);
name = "Copy Carthage Frameworks";
outputPaths = (
Expand Down Expand Up @@ -739,6 +728,7 @@
inputPaths = (
Reachability,
Sodium,
NWWebSocket,
);
name = "Copy Carthage Frameworks";
outputPaths = (
Expand All @@ -758,7 +748,6 @@
E26B8606244A079E00735172 /* PusherEncryptionHelpers.swift in Sources */,
539D9AFE2507F68400B5765A /* Constants.swift in Sources */,
E2B21F0A243F5BB50049A35B /* PusherConnection.swift in Sources */,
539D9B05250913B300B5765A /* WebSocketConnection.swift in Sources */,
33BA54201D9035BD00CD853B /* PusherDelegate.swift in Sources */,
E2498293231E612700CFBBD6 /* PusherError.swift in Sources */,
73D8A2282435F325001FDE05 /* PusherDecryptor.swift in Sources */,
Expand All @@ -777,7 +766,6 @@
3389F56E1CAEDDD800563F49 /* PusherPresenceChannel.swift in Sources */,
33C1FD6F1D81BFC300921AD7 /* ObjectiveC.swift in Sources */,
3390D1E61F054D0400E1944D /* AuthRequestBuilderProtocol.swift in Sources */,
53140358250B8A9F00F3D7BF /* WebSocket.swift in Sources */,
330D7A6A1CAEDA6C0032FF2C /* PusherSwift.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand All @@ -788,7 +776,6 @@
files = (
73D8A22F2435F393001FDE05 /* PusherEventFactory+DecryptionTests.swift in Sources */,
33BB997A1D21230100B25C2A /* PusherConnectionTests.swift in Sources */,
536F96B8252C841000D2C2F4 /* WebSocketTests.swift in Sources */,
736E53F5242A378B0052CC1B /* String+Extensions.swift in Sources */,
E2F40FA723ED79BC00985C40 /* PusherCryptoTest.swift in Sources */,
33BB99791D21230100B25C2A /* PusherClientInitializationTests.swift in Sources */,
Expand Down Expand Up @@ -816,7 +803,6 @@
E26B8607244A079E00735172 /* PusherEncryptionHelpers.swift in Sources */,
E2B21F0B243F5BB50049A35B /* PusherConnection.swift in Sources */,
73D8A1E72435E5F3001FDE05 /* PusherDelegate.swift in Sources */,
539D9B06250913B300B5765A /* WebSocketConnection.swift in Sources */,
73D8A1E82435E5F3001FDE05 /* PusherError.swift in Sources */,
73D8A2292435F329001FDE05 /* PusherDecryptor.swift in Sources */,
73D8A1EB2435E5F3001FDE05 /* PusherCrypto.swift in Sources */,
Expand All @@ -835,7 +821,6 @@
73D8A1F22435E5F3001FDE05 /* PusherPresenceChannel.swift in Sources */,
73D8A1F32435E5F3001FDE05 /* ObjectiveC.swift in Sources */,
73D8A1F52435E5F3001FDE05 /* AuthRequestBuilderProtocol.swift in Sources */,
53140359250B8A9F00F3D7BF /* WebSocket.swift in Sources */,
73D8A1F62435E5F3001FDE05 /* PusherSwift.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand All @@ -849,7 +834,6 @@
73D8A2102435F24E001FDE05 /* String+Extensions.swift in Sources */,
73D8A2112435F24E001FDE05 /* PusherCryptoTest.swift in Sources */,
D32DBA1B2445BCD60064DA56 /* PrivateEncryptedChannelTests.swift in Sources */,
536F96B9252C841000D2C2F4 /* WebSocketTests.swift in Sources */,
73D8A2122435F24E001FDE05 /* PusherClientInitializationTests.swift in Sources */,
73D8A2132435F24E001FDE05 /* PresenceChannelTests.swift in Sources */,
73D8A2142435F24E001FDE05 /* PusherTopLevelAPITests.swift in Sources */,
Expand Down
17 changes: 9 additions & 8 deletions Sources/Extensions/PusherWebsocketDelegate.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import Foundation
import Network
import NWWebSocket

extension PusherConnection: WebSocketConnectionDelegate {

Expand All @@ -9,7 +10,7 @@ extension PusherConnection: WebSocketConnectionDelegate {
- parameter connection: The websocket that has received the message
- parameter string: The message received over the websocket
*/
func webSocketDidReceiveMessage(connection: WebSocketConnection, string: String) {
public func webSocketDidReceiveMessage(connection: WebSocketConnection, string: String) {
self.delegate?.debugLog?(message: PusherLogger.debug(for: .receivedMessage, context: string))

guard let payload = PusherParser.getPusherEventJSON(from: string),
Expand All @@ -33,7 +34,7 @@ extension PusherConnection: WebSocketConnectionDelegate {

/// Delegate method called when a pong is received over a websocket
/// - Parameter connection: The websocket that has received the pong
func webSocketDidReceivePong(connection: WebSocketConnection) {
public func webSocketDidReceivePong(connection: WebSocketConnection) {
self.delegate?.debugLog?(message: PusherLogger.debug(for: .pongReceived))
resetActivityTimeoutTimer()
}
Expand All @@ -45,9 +46,9 @@ extension PusherConnection: WebSocketConnectionDelegate {
- parameter closeCode: The closure code for the websocket connection.
- parameter reason: Optional further information on the connection closure.
*/
func webSocketDidDisconnect(connection: WebSocketConnection,
closeCode: NWProtocolWebSocket.CloseCode,
reason: Data?) {
public func webSocketDidDisconnect(connection: WebSocketConnection,
closeCode: NWProtocolWebSocket.CloseCode,
reason: Data?) {
// Handles setting channel subscriptions to unsubscribed wheter disconnection
// is intentional or not
if connectionState == .disconnecting || connectionState == .connected {
Expand Down Expand Up @@ -206,15 +207,15 @@ extension PusherConnection: WebSocketConnectionDelegate {

- parameter connection: The websocket that connected
*/
func webSocketDidConnect(connection: WebSocketConnection) {
public func webSocketDidConnect(connection: WebSocketConnection) {
self.socketConnected = true
}

func webSocketDidReceiveMessage(connection: WebSocketConnection, data: Data) {
public func webSocketDidReceiveMessage(connection: WebSocketConnection, data: Data) {
//
}

func webSocketDidReceiveError(connection: WebSocketConnection, error: Error) {
public func webSocketDidReceiveError(connection: WebSocketConnection, error: Error) {
self.delegate?.debugLog?(message: PusherLogger.debug(for: .errorReceived,
context: """
Error (code: \((error as NSError).code)): \(error.localizedDescription)
Expand Down
Loading

0 comments on commit 3d1bc1c

Please sign in to comment.