DatasyncService

public final class DatasyncService : WebcomService
extension DatasyncService: WebcomCombinable

An object representing the Datasync service of a WebcomApplication instance. This service consists of a real-time database with a tree-like data model (equivalent to a JSON object).

To get an object of this type, use the WebcomApplication.datasyncService property of a WebcomApplication instance. There is only one instance of this class for each WebcomApplication instance.

A web socket with the back-end is opened for each instance.

Stored Properties

API

  • The states of the web socket opened by this service.

    Declaration

    Swift

    public var state: DatasyncState { get }
  • Indicates whether the connection of the web socket associated to this service is enabled.

    When an instance is initialized, this property is true. The SDK never modifies it from its own.

    When this property is true, the web socket connects as soon as there is network connectivity and the application is in foreground. When this property is false, the web socket disconnects.

    Declaration

    Swift

    public var isConnectionEnabled: Bool { get set }
  • The cache.

    See WebcomConfiguration.CacheMode for know when this property is usable or not.

    The format of the returned string is opaque. A nil value indicates that the cache could not be retrieved.

    Declaration

    Swift

    public var cache: String? { get }
  • Cleans the cache and stop updating it for all already cancelled subscriptions.

    Calling this method is equivalent to having used the DatasyncCompletedSubscriptionPolicy.forgetData policy for all the DatasyncSubscription instances linked to this service completed so far. However, this has no effect on future cancellations or revocations.

    Declaration

    Swift

    public func cleanCache()
  • Saves the cache.

    See WebcomConfiguration.CacheMode for know when this method is usable or not.

    Declaration

    Swift

    @discardableResult
    public func saveCache() -> Bool
  • Returns a new Datasync manager to manage some database nodes and event subscriptions.

    Declaration

    Swift

    public func createManager(defaultCompletedSubscriptionPolicy: DatasyncCompletedSubscriptionPolicy = .keepData, defaultCallbackQueue: DispatchQueue? = nil, file: StaticString = #fileID, line: UInt = #line) -> DatasyncManager

    Parameters

    defaultCompletedSubscriptionPolicy

    The policy to apply by default to subscriptions created from the returned manager when they are completed.

    defaultCallbackQueue

    The queue used to schedule asynchronous callbacks of methods of nodes created from the returned manager, when no explicit queue is passed to those method calls. When nil, the defaultCallbackQueue of the application from which this service comes is used instead.

    file

    The file from which the method is called. This is used for debugging purposes.

    line

    The line from which the method is called. This is used for debugging purposes.

    Return Value

    A new DatasyncManager instance

  • Starts publishing the presence of the current user.

    A user is said to be present when he/she is authenticated and connected on at least one device. A user is connected when the web socket of the Datasync service is connected with the back-end.

    The presence is represented with the value of a node using an unspecified format. The presence is published until the stopPublishingMyPresence() method is called or the current user become unauthenticated.

    The presence of the user can only be published on one node at a time. When this method is called, any presence publication already started is stopped before processing further.

    Declaration

    Swift

    public func startPublishingMyPresence(on path: String, file: StaticString = #fileID, line: UInt = #line)

    Parameters

    path

    The path of the node where to store the presence status of the current user.

    file

    The file from which the method is called. This is used for debugging purposes.

    line

    The line from which the method is called. This is used for debugging purposes.

  • Stops publishing the presence of the current user.

    When the presence of the current user is currently not published, this method is a no-operation. Use the startPublishingMyPresence(on:file:line:) method to start publishing the presence of the current user.

    Declaration

    Swift

    public func stopPublishingMyPresence()
  • Indicates whether a user is currently present.

    This method is designed to work in concert with the startPublishingMyPresence(on:file:line:) method. This method analyzes the value of a node whose value corresponds to the presence state of another user, in the sense of the latter method.

    Declaration

    Swift

    public func isPresent(state: WebcomPresenceState?) -> Bool

    Parameters

    state

    The value of a node corresponding to the presence state of a user.

    Return Value

    true when nodeValue corresponds to a present user, false otherwise.

Combine Module

  • The type that wraps DatasyncService in order to enrich it with a Combine-based API.

    See also the documentation section of WebcomWrapper for the corresponding wrapped type.

    To use this type, import the following dependency in your code:

    import WebcomCombine
    
    See more

    Declaration

    Swift

    public final class CombineWrapper : WebcomWrapper, Equatable, CustomDebugStringConvertible
  • The wrapping instance, which has a Combine-based API.

    Declaration

    Swift

    public var forCombine: CombineWrapper { get }