-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: add WebSocketClient Resolves: none. * Update ConnectingToWebSocket.md
- Loading branch information
1 parent
e1512dc
commit 3fdaeba
Showing
16 changed files
with
130 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# ``WebSocketClient`` | ||
|
||
## Topics | ||
|
||
### Creating a WebSocket Client | ||
|
||
- ``WebSocketClient/init(session:)`` | ||
|
||
### Connecting to a WebSocket | ||
|
||
- ``WebSocket`` | ||
- ``WebSocketMessage`` | ||
- ``WebSocketCloseCode`` | ||
- ``WebSocketCloseHandler`` | ||
- ``WebSocketError`` | ||
- ``WebSocketClient/webSocket(_:_:_:)`` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
// | ||
// WebSocketClient.swift | ||
// RxNetworkKit | ||
// | ||
// Created by Loay Ashraf on 17/05/2024. | ||
// | ||
|
||
import Foundation | ||
|
||
/// Entry point for connecting to WebSocket servers. | ||
public class WebSocketClient { | ||
|
||
/// Principal `Session` object that encapsulates `URLSession` instance. | ||
private let session: Session | ||
/// Principal `URLSession` object used to establish connections to WebSocket servers. | ||
private var urlSession: URLSession { | ||
session.urlSession | ||
} | ||
|
||
/// Creates a `WebSocketClient` instance. | ||
/// | ||
/// - Parameters: | ||
/// - session: `Session` object that encapsulates `URLSession` instance. | ||
public init(session: Session) { | ||
// Initialize manager's properties. | ||
self.session = session | ||
} | ||
|
||
/// Creates a WebSocket object and establishes connection using provided url and protocols. | ||
/// | ||
/// - Parameters: | ||
/// - url: `URL` of websocket server. | ||
/// - protocols: `[String]` websocket connection protocols. | ||
/// - closeHandler: `WebSocketCloseHandler` used to provide close coda and reason upon connection closure. | ||
/// | ||
/// - Returns: `WebSocket` object that represents the connection. | ||
public func webSocket<T: Decodable>(_ url: URL, _ protocols: [String], _ closeHandler: WebSocketCloseHandler) -> WebSocket<T> { | ||
let task = urlSession.webSocketTask(with: url, protocols: protocols) | ||
let webSocket = WebSocket<T>(task: task, closeHandler: closeHandler) | ||
return webSocket | ||
} | ||
|
||
} |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.