Skip to content

Commit 4a26584

Browse files
Merge pull request #346 from pusher/feature/334-remove-legacy-methods
Removes deprecated legacy 'bind(…)' methods
2 parents af050ec + 571abdc commit 4a26584

10 files changed

+57
-292
lines changed

Sources/Models/PusherChannel.swift

Lines changed: 0 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,6 @@ open class PusherChannel: NSObject {
3535
}
3636
}
3737

38-
internal var shouldParseJSONForLegacyCallbacks: Bool {
39-
return connection?.options.attemptToReturnJSONObject ?? true
40-
}
41-
4238
/**
4339
Initializes a new PusherChannel with a given name and connection
4440

@@ -56,37 +52,6 @@ open class PusherChannel: NSObject {
5652
self.type = PusherChannelType(name: name)
5753
}
5854

59-
/**
60-
Binds a callback to a given event name, scoped to the PusherChannel the function is
61-
called on
62-
63-
- parameter eventName: The name of the event to bind to
64-
- parameter callback: The function to call when a new event is received. The
65-
callback receives the event's data payload
66-
67-
- returns: A unique callbackId that can be used to unbind the callback at a later time
68-
*/
69-
@available(*, deprecated, message: "This will be removed in v10.0.0. Use 'bind(eventName:eventCallback:)' instead.")
70-
@discardableResult open func bind(eventName: String, callback: @escaping (Any?) -> Void) -> String {
71-
return bind(eventName: eventName, eventCallback: { [weak self] (event: PusherEvent) -> Void in
72-
guard let self = self else { return }
73-
// Mimic the old parsing behavior for backwards compatibility
74-
let callbackData: Any?
75-
if self.shouldParseJSONForLegacyCallbacks {
76-
if let data = event.dataToJSONObject() {
77-
// Parsed data
78-
callbackData = data
79-
} else {
80-
// Unparsed string if we couldn't parse
81-
callbackData = event.data
82-
}
83-
} else {
84-
callbackData = event.raw[Constants.JSONKeys.data]
85-
}
86-
callback(callbackData)
87-
})
88-
}
89-
9055
/**
9156
Binds a callback to a given event name, scoped to the PusherChannel the function is
9257
called on

Sources/Models/PusherError.swift

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,6 @@ open class PusherError: NSObject {
1010
/// The error message.
1111
public let message: String
1212

13-
// The websocket payload which needs to passed to legacy callbacks for backwards compatibility
14-
@nonobjc internal let raw: [String: Any]
15-
1613
@nonobjc internal init?(jsonObject: [String: Any]) {
1714
guard let data = jsonObject[Constants.JSONKeys.data] as? [String: Any] else {
1815
return nil
@@ -24,6 +21,5 @@ open class PusherError: NSObject {
2421

2522
self.code = data[Constants.JSONKeys.code] as? Int
2623
self.message = message
27-
self.raw = jsonObject
2824
}
2925
}

Sources/Models/PusherGlobalChannel.swift

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import Foundation
33
@objcMembers
44
@objc open class GlobalChannel: PusherChannel {
55
open var globalCallbacks: [String: (PusherEvent) -> Void] = [:]
6-
open var globalLegacyCallbacks: [String: (Any?) -> Void] = [:]
76

87
/**
98
Initializes a new GlobalChannel instance
@@ -28,17 +27,6 @@ import Foundation
2827
}
2928
}
3029

31-
/**
32-
Calls the appropriate legacy callbacks for the given event name in the scope of the global channel
33-
34-
- parameter event: The JSON object received from the websocket
35-
*/
36-
internal func handleGlobalEventLegacy(event: [String: Any]) {
37-
for (_, callback) in self.globalLegacyCallbacks {
38-
callback(event)
39-
}
40-
}
41-
4230
/**
4331
Binds a callback to the global channel
4432

@@ -52,34 +40,19 @@ import Foundation
5240
return randomId
5341
}
5442

55-
/**
56-
Binds a callback to the global channel
57-
58-
- parameter callback: The function to call when a message is received
59-
60-
- returns: A unique callbackId that can be used to unbind the callback at a later time
61-
*/
62-
internal func bindLegacy(_ callback: @escaping (Any?) -> Void) -> String {
63-
let randomId = UUID().uuidString
64-
self.globalLegacyCallbacks[randomId] = callback
65-
return randomId
66-
}
67-
6843
/**
6944
Unbinds the callback with the given callbackId from the global channel
7045

7146
- parameter callbackId: The unique callbackId string used to identify which callback to unbind
7247
*/
7348
internal func unbind(callbackId: String) {
7449
globalCallbacks.removeValue(forKey: callbackId)
75-
globalLegacyCallbacks.removeValue(forKey: callbackId)
7650
}
7751

