Skip to content

Commit 98a7b20

Browse files
Deduplicate resetConnection code to ensure consistency in both paths (#399)
* Bump to version 10.1.2 Co-authored-by: Pusher CI <[email protected]>
1 parent af91232 commit 98a7b20

9 files changed

+30
-37
lines changed

PusherSwift.podspec

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Pod::Spec.new do |s|
22
s.name = 'PusherSwift'
3-
s.version = '10.1.1'
3+
s.version = '10.1.2'
44
s.summary = 'A Pusher client library in Swift'
55
s.homepage = 'https://github.com/pusher/pusher-websocket-swift'
66
s.license = 'MIT'

PusherSwiftWithEncryption.podspec

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Pod::Spec.new do |s|
22
s.name = 'PusherSwiftWithEncryption'
3-
s.version = '10.1.1'
3+
s.version = '10.1.2'
44
s.summary = 'A Pusher client library in Swift that supports encrypted channels'
55
s.homepage = 'https://github.com/pusher/pusher-websocket-swift'
66
s.license = 'MIT'

Sources/Extensions/PusherConnection+WebsocketDelegate.swift

+1-12
Original file line numberDiff line numberDiff line change
@@ -50,18 +50,7 @@ extension PusherConnection: WebSocketConnectionDelegate {
5050
public func webSocketDidDisconnect(connection: WebSocketConnection,
5151
closeCode: NWProtocolWebSocket.CloseCode,
5252
reason: Data?) {
53-
// Handles setting channel subscriptions to unsubscribed whether disconnection
54-
// is intentional or not
55-
if connectionState == .disconnecting || connectionState == .connected {
56-
for (_, channel) in self.channels.channels {
57-
channel.subscribed = false
58-
}
59-
}
60-
61-
self.connectionEstablishedMessageReceived = false
62-
self.socketConnected = false
63-
64-
updateConnectionState(to: .disconnected)
53+
resetConnection()
6554

6655
guard !intentionalDisconnect else {
6756
Logger.shared.debug(for: .intentionalDisconnection)

Sources/Info.plist

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
<key>CFBundlePackageType</key>
1616
<string>FMWK</string>
1717
<key>CFBundleShortVersionString</key>
18-
<string>10.1.1</string>
18+
<string>10.1.2</string>
1919
<key>CFBundleSignature</key>
2020
<string>????</string>
2121
<key>CFBundleVersion</key>

Sources/PusherSwift.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import Foundation
22
import NWWebSocket
33

44
let PROTOCOL = 7
5-
let VERSION = "10.1.1"
5+
let VERSION = "10.1.2"
66
// swiftlint:disable:next identifier_name
77
let CLIENT_NAME = "pusher-websocket-swift"
88

Sources/Services/PusherConnection.swift

+22-18
Original file line numberDiff line numberDiff line change
@@ -343,12 +343,7 @@ import NWWebSocket
343343
}
344344
}
345345

346-
/**
347-
Set the connection state to disconnected, mark channels as unsubscribed,
348-
reset connection-related state to initial state, and initiate reconnect
349-
process
350-
*/
351-
private func resetConnectionAndAttemptReconnect() {
346+
internal func resetConnection() {
352347
if connectionState != .disconnected {
353348
updateConnectionState(to: .disconnected)
354349
}
@@ -362,7 +357,16 @@ import NWWebSocket
362357
socketConnected = false
363358
connectionEstablishedMessageReceived = false
364359
socketId = nil
365-
360+
}
361+
362+
/**
363+
Set the connection state to disconnected, mark channels as unsubscribed,
364+
reset connection-related state to initial state, and initiate reconnect
365+
process
366+
*/
367+
private func resetConnectionAndAttemptReconnect() {
368+
resetConnection()
369+
366370
guard !intentionalDisconnect else {
367371
return
368372
}
@@ -463,7 +467,7 @@ import NWWebSocket
463467
}
464468
}
465469
}
466-
470+
467471
let subscriptionEvent = event.copy(withEventName: Constants.Events.Pusher.subscriptionSucceeded)
468472
callGlobalCallbacks(event: subscriptionEvent)
469473
chan.handleEvent(event: subscriptionEvent)
@@ -553,21 +557,21 @@ import NWWebSocket
553557
Logger.shared.debug(for: .unableToRemoveMemberFromChannel)
554558
}
555559
}
556-
560+
557561
/**
558562
Handle subscription count event
559-
563+
560564
- parameter event: The event to be processed
561565
*/
562-
566+
563567
private func handleSubscriptionCountEvent(event: PusherEvent) {
564568
guard let channelName = event.channelName,
565569
let channel = self.channels.find(name: channelName),
566570
let subscriptionCountData = event.dataToJSONObject() as? [String: Any],
567571
let count = subscriptionCountData[Constants.JSONKeys.subscriptionCount] as? Int else {
568572
return
569573
}
570-
574+
571575
channel.updateSubscriptionCount(count: count)
572576
}
573577

@@ -628,7 +632,7 @@ import NWWebSocket
628632

629633
case Constants.Events.PusherInternal.memberRemoved:
630634
handleMemberRemovedEvent(event: event)
631-
635+
632636
case Constants.Events.PusherInternal.subscriptionCount:
633637
handleSubscriptionCountEvent(event: event)
634638

@@ -652,14 +656,14 @@ import NWWebSocket
652656
}
653657

654658
/**
655-
Uses the appropriate authentication method to authenticate subscriptions to private and
659+
Uses the appropriate authorization method to authorize subscriptions to private and
656660
presence channels
657661

658-
- parameter channel: The PusherChannel to authenticate
659-
- parameter auth: A PusherAuth value if subscription is being made to an
660-
authenticated channel without using the default auth methods
662+
- parameter channel: The PusherChannel to authorize
663+
- parameter auth: A PusherAuth value if subscription is being made to a
664+
channel without using the default authorization method
661665

662-
- returns: A Bool indicating whether or not the authentication request was made
666+
- returns: A Bool indicating whether or not the authorization request was made
663667
successfully
664668
*/
665669
private func authorize(_ channel: PusherChannel, auth: PusherAuth? = nil) -> Bool {

Tests/Info.plist

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
<key>CFBundlePackageType</key>
1616
<string>BNDL</string>
1717
<key>CFBundleShortVersionString</key>
18-
<string>10.1.1</string>
18+
<string>10.1.2</string>
1919
<key>CFBundleSignature</key>
2020
<string>????</string>
2121
<key>CFBundleVersion</key>

Tests/Integration/PusherClientInitializationTests.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import XCTest
22

33
@testable import PusherSwift
44

5-
let VERSION = "10.1.1"
5+
let VERSION = "10.1.2"
66

77
class ClientInitializationTests: XCTestCase {
88
private var key: String!

Tests/Integration/PusherTopLevelAPITests.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,6 @@ class PusherTopLevelApiTests: XCTestCase {
138138

139139
let chan = pusher.subscribe(TestObjects.Event.testChannelName)
140140
connectionDelegate.registerCallback(connectionState: ConnectionState.disconnected) {
141-
XCTAssertFalse(chan.subscribed)
142141
disconnected.fulfill()
143142
}
144143

@@ -150,6 +149,7 @@ class PusherTopLevelApiTests: XCTestCase {
150149

151150
pusher.connect()
152151
waitForExpectations(timeout: 0.5)
152+
XCTAssertFalse(chan.subscribed)
153153
}
154154

155155
/* subscribing to channels when already connected */

0 commit comments

Comments
 (0)