Skip to content

Commit

Permalink
Merge pull request #12 from reown-com/socket-fix
Browse files Browse the repository at this point in the history
socket fix
  • Loading branch information
llbartekll authored Sep 17, 2024
2 parents 42e3fba + 61c93cf commit e10d164
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 7 deletions.
8 changes: 2 additions & 6 deletions Sources/WalletConnectRelay/Dispatching.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ protocol Dispatching {
var isSocketConnected: Bool { get }
var networkConnectionStatusPublisher: AnyPublisher<NetworkConnectionStatus, Never> { get }
var socketConnectionStatusPublisher: AnyPublisher<SocketConnectionStatus, Never> { get }
func send(_ string: String, completion: @escaping (Error?) -> Void)
// func send(_ string: String, completion: @escaping (Error?) -> Void)
func protectedSend(_ string: String, completion: @escaping (Error?) -> Void)
func protectedSend(_ string: String) async throws
func connect() throws
Expand Down Expand Up @@ -58,11 +58,7 @@ final class Dispatcher: NSObject, Dispatching {
setUpWebSocketSession()
}

func send(_ string: String, completion: @escaping (Error?) -> Void) {
guard socket.isConnected else {
completion(NetworkError.connectionFailed)
return
}
private func send(_ string: String, completion: @escaping (Error?) -> Void) {
socket.write(string: string) {
completion(nil)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,7 @@ extension AutomaticSocketConnectionHandler: SocketConnectionHandler {
isConnecting = false
handleFailedConnectionAndReconnectIfNeeded() // Trigger reconnection
}
logger.debug("Will throw an error \(NetworkError.connectionFailed)")
continuation.resume(throwing: NetworkError.connectionFailed)
}
}
Expand Down
2 changes: 1 addition & 1 deletion Tests/RelayerTests/DispatcherTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ final class DispatcherTests: XCTestCase {

func testSendWhileConnected() {
try! sut.connect()
sut.send("1") {_ in}
sut.protectedSend("1") {_ in}
XCTAssertEqual(webSocket.sendCallCount, 1)
}

Expand Down

0 comments on commit e10d164

Please sign in to comment.