Skip to content

Commit

Permalink
refactor: cosmetic changes
Browse files Browse the repository at this point in the history
  • Loading branch information
pokryfka committed Oct 27, 2023
1 parent 6416588 commit d6ef7f7
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
2 changes: 1 addition & 1 deletion Sources/GraphQLWebSocket/Client.swift
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ public class GraphQLWebSocket: WebSocketDelegate {
switch (self.health, message) {
case (.acknowledged, _), (.disposed, _), (_, .initialise):
// We can send any message when the connection has been ACK and meta messages when the server hasn't ACK the connection yet.
socket.write(data: data) { _ in }
socket.send(data) { _ in }
self.config.logger.debug("\(message.description) sent to the server!")

default:
Expand Down
9 changes: 5 additions & 4 deletions Sources/GraphQLWebSocket/WebSocketClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ import Foundation
public protocol WebSocketClient: AnyObject {
func connect()
func disconnect(closeCode: Int)
func write(string: String, completion: ((Error?) -> ())?)
func write(data: Data, completion: ((Error?) -> ())?)
func send(_ string: String, completion: ((Error?) -> ())?)
func send(_ data: Data, completion: ((Error?) -> ())?)
/// Note that the callback is called after PING is sent and PONG received.
func sendPing(pongReceiveHandler: ((Error?) -> ())?)
}
Expand Down Expand Up @@ -62,6 +62,7 @@ class WebSocket: NSObject, WebSocketClient, URLSessionWebSocketDelegate {

/// Starts receiving incoming messages.
private func receive() {
assert(delegate != nil, "Delegate not set")
socket.receive { [weak self] result in
guard let self else { return }
self.callbackQueue.async {
Expand Down Expand Up @@ -98,14 +99,14 @@ class WebSocket: NSObject, WebSocketClient, URLSessionWebSocketDelegate {
socket.cancel(with: closeCode, reason: nil)
}

func write(string: String, completion: ((Error?) -> ())?) {
func send(_ string: String, completion: ((Error?) -> ())?) {
assert(socket.state == .running)
socket.send(.string(string)) { error in
completion?(error)
}
}

func write(data: Data, completion: ((Error?) -> ())?) {
func send(_ data: Data, completion: ((Error?) -> ())?) {
assert(socket.state == .running)
socket.send(.data(data)) { error in
completion?(error)
Expand Down

0 comments on commit d6ef7f7

Please sign in to comment.