diff --git a/Example/IntegrationTests/Relay/RelayClientEndToEndTests.swift b/Example/IntegrationTests/Relay/RelayClientEndToEndTests.swift index 6ec21e45c..12baaea83 100644 --- a/Example/IntegrationTests/Relay/RelayClientEndToEndTests.swift +++ b/Example/IntegrationTests/Relay/RelayClientEndToEndTests.swift @@ -22,6 +22,7 @@ final class RelayClientEndToEndTests: XCTestCase { ) let urlFactory = RelayUrlFactory(socketAuthenticator: socketAuthenticator) let socket = WebSocket(url: urlFactory.create(host: relayHost, projectId: projectId)) + let logger = ConsoleLogger() let dispatcher = Dispatcher(socket: socket, socketConnectionHandler: ManualSocketConnectionHandler(socket: socket), logger: logger) return RelayClient(dispatcher: dispatcher, logger: logger, keyValueStorage: RuntimeKeyValueStorage()) diff --git a/Sources/WalletConnectRelay/EnvironmentInfo.swift b/Sources/WalletConnectRelay/EnvironmentInfo.swift new file mode 100644 index 000000000..51fc372ff --- /dev/null +++ b/Sources/WalletConnectRelay/EnvironmentInfo.swift @@ -0,0 +1,24 @@ +import UIKit + +enum EnvironmentInfo { + + static var userAgent: String { + "\(protocolName)/\(sdkName)/\(operatingSystem)" + } + + static var protocolName: String { + "wc-2" + } + + static var sdkName: String { + "swift-\(sdkVersion)" + } + + static var sdkVersion: String { + "2.0.0-rc.0" // HARDCODED!! Is there a runtime way to get this? + } + + static var operatingSystem: String { + "\(UIDevice.current.systemName)-\(UIDevice.current.systemVersion)" + } +} diff --git a/Sources/WalletConnectRelay/RelayClient.swift b/Sources/WalletConnectRelay/RelayClient.swift index b056b1b08..47dc706b8 100644 --- a/Sources/WalletConnectRelay/RelayClient.swift +++ b/Sources/WalletConnectRelay/RelayClient.swift @@ -76,6 +76,7 @@ public final class RelayClient { host: relayHost, projectId: projectId )) + socket.request.addValue(EnvironmentInfo.userAgent, forHTTPHeaderField: "User-Agent") let socketConnectionHandler: SocketConnectionHandler switch socketConnectionType { case .automatic: diff --git a/Sources/WalletConnectRelay/SocketConnectionHandler/WebSocket.swift b/Sources/WalletConnectRelay/SocketConnectionHandler/WebSocket.swift index 0e7253ad9..fd9d96a56 100644 --- a/Sources/WalletConnectRelay/SocketConnectionHandler/WebSocket.swift +++ b/Sources/WalletConnectRelay/SocketConnectionHandler/WebSocket.swift @@ -5,7 +5,7 @@ public protocol WebSocketConnecting: AnyObject { var onConnect: (() -> Void)? { get set } var onDisconnect: ((Error?) -> Void)? { get set } var onText: ((String) -> Void)? { get set } - + var request: URLRequest { get set } func connect() func disconnect() func write(string: String, completion: (() -> Void)?) diff --git a/Tests/RelayerTests/DispatcherTests.swift b/Tests/RelayerTests/DispatcherTests.swift index 2bfecbfd2..b8d6e1040 100644 --- a/Tests/RelayerTests/DispatcherTests.swift +++ b/Tests/RelayerTests/DispatcherTests.swift @@ -5,6 +5,8 @@ import TestingUtils import Combine class WebSocketMock: WebSocketConnecting { + var request: URLRequest = URLRequest(url: URL(string: "wss://relay.walletconnect.com")!) + var onText: ((String) -> Void)? var onConnect: (() -> Void)?