WebcomWrapper

public protocol WebcomWrapper

A type that wraps a callback-based type in order to enrich it with another API.

Requirements

  • The type of the wrapped instance, which has a callback-based API.

    Declaration

    Swift

    associatedtype Wrapped
  • The wrapped instance, which has a callback-based API.

    Declaration

    Swift

    var wrapped: Wrapped { get }
  • authenticationToken Extension method

    The authentication token.

    Declaration

    Swift

    public var authenticationToken: String { get }
  • creationDate Extension method

    The creation date of the user account.

    Declaration

    Swift

    public var creationDate: Date { get }
  • displayName Extension method

    The display name of the user, or nil when it is unavailable.

    Declaration

    Swift

    public var displayName: String? { get }
  • expirationDate Extension method

    The expiration date of the authentication.

    Declaration

    Swift

    public var expirationDate: Date { get }
  • provider Extension method

    The provider of the current identity.

    Declaration

    Swift

    public var provider: AuthenticationProvider { get }
  • providers Extension method

    The providers used to get the different identities, starting from the current one.

    By definition, the resulting array is never empty.

    Declaration

    Swift

    public var providers: [AuthenticationProvider] { get }
  • providerExtra Extension method

    Additional data specific to the provider of the latest identity.

    Typically, an OAuth2 provider may provide confidential data such as access or refresh tokens.

    This property contains technical data while providerExtra contains data about the authenticated user.

    Declaration

    Swift

    public var providerExtra: [String : Any] { get }
  • providerUID Extension method

    The unique identifier of the user for the current identity.

    Declaration

    Swift

    public var providerUID: String { get }
  • providerProfile Extension method

    The profile of the user for the provider of the latest identity.

    This property contains data about the authenticated user while providerExtra contains technical data.

    Declaration

    Swift

    public var providerProfile: [String : Any] { get }
  • previousProviderIdentities Extension method

    The previous provider identities.

    Declaration

    Swift

    public var previousProviderIdentities: [AuthenticationProviderIdentity] { get }
  • uid Extension method

    The unique identifier of the user for the back-end.

    Declaration

    Swift

    public var uid: String { get }
  • eMail Extension method

    The e-mail of the user, or nil when it is unavailable.

    Declaration

    Swift

    public var eMail: String? { get }
  • identity Extension method

    The identity of the user, or nil when it is unavailable.

    When the provider is AuthenticationProvider.internal(_:), the returned value is the providerUID. Otherwise, it is the eMail value.

    Declaration

    Swift

    public var identity: String? { get }
  • avatarURL Extension method

    The URL of an avatar representing the user, or nil when it is unavailable.

    Declaration

    Swift

    public var avatarURL: URL? { get }
  • provider Extension method

    The authentication provider corresponding to this method.

    Declaration

    Swift

    public var provider: AuthenticationProvider { get }
  • internalProvider Extension method

    The provider.

    Declaration

    Swift

    public var internalProvider: AuthenticationProvider.InternalFamily { get }
  • mode Extension method

    The authentication mode.

    Declaration

    Swift

    public var mode: Wrapped.Mode { get }
  • sender Extension method

    The sender to be used by the AuthenticationProvider.InternalFamily.phone provider. When nil, the default sender, defined on the back-end, is used. This parameter is only meaningful when internalProvider is AuthenticationProvider.InternalFamily.phone. Otherwise, this value is ignored.

    Declaration

    Swift

    public var sender: String? { get }
  • identifier Extension method

    The unique identifier of the user for the provider.

    Declaration

    Swift

    public var identifier: String? { get }
  • profile Extension method

    The profile of the user.

    This property is used by the attachIdentity(queue:then:) method.

    It is not designed to store business applicative data about the user. For that purpose, use the DatasyncService.

    Declaration

    Swift

    public var profile: [String : Any] { get nonmutating set }
  • displayName Extension method

    The display name of the user.

    This property is used by the attachIdentity(queue:then:) method.

    Declaration

    Swift

    public var displayName: String? { get nonmutating set }
  • messageLocale Extension method

    The locale used for verification and one-time password messages sent to the user.

    It must be in the ll-CC format, where ll is the ISO 639 alpha-2 code for the language and CC is the ISO 3166 alpha-2 code for the country variant.

    Example: en-US

    When nil, the preferred locale of the user contained in the main bundle is used.

    This property is used by the requestPasswordResetLink(queue:then:), attachIdentity(queue:then:) and requestOneTimePassword(queue:then:) methods.

    Declaration

    Swift

    public var messageLocale: String? { get nonmutating set }
  • passwordResetMessageTemplate Extension method

    The identifier of the template, as defined on the developer console, to use for the password reset message.

    This property is used by the requestPasswordResetLink(queue:then:) method.

    Declaration

    Swift

    public var passwordResetMessageTemplate: String? { get nonmutating set }
  • verificationMessageTemplate Extension method

    The identifier of the template, as defined on the developer console, to use for the verification message.

    This property is used by the attachIdentity(queue:then:) method.

    Declaration

    Swift

    public var verificationMessageTemplate: String? { get nonmutating set }
  • The identifier of the template, as defined on the developer console, to use for the one-time password message.

    This property is used by the requestOneTimePassword(queue:then:) method.

    Declaration

    Swift

    public var oneTimePasswordMessageTemplate: String? { get nonmutating set }
  • setIdentifier(_:) Extension method

    Sets the unique identifier of the user for the provider.

    This method must be called after initializing this instance or just after AuthenticationService.initializeAuthentication(with:context:).

    Declaration

    Swift

    @discardableResult
    public func setIdentifier(_ identifier: String) -> WebcomResult<Void>

    Parameters

    identifier

    The unique identifier of the user for the provider, or nil to set it later.

    Return Value

    A WebcomResult with a void value in case of success or a WebcomError value in case of the failure.

  • setStaticPassword(_:) Extension method

    Sets the static password of the user.

    Only use this method if the authentication mode is Mode.staticPassword.

    Declaration

    Swift

    @discardableResult
    public func setStaticPassword(_ password: String) -> WebcomResult<Void>

    Parameters

    password

    The password of the user.

    Return Value

    A WebcomResult with a void value in case of success or a WebcomError value in case of the failure.

  • setVerificationToken(_:) Extension method

    Sets the verification token sent by the provider for sign-up.

    Only use this method if the authentication mode is Mode.staticPassword. When authentication mode is Mode.oneTimePassword, use the setVerificationOneTimePassword(_:) method instead.

    Declaration

    Swift

    @discardableResult
    public func setVerificationToken(_ token: String) -> WebcomResult<Void>

    Parameters

    token

    The verification token.

    Return Value

    A WebcomResult with a void value in case of success or a WebcomError value in case of the failure.

  • Sets the verification one-time password sent by the provider for sign-up.

    Only use this method if the authentication mode is Mode.oneTimePassword. When authentication mode is Mode.staticPassword, use the setVerificationToken(_:) method instead.

    Declaration

    Swift

    @discardableResult
    public func setVerificationOneTimePassword(_ password: String) -> WebcomResult<Void>

    Parameters

    password

    The verification one-time password.

    Return Value

    A WebcomResult with a void value in case of success or a WebcomError value in case of the failure.

  • setOneTimePassword(_:) Extension method

    Sets the one-time password sent by the provider for sign-in.

    Only use this method when the authentication mode is Mode.oneTimePassword and for sign-in. To set the one-time password for sign-up, use the setVerificationOneTimePassword(_:) method instead. To set the static password for sign-up, use the setStaticPassword(_:) method instead.

    Declaration

    Swift

    @discardableResult
    public func setOneTimePassword(_ password: String) -> WebcomResult<Void>

    Parameters

    password

    The sign-in one-time password.

    Return Value

    A WebcomResult with a void value in case of success or a WebcomError value in case of the failure.

  • ongoingAuthentication Extension method

    The ongoing authentication process.

    This property is nil when there is no ongoing authentication process.

    Declaration

    Swift

    public var ongoingAuthentication: Wrapped.AuthenticationProcess? { get }
  • Initializes an authentication process.

    After using this method, the continueAuthentication(queue:then:) method must be called to continue the authentication process. Some additional steps, depending on the method, may be required between the two.

    The method may be any authentication method, but single-steps ones should better use authenticate(with:queue:then:) directly, since it includes the call to continueAuthentication(queue:then:).

    So, in practice, method should be an instance of AuthenticationMethodInternal.

    Declaration

    Swift

    @discardableResult
    public func initializeAuthentication(with method: AuthenticationMethod, context: AuthenticationService.Context = .new) -> WebcomResult<Void>

    Parameters

    method

    The authentication method to use for the authentication process.

    context

    The context to use for the authentication process.

    Return Value

    A WebcomResult with a void value in case of success or a WebcomError value in case of the failure.

  • Initializes an authentication process.

    After using this method, the continueAuthentication(queue:then:) method must be called to continue the authentication process. Some additional steps, depending on the method, may be required between the two.

    The method may be any authentication method, but single-steps ones should better use authenticate(with:queue:then:) directly, since it includes the call to continueAuthentication(queue:then:).

    So, in practice, method should be a wrapped instance of AuthenticationMethodInternal.

    Declaration

    Swift

    @discardableResult
    public func initializeAuthentication<Method>(with method: Method, context: AuthenticationService.Context = .new) -> WebcomResult<Void> where Method : WebcomWrapper, Method.Wrapped : AuthenticationMethod

    Parameters

    method

    The authentication method to use for the authentication process.

    context

    The context to use for the authentication process.

    Return Value

    A WebcomResult with a void value in case of success or a WebcomError value in case of the failure.

  • cancelAuthentication() Extension method

    Cancels the currently ongoing authentication process.

    When there is no ongoing authentication process, this method is a no-op.

    Declaration

    Swift

    public func cancelAuthentication()
  • Subscribes to authentication events.

    A subscription must always be stored somewhere in order to be cancelled when it is no longer used. Until a subscription is cancelled, it remains active and consumes resources. The easiest way is to let this instance store it by setting the stores parameter to true (which is its default value). Otherwise, the returned subscription instance must be stored by the application.

    Subscriptions stored by a AuthenticationService are cancelled automatically when it is deinitialized.

    They can also be cancelled manually:

    Declaration

    Swift

    @discardableResult
    public func subscribe(stores: Bool = true, file: StaticString = #fileID, line: UInt = #line, queue: DispatchQueue? = nil, onEvent eventCallback: @escaping (_ event: AuthenticationEvent) -> Void, onCompletion completionCallback: (() -> Void)? = nil) -> AuthenticationSubscription?

    Parameters

    stores

    Indicates whether the returned subscription should be stored by this instance.

    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.

    queue

    The queue to which the provided eventCallback and completionCallback dispatch. When nil, the default callback queue of the application of this instance is used.

    eventCallback

    The closure to call when an authentication event occurs.

    event

    The event that occurred.

    completionCallback

    The closure to call when the subscription completes.

    Return Value

    An instance describing the subscription, or nil if the subscription failed.

  • unsubscribeFromAll() Extension method

    Cancels all stored subscriptions.

    Subscriptions are stored by the subscribe(stores:file:line:queue:callback:) method when the stores parameter is set to true (which is its default value).

    Usually, there is no need to call this method since it is done automatically when this instance is deinitialized.

    Declaration

    Swift

    public func unsubscribeFromAll()

Wrapped == DataNode

  • path Extension method

    The absolute path of the node referred by this instance.

    The path consists of the keys of the ancestors of this node, starting from the root of the tree, separated by / (slash) characters. The last segment of the path is the key of this node. The before last segment of the path, if any, is the key of the parent of this node. The path always begins with a /. The path of the root node is "/".

    Declaration

    Swift

    public var path: String { get }
  • key Extension method

    The key of the node represented by this instance.

    It corresponds to the last segment of the path. It does not contain any / (slash) character. The key of the root node is the empty string ("").

    Since

    2.2.0

    Declaration

    Swift

    public var key: WebcomKey { get }

Wrapped == DatasyncManager

  • service Extension method

    The service from which this manager comes.

    Declaration

    Swift

    public var service: DatasyncService { get }
  • The policy applied by default to subscriptions created from this manager when they are completed.

    A specific policy may be applied to a subscription by setting the DatasyncSubscription.completedSubscriptionPolicy property before the completion callback is called.

    Declaration

    Swift

    public var defaultCompletedSubscriptionPolicy: DatasyncCompletedSubscriptionPolicy { get }
  • unsubscribeFromAll() Extension method

    Cancels all stored subscriptions.

    Subscriptions are stored by the DatasyncNode.subscribe(to:childrenConstraint:stores:file:line:queue:onEvent:onCompletion:) method with nodes belonging to this manager instance, when the stores parameter is set to true (which is its default value).

    Usually, there is no need to call this method since it is done automatically when this instance is deinitialized.

    Declaration

    Swift

    public func unsubscribeFromAll()
  • date(fromPushIdentifier:) Extension method

    Returns the creation date of a timestamp-based node key.

    Warning

    This method was deprecated in version 2.2.0. Use pushIdentifier.date instead.

    Declaration

    Swift

    @available(*, deprecated, renamed: "WebcomKey.date")
    public func date(fromPushIdentifier pushIdentifier: WebcomKey) -> Date?
  • encodedKey(from:) Extension method

    Encodes the input string to get a value that may be used as a valid node key. Returns a string that may be used as a valid node key to represent a given value.

    The returned value may be decoded as follow to retrieve the input value:

    • in Swift, use the removingPercentEncoding property,
    • in JavaScript (e.g. for security rules), use the decodeURIComponent() global function.

    Declaration

    Swift

    public func encodedKey(from rawKey: String) -> String?

    Parameters

    rawKey

    The input string to encode.

    Return Value

    An encoded form of the input string, or nil when the input string cannot be encoded.

  • runOnlyFirstTime(_:) Extension method

    Runs a block the first time this method is used for a given instance.

    The first time this method is called for a given instance, the block is run. On subsequent calls on the same instance, this method is a no-operation, whether the block is the same of different from the first call.

    This method is designed to be used in the viewDidAppear(_:) or the viewWillAppear(_:) method of a view controller to do some subscriptions, that need the user interface to be already loaded.

    Declaration

    Swift

    public func runOnlyFirstTime(_ block: () -> Void)

    Parameters

    block

    The block to run.

Wrapped == DatasyncNode

  • path Extension method

    The absolute path of the node referred by this instance.

    The path consists of the keys of the ancestors of this node, starting from the root of the tree, separated by / (slash) characters. The last segment of the path is the key of this node. The before last segment of the path, if any, is the key of the parent of this node. The path always begins with a /. The path of the root node is "/".

    Declaration

    Swift

    public var path: String { get }
  • key Extension method

    The key of the node represented by this instance.

    It corresponds to the last segment of the path. It does not contain any / (slash) character. The key of the root node is the empty string ("").

    Declaration

    Swift

    public var key: WebcomKey { get }
  • cacheValue Extension method

    The value of the node referred by this instance from the cache.

    When there is no value available in the cache, the returned value is null (not to be confused with the Swift nil keyword).

    In general, to get the value of a node, it is preferable to use the value(queue:then:) method.

    Declaration

    Swift

    public var cacheValue: DatasyncValue { get }
  • Creates a subscription that assigns the children of the referred node to a dictionary.

    In the dictionary:

    • the keys are the keys of the children, as returned by DatasyncEvent.key,
    • the values are decoded from the values of the children using DatasyncValue.decoded().

    This method uses an underlying subscription to follow children additions, changes and removals. The dictionary is updated each time an event is received for that subscription. If the value of an added or changed child could not be decoded, the corresponding element in the dictionary is removed. If the subscription is revoked by the back-end, the dictionary is cleared.

    Depending on stores, the subscription may be stored by the DatasyncManager of the referred node, as the subscribe(to:childrenConstraint:stores:file:line:queue:onEvent:onCompletion:) method does.

    To avoid a retain cycle, the subscription does not keep a strong reference on the object. The developer must ensure that its lifetime is at least as long as that of the subscription. This is the case when the dictionary and the DatasyncManager are stored in the same object, provided that stores is true.

    Example:

    class EmployeeDirectory {
    
        struct Employee: Decodable {
            let name: String
            let yearOfBirth: Int
        }
    
        let datasyncManager = Webcom.defaultApplication.datasyncService.createManager()
        var employees: [String: Employee] = [:]
    
        func assignEmployees() {
            let employeesNode = datasyncManager / "employees"
            employeesNode?.assignChildren(to: \.employees, on: self)
        }
    
        ...
    }
    

    Declaration

    Swift

    @discardableResult
    public func assignChildren<R>(to keyPath: ReferenceWritableKeyPath<R, [WebcomKey : some Decodable]>, on object: R, stores: Bool = true, queue: DispatchQueue? = nil, file: StaticString = #fileID, line: UInt = #line) -> DatasyncSubscription? where R : AnyObject

    Parameters

    keyPath

    A key path that indicates the dictionary property to assign.

    object

    The object that contains the dictionary property to assign.

    stores

    Indicates whether the returned subscription should be stored by the manager.

    queue

    The queue to which dictionary updates are dispatched. When nil, the default callback queue of the manager of this instance is used.

    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

    An instance describing the underlying subscription, or nil if the subscription failed.

  • Cancels an operation registered using the DatasyncTime.nextDisconnection value for the node referred by this instance.

    If no operation is currently registered, this method has no effect. This method cannot cancel an operation that has already been performed by the back-end.

    Declaration

    Swift

    public func cancelNextDisconnectionAction()

Wrapped == DatasyncService

  • state Extension method

    The states of the web socket opened by this service.

    Declaration

    Swift

    public var state: DatasyncState { get }
  • isConnectionEnabled Extension method

    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 nonmutating set }
  • cache Extension method

    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 }
  • cleanCache() Extension method

    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()
  • saveCache() Extension method

    Saves the cache.

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

    Declaration

    Swift

    @discardableResult
    public func saveCache() -> Bool
  • 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.

  • stopPublishingMyPresence() Extension method

    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()
  • isPresent(state:) Extension method

    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.

