Skip to content

Commit 4229611

Browse files
TroySwanTroy Wenhamt-osawa-009
authored
MonitorMiddleware changes to maintain connection (#12)
* Update Cartfile * Update ScClient.swift * changed MinitorMiddleware to prevent recieving message before client handshake error Co-authored-by: Troy Wenham <troy.wenham@amadeus.com> Co-authored-by: Takuya Ohsawa <7766795+t-osawa-009@users.noreply.github.com>
1 parent a8eddb2 commit 4229611

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

Sources/MonitorMiddleware.swift

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public struct MonitorMiddleware {
4444
queue.maxConcurrentOperationCount = 1
4545
queue.qualityOfService = .default
4646
queue.isSuspended = true
47-
47+
4848
return { dispatch, fetchState in
4949
guard let url = configuration.url else {
5050
fatalError("invalid url")
@@ -53,9 +53,14 @@ public struct MonitorMiddleware {
5353
client.connect()
5454
return { next in
5555
return { action in
56+
if !client.socket.isConnected {
57+
client.connect()
58+
return next(action)
59+
}
5660
next(action)
5761
queue.isSuspended = !client.socket.isConnected
5862
queue.addOperation(SendActionInfoOperation(state: fetchState()!, action: action, client: client))
63+
5964
}
6065
}
6166
}

Sources/ScClient.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -172,8 +172,8 @@ extension ScClient: WebSocketDelegate {
172172
}
173173

174174
public func websocketDidReceiveMessage(socket: WebSocketClient, text: String) {
175-
if (text == "#1") {
176-
socket.write(string: "#2")
175+
if (text == "") {
176+
socket.write(string: "")
177177
} else {
178178
if let messageObject = JSONConverter.deserializeString(message: text) {
179179
if let (data, rid, cid, eventName, error) = Parser.getMessageDetails(myMessage: messageObject) {

0 commit comments

Comments
 (0)