Skip to content

Commit

Permalink
add ipf connection state in sample app
Browse files Browse the repository at this point in the history
  • Loading branch information
kosyloa committed Sep 12, 2023
1 parent 276de06 commit e0a7540
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 7 deletions.
4 changes: 4 additions & 0 deletions DXFeedFramework.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
64278C6E2A602D2B0074B5AA /* Candle.swift in Sources */ = {isa = PBXBuildFile; fileRef = 64278C6D2A602D2B0074B5AA /* Candle.swift */; };
64278C702A602FA00074B5AA /* Candle+Ext.swift in Sources */ = {isa = PBXBuildFile; fileRef = 64278C6F2A602FA00074B5AA /* Candle+Ext.swift */; };
64278C722A6030290074B5AA /* CandleMapper.swift in Sources */ = {isa = PBXBuildFile; fileRef = 64278C712A6030290074B5AA /* CandleMapper.swift */; };
6428EF282AB0856400F54F59 /* DXInstrumentProfileConnectionState+Ext.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6428EF272AB0856400F54F59 /* DXInstrumentProfileConnectionState+Ext.swift */; };
642BE4C42A2E1AFF0052340A /* Quote.swift in Sources */ = {isa = PBXBuildFile; fileRef = 642BE4C32A2E1AFF0052340A /* Quote.swift */; };
642BE4C82A2E1BD40052340A /* QuoteMapper.swift in Sources */ = {isa = PBXBuildFile; fileRef = 642BE4C72A2E1BD40052340A /* QuoteMapper.swift */; };
642BE4CA2A2E1C640052340A /* MarketEvent.swift in Sources */ = {isa = PBXBuildFile; fileRef = 642BE4C92A2E1C640052340A /* MarketEvent.swift */; };
Expand Down Expand Up @@ -434,6 +435,7 @@
64278C6D2A602D2B0074B5AA /* Candle.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Candle.swift; sourceTree = "<group>"; };
64278C6F2A602FA00074B5AA /* Candle+Ext.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Candle+Ext.swift"; sourceTree = "<group>"; };
64278C712A6030290074B5AA /* CandleMapper.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CandleMapper.swift; sourceTree = "<group>"; };
6428EF272AB0856400F54F59 /* DXInstrumentProfileConnectionState+Ext.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "DXInstrumentProfileConnectionState+Ext.swift"; sourceTree = "<group>"; };
642BE4C32A2E1AFF0052340A /* Quote.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Quote.swift; sourceTree = "<group>"; };
642BE4C72A2E1BD40052340A /* QuoteMapper.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = QuoteMapper.swift; sourceTree = "<group>"; };
642BE4C92A2E1C640052340A /* MarketEvent.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MarketEvent.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -767,6 +769,7 @@
642DC9262AAA21C000974F5C /* IpfTableApp */ = {
isa = PBXGroup;
children = (
6428EF272AB0856400F54F59 /* DXInstrumentProfileConnectionState+Ext.swift */,
642DC9272AAA21C000974F5C /* AppDelegate.swift */,
642DC9292AAA21C000974F5C /* SceneDelegate.swift */,
642DC92B2AAA21C000974F5C /* ViewController.swift */,
Expand Down Expand Up @@ -1721,6 +1724,7 @@
6464074F2A9F62D4006FF769 /* Date+Ext.swift in Sources */,
6447A5F12A8FDD1B00739CCF /* BitUtil.swift in Sources */,
64963B6A2A8E545C001E40F7 /* IEventType.swift in Sources */,
6428EF282AB0856400F54F59 /* DXInstrumentProfileConnectionState+Ext.swift in Sources */,
640C3FCE2A61788500555161 /* CandleExchange.swift in Sources */,
641BCBBC2A20ED8100FE23C2 /* DXEndpointObserver.swift in Sources */,
64656F772A1DFED9006A0B19 /* EndpointState+Native.swift in Sources */,
Expand Down
23 changes: 18 additions & 5 deletions Samples/IpfTableApp/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,16 @@
<!--View Controller-->
<scene sceneID="tne-QT-ifu">
<objects>
<viewController id="BYZ-38-t0r" customClass="ViewController" customModule="IpfTableApp" customModuleProvider="target" sceneMemberID="viewController">
<viewController id="BYZ-38-t0r" customClass="ViewController" customModule="DXIpfTableApp" customModuleProvider="target" sceneMemberID="viewController">
<view key="view" contentMode="scaleToFill" id="8bC-Xf-vdC">
<rect key="frame" x="0.0" y="0.0" width="393" height="852"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<tableView clipsSubviews="YES" contentMode="scaleToFill" alwaysBounceVertical="YES" dataMode="prototypes" style="plain" separatorStyle="default" allowsSelection="NO" rowHeight="-1" estimatedRowHeight="-1" sectionHeaderHeight="-1" estimatedSectionHeaderHeight="-1" sectionFooterHeight="-1" estimatedSectionFooterHeight="-1" translatesAutoresizingMaskIntoConstraints="NO" id="ZCr-Nz-ChJ">
<rect key="frame" x="10" y="159" width="373" height="609"/>
<rect key="frame" x="10" y="159" width="373" height="589"/>
<color key="backgroundColor" systemColor="systemBackgroundColor"/>
<prototypes>
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" preservesSuperviewLayoutMargins="YES" selectionStyle="default" indentationWidth="10" reuseIdentifier="IpfCellId" id="3O0-l5-3RR" customClass="IpfCell" customModule="IpfTableApp" customModuleProvider="target">
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" preservesSuperviewLayoutMargins="YES" selectionStyle="default" indentationWidth="10" reuseIdentifier="IpfCellId" id="3O0-l5-3RR" customClass="IpfCell" customModule="DXIpfTableApp" customModuleProvider="target">
<rect key="frame" x="0.0" y="50" width="373" height="76.333335876464844"/>
<autoresizingMask key="autoresizingMask"/>
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" preservesSuperviewLayoutMargins="YES" insetsLayoutMarginsFromSafeArea="NO" tableViewCell="3O0-l5-3RR" id="w1E-ah-zfn">
Expand Down Expand Up @@ -92,18 +92,29 @@
</connections>
</button>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="KtK-Uq-c7X">
<rect key="frame" x="15" y="778" width="363" height="30"/>
<rect key="frame" x="15" y="758" width="363" height="30"/>
<constraints>
<constraint firstAttribute="height" constant="30" id="G0X-0Q-cB1"/>
</constraints>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<nil key="textColor"/>
<nil key="highlightedColor"/>
</label>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="gMX-jC-dLE">
<rect key="frame" x="15" y="798" width="363" height="30"/>
<constraints>
<constraint firstAttribute="height" constant="30" id="vOX-iT-Yhy"/>
</constraints>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<nil key="textColor"/>
<nil key="highlightedColor"/>
</label>
</subviews>
<viewLayoutGuide key="safeArea" id="6Tk-OE-BBY"/>
<color key="backgroundColor" systemColor="systemBackgroundColor"/>
<constraints>
<constraint firstItem="gMX-jC-dLE" firstAttribute="top" secondItem="KtK-Uq-c7X" secondAttribute="bottom" constant="10" id="4Xm-eX-KRM"/>
<constraint firstItem="6Tk-OE-BBY" firstAttribute="trailing" secondItem="gMX-jC-dLE" secondAttribute="trailing" constant="15" id="7n9-EU-425"/>
<constraint firstItem="KtK-Uq-c7X" firstAttribute="top" secondItem="ZCr-Nz-ChJ" secondAttribute="bottom" constant="10" id="9C6-L9-Amu"/>
<constraint firstItem="y2L-8f-MGd" firstAttribute="centerY" secondItem="DvD-IW-DUO" secondAttribute="centerY" id="ItQ-dR-I08"/>
<constraint firstItem="ZCr-Nz-ChJ" firstAttribute="top" secondItem="6Tk-OE-BBY" secondAttribute="top" constant="100" id="KeM-bn-WZJ"/>
Expand All @@ -113,14 +124,16 @@
<constraint firstItem="6Tk-OE-BBY" firstAttribute="trailing" secondItem="DvD-IW-DUO" secondAttribute="trailing" constant="10" id="LzD-eG-epw"/>
<constraint firstItem="y2L-8f-MGd" firstAttribute="leading" secondItem="6Tk-OE-BBY" secondAttribute="leading" constant="10" id="Rk3-h6-j4f"/>
<constraint firstItem="DvD-IW-DUO" firstAttribute="leading" secondItem="y2L-8f-MGd" secondAttribute="trailing" constant="15" id="Xug-oV-hv4"/>
<constraint firstItem="6Tk-OE-BBY" firstAttribute="bottom" secondItem="KtK-Uq-c7X" secondAttribute="bottom" constant="10" id="ZWs-AJ-IRv"/>
<constraint firstItem="gMX-jC-dLE" firstAttribute="bottom" secondItem="6Tk-OE-BBY" secondAttribute="bottom" constant="10" id="eMb-Jh-aFT"/>
<constraint firstItem="6Tk-OE-BBY" firstAttribute="trailing" secondItem="KtK-Uq-c7X" secondAttribute="trailing" constant="15" id="esu-8p-kPl"/>
<constraint firstItem="gMX-jC-dLE" firstAttribute="leading" secondItem="6Tk-OE-BBY" secondAttribute="leading" constant="15" id="rDA-Aj-1gU"/>
<constraint firstItem="ZCr-Nz-ChJ" firstAttribute="leading" secondItem="6Tk-OE-BBY" secondAttribute="leading" constant="10" id="sT1-Rd-2fW"/>
<constraint firstItem="y2L-8f-MGd" firstAttribute="top" secondItem="6Tk-OE-BBY" secondAttribute="top" constant="20" id="zGd-j6-8rA"/>
</constraints>
</view>
<connections>
<outlet property="addressTextField" destination="y2L-8f-MGd" id="yTg-Wd-R32"/>
<outlet property="connectionStateLbel" destination="gMX-jC-dLE" id="SSl-Mi-EAM"/>
<outlet property="ipfTableView" destination="ZCr-Nz-ChJ" id="5vo-Qq-0Sc"/>
<outlet property="lastUpdateLabel" destination="KtK-Uq-c7X" id="gUw-cH-k2u"/>
</connections>
Expand Down
27 changes: 27 additions & 0 deletions Samples/IpfTableApp/DXInstrumentProfileConnectionState+Ext.swift
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
}
}
19 changes: 17 additions & 2 deletions Samples/IpfTableApp/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class ViewController: UIViewController {

@IBOutlet var ipfTableView: UITableView!
@IBOutlet var lastUpdateLabel: UILabel!
@IBOutlet var connectionStateLbel: UILabel!

@IBOutlet var addressTextField: UITextField!

Expand All @@ -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
Expand All @@ -40,6 +44,7 @@ class ViewController: UIViewController {
}

@IBAction func connectTapped(_ sender: Any) {
resetConnectionState()
collector = nil
connection = nil
do {
Expand All @@ -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)")
}
}
}

Expand Down

0 comments on commit e0a7540

Please sign in to comment.