Skip to content

Commit 3d1bc1c

Browse files
committed
Migrate native WebSocket client to NWWebSocket library
- 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.
1 parent 372ae42 commit 3d1bc1c

File tree

13 files changed

+26
-515
lines changed

13 files changed

+26
-515
lines changed

Cartfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
github "ashleymills/Reachability.swift" ~> 5.0.0
22
github "jedisct1/swift-sodium" == 0.8.0
3+
github "pusher/NWWebSocket" ~> 0.2.1

Cartfile.resolved

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
github "ashleymills/Reachability.swift" "v5.0.0"
22
github "jedisct1/swift-sodium" "0.8.0"
3+
github "pusher/NWWebSocket" "0.2.1"

Package.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,14 @@ let package = Package(
1010
],
1111
dependencies: [
1212
.package(url: "https://github.com/ashleymills/Reachability.swift.git", .upToNextMajor(from: "5.0.0")),
13+
.package(url: "https://github.com/pusher/NWWebSocket.git", .upToNextMajor(from: "0.2.1")),
1314
],
1415
targets: [
1516
.target(
1617
name: "PusherSwift",
1718
dependencies: [
1819
"Reachability",
20+
"NWWebSocket",
1921
],
2022
path: "Sources",
2123
exclude: ["PusherSwiftWithEncryption-Only"]

PusherSwift.xcodeproj/project.pbxproj

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -32,16 +32,10 @@
3232
33C40CB91C1DFC9C008A54E3 /* PusherSwift.h in Headers */ = {isa = PBXBuildFile; fileRef = 33831CD61A9CFFF200B124F1 /* PusherSwift.h */; settings = {ATTRIBUTES = (Public, ); }; };
3333
53140355250A8F7600F3D7BF /* PusherChannelsProtocolCloseCode.swift in Sources */ = {isa = PBXBuildFile; fileRef = 53140354250A8F7600F3D7BF /* PusherChannelsProtocolCloseCode.swift */; };
3434
53140356250A8F7600F3D7BF /* PusherChannelsProtocolCloseCode.swift in Sources */ = {isa = PBXBuildFile; fileRef = 53140354250A8F7600F3D7BF /* PusherChannelsProtocolCloseCode.swift */; };
35-
53140358250B8A9F00F3D7BF /* WebSocket.swift in Sources */ = {isa = PBXBuildFile; fileRef = 53140357250B8A9F00F3D7BF /* WebSocket.swift */; };
36-
53140359250B8A9F00F3D7BF /* WebSocket.swift in Sources */ = {isa = PBXBuildFile; fileRef = 53140357250B8A9F00F3D7BF /* WebSocket.swift */; };
37-
536F96B8252C841000D2C2F4 /* WebSocketTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 536F96B7252C841000D2C2F4 /* WebSocketTests.swift */; };
38-
536F96B9252C841000D2C2F4 /* WebSocketTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 536F96B7252C841000D2C2F4 /* WebSocketTests.swift */; };
3935
539D9AFC2507F67300B5765A /* PusherLogger.swift in Sources */ = {isa = PBXBuildFile; fileRef = 539D9AFB2507F67300B5765A /* PusherLogger.swift */; };
4036
539D9AFE2507F68400B5765A /* Constants.swift in Sources */ = {isa = PBXBuildFile; fileRef = 539D9AFD2507F68400B5765A /* Constants.swift */; };
4137
539D9AFF2507F69400B5765A /* Constants.swift in Sources */ = {isa = PBXBuildFile; fileRef = 539D9AFD2507F68400B5765A /* Constants.swift */; };
4238
539D9B002507F69B00B5765A /* PusherLogger.swift in Sources */ = {isa = PBXBuildFile; fileRef = 539D9AFB2507F67300B5765A /* PusherLogger.swift */; };
43-
539D9B05250913B300B5765A /* WebSocketConnection.swift in Sources */ = {isa = PBXBuildFile; fileRef = 539D9B04250913B300B5765A /* WebSocketConnection.swift */; };
44-
539D9B06250913B300B5765A /* WebSocketConnection.swift in Sources */ = {isa = PBXBuildFile; fileRef = 539D9B04250913B300B5765A /* WebSocketConnection.swift */; };
4539
736E53F5242A378B0052CC1B /* String+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 736E53F3242A35D90052CC1B /* String+Extensions.swift */; };
4640
736E53F7242A45AC0052CC1B /* XCTest+Assertions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 736E53F6242A45AC0052CC1B /* XCTest+Assertions.swift */; };
4741
73D8A1E72435E5F3001FDE05 /* PusherDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 33BA541F1D9035BD00CD853B /* PusherDelegate.swift */; };
@@ -148,11 +142,8 @@
148142
33BB99671D21226C00B25C2A /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; name = Info.plist; path = ../Tests/Info.plist; sourceTree = "<group>"; };
149143
33C1FD6E1D81BFC300921AD7 /* ObjectiveC.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ObjectiveC.swift; sourceTree = "<group>"; };
150144
53140354250A8F7600F3D7BF /* PusherChannelsProtocolCloseCode.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PusherChannelsProtocolCloseCode.swift; sourceTree = "<group>"; };
151-
53140357250B8A9F00F3D7BF /* WebSocket.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WebSocket.swift; sourceTree = "<group>"; };
152-
536F96B7252C841000D2C2F4 /* WebSocketTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WebSocketTests.swift; sourceTree = "<group>"; };
153145
539D9AFB2507F67300B5765A /* PusherLogger.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PusherLogger.swift; sourceTree = "<group>"; };
154146
539D9AFD2507F68400B5765A /* Constants.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Constants.swift; sourceTree = "<group>"; };
155-
539D9B04250913B300B5765A /* WebSocketConnection.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WebSocketConnection.swift; sourceTree = "<group>"; };
156147
736E53F3242A35D90052CC1B /* String+Extensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "String+Extensions.swift"; sourceTree = "<group>"; };
157148
736E53F6242A45AC0052CC1B /* XCTest+Assertions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "XCTest+Assertions.swift"; sourceTree = "<group>"; };
158149
73D8A1FE2435E5F3001FDE05 /* PusherSwiftWithEncryption.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = PusherSwiftWithEncryption.framework; sourceTree = BUILT_PRODUCTS_DIR; };
@@ -275,7 +266,6 @@
275266
3390D1E71F054D1E00E1944D /* Authorizer.swift */,
276267
3390D1E51F054D0400E1944D /* AuthRequestBuilderProtocol.swift */,
277268
33BA541F1D9035BD00CD853B /* PusherDelegate.swift */,
278-
539D9B04250913B300B5765A /* WebSocketConnection.swift */,
279269
);
280270
path = Protocols;
281271
sourceTree = "<group>";
@@ -292,7 +282,6 @@
292282
E2B21F06243F5B860049A35B /* PusherEvent.swift */,
293283
3389F5751CAEDE2800563F49 /* PusherGlobalChannel.swift */,
294284
3389F56D1CAEDDD800563F49 /* PusherPresenceChannel.swift */,
295-
53140357250B8A9F00F3D7BF /* WebSocket.swift */,
296285
);
297286
path = Models;
298287
sourceTree = "<group>";
@@ -408,7 +397,6 @@
408397
3342F3BB1D808AC500C0296E /* ClientEventTests.swift */,
409398
33BB99611D21226C00B25C2A /* PresenceChannelTests.swift */,
410399
33BB99621D21226C00B25C2A /* PusherChannelTests.swift */,
411-
536F96B7252C841000D2C2F4 /* WebSocketTests.swift */,
412400
);
413401
path = Models;
414402
sourceTree = "<group>";
@@ -651,6 +639,7 @@
651639
);
652640
inputPaths = (
653641
Reachability,
642+
NWWebSocket,
654643
);
655644
name = "Copy Carthage Frameworks";
656645
outputPaths = (
@@ -739,6 +728,7 @@
739728
inputPaths = (
740729
Reachability,
741730
Sodium,
731+
NWWebSocket,
742732
);
743733
name = "Copy Carthage Frameworks";
744734
outputPaths = (
@@ -758,7 +748,6 @@
758748
E26B8606244A079E00735172 /* PusherEncryptionHelpers.swift in Sources */,
759749
539D9AFE2507F68400B5765A /* Constants.swift in Sources */,
760750
E2B21F0A243F5BB50049A35B /* PusherConnection.swift in Sources */,
761-
539D9B05250913B300B5765A /* WebSocketConnection.swift in Sources */,
762751
33BA54201D9035BD00CD853B /* PusherDelegate.swift in Sources */,
763752
E2498293231E612700CFBBD6 /* PusherError.swift in Sources */,
764753
73D8A2282435F325001FDE05 /* PusherDecryptor.swift in Sources */,
@@ -777,7 +766,6 @@
777766
3389F56E1CAEDDD800563F49 /* PusherPresenceChannel.swift in Sources */,
778767
33C1FD6F1D81BFC300921AD7 /* ObjectiveC.swift in Sources */,
779768
3390D1E61F054D0400E1944D /* AuthRequestBuilderProtocol.swift in Sources */,
780-
53140358250B8A9F00F3D7BF /* WebSocket.swift in Sources */,
781769
330D7A6A1CAEDA6C0032FF2C /* PusherSwift.swift in Sources */,
782770
);
783771
runOnlyForDeploymentPostprocessing = 0;
@@ -788,7 +776,6 @@
788776
files = (
789777
73D8A22F2435F393001FDE05 /* PusherEventFactory+DecryptionTests.swift in Sources */,
790778
33BB997A1D21230100B25C2A /* PusherConnectionTests.swift in Sources */,
791-
536F96B8252C841000D2C2F4 /* WebSocketTests.swift in Sources */,
792779
736E53F5242A378B0052CC1B /* String+Extensions.swift in Sources */,
793780
E2F40FA723ED79BC00985C40 /* PusherCryptoTest.swift in Sources */,
794781
33BB99791D21230100B25C2A /* PusherClientInitializationTests.swift in Sources */,
@@ -816,7 +803,6 @@
816803
E26B8607244A079E00735172 /* PusherEncryptionHelpers.swift in Sources */,
817804
E2B21F0B243F5BB50049A35B /* PusherConnection.swift in Sources */,
818805
73D8A1E72435E5F3001FDE05 /* PusherDelegate.swift in Sources */,
819-
539D9B06250913B300B5765A /* WebSocketConnection.swift in Sources */,
820806
73D8A1E82435E5F3001FDE05 /* PusherError.swift in Sources */,
821807
73D8A2292435F329001FDE05 /* PusherDecryptor.swift in Sources */,
822808
73D8A1EB2435E5F3001FDE05 /* PusherCrypto.swift in Sources */,
@@ -835,7 +821,6 @@
835821
73D8A1F22435E5F3001FDE05 /* PusherPresenceChannel.swift in Sources */,
836822
73D8A1F32435E5F3001FDE05 /* ObjectiveC.swift in Sources */,
837823
73D8A1F52435E5F3001FDE05 /* AuthRequestBuilderProtocol.swift in Sources */,
838-
53140359250B8A9F00F3D7BF /* WebSocket.swift in Sources */,
839824
73D8A1F62435E5F3001FDE05 /* PusherSwift.swift in Sources */,
840825
);
841826
runOnlyForDeploymentPostprocessing = 0;
@@ -849,7 +834,6 @@
849834
73D8A2102435F24E001FDE05 /* String+Extensions.swift in Sources */,
850835
73D8A2112435F24E001FDE05 /* PusherCryptoTest.swift in Sources */,
851836
D32DBA1B2445BCD60064DA56 /* PrivateEncryptedChannelTests.swift in Sources */,
852-
536F96B9252C841000D2C2F4 /* WebSocketTests.swift in Sources */,
853837
73D8A2122435F24E001FDE05 /* PusherClientInitializationTests.swift in Sources */,
854838
73D8A2132435F24E001FDE05 /* PresenceChannelTests.swift in Sources */,
855839
73D8A2142435F24E001FDE05 /* PusherTopLevelAPITests.swift in Sources */,

Sources/Extensions/PusherWebsocketDelegate.swift

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import Foundation
22
import Network
3+
import NWWebSocket
34

45
extension PusherConnection: WebSocketConnectionDelegate {
56

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

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

3435
/// Delegate method called when a pong is received over a websocket
3536
/// - Parameter connection: The websocket that has received the pong
36-
func webSocketDidReceivePong(connection: WebSocketConnection) {
37+
public func webSocketDidReceivePong(connection: WebSocketConnection) {
3738
self.delegate?.debugLog?(message: PusherLogger.debug(for: .pongReceived))
3839
resetActivityTimeoutTimer()
3940
}
@@ -45,9 +46,9 @@ extension PusherConnection: WebSocketConnectionDelegate {
4546
- parameter closeCode: The closure code for the websocket connection.
4647
- parameter reason: Optional further information on the connection closure.
4748
*/
48-
func webSocketDidDisconnect(connection: WebSocketConnection,
49-
closeCode: NWProtocolWebSocket.CloseCode,
50-
reason: Data?) {
49+
public func webSocketDidDisconnect(connection: WebSocketConnection,
50+
closeCode: NWProtocolWebSocket.CloseCode,
51+
reason: Data?) {
5152
// Handles setting channel subscriptions to unsubscribed wheter disconnection
5253
// is intentional or not
5354
if connectionState == .disconnecting || connectionState == .connected {
@@ -206,15 +207,15 @@ extension PusherConnection: WebSocketConnectionDelegate {
206207

207208
- parameter connection: The websocket that connected
208209
*/
209-
func webSocketDidConnect(connection: WebSocketConnection) {
210+
public func webSocketDidConnect(connection: WebSocketConnection) {
210211
self.socketConnected = true
211212
}
212213

213-
func webSocketDidReceiveMessage(connection: WebSocketConnection, data: Data) {
214+
public func webSocketDidReceiveMessage(connection: WebSocketConnection, data: Data) {
214215
//
215216
}
216217

217-
func webSocketDidReceiveError(connection: WebSocketConnection, error: Error) {
218+
public func webSocketDidReceiveError(connection: WebSocketConnection, error: Error) {
218219
self.delegate?.debugLog?(message: PusherLogger.debug(for: .errorReceived,
219220
context: """
220221
Error (code: \((error as NSError).code)): \(error.localizedDescription)

0 commit comments

Comments
 (0)