Skip to content

Commit

Permalink
Merge pull request #10 from srea/feature/change-option-interface
Browse files Browse the repository at this point in the history
Update Option Interface
  • Loading branch information
srea committed Dec 26, 2019
2 parents e410ed8 + 84caf13 commit 9a03785
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 24 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.5;
MARKETING_VERSION = 1.0.6;
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.5;
MARKETING_VERSION = 1.0.6;
PRODUCT_BUNDLE_IDENTIFIER = co.minipro.app.RIBsTreeViewerClient;
PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)";
SKIP_INSTALL = YES;
Expand Down
43 changes: 21 additions & 22 deletions RIBsTreeViewerClient/Sources/RIBsTreeViewer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,50 +11,49 @@ import RxSwift
import RIBs

public protocol RIBsTreeViewer {
init(router: Routing, option: [RIBsTreeViewerOption: Any]?)
init(router: Routing, options: [RIBsTreeViewerOption]?)
func start()
func stop()
}

public enum RIBsTreeViewerOption {
case webSocketURL
case monitoringInterval
case webSocketURL(String)
case monitoringIntervalMillis(Int)
}

@available(iOS 13.0, *)
public class RIBsTreeViewerImpl: RIBsTreeViewer {

private let router: Routing
private let webSocket: WebSocketClient
private let monitoringIntervalMillis: Int
private var watchingDisposable: Disposable?
private let option: [RIBsTreeViewerOption: Any]?

required public init(router: Routing, option: [RIBsTreeViewerOption: Any]?) {
self.option = option
required public init(router: Routing, options: [RIBsTreeViewerOption]?) {
self.router = router

let webSocketURL: String
if let url = option?[.webSocketURL] as? String {
webSocketURL = url
} else {
webSocketURL = "ws://0.0.0.0:8080"
}
var webSocketURLString = "ws://0.0.0.0:8080"
var monitoringIntervalMillis = 1000

options?.forEach({ option in
switch option {
case .webSocketURL(let url):
webSocketURLString = url
break
case .monitoringIntervalMillis(let intervalMillis):
monitoringIntervalMillis = intervalMillis
break
}
})

self.webSocket = WebSocketClient.init(url: URL(string: webSocketURL)!)
self.monitoringIntervalMillis = monitoringIntervalMillis
self.webSocket = WebSocketClient.init(url: URL(string: webSocketURLString)!)
self.webSocket.delegate = self
}

public func start() {
webSocket.connect()

let watchingInterval: Int
if let interval = option?[.monitoringInterval] as? Int {
watchingInterval = interval
} else {
watchingInterval = 1000
}

watchingDisposable = Observable<Int>.interval(.milliseconds(watchingInterval), scheduler: MainScheduler.instance)
watchingDisposable = Observable<Int>.interval(.milliseconds(monitoringIntervalMillis), scheduler: MainScheduler.instance)
.map { [unowned self] _ in
self.tree(router: self.router)
}
Expand Down

0 comments on commit 9a03785

Please sign in to comment.