Skip to content

Commit

Permalink
Merge pull request #349 from WalletConnect/user-agent
Browse files Browse the repository at this point in the history
  • Loading branch information
André Vants authored Jul 18, 2022
2 parents ac6a91c + 3be9ea2 commit 01f3c4b
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down
24 changes: 24 additions & 0 deletions Sources/WalletConnectRelay/EnvironmentInfo.swift
Original file line number Diff line number Diff line change
@@ -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)"
}
}
1 change: 1 addition & 0 deletions Sources/WalletConnectRelay/RelayClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)?)
Expand Down
2 changes: 2 additions & 0 deletions Tests/RelayerTests/DispatcherTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)?
Expand Down

0 comments on commit 01f3c4b

Please sign in to comment.