9
9
import Foundation
10
10
import Combine
11
11
import Amplify
12
+ @_spi ( WebSocket) import AmplifyNetwork
12
13
13
- @_spi ( AppSyncRTC)
14
- public protocol AppSyncRealTimeClientProtocol {
14
+ protocol AppSyncRealTimeClientProtocol {
15
15
func connect( ) async throws
16
16
func disconnectWhenIdel( ) async
17
17
func disconnect( ) async
@@ -23,8 +23,7 @@ public protocol AppSyncRealTimeClientProtocol {
23
23
The AppSyncRealTimeClient conforms to the AppSync real-time WebSocket protocol.
24
24
ref: https://docs.aws.amazon.com/appsync/latest/devguide/real-time-websocket-client.html
25
25
*/
26
- @_spi ( AppSyncRTC)
27
- public actor AppSyncRealTimeClient : AppSyncRealTimeClientProtocol {
26
+ actor AppSyncRealTimeClient : AppSyncRealTimeClientProtocol {
28
27
29
28
static let jsonEncoder = JSONEncoder ( )
30
29
static let jsonDecoder = JSONDecoder ( )
@@ -59,7 +58,7 @@ public actor AppSyncRealTimeClient: AppSyncRealTimeClientProtocol {
59
58
/// Writable data stream convert WebSocketEvent to AppSyncRealTimeResponse
60
59
internal let subject = PassthroughSubject < AppSyncRealTimeResponse , Never > ( )
61
60
62
- public var isConnected : Bool {
61
+ var isConnected : Bool {
63
62
self . state. value == . connected
64
63
}
65
64
@@ -70,7 +69,7 @@ public actor AppSyncRealTimeClient: AppSyncRealTimeClientProtocol {
70
69
- requestInterceptor: Interceptor for decocating AppSyncRealTimeRequest
71
70
- webSocketClient: WebSocketClient for reading/writing to connection
72
71
*/
73
- public init (
72
+ init (
74
73
endpoint: URL ,
75
74
requestInterceptor: AppSyncRequestInterceptor ,
76
75
webSocketClient: AppSyncWebSocketClientProtocol
@@ -93,7 +92,7 @@ public actor AppSyncRealTimeClient: AppSyncRealTimeClientProtocol {
93
92
/**
94
93
Connecting to remote AppSync real-time server.
95
94
*/
96
- public func connect( ) async throws {
95
+ func connect( ) async throws {
97
96
switch self . state. value {
98
97
case . connecting, . connected:
99
98
log. debug ( " [AppSyncRealTimeClient] client is already connecting or connected " )
@@ -125,7 +124,7 @@ public actor AppSyncRealTimeClient: AppSyncRealTimeClientProtocol {
125
124
/**
126
125
Disconnect only when there are no subscriptions exist.
127
126
*/
128
- public func disconnectWhenIdel( ) async {
127
+ func disconnectWhenIdel( ) async {
129
128
if self . subscriptions. isEmpty {
130
129
log. debug ( " [AppSyncRealTimeClient] no subscription exist, client is trying to disconnect " )
131
130
await disconnect ( )
@@ -137,7 +136,7 @@ public actor AppSyncRealTimeClient: AppSyncRealTimeClientProtocol {
137
136
/**
138
137
Disconnect from AppSync real-time server.
139
138
*/
140
- public func disconnect( ) async {
139
+ func disconnect( ) async {
141
140
guard self . state. value != . disconnecting else {
142
141
log. debug ( " [AppSyncRealTimeClient] client already disconnecting " )
143
142
return
@@ -161,7 +160,7 @@ public actor AppSyncRealTimeClient: AppSyncRealTimeClientProtocol {
161
160
- Returns:
162
161
A never fail data stream for AppSyncSubscriptionEvent.
163
162
*/
164
- public func subscribe( id: String , query: String ) async throws -> AnyPublisher < AppSyncSubscriptionEvent , Never > {
163
+ func subscribe( id: String , query: String ) async throws -> AnyPublisher < AppSyncSubscriptionEvent , Never > {
165
164
log. debug ( " [AppSyncRealTimeClient] Received subscription request id: \( id) , query: \( query) " )
166
165
let subscription = AppSyncRealTimeSubscription ( id: id, query: query, appSyncRealTimeClient: self )
167
166
subscriptions [ id] = subscription
0 commit comments