Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add initial connection parameter to WebSocketTransport #1458

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion Sources/ApolloWebSocket/WebSocketTransport.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public class WebSocketTransport {
public static var provider: ApolloWebSocketClient.Type = ApolloWebSocket.self
public weak var delegate: WebSocketTransportDelegate?

let connectOnInit: Bool
let reconnect: Atomic<Bool>
var websocket: ApolloWebSocketClient
let error: Atomic<Error?> = Atomic(nil)
Expand Down Expand Up @@ -103,6 +104,7 @@ public class WebSocketTransport {
/// - Parameter reconnect: Whether to auto reconnect when websocket looses connection. Defaults to true.
/// - Parameter reconnectionInterval: How long to wait before attempting to reconnect. Defaults to half a second.
/// - Parameter allowSendingDuplicates: Allow sending duplicate messages. Important when reconnected. Defaults to true.
/// - Parameter connectOnInit: Whether the websocket connects immediately on creation. If false, remember to call `resumeWebSocketConnection()` to connect. Defaults to true.
/// - Parameter connectingPayload: [optional] The payload to send on connection. Defaults to an empty `GraphQLMap`.
/// - Parameter requestBodyCreator: The `RequestBodyCreator` to use when serializing requests. Defaults to an `ApolloRequestBodyCreator`.
public init(request: URLRequest,
Expand All @@ -112,6 +114,7 @@ public class WebSocketTransport {
reconnect: Bool = true,
reconnectionInterval: TimeInterval = 0.5,
allowSendingDuplicates: Bool = true,
connectOnInit: Bool = true,
designatednerd marked this conversation as resolved.
Show resolved Hide resolved
connectingPayload: GraphQLMap? = [:],
requestBodyCreator: RequestBodyCreator = ApolloRequestBodyCreator()) {
self.connectingPayload = connectingPayload
Expand All @@ -123,9 +126,12 @@ public class WebSocketTransport {
self.websocket = WebSocketTransport.provider.init(request: request, protocols: protocols)
self.clientName = clientName
self.clientVersion = clientVersion
self.connectOnInit = connectOnInit
self.addApolloClientHeaders(to: &self.websocket.request)
self.websocket.delegate = self
self.websocket.connect()
if connectOnInit {
self.websocket.connect()
}
self.websocket.callbackQueue = processingQueue
}

Expand Down