HAConnection
public protocol HAConnection : AnyObject
The interface for the API itself
See also
HAKit for how to create an instance
-
Handler invoked when a subscription receives a new event
Declaration
Swift
typealias SubscriptionHandler = (HACancellable, HAData) -> Void -
The delegate of the connection
Declaration
Swift
var delegate: HAConnectionDelegate? { get set } -
The current configuration for the connection
Declaration
Swift
var configuration: HAConnectionConfiguration { get set } -
The current state of the connection
Declaration
Swift
var state: HAConnectionState { get } -
Container for caches, either from this library or created externally
Declaration
Swift
var caches: HACachesContainer { get } -
The queue to invoke all handlers on This defaults to
DispatchQueue.mainDeclaration
Swift
var callbackQueue: DispatchQueue { get set } -
Attempt to connect to the server This will attempt immediately and then make retry attempts based on timing and/or reachability and/or application state. Calling connect again without disconnecting will send a ‘ping’ request to verify connection.
Declaration
Swift
func connect() -
Disconnect from the server or end reconnection attempts
Declaration
Swift
func disconnect() -
Send a request
If the connection is currently disconnected, or this request fails to be responded to, this will be reissued in the future until it individually fails or is cancelled.
Declaration
Swift
@discardableResult func send( _ request: HARequest, completion: @escaping RequestCompletion ) -> HACancellableParameters
requestThe request to send; invoked at most once
completionThe handler to invoke on completion
Return Value
A token which can be used to cancel the request
-
Send a request with a concrete response type
If the connection is currently disconnected, or this request fails to be responded to, this will be reissued in the future until it individually fails or is cancelled.
See also
HATypedRequestextensions which create instances of itDeclaration
Swift
@discardableResult func send<T>( _ request: HATypedRequest<T>, completion: @escaping (Result<T, HAError>) -> Void ) -> HACancellableParameters
requestThe request to send; invoked at most once
completionThe handler to invoke on completion
Return Value
A token which can be used to cancel the request
-
Start a subscription to a request
Subscriptions will automatically be restarted if the current connection to the server disconnects and then reconnects.
Declaration
Swift
@discardableResult func subscribe( to request: HARequest, handler: @escaping SubscriptionHandler ) -> HACancellableParameters
requestThe request to send to start the subscription
handlerThe handler to invoke when new events are received for the subscription; invoked many times
Return Value
A token which can be used to cancel the subscription
-
Start a subscription and be notified about its start state
Subscriptions will automatically be restarted if the current connection to the server disconnects and then reconnects. When each restart event occurs, the
initiatedhandler will be invoked again.Declaration
Swift
@discardableResult func subscribe( to request: HARequest, initiated: @escaping SubscriptionInitiatedHandler, handler: @escaping SubscriptionHandler ) -> HACancellableParameters
requestThe request to send to start the subscription
initiatedThe handler to invoke when the subscription’s initial request succeeds or fails; invoked once per underlying WebSocket connection
handlerThe handler to invoke when new events are received for the subscription; invoked many times
-
Start a subscription to a request with a concrete event type
Subscriptions will automatically be restarted if the current connection to the server disconnects and then reconnects.
See also
HATypedSubscriptionextensions which create instances of itDeclaration
Swift
@discardableResult func subscribe<T>( to request: HATypedSubscription<T>, handler: @escaping (HACancellable, T) -> Void ) -> HACancellableParameters
requestThe request to send to start the subscription
handlerThe handler to invoke when new events are received for the subscription; invoked many times
Return Value
A token which can be used to cancel the subscription
-
Start a subscription to a request with a concrete event type
Subscriptions will automatically be restarted if the current connection to the server disconnects and then reconnects. When each restart event occurs, the
initiatedhandler will be invoked again.See also
HATypedSubscriptionextensions which create instances of itDeclaration
Swift
@discardableResult func subscribe<T>( to request: HATypedSubscription<T>, initiated: @escaping SubscriptionInitiatedHandler, handler: @escaping (HACancellable, T) -> Void ) -> HACancellableParameters
requestThe request to send to start the subscription
initiatedThe handler to invoke when the subscription’s initial request succeeds or fails; invoked once per underlying WebSocket connection
handlerThe handler to invoke when new events are received for the subscription; invoked many times
Return Value
A token which can be used to cancel the subscription
View on GitHub