ConnectionState

@frozen
public enum ConnectionState : Codable, Equatable, CustomStringConvertible

A value representing the connection state of the web socket.

Cases

  • 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 becomes true, including when opening the web socket at DatasyncService initialization, this associated value becomes true and the web socket tries to connect to the back-end. It becomes false 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)

Initializers

  • Declaration

    Swift

    public init(from decoder: Decoder) throws

Encodable Protocol

  • Declaration

    Swift

    public func encode(to encoder: Encoder) throws

API

  • 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 be nil 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 subtracting backEndTimeOffsetMS 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, or nil when backEndTimeOffsetMS is itself nil.

  • Converts a back-end-related date to a device-related date.

    This method adjusts the backEndDate by subtracting backEndTimeOffsetMS 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, or nil when backEndTimeOffsetMS is itself nil.

CustomStringConvertible Protocol

  • Declaration

    Swift

    public var description: String { get }