Skip to content

Commit 44ce6ec

Browse files
Merge branch 'release/1.1.0'
2 parents 7dc8edf + 4a35f1e commit 44ce6ec

20 files changed

Lines changed: 242 additions & 75 deletions

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
# CHANGELOG
22
All notable changes to this project will be documented in this file.
33

4+
### [1.1.0](https://github.com/Insurlytech/CometDClient-iOS/1.1.0)
5+
6+
* Errors - Create recorder for sharing important errors
7+
* Errors - Refact error to be more precise on the failure
8+
49
### [1.0.0](https://github.com/Insurlytech/CometDClient-iOS/1.0.0)
510

611
* First release of CometD Client for iOS

CometDClient.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
Pod::Spec.new do |spec|
1010
spec.name = "CometDClient"
11-
spec.version = "1.0.0"
11+
spec.version = "1.1.0"
1212
spec.summary = "Swift client for CometD"
1313
spec.description = <<-DESC
1414
CometD is a scalable web event routing bus that allows you to write low-latency, server-side, event-driven web applications. Typical examples of such applications are stock trading applications, web chat applications, online games, and monitoring consoles.

Package.resolved

Lines changed: 1 addition & 1 deletion
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
@@ -15,7 +15,7 @@ let package = Package(
1515
// Dependencies declare other packages that this package depends on.
1616
.package(url: "https://github.com/daltoniam/Starscream.git", .upToNextMajor(from: "4.0.3")),
1717
.package(url: "https://github.com/DaveWoodCom/XCGLogger.git", .upToNextMajor(from: "7.0.0")),
18-
.package(url: "https://github.com/SwiftyJSON/SwiftyJSON.git", .upToNextMajor(from: "4.0.0"))
18+
.package(url: "https://github.com/SwiftyJSON/SwiftyJSON.git", .upToNextMajor(from: "5.0.0"))
1919
],
2020
targets: [
2121
// Targets are the basic building blocks of a package. A target can define a module or a test suite.

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ Check out [Get Started](http://cocoapods.org/) tab on [cocoapods.org](http://coc
1818

1919
To use CometDClient in your 'Podfile':
2020

21-
pod 'CometDClient', '~> 1.0.0'
21+
pod 'CometDClient', '~> 1.1.0'
2222

2323
Then run:
2424

Sources/CometDClient/Bayeux/Models/Bayeux.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,7 @@ public enum Bayeux: String {
2121
case error = "error"
2222
case advice = "advice"
2323
case ext = "ext"
24+
case code = "code"
25+
case message = "message"
26+
case context = "context"
2427
}

Sources/CometDClient/CometdClient.swift

Lines changed: 27 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,13 @@ public class CometdClient: CometdClientContract {
1414
// MARK: Properties
1515
private lazy var bayeuxClient: BayeuxClientContract = BayeuxClient(log: log, timeOut: timeOut)
1616
private lazy var subscriber: SubscriberContract = Subscriber(bayeuxClient: bayeuxClient, log: log)
17-
private lazy var transportAdapter = CometdClientTransportAdapter(bayeuxClient: bayeuxClient, subscriber: subscriber, log: log, delegate: self)
17+
private lazy var transportAdapter = CometdClientTransportAdapter(
18+
bayeuxClient: bayeuxClient,
19+
subscriber: subscriber,
20+
log: log,
21+
delegate: self,
22+
recorder: recorder
23+
)
1824

1925
private var forceSecure = false
2026
/// Default in 10 seconds
@@ -24,6 +30,7 @@ public class CometdClient: CometdClientContract {
2430
public var isConnected: Bool { bayeuxClient.isConnected }
2531
public var clientId: String? { bayeuxClient.clientId }
2632

33+
public private(set) weak var recorder: CometDClientRecorder?
2734
public weak var delegate: CometdClientDelegate?
2835

2936
// MARK: Lifecycle
@@ -36,7 +43,7 @@ public class CometdClient: CometdClientContract {
3643
self.forceSecure = isSecure
3744
}
3845

39-
public func configure(url: String, backoffIncrement: Int = 1000, maxBackoff: Int = 60000, appendMessageTypeToURL: Bool = false) {
46+
public func configure(url: String, backoffIncrement: Int = 1000, maxBackoff: Int = 60000, appendMessageTypeToURL: Bool = false, recorder: CometDClientRecorder?) {
4047
// Check protocol (only websocket for now)
4148
let rawUrl = URL(string: url)
4249
guard let path = rawUrl?.path, let host = rawUrl?.host else {
@@ -52,7 +59,8 @@ public class CometdClient: CometdClientContract {
5259
cometdURLString = scheme + host + path
5360
}
5461

55-
let transport = WebsocketTransport(url: cometdURLString, logLevel: log.outputLevel)
62+
self.recorder = recorder
63+
let transport = WebsocketTransport(url: cometdURLString, logLevel: log.outputLevel, recorder: recorder)
5664
transport.delegate = transportAdapter
5765
self.bayeuxClient.transport = transport
5866
}
@@ -104,13 +112,13 @@ extension CometdClient: CometdClientTransportAdapterDelegate {
104112
delegate?.didReceivePong(from: self)
105113
}
106114
func didWriteError(error: Error, from adapter: CometdClientTransportAdapter) {
107-
delegate?.didWriteError(error: error, from: self)
115+
delegate?.didWriteError(error: CometDClientError.write, from: self)
108116
}
109-
func didFailConnection(error: Error?, from adapter: CometdClientTransportAdapter) {
110-
delegate?.didFailConnection(error: error, from: self)
117+
func didLostConnection(error: Error, from adapter: CometdClientTransportAdapter) {
118+
delegate?.didLostConnection(error: CometDClientError.lostConnection, from: self)
111119
}
112-
func didDisconnected(error: Error?, from adapter: CometdClientTransportAdapter) {
113-
delegate?.didDisconnected(error: error, from: self)
120+
func didDisconnected(error: Error, from adapter: CometdClientTransportAdapter) {
121+
delegate?.didDisconnected(error: CometDClientError.lostConnection, from: self)
114122
}
115123
}
116124

@@ -122,8 +130,15 @@ extension CometdClient: CometdClientMessageResolverDelegate {
122130
func handshakeDidSucceeded(dictionary: NSDictionary, from resolver: CometdClientMessageResolver) {
123131
delegate?.handshakeDidSucceeded(dictionary: dictionary, from: self)
124132
}
125-
func handshakeDidFailed(from resolver: CometdClientMessageResolver) {
126-
delegate?.handshakeDidFailed(from: self)
133+
func handshakeDidFailed(error: Error, from resolver: CometdClientMessageResolver) {
134+
let handshakeError: CometDClientError
135+
switch error {
136+
case let error as CometdClientMessageResolverError where error.code == CometdClientMessageResolverError.Constant.SIMPLE_UNMATCHED_LOGIN_PASSWORD:
137+
handshakeError = .handshake(reason: HandshakeError.wrongCredential)
138+
default:
139+
handshakeError = .handshake(reason: nil)
140+
}
141+
delegate?.handshakeDidFailed(error: handshakeError, from: self)
127142
}
128143
func didDisconnected(from adapter: CometdClientMessageResolver) {
129144
delegate?.didDisconnected(error: nil, from: self)
@@ -140,7 +155,7 @@ extension CometdClient: CometdClientMessageResolverDelegate {
140155
func didUnsubscribeFromChannel(channel: String, from resolver: CometdClientMessageResolver) {
141156
delegate?.didUnsubscribeFromChannel(channel: channel, from: self)
142157
}
143-
func subscriptionFailedWithError(error: SubscriptionError, from resolver: CometdClientMessageResolver) {
144-
delegate?.subscriptionFailedWithError(error: error, from: self)
158+
func subscriptionFailedWithError(error: Error, from resolver: CometdClientMessageResolver) {
159+
delegate?.subscriptionFailedWithError(error: CometDClientError.subscription, from: self)
145160
}
146161
}

Sources/CometDClient/CometdClientContract.swift

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,9 @@ public protocol CometdClientContract: class {
1313
var clientId: String? { get }
1414
var log: XCGLogger { get }
1515
var delegate: CometdClientDelegate? { get set }
16+
var recorder: CometDClientRecorder? { get }
1617

17-
func configure(url: String, backoffIncrement: Int, maxBackoff: Int, appendMessageTypeToURL: Bool)
18+
func configure(url: String, backoffIncrement: Int, maxBackoff: Int, appendMessageTypeToURL: Bool, recorder: CometDClientRecorder?)
1819

1920
func handshake(fields: [String: Any])
2021
func disconnectFromServer()
@@ -30,7 +31,7 @@ public protocol CometdClientContract: class {
3031
}
3132

3233
public extension CometdClientContract {
33-
func configure(url: String) {
34-
configure(url: url, backoffIncrement: 1000, maxBackoff: 60000, appendMessageTypeToURL: false)
34+
func configure(url: String, recorder: CometDClientRecorder?) {
35+
configure(url: url, backoffIncrement: 1000, maxBackoff: 60000, appendMessageTypeToURL: false, recorder: recorder)
3536
}
3637
}

Sources/CometDClient/CometdClientDelegate.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,13 @@ public protocol CometdClientDelegate: class {
1414
func didReceivePong(from client: CometdClientContract)
1515
func didConnected(from client: CometdClientContract)
1616
func handshakeDidSucceeded(dictionary: NSDictionary, from client: CometdClientContract)
17-
func handshakeDidFailed(from client: CometdClientContract)
17+
func handshakeDidFailed(error: Error, from client: CometdClientContract)
1818
func didDisconnected(error: Error?, from client: CometdClientContract)
1919
func didAdvisedToReconnect(from client: CometdClientContract)
20-
func didFailConnection(error: Error?, from client: CometdClientContract)
20+
func didLostConnection(error: Error, from client: CometdClientContract)
2121
func didSubscribeToChannel(channel: String, from client: CometdClientContract)
2222
func didUnsubscribeFromChannel(channel: String, from client: CometdClientContract)
23-
func subscriptionFailedWithError(error: SubscriptionError, from client: CometdClientContract)
23+
func subscriptionFailedWithError(error: Error, from client: CometdClientContract)
2424
func didWriteError(error: Error, from client: CometdClientContract)
2525
}
2626

@@ -29,12 +29,12 @@ public extension CometdClientDelegate {
2929
func didReceivePong(from client: CometdClientContract) { }
3030
func didConnected(from client: CometdClientContract) { }
3131
func handshakeDidSucceeded(dictionary: NSDictionary, from client: CometdClientContract) { }
32-
func handshakeDidFailed(from client: CometdClientContract) { }
32+
func handshakeDidFailed(error: Error, from client: CometdClientContract) { }
3333
func didDisconnected(error: Error?, from client: CometdClientContract) { }
3434
func didAdvisedToReconnect(from client: CometdClientContract) { }
35-
func didFailConnection(error: Error?, from client: CometdClientContract) { }
35+
func didLostConnection(error: Error, from client: CometdClientContract) { }
3636
func didSubscribeToChannel(channel: String, from client: CometdClientContract) { }
3737
func didUnsubscribeFromChannel(channel: String, from client: CometdClientContract) { }
38-
func subscriptionFailedWithError(error: SubscriptionError, from client: CometdClientContract) { }
38+
func subscriptionFailedWithError(error: Error, from client: CometdClientContract) { }
3939
func didWriteError(error: Error, from client: CometdClientContract) { }
4040
}

Sources/CometDClient/CometdClientTransportAdapter.swift

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ import XCGLogger
1212
protocol CometdClientTransportAdapterDelegate: class {
1313
func didReceivePong(from adapter: CometdClientTransportAdapter)
1414
func didWriteError(error: Error, from adapter: CometdClientTransportAdapter)
15-
func didFailConnection(error: Error?, from adapter: CometdClientTransportAdapter)
16-
func didDisconnected(error: Error?, from adapter: CometdClientTransportAdapter)
15+
func didLostConnection(error: Error, from adapter: CometdClientTransportAdapter)
16+
func didDisconnected(error: Error, from adapter: CometdClientTransportAdapter)
1717
}
1818

1919
// MARK: Transport Delegate
@@ -24,22 +24,25 @@ class CometdClientTransportAdapter: TransportDelegate {
2424
private let bayeuxClient: BayeuxClientContract
2525
private let subscriber: SubscriberContract
2626
private let log: XCGLogger
27+
private weak var recorder: CometDClientRecorder?
2728

2829
weak var delegate: Delegate?
2930

3031
private lazy var messageResolver = CometdClientMessageResolver(
3132
bayeuxClient: bayeuxClient,
3233
subscriber: subscriber,
3334
log: log,
34-
delegate: delegate
35+
delegate: delegate,
36+
recorder: recorder
3537
)
3638

3739
// MARK: Lifecycle
38-
init(bayeuxClient: BayeuxClientContract, subscriber: SubscriberContract, log: XCGLogger, delegate: Delegate?) {
40+
init(bayeuxClient: BayeuxClientContract, subscriber: SubscriberContract, log: XCGLogger, delegate: Delegate?, recorder: CometDClientRecorder?) {
3941
self.bayeuxClient = bayeuxClient
4042
self.subscriber = subscriber
4143
self.log = log
4244
self.delegate = delegate
45+
self.recorder = recorder
4346
}
4447

4548
// MARK: TransportDelegate
@@ -49,22 +52,23 @@ class CometdClientTransportAdapter: TransportDelegate {
4952
bayeuxClient.handshake()
5053
}
5154

52-
public func didDisconnect(_ error: Error?) {
55+
56+
func didDisconnect(_ error: Error) {
5357
log.debug("CometdClient didDisconnect")
5458
bayeuxClient.connectionInitiated = false
5559
bayeuxClient.isConnected = false
5660
delegate?.didDisconnected(error: error, from: self)
5761
}
5862

59-
public func didFailConnection(_ error: Error?) {
63+
func didLostConnection(_ error: Error) {
6064
log.warning("CometdClient didFailConnection")
6165
bayeuxClient.connectionInitiated = false
6266
bayeuxClient.isConnected = false
63-
delegate?.didFailConnection(error: error, from: self)
67+
delegate?.didLostConnection(error: error, from: self)
6468
}
6569

66-
public func didWriteError(_ error: Error?) {
67-
delegate?.didWriteError(error: error ?? CometdSocketError.transportWrite, from: self)
70+
func didWriteError(_ error: Error?) {
71+
delegate?.didWriteError(error: error ?? WebsocketTransportError.write(error: nil), from: self)
6872
}
6973

7074
public func didReceiveMessage(_ text: String) {

0 commit comments

Comments
 (0)