-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add ipf connection state in sample app
- Loading branch information
Showing
4 changed files
with
66 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
Samples/IpfTableApp/DXInstrumentProfileConnectionState+Ext.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
// | ||
// DXInstrumentProfileConnectionState+Ext.swift | ||
// DXFeedFramework | ||
// | ||
// Created by Aleksey Kosylo on 12.09.23. | ||
// | ||
|
||
import Foundation | ||
|
||
public extension DXInstrumentProfileConnectionState { | ||
func convetToString() -> String { | ||
var status = "Not connected 🔴" | ||
switch self { | ||
case .notConnected: | ||
status = "Not connected 🔴" | ||
case .connecting: | ||
status = "Connecting 🟠" | ||
case .connected: | ||
status = "Connected 🟢" | ||
case .closed: | ||
status = "Closed 🔴" | ||
case .completed: | ||
status = "Completed 🟢" | ||
} | ||
return status | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,6 +17,7 @@ class ViewController: UIViewController { | |
|
||
@IBOutlet var ipfTableView: UITableView! | ||
@IBOutlet var lastUpdateLabel: UILabel! | ||
@IBOutlet var connectionStateLbel: UILabel! | ||
|
||
@IBOutlet var addressTextField: UITextField! | ||
|
||
|
@@ -27,6 +28,9 @@ class ViewController: UIViewController { | |
|
||
override func viewDidLoad() { | ||
super.viewDidLoad() | ||
resetConnectionState() | ||
|
||
connectionStateLbel.textColor = .white | ||
addressTextField.text = "https://demo:[email protected]/ipf" | ||
view.backgroundColor = .tableBackground | ||
ipfTableView.backgroundColor = .tableBackground | ||
|
@@ -40,6 +44,7 @@ class ViewController: UIViewController { | |
} | ||
|
||
@IBAction func connectTapped(_ sender: Any) { | ||
resetConnectionState() | ||
collector = nil | ||
connection = nil | ||
do { | ||
|
@@ -51,17 +56,27 @@ class ViewController: UIViewController { | |
try collector?.add(observer: self) | ||
try connection?.start() | ||
// We can wait until we get first full snapshot of instrument profiles | ||
connection?.waitUntilCompleted(3000) | ||
// connection?.waitUntilCompleted(3000) | ||
} catch { | ||
print("Error during creation IPF data source: \(error)") | ||
} | ||
} | ||
func resetConnectionState() { | ||
buffer.removeAll() | ||
ipfList = [InstrumentProfile]() | ||
ipfTableView.reloadData() | ||
lastUpdateLabel.text = "" | ||
connectionStateLbel.text = DXInstrumentProfileConnectionState.notConnected.convetToString() | ||
} | ||
} | ||
|
||
extension ViewController: DXInstrumentProfileConnectionObserver { | ||
func connectionDidChangeState(old: DXFeedFramework.DXInstrumentProfileConnectionState, | ||
new: DXFeedFramework.DXInstrumentProfileConnectionState) { | ||
print("\(CACurrentMediaTime()) connectionDidChangeState: \(new)") | ||
DispatchQueue.main.async { | ||
self.connectionStateLbel.text = new.convetToString() | ||
print("\(CACurrentMediaTime()) connectionDidChangeState: \(new)") | ||
} | ||
} | ||
} | ||
|
||
|