7852
/**
7953
Unbinds all callbacks from the channel
8054
*/
8155
override open func unbindAll() {
8256
globalCallbacks = [:]
83-
globalLegacyCallbacks = [:]
8457
}
8558
}

Sources/PusherSwift.swift

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -113,19 +113,6 @@ let CLIENT_NAME = "pusher-websocket-swift"
113113
self.connection.unsubscribeAll()
114114
}
115115

116-
/**
117-
Binds the client's global channel to all events
118-
119-
- parameter callback: The function to call when a new event is received. The callback
120-
receives the event's data payload
121-
122-
- returns: A unique string that can be used to unbind the callback from the client
123-
*/
124-
@available(*, deprecated, message: "This will be removed in v10.0.0. Use 'bind(eventCallback:)' instead.")
125-
@discardableResult open func bind(_ callback: @escaping (Any?) -> Void) -> String {
126-
return self.connection.addLegacyCallbackToGlobalChannel(callback)
127-
}
128-
129116
/**
130117
Binds the client's global channel to all events
131118

Sources/Services/PusherConnection.swift

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -300,17 +300,6 @@ import NWWebSocket
300300
return globalChannel.bind(callback)
301301
}
302302

303-
/**
304-
Add legacy callback to the connection's global channel
305-
306-
- parameter callback: The callback to be stored
307-
308-
- returns: A callbackId that can be used to remove the callback from the connection
309-
*/
310-
internal func addLegacyCallbackToGlobalChannel(_ callback: @escaping (Any?) -> Void) -> String {
311-
return globalChannel.bindLegacy(callback)
312-
}
313-
314303
/**
315304
Remove the callback with id of callbackId from the connection's global channel
316305

@@ -565,7 +554,6 @@ import NWWebSocket
565554
open func handleError(error: PusherError) {
566555
resetActivityTimeoutTimer()
567556
self.delegate?.receivedError?(error: error)
568-
self.globalChannel?.handleGlobalEventLegacy(event: error.raw)
569557
}
570558

571559
/**
@@ -633,7 +621,6 @@ import NWWebSocket
633621
*/
634622
private func callGlobalCallbacks(event: PusherEvent) {
635623
globalChannel?.handleGlobalEvent(event: event)
636-
globalChannel?.handleGlobalEventLegacy(event: event.raw)
637624
}
638625

639626
/**

Tests/Integration/AuthenticationTests.swift

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -125,17 +125,12 @@ class AuthenticationTests: XCTestCase {
125125
let chan = pusher.subscribe("private-test-channel")
126126
XCTAssertFalse(chan.subscribed, "the channel should not be subscribed")
127127

128-
_ = pusher.bind({ (data: Any?) -> Void in
129-
guard let data = data as? [String: AnyObject],
130-
let eventName = data["event"] as? String,
131-
eventName == "pusher:subscription_error" else {
132-
return
133-
}
134-
135-
XCTAssertEqual("private-test-channel", data["channel"] as? String)
128+
pusher.bind { event in
129+
XCTAssertEqual(event.eventName, "pusher:subscription_error")
130+
XCTAssertEqual(event.channelName, "private-test-channel")
136131
XCTAssertTrue(Thread.isMainThread)
137132
ex.fulfill()
138-
})
133+
}
139134

140135
pusher.connect()
141136

0 commit comments

Comments
 (0)