Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add user agent #349

Merged
merged 1 commit into from
Jul 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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