You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
A Swift package that establishes [WebSocket connections](https://en.wikipedia.org/wiki/WebSocket) and publishes received messages and errors from an [Observable Object](https://developer.apple.com/documentation/combine/observableobject).
10
10
11
11
## Usage
@@ -14,7 +14,7 @@ A Swift package that establishes [WebSocket connections](https://en.wikipedia.or
14
14
15
15
```swift
16
16
let websocketURL =URL(string: "wss://websocket-endpoint.com")!
17
-
let wsClient =ObservableWebSocketClient(websocketURL: websocketURL)
17
+
let wsClient =ObservableWebSocket(websocketURL: websocketURL)
18
18
19
19
/*
20
20
A `URLSessionWebSocketTask` is created and resumed just after the
@@ -67,7 +67,7 @@ Passing in a `pingTimerInterval` during the client initialization will cause a t
67
67
68
68
```swift
69
69
let websocketURL =URL(string: "wss://endpoint.com")!
70
-
let wsClient =ObservableWebSocketClient(
70
+
let wsClient =ObservableWebSocket(
71
71
websocketURL: websocketURL,
72
72
pingTimerInterval: 18, // Every 18 seconds
73
73
pingMessage: "{\"type\": \"ping\"}"// The format is defined by the WS server
@@ -79,7 +79,7 @@ To generate a unique ID for the ping-type message, use the closure in `pingMessa
79
79
80
80
```swift
81
81
let websocketURL =URL(string: "wss://endpoint.com")!
82
-
let wsClient =ObservableWebSocketClient(
82
+
let wsClient =ObservableWebSocket(
83
83
websocketURL: websocketURL,
84
84
pingTimerInterval: 18, // Every 18 seconds
85
85
pingMessageWithGeneratedId: { generatedId in
@@ -89,14 +89,14 @@ let wsClient = ObservableWebSocketClient(
89
89
```
90
90
91
91
### Sending messages
92
-
After the client is initialized and a connection is established, messages can be sent via the `ObservableWebSocketClient.sendMessage(_:)` API:
92
+
After the client is initialized and a connection is established, messages can be sent via the `ObservableWebSocket.sendMessage(_:)` API:
In this demo app, the `ObservableWebSocketClient` connects to a [Kucoin WebSocket server](https://www.kucoin.com/docs/websocket/introduction) and sends `ping` messages every `pingTimerInterval` to keep the connection alive. The server responds with `welcome` and `pong` messages:
99
+
In this demo app, the `ObservableWebSocket` connects to a [Kucoin WebSocket server](https://www.kucoin.com/docs/websocket/introduction) and sends `ping` messages every `pingTimerInterval` to keep the connection alive. The server responds with `welcome` and `pong` messages:
0 commit comments