Skip to content

Commit

Permalink
Merge pull request #9 from srea/feature/reconnect
Browse files Browse the repository at this point in the history
Feature/reconnect
  • Loading branch information
srea authored Dec 23, 2019
2 parents 8c7c580 + 8fba886 commit c37ed79
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
4 changes: 2 additions & 2 deletions RIBsTreeViewerClient.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@
"@executable_path/Frameworks",
"@loader_path/Frameworks",
);
MARKETING_VERSION = 1.0.4;
MARKETING_VERSION = 1.0.5;
PRODUCT_BUNDLE_IDENTIFIER = co.minipro.app.RIBsTreeViewerClient;
PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)";
SKIP_INSTALL = YES;
Expand Down Expand Up @@ -352,7 +352,7 @@
"@executable_path/Frameworks",
"@loader_path/Frameworks",
);
MARKETING_VERSION = 1.0.4;
MARKETING_VERSION = 1.0.5;
PRODUCT_BUNDLE_IDENTIFIER = co.minipro.app.RIBsTreeViewerClient;
PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)";
SKIP_INSTALL = YES;
Expand Down
20 changes: 14 additions & 6 deletions RIBsTreeViewerClient/Sources/RIBsTreeViewer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,7 @@ public class RIBsTreeViewerImpl: RIBsTreeViewer {
let jsonData = try JSONSerialization.data(withJSONObject: $0)
let jsonString = String(bytes: jsonData, encoding: .utf8)!
self?.webSocket.send(text: jsonString)
} catch {
// TODO: Error Handling
} catch let error {
}
})

Expand Down Expand Up @@ -170,20 +169,25 @@ class WebSocketClient: NSObject {
var webSocketTask: URLSessionWebSocketTask!
var urlSession: URLSession!
let delegateQueue = OperationQueue()
let url: URL

init(url: URL) {
self.url = url
super.init()
urlSession = URLSession(configuration: .default, delegate: self, delegateQueue: delegateQueue)
webSocketTask = urlSession.webSocketTask(with: url)
self.urlSession = URLSession(configuration: .default, delegate: self, delegateQueue: delegateQueue)
self.webSocketTask = urlSession.webSocketTask(with: url)
}

func connect() {
if webSocketTask.state == .completed {
webSocketTask = urlSession.webSocketTask(with: url)
}
webSocketTask.resume()
listen()
}

func disconnect() {
webSocketTask.cancel()
webSocketTask.cancel(with: .goingAway, reason: nil)
}

func send(data: Data) {
Expand All @@ -205,7 +209,8 @@ class WebSocketClient: NSObject {
}

private func listen() {
webSocketTask.receive { result in
webSocketTask.receive { [weak self] result in
guard let `self` = self else { return }
switch result {
case .success(let message):
switch message {
Expand Down Expand Up @@ -235,3 +240,6 @@ extension WebSocketClient: URLSessionWebSocketDelegate {
self.delegate?.onDisconnedted(client: self)
}
}

#endif

0 comments on commit c37ed79

Please sign in to comment.