Wrapped == WebcomApplication

  • configuration Extension method

    The configuration corresponding to this application.

    Declaration

    Swift

    public var configuration: WebcomConfiguration { get }
  • defaultSession Extension method

    The URLSession instance used by this application.

    When this property is nil, Webcom.defaultSession is used instead.

    Declaration

    Swift

    public var defaultSession: URLSession? { get nonmutating set }
  • defaultCallbackQueue Extension method

    The DispatchQueue used by default to schedule callbacks.

    When this property is nil, Webcom.defaultCallbackQueue is used instead.

    Declaration

    Swift

    public var defaultCallbackQueue: DispatchQueue? { get nonmutating set }
  • jsonEncoder Extension method

    The JSONEncoder instance used to serialize data for this application.

    This property is initialized using the createDefaultJSONEncoder() static function.

    Declaration

    Swift

    public var jsonEncoder: JSONEncoder { get nonmutating set }
  • jsonDecoder Extension method

    The JSONDecoder instance used to deserialize data for this application.

    This property is initialized using the createDefaultJSONDecoder() static function.

    Declaration

    Swift

    public var jsonDecoder: JSONDecoder { get nonmutating set }
  • createDefaultJSONEncoder() Extension method

    Returns a new JSON encoder.

    The returned instance is configured with:

    • iso8601 date encoding strategy,
    • base64 data encoding strategy.

    This function is used to initialize the jsonEncoder property of instances.

    Declaration

    Swift

    public static func createDefaultJSONEncoder() -> JSONEncoder

    Return Value

    A new JSONEncoder instance

  • createDefaultJSONDecoder() Extension method

    Returns a new JSON decoder.

    The returned instance is configured with:

    • iso8601 date decoding strategy,
    • base64 data decoding strategy.

    This function is used to initialize the jsonDecoder property of instances.

    Declaration

    Swift

    public static func createDefaultJSONDecoder() -> JSONDecoder

    Return Value

    A new JSONDecoder instance

  • identifier Extension method

    The identifier of this application on the back-end.

    Declaration

    Swift

    public var identifier: String { get }