Skip to content

Commit c01b5a7

Browse files
Async API added to iOS package
1 parent 4e1d503 commit c01b5a7

File tree

10 files changed

+260
-80
lines changed

10 files changed

+260
-80
lines changed

packages/streamr-libstreamrproxyclient/.gitignore

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,10 @@
77
wrappers/python/dist
88
wrappers/python/src/streamrproxyclient/libstreamrproxyclient.dylib
99
wrappers/python/src/streamrproxyclient/libstreamrproxyclient.so
10-
dist/*
1110
**/**.dylib
1211
**/**.so
1312
**/wheelhouse/
1413
*.tgz
1514
*.so.*
1615
**/libstreamrproxyclient.[0-9].[0-9].[0-9].dylib
17-
dist/
18-
dist/**
19-
wrappers/python/src/streamrproxyclient/libstreamrproxyclient.dylib
16+
wrappers/python/src/streamrproxyclient/libstreamrproxyclient.dylib

packages/streamr-libstreamrproxyclient/dist/ios-swift-package/StreamrProxyClient/Package.swift

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ let package = Package(
1010
.iOS(.v17)
1111
],
1212
products: [
13+
.library(
14+
name: "StreamrProxyClientActor",
15+
targets: ["StreamrProxyClientActor"]),
1316
.library(
1417
name: "StreamrProxyClient",
1518
targets: ["StreamrProxyClient"]),
@@ -19,6 +22,13 @@ let package = Package(
1922
],
2023

2124
targets: [
25+
.target(
26+
name: "StreamrProxyClientActor",
27+
dependencies: ["StreamrProxyClient"],
28+
linkerSettings: [
29+
.linkedFramework("Foundation")
30+
// Add any other frameworks your library depends on
31+
]),
2232
.target(
2333
name: "StreamrProxyClient",
2434
dependencies: ["streamr", "ProxyClientAPI"],

packages/streamr-libstreamrproxyclient/dist/ios-swift-package/StreamrProxyClient/README.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,35 @@ func test() throws {
8080
}
8181
```
8282

83+
Async API:
84+
85+
```swift
86+
func test() async throws {
87+
// Initialize client
88+
let client = try StreamrProxyClientActor(
89+
ownEthereumAddress: "0x1234567890123456789012345678901234567890",
90+
streamPartId: "0xd2078dc2d780029473a39ce873fc182587be69db/low-level-client#0"
91+
)
92+
93+
// Create proxy configuration
94+
let proxy = StreamrProxyAddress(
95+
websocketUrl: "ws://95.216.15.80:44211",
96+
ethereumAddress: "0xd0d14b38d1f6b59d3772a63d84ece0a79e6e1c1f"
97+
)
98+
99+
// Connect to proxy
100+
let connectResult = await client.connect(proxies: [proxy])
101+
102+
// Check connection result
103+
if connectResult.numConnected > 0 {
104+
// Publish message
105+
let publishResult = await client.publish(
106+
content: "test message",
107+
ethereumPrivateKey: "0x..."
108+
)
109+
}
110+
}
111+
83112
## API Documentation
84113

85114
StreamrProxyClient provides a Swift interface to the C++ StreamrProxyClient library. The interface is defined in the StreamrProxyClientAPI protocol.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
//
2+
// StreamrProxyClientActor.swift
3+
// StreamrProxyClient
4+
//
5+
// Created by Santtu Rantanen on 21.12.2024.
6+
//
7+
import ProxyClientAPI
8+
import StreamrProxyClient
9+
10+
public actor StreamrProxyClientActor {
11+
let client: StreamrProxyClient
12+
13+
public init(ownEthereumAddress: String, streamPartId: String) throws {
14+
self.client = try StreamrProxyClient(
15+
ownEthereumAddress: ownEthereumAddress,
16+
streamPartId: streamPartId
17+
)
18+
}
19+
20+
public init(client: StreamrProxyClient) {
21+
self.client = client
22+
}
23+
24+
public func connect(proxies: [StreamrProxyAddress]) -> StreamrProxyResult {
25+
client.connect(proxies: proxies)
26+
}
27+
28+
public func publish(content: String, ethereumPrivateKey: String) -> StreamrProxyResult {
29+
client.publish(content: content, ethereumPrivateKey: ethereumPrivateKey)
30+
}
31+
}

packages/streamr-libstreamrproxyclient/examples/ios/LocationShare/LocationShare.xcodeproj/project.pbxproj

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,12 @@
2020
413E46F62C7898D40030132D /* PeerDesc.swift in Sources */ = {isa = PBXBuildFile; fileRef = 413E46F52C7898D40030132D /* PeerDesc.swift */; };
2121
4154A2B22CDC93770057D042 /* StreamrProxyClient in Frameworks */ = {isa = PBXBuildFile; productRef = 4154A2B12CDC93770057D042 /* StreamrProxyClient */; };
2222
4154A2B52CDCAFC70057D042 /* ProxyClientTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4154A2B42CDCAFB40057D042 /* ProxyClientTests.swift */; };
23+
41B663952D1650B200281EDB /* ProxyClientAPI in Frameworks */ = {isa = PBXBuildFile; productRef = 41B663942D1650B200281EDB /* ProxyClientAPI */; };
24+
41B663972D1650B200281EDB /* StreamrProxyClient in Frameworks */ = {isa = PBXBuildFile; productRef = 41B663962D1650B200281EDB /* StreamrProxyClient */; };
25+
41B663992D1650B200281EDB /* StreamrProxyClientActor in Frameworks */ = {isa = PBXBuildFile; productRef = 41B663982D1650B200281EDB /* StreamrProxyClientActor */; };
26+
41B6639E2D165AAA00281EDB /* ProxyClientAPI in Frameworks */ = {isa = PBXBuildFile; productRef = 41B6639D2D165AAA00281EDB /* ProxyClientAPI */; };
27+
41B663A02D165AAA00281EDB /* StreamrProxyClient in Frameworks */ = {isa = PBXBuildFile; productRef = 41B6639F2D165AAA00281EDB /* StreamrProxyClient */; };
28+
41B663A22D165AAA00281EDB /* StreamrProxyClientActor in Frameworks */ = {isa = PBXBuildFile; productRef = 41B663A12D165AAA00281EDB /* StreamrProxyClientActor */; };
2329
/* End PBXBuildFile section */
2430

