Skip to content

Commit

Permalink
Deduplicate resetConnection code to ensure consistency in both paths (#…
Browse files Browse the repository at this point in the history
…399)

* Bump to version 10.1.2

Co-authored-by: Pusher CI <[email protected]>
  • Loading branch information
sonologico and pusher-ci authored Nov 10, 2022
1 parent af91232 commit 98a7b20
Show file tree
Hide file tree
Showing 9 changed files with 30 additions and 37 deletions.
2 changes: 1 addition & 1 deletion PusherSwift.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = 'PusherSwift'
s.version = '10.1.1'
s.version = '10.1.2'
s.summary = 'A Pusher client library in Swift'
s.homepage = 'https://github.com/pusher/pusher-websocket-swift'
s.license = 'MIT'
Expand Down
2 changes: 1 addition & 1 deletion PusherSwiftWithEncryption.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = 'PusherSwiftWithEncryption'
s.version = '10.1.1'
s.version = '10.1.2'
s.summary = 'A Pusher client library in Swift that supports encrypted channels'
s.homepage = 'https://github.com/pusher/pusher-websocket-swift'
s.license = 'MIT'
Expand Down
13 changes: 1 addition & 12 deletions Sources/Extensions/PusherConnection+WebsocketDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -50,18 +50,7 @@ extension PusherConnection: WebSocketConnectionDelegate {
public func webSocketDidDisconnect(connection: WebSocketConnection,
closeCode: NWProtocolWebSocket.CloseCode,
reason: Data?) {
// Handles setting channel subscriptions to unsubscribed whether disconnection
// is intentional or not
if connectionState == .disconnecting || connectionState == .connected {
for (_, channel) in self.channels.channels {
channel.subscribed = false
}
}

self.connectionEstablishedMessageReceived = false
self.socketConnected = false

updateConnectionState(to: .disconnected)
resetConnection()

guard !intentionalDisconnect else {
Logger.shared.debug(for: .intentionalDisconnection)
Expand Down
2 changes: 1 addition & 1 deletion Sources/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<key>CFBundlePackageType</key>
<string>FMWK</string>
<key>CFBundleShortVersionString</key>
<string>10.1.1</string>
<string>10.1.2</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
Expand Down
2 changes: 1 addition & 1 deletion Sources/PusherSwift.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import Foundation
import NWWebSocket

let PROTOCOL = 7
let VERSION = "10.1.1"
let VERSION = "10.1.2"
// swiftlint:disable:next identifier_name
let CLIENT_NAME = "pusher-websocket-swift"

Expand Down
40 changes: 22 additions & 18 deletions Sources/Services/PusherConnection.swift
Original file line number Diff line number Diff line change
Expand Up @@ -343,12 +343,7 @@ import NWWebSocket
}
}

/**
Set the connection state to disconnected, mark channels as unsubscribed,
reset connection-related state to initial state, and initiate reconnect
process
*/
private func resetConnectionAndAttemptReconnect() {
internal func resetConnection() {
if connectionState != .disconnected {
updateConnectionState(to: .disconnected)
}
Expand All @@ -362,7 +357,16 @@ import NWWebSocket
socketConnected = false
connectionEstablishedMessageReceived = false
socketId = nil

}

/**
Set the connection state to disconnected, mark channels as unsubscribed,
reset connection-related state to initial state, and initiate reconnect
process
*/
private func resetConnectionAndAttemptReconnect() {
resetConnection()

guard !intentionalDisconnect else {
return
}
Expand Down Expand Up @@ -463,7 +467,7 @@ import NWWebSocket
}
}
}

let subscriptionEvent = event.copy(withEventName: Constants.Events.Pusher.subscriptionSucceeded)
callGlobalCallbacks(event: subscriptionEvent)
chan.handleEvent(event: subscriptionEvent)
Expand Down Expand Up @@ -553,21 +557,21 @@ import NWWebSocket
Logger.shared.debug(for: .unableToRemoveMemberFromChannel)
}
}

/**
Handle subscription count event

- parameter event: The event to be processed
*/

private func handleSubscriptionCountEvent(event: PusherEvent) {
guard let channelName = event.channelName,
let channel = self.channels.find(name: channelName),
let subscriptionCountData = event.dataToJSONObject() as? [String: Any],
let count = subscriptionCountData[Constants.JSONKeys.subscriptionCount] as? Int else {
return
}

channel.updateSubscriptionCount(count: count)
}

Expand Down Expand Up @@ -628,7 +632,7 @@ import NWWebSocket

case Constants.Events.PusherInternal.memberRemoved:
handleMemberRemovedEvent(event: event)

case Constants.Events.PusherInternal.subscriptionCount:
handleSubscriptionCountEvent(event: event)

Expand All @@ -652,14 +656,14 @@ import NWWebSocket
}

/**
Uses the appropriate authentication method to authenticate subscriptions to private and
Uses the appropriate authorization method to authorize subscriptions to private and
presence channels

- parameter channel: The PusherChannel to authenticate
- parameter auth: A PusherAuth value if subscription is being made to an
authenticated channel without using the default auth methods
- parameter channel: The PusherChannel to authorize
- parameter auth: A PusherAuth value if subscription is being made to a
channel without using the default authorization method

- returns: A Bool indicating whether or not the authentication request was made
- returns: A Bool indicating whether or not the authorization request was made
successfully
*/
private func authorize(_ channel: PusherChannel, auth: PusherAuth? = nil) -> Bool {
Expand Down
2 changes: 1 addition & 1 deletion Tests/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<key>CFBundlePackageType</key>
<string>BNDL</string>
<key>CFBundleShortVersionString</key>
<string>10.1.1</string>
<string>10.1.2</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
Expand Down
2 changes: 1 addition & 1 deletion Tests/Integration/PusherClientInitializationTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import XCTest

@testable import PusherSwift

let VERSION = "10.1.1"
let VERSION = "10.1.2"

class ClientInitializationTests: XCTestCase {
private var key: String!
Expand Down
2 changes: 1 addition & 1 deletion Tests/Integration/PusherTopLevelAPITests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,6 @@ class PusherTopLevelApiTests: XCTestCase {

let chan = pusher.subscribe(TestObjects.Event.testChannelName)
connectionDelegate.registerCallback(connectionState: ConnectionState.disconnected) {
XCTAssertFalse(chan.subscribed)
disconnected.fulfill()
}

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

pusher.connect()
waitForExpectations(timeout: 0.5)
XCTAssertFalse(chan.subscribed)
}

/* subscribing to channels when already connected */
Expand Down

0 comments on commit 98a7b20

Please sign in to comment.