Skip to content

Commit a52e13a

Browse files
authored
Merge pull request #255 from olha-danylova/master
7.0.1
2 parents e14b3aa + 94640fa commit a52e13a

File tree

16 files changed

+137
-147
lines changed

16 files changed

+137
-147
lines changed

BackendlessSwift.podspec

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
Pod::Spec.new do |s|
22
s.name = 'BackendlessSwift'
33
s.module_name = 'Backendless'
4-
s.version = '7.0.0'
5-
s.source = { :git => 'https://github.com/Backendless/Swift-SDK.git', :tag => '7.0.0' }
4+
s.version = '7.0.1'
5+
s.source = { :git => 'https://github.com/Backendless/Swift-SDK.git', :tag => '7.0.1' }
66
s.license = { :type => 'MIT', :text => 'Copyright (c) 2013-2023 by Backendless Corp' }
77
s.homepage = 'http://backendless.com'
88
s.authors = { 'Mark Piller' => '[email protected]', 'Olha Danylova' => '[email protected]' }
@@ -13,9 +13,9 @@ Pod::Spec.new do |s|
1313
'SWIFT_VERSION' => '5.0'
1414
}
1515

16-
s.ios.deployment_target = '11.0'
16+
s.ios.deployment_target = '12.0'
1717
s.osx.deployment_target = '10.13'
18-
s.tvos.deployment_target = '11.0'
18+
s.tvos.deployment_target = '12.0'
1919
s.watchos.deployment_target = '5.0'
2020
s.requires_arc = true
2121
s.source_files = 'Sources/SwiftSDK/**/*.swift', 'Sources/SwiftSDK/*.swift', 'Tests/SwiftSDKTests/TestObjects/*.swift'

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# RELEASE HISTORY
22

3+
### 7.0.1 / September 21, 2023
4+
* fixed RT issue when user was able to subscribe only for one messaging channel
5+
* some deprecated code was updated under the hood
6+
* minimal iOS and tvOS versions changed to 12.0
7+
38
### 7.0.0 / July 25, 2023
49
* added implementation for BackendlessExpression
510

