ConnectionState
@frozen
public enum ConnectionState : Codable, Equatable, CustomStringConvertible
A value representing the connection state of the web socket.
-
Indicates that the web socket is connected.
The associated value is the time offset in milliseconds of the back-end relative to the device. A positive value (respectively a negative value) indicates that the back-end time is ahead of (respectively behind) the device time.
Declaration
Swift
case connected(backEndTimeOffsetMS: Int)
-
Indicates that the web socket is unconnected.
The first associated value is the last known, if any, time offset in milliseconds of the back-end relative to the device. It is
nil
or non-nil
depending on whether the web socket has already been connected or not. A positive value (respectively a negative value) indicates that the back-end time is ahead of (respectively behind) the device time.The second associated value indicates whether the web socket is initializing. Each time the
DatasyncService.isConnectionEnabled
property becomestrue
, including when opening the web socket atDatasyncService
initialization, this associated value becomestrue
and the web socket tries to connect to the back-end. It becomesfalse
again as the soon as this connection attempt is concluded, whether it succeeded or failed. In case of success, this connection state becomes.connected(backEndTimeOffsetMS:)
. In case of failure, it remains.disconnected(backEndTimeOffsetMS:isInitializing:)
.Declaration
Swift
case disconnected(backEndTimeOffsetMS: Int?, isInitializing: Bool)
-
Declaration
Swift
public init(from decoder: Decoder) throws
-
Declaration
Swift
public func encode(to encoder: Encoder) throws
-
The time offset in milliseconds of the back-end relative to the device.
A positive value (respectively a negative value) indicates that the back-end time is ahead of (respectively behind) the device time.
This property is non-
nil
when this value matches the.connected(backEndTimeOffsetMS:)
case. This property may benil
or non-nil
when this value matches the.disconnected(backEndTimeOffsetMS:isInitializing:)
case, depending on whether the web socket has already been connected or not.Declaration
Swift
public var backEndTimeOffsetMS: Int? { get }
-
Converts a back-end-related date to a device-related date.
This method adjusts the
backEndDate
by subtractingbackEndTimeOffsetMS
from it.Declaration
Swift
public func deviceDate(for backEndDate: Date) -> Date?
Parameters
backEndDate
The back-end-related date to convert.
Return Value
The device-related-date corresponding to
backEndDate
, ornil
whenbackEndTimeOffsetMS
is itselfnil
. -
Converts a back-end-related date to a device-related date.
This method adjusts the
backEndDate
by subtractingbackEndTimeOffsetMS
from it.Declaration
Swift
public func deviceDate(for backEndDate: WebcomDate) -> Date?
Parameters
backEndDate
The back-end-related date to convert.
Return Value
The device-related-date corresponding to
backEndDate
, ornil
whenbackEndTimeOffsetMS
is itselfnil
.
-
Declaration
Swift
public var description: String { get }