2531
/* Begin PBXContainerItemProxy section */
@@ -63,8 +69,14 @@
6369
isa = PBXFrameworksBuildPhase;
6470
buildActionMask = 2147483647;
6571
files = (
72+
41B663A02D165AAA00281EDB /* StreamrProxyClient in Frameworks */,
6673
412FDA7B2CAF8DC3008DC50E /* libc++abi.tbd in Frameworks */,
74+
41B6639E2D165AAA00281EDB /* ProxyClientAPI in Frameworks */,
75+
41B663972D1650B200281EDB /* StreamrProxyClient in Frameworks */,
76+
41B663992D1650B200281EDB /* StreamrProxyClientActor in Frameworks */,
77+
41B663952D1650B200281EDB /* ProxyClientAPI in Frameworks */,
6778
4154A2B22CDC93770057D042 /* StreamrProxyClient in Frameworks */,
79+
41B663A22D165AAA00281EDB /* StreamrProxyClientActor in Frameworks */,
6880
);
6981
runOnlyForDeploymentPostprocessing = 0;
7082
};
@@ -245,7 +257,7 @@
245257
);
246258
mainGroup = 413E46B62C7867670030132D;
247259
packageReferences = (
248-
418411792CE0BD3C0046B113 /* XCLocalSwiftPackageReference "../../../dist/ios-swift-package/StreamrProxyClient" */,
260+
41B6639C2D165AAA00281EDB /* XCLocalSwiftPackageReference "../../../dist/ios-swift-package/StreamrProxyClient" */,
249261
);
250262
productRefGroup = 413E46C02C7867670030132D /* Products */;
251263
projectDirPath = "";
@@ -639,7 +651,7 @@
639651
/* End XCConfigurationList section */
640652

641653
/* Begin XCLocalSwiftPackageReference section */
642-
418411792CE0BD3C0046B113 /* XCLocalSwiftPackageReference "../../../dist/ios-swift-package/StreamrProxyClient" */ = {
654+
41B6639C2D165AAA00281EDB /* XCLocalSwiftPackageReference "../../../dist/ios-swift-package/StreamrProxyClient" */ = {
643655
isa = XCLocalSwiftPackageReference;
644656
relativePath = "../../../dist/ios-swift-package/StreamrProxyClient";
645657
};
@@ -650,6 +662,30 @@
650662
isa = XCSwiftPackageProductDependency;
651663
productName = StreamrProxyClient;
652664
};
665+
41B663942D1650B200281EDB /* ProxyClientAPI */ = {
666+
isa = XCSwiftPackageProductDependency;
667+
productName = ProxyClientAPI;
668+
};
669+
41B663962D1650B200281EDB /* StreamrProxyClient */ = {
670+
isa = XCSwiftPackageProductDependency;
671+
productName = StreamrProxyClient;
672+
};
673+
41B663982D1650B200281EDB /* StreamrProxyClientActor */ = {
674+
isa = XCSwiftPackageProductDependency;
675+
productName = StreamrProxyClientActor;
676+
};
677+
41B6639D2D165AAA00281EDB /* ProxyClientAPI */ = {
678+
isa = XCSwiftPackageProductDependency;
679+
productName = ProxyClientAPI;
680+
};
681+
41B6639F2D165AAA00281EDB /* StreamrProxyClient */ = {
682+
isa = XCSwiftPackageProductDependency;
683+
productName = StreamrProxyClient;
684+
};
685+
41B663A12D165AAA00281EDB /* StreamrProxyClientActor */ = {
686+
isa = XCSwiftPackageProductDependency;
687+
productName = StreamrProxyClientActor;
688+
};
653689
/* End XCSwiftPackageProductDependency section */
654690
};
655691
rootObject = 413E46B72C7867670030132D /* Project object */;

0 commit comments

Comments
 (0)