Package.resolved

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Package.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ let package = Package(
99
.library(name: "Backendless", targets: ["SwiftSDK"]),
1010
],
1111
dependencies: [
12-
.package(name: "SocketIO", url: "https://github.com/socketio/socket.io-client-swift", from: "16.0.1")
12+
.package(name: "SocketIO", url: "https://github.com/socketio/socket.io-client-swift", from: "16.1.0")
1313
],
1414
targets: [
1515
.target(name: "SwiftSDK", dependencies: ["SocketIO"]),

Podfile

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
platform :ios, '11.0'
1+
platform :ios, '12.0'
22

33
target 'SwiftSDK' do
44
use_frameworks!
@@ -8,15 +8,14 @@ target 'SwiftSDK' do
88
inherit! :search_paths
99
pod 'Socket.IO-Client-Swift', '~> 16.0'
1010
end
11-
1211
end
1312

1413
post_install do |installer|
15-
installer.generated_projects.each do |project|
16-
project.targets.each do |target|
17-
target.build_configurations.each do |config|
18-
config.build_settings['IPHONEOS_DEPLOYMENT_TARGET'] = '11.0'
19-
end
20-
end
21-
end
14+
installer.generated_projects.each do |project|
15+
project.targets.each do |target|
16+
target.build_configurations.each do |config|
17+
config.build_settings['IPHONEOS_DEPLOYMENT_TARGET'] = '12.0'
18+
end
19+
end
20+
end
2221
end

Sources/.DS_Store

0 Bytes
Binary file not shown.

Sources/SwiftSDK/Messaging/RT/Channel.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ import Foundation
4040
}
4141
if !self.isJoined {
4242
self.rt?.connect(responseHandler: {
43-
self.isJoined = true
43+
self.isJoined = true
4444
self.rt?.processConnectSubscriptions()
4545
self.rt?.subscribeForWaiting()
4646
}, errorHandler: { fault in

Sources/SwiftSDK/Messaging/RT/RTMessaging.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ class RTMessaging: RTListener {
3535
func connect(responseHandler: (() -> Void)!, errorHandler: ((Fault) -> Void)!) {
3636
let options = ["channel": channelName] as [String : Any]
3737
let subscription = createSubscription(type: RtTypes.pubSubConnect, options: options, connectionHandler: responseHandler, responseHandler: nil, errorHandler: errorHandler)
38-
self.subscriptionId = subscription.subscriptionId
38+
self.subscriptionId = subscription.subscriptionId
3939
subscription.subscribe()
4040
}
4141

@@ -253,7 +253,7 @@ class RTMessaging: RTListener {
253253
}
254254

255255
func processConnectSubscriptions() {
256-
if var connectSubscriptions = RTClient.shared.getSimpleListeners(type: RtTypes.pubSubConnect) {
256+
if var connectSubscriptions = RTClient.shared.getSimpleListeners(type: RtTypes.pubSubConnect) {
257257
connectSubscriptions = connectSubscriptions.filter({ $0.options?.contains(where: { $0.value as? String == self.channelName }) ?? false })
258258
for subscription in connectSubscriptions {
259259
subscription.onResult!(nil)

Sources/SwiftSDK/RT/RTClient.swift

Lines changed: 33 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ class RTClient {
3232
private var socket: SocketIOClient?
3333
private var socketManager: SocketManager?
3434
private var subscriptions: [String : RTSubscription]
35+
private var subscribedOnConnect = [String]()
3536
private var eventSubscriptions: [String : [RTSubscription]]
3637
private var methods: [String : RTMethodRequest]
3738
var socketCreated = false
@@ -41,7 +42,6 @@ class RTClient {
4142
private var onResultReady = false
4243
private var onMethodResultReady = false
4344
private var onDisconnectCalledOnce = false
44-
private var _lock: NSLock
4545
private var reconnectAttempt: Int = 1
4646
private var timeInterval: Double = 0.2 // seconds
4747
var onSocketConnectCallback: (() -> Void)?
@@ -51,9 +51,9 @@ class RTClient {
5151
private init() {
5252
self.waitingSubscriptions = [RTSubscription]()
5353
self.subscriptions = [String : RTSubscription]()
54+
self.subscribedOnConnect = [String]()
5455
self.eventSubscriptions = [String : [RTSubscription]]()
5556
self.methods = [String : RTMethodRequest]()
56-
_lock = NSLock()
5757
}
5858

5959
func connectSocket(connected: (() -> Void)!) {
@@ -68,11 +68,11 @@ class RTClient {
6868
let path = "/" + Backendless.shared.getApplicationId()
6969

7070
var clientId = ""
71-
#if os(iOS) || os(tvOS)
71+
#if os(iOS) || os(tvOS)
7272
clientId = DeviceHelper.shared.deviceId
73-
#elseif os(OSX)
73+
#elseif os(OSX)
7474
clientId = DeviceHelper.shared.deviceId
75-
#endif
75+
#endif
7676

7777
var connectParams = ["apiKey": Backendless.shared.getApiKey(), "clientId": clientId]
7878
if let userToken = UserDefaultsHelper.shared.getUserToken() {
@@ -88,7 +88,7 @@ class RTClient {
8888
let _ = Backendless.shared.rt.addConnectErrorEventListener(responseHandler: { _ in
8989
self.tryToReconnectSocket()
9090
})
91-
91+
9292
if self.socket != nil {
9393
self.socketOnceCreated = true
9494
self.socketCreated = true
@@ -119,23 +119,22 @@ class RTClient {
119119
}
120120

121121
func subscribe(data: [String : Any], subscription: RTSubscription) {
122-
if self.socketConnected {
123-
self.socket?.emit("SUB_ON", data)
124-
}
125-
else {
126-
self.connectSocket(connected: {
127-
self.socket?.emit("SUB_ON", data)
128-
})
129-
}
130122
if !self.needResubscribe {
131123
self.subscriptions[subscription.subscriptionId!] = subscription
132124
}
125+
if !self.socketConnected {
126+
self.connectSocket(connected: { })
127+
}
128+
else if !self.subscribedOnConnect.contains(subscription.subscriptionId!) {
129+
self.socket?.emit("SUB_ON", data)
130+
}
133131
}
134132

135133
func unsubscribe(subscriptionId: String) {
136134
if self.subscriptions.keys.contains(subscriptionId) {
137135
self.socket?.emit("SUB_OFF", ["id": subscriptionId])
138136
self.subscriptions.removeValue(forKey: subscriptionId)
137+
self.subscribedOnConnect.removeAll { $0 == subscriptionId }
139138
}
140139
else {
141140
for type in self.eventSubscriptions.keys {
@@ -180,15 +179,24 @@ class RTClient {
180179
let type = subscription.type,
181180
let options = subscription.options {
182181
let data = ["id": subscriptionId, "name": type, "options": options] as [String : Any]
183-
self.subscribe(data: data, subscription: subscription)
182+
self.socket?.emit("SUB_ON", data)
184183
}
185184
}
186185
self.needResubscribe = false
187186
}
188187
else if !self.needResubscribe {
189188
connected()
189+
for subscriptionId in self.subscriptions.keys {
190+
if let subscription = self.subscriptions[subscriptionId],
191+
let type = subscription.type,
192+
let options = subscription.options {
193+
let data = ["id": subscriptionId, "name": type, "options": options] as [String : Any]
194+
self.socket?.emit("SUB_ON", data)
195+
self.subscribedOnConnect.append(subscriptionId)
196+
}
197+
}
190198
}
191-
199+
192200
self.onResult()
193201
self.onMethodResult()
194202

@@ -201,7 +209,7 @@ class RTClient {
201209
self.subscribeForObjectChangesWaiting()
202210
})
203211

204-
self.socket?.on("connect_error", callback: { data, ack in
212+
self.socket?.on("connect_error", callback: { data, ack in
205213
if let reason = data.first as? String {
206214
self.onConnectErrorOrDisconnect(reason: reason, type: ConnectEvents.connectError)
207215
}
@@ -245,7 +253,7 @@ class RTClient {
245253
for subscription in reconnectAttemptSubscriptions {
246254
let attempt = NSNumber(value: self.reconnectAttempt)
247255
let timeout = NSNumber(value: maxTimeInterval * 1000)
248-
let reconnectAttemptObject = ReconnectAttemptObject(attempt: attempt, timeout: timeout)
256+
let reconnectAttemptObject = ReconnectAttemptObject(attempt: attempt, timeout: timeout)
249257
subscription.onResult!(reconnectAttemptObject)
250258
}
251259
}
@@ -274,12 +282,12 @@ class RTClient {
274282
func onResult() {
275283
if !self.onResultReady {
276284
self.socket?.on("SUB_RES", callback: { data, ack in
277-
self.onResultReady = true
285+
self.onResultReady = true
278286
if let resultData = data.first as? [String : Any],
279287
let subscriptionId = resultData["id"] as? String,
280288
let subscription = self.subscriptions[subscriptionId] {
281289

282-
if let result = resultData["data"] {
290+
if let result = resultData["data"] {
283291
subscription.ready = true
284292
if let result = result as? String, result == "connected", subscription.onConnect != nil {
285293
subscription.onConnect!()
@@ -331,7 +339,7 @@ class RTClient {
331339
self.methods.removeValue(forKey: methodId)
332340
}
333341
}
334-
else if resultData["id"] != nil, method.onResult != nil {
342+
else if resultData["id"] != nil, method.onResult != nil {
335343
if let result = resultData["result"] {
336344
method.onResult!(result)
337345
}
@@ -361,7 +369,7 @@ class RTClient {
361369
subscriptions = [RTSubscription]()
362370
}
363371
subscriptions?.append(subscription)
364-
eventSubscriptions[type] = subscriptions
372+
eventSubscriptions[type] = subscriptions
365373
}
366374

367375
func getSimpleListeners(type: String) -> [RTSubscription]? {
@@ -391,7 +399,7 @@ class RTClient {
391399

392400
subscriptions?.append(subscription)
393401
eventSubscriptions[type] = subscriptions
394-
return subscription
402+
return subscription
395403
}
396404

397405
func removeEventListeners(type: String) {
@@ -427,8 +435,8 @@ class RTClient {
427435
var indexesToRemove = [Int]() // waiting subscriptions will be removed after subscription is done
428436
for waitingSubscription in waitingSubscriptions {
429437
if let data = waitingSubscription.data,
430-
let name = data["name"] as? String,
431-
(name == RtTypes.objectsChanges || name == RtTypes.relationsChanges) {
438+
let name = data["name"] as? String,
439+
(name == RtTypes.objectsChanges || name == RtTypes.relationsChanges) {
432440
waitingSubscription.subscribe()
433441
indexesToRemove.append(waitingSubscriptions.firstIndex(of: waitingSubscription)!)
434442
}

Sources/SwiftSDK/RT/RTListener.swift

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@ import Foundation
3636

3737
func createSubscription(type: String, options: [String : Any], connectionHandler: (() -> Void)?, responseHandler: ((Any) -> Void)?, errorHandler: ((Fault) -> Void)!) -> RTSubscription {
3838
let subscriptionId = UUID().uuidString
39-
let data = ["id": subscriptionId, "name": type, "options": options] as [String : Any]
39+
let data = ["id": subscriptionId, "name": type, "options": options] as [String : Any]
40+
4041
onStop = { subscription in
4142
var subscriptionStack = [RTSubscription]()
4243
if self.subscriptions[type] != nil {
@@ -76,7 +77,7 @@ import Foundation
7677
subscriptionStack = [RTSubscription]()
7778
}
7879
subscriptionStack?.append(subscription)
79-
self.subscriptions[typeName] = subscriptionStack
80+
self.subscriptions[typeName] = subscriptionStack
8081
return subscription
8182
}
8283

0 commit comments

Comments
 (0)