Skip to content

Commit

Permalink
Update network links (#234)
Browse files Browse the repository at this point in the history
* update the links to point to new more performant endpoints

* update the urls as well

* remove envToUrl

* bump podspec

---------

Co-authored-by: Pat Nakajima <[email protected]>
  • Loading branch information
nplasterer and nakajima authored Feb 6, 2024
1 parent 61d2eb8 commit fb8adfe
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 17 deletions.
8 changes: 0 additions & 8 deletions Sources/XMTPiOS/ApiClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -75,14 +75,6 @@ final class GRPCApiClient: ApiClient {
}
}

static func envToUrl(env: XMTPEnvironment) -> String {
switch env {
case XMTPEnvironment.local: return "http://localhost:5556"
case XMTPEnvironment.dev: return "https://dev.xmtp.network:5556"
case XMTPEnvironment.production: return "https://production.xmtp.network:5556"
}
}

func setAuthToken(_ token: String) {
authToken = token
}
Expand Down
8 changes: 4 additions & 4 deletions Sources/XMTPiOS/Client.swift
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ public final class Client {
public static func create(account: SigningKey, options: ClientOptions? = nil) async throws -> Client {
let options = options ?? ClientOptions()
do {
let client = try await LibXMTP.createV2Client(host: GRPCApiClient.envToUrl(env: options.api.env), isSecure: options.api.env != .local)
let client = try await LibXMTP.createV2Client(host: options.api.env.url, isSecure: options.api.env != .local)
let apiClient = try GRPCApiClient(
environment: options.api.env,
secure: options.api.isSecure,
Expand All @@ -123,7 +123,7 @@ public final class Client {
let dbURL = URL.documentsDirectory.appendingPathComponent("xmtp-\(options?.api.env.rawValue ?? "")-\(address).db3")
let v3Client = try await LibXMTP.createClient(
logger: XMTPLogger(),
host: GRPCApiClient.envToUrl(env: options?.api.env ?? .local),
host: (options?.api.env ?? .local).url,
isSecure: (options?.api.env ?? .local) != .local,
db: dbURL.path,
encryptionKey: options?.mlsEncryptionKey,
Expand Down Expand Up @@ -242,7 +242,7 @@ public final class Client {

let options = options ?? ClientOptions()

let client = try await LibXMTP.createV2Client(host: GRPCApiClient.envToUrl(env: options.api.env), isSecure: options.api.env != .local)
let client = try await LibXMTP.createV2Client(host: options.api.env.url, isSecure: options.api.env != .local)
let apiClient = try GRPCApiClient(
environment: options.api.env,
secure: options.api.isSecure,
Expand Down Expand Up @@ -296,7 +296,7 @@ public final class Client {
public static func canMessage(_ peerAddress: String, options: ClientOptions? = nil) async throws -> Bool {
let options = options ?? ClientOptions()

let client = try await LibXMTP.createV2Client(host: GRPCApiClient.envToUrl(env: options.api.env), isSecure: options.api.env != .local)
let client = try await LibXMTP.createV2Client(host: options.api.env.url, isSecure: options.api.env != .local)
let apiClient = try GRPCApiClient(
environment: options.api.env,
secure: options.api.isSecure,
Expand Down
17 changes: 14 additions & 3 deletions Sources/XMTPiOS/XMTPEnvironment.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,18 @@ import Foundation

/// Contains hosts an `ApiClient` can connect to
public enum XMTPEnvironment: String, Sendable {
case dev = "dev.xmtp.network",
production = "production.xmtp.network",
local = "localhost"
case dev = "grpc.dev.xmtp.network:443",
production = "grpc.production.xmtp.network:443",
local = "localhost:5556"

var url: String {
switch self {
case .dev:
return "https://\(rawValue)"
case .production:
return "https://\(rawValue)"
case .local:
return "http://\(rawValue)"
}
}
}
2 changes: 1 addition & 1 deletion Tests/XMTPTests/IntegrationTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ final class IntegrationTests: XCTestCase {

let authToken = try await authorized.createAuthToken()

let rustClient = try await LibXMTP.createV2Client(host: GRPCApiClient.envToUrl(env: .local), isSecure: false)
let rustClient = try await LibXMTP.createV2Client(host: XMTPEnvironment.local.url, isSecure: false)
let api = try GRPCApiClient(environment: .local, secure: false, rustClient: rustClient)
api.setAuthToken(authToken)

Expand Down
2 changes: 1 addition & 1 deletion XMTP.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -44,5 +44,5 @@ Pod::Spec.new do |spec|
spec.dependency "web3.swift"
spec.dependency "GzipSwift"
spec.dependency "Connect-Swift", "= 0.3.0"
spec.dependency 'LibXMTP', '= 0.4.1-beta0'
spec.dependency 'LibXMTP', '= 0.4.1-beta3'
end

0 comments on commit fb8adfe

Please sign in to comment.