Class: DatasyncService

DatasyncService

Exposes the functions of the Webcom Datasync service. This service provides a real time interface to a Webcom database. Under the hood, it works using a websocket between the client and the Webcom back end.

Since:
  • 2.11

Members

(readonly) currentState :DatasyncService.State

The current state of the real-time connection to the Webcom back end managed by this instance of DatasyncService. This property returns the same value as the virtual data node at the special ".info" path.

Type:

(readonly) offlineData

Returns the currently available data in the local cache, encoded into a string. It is intended to be saved somewhere by the client before shutting down the application, and then provided back to the application at start, through the "offlineData" property of the options passed to the Webcom constructor.

(readonly) options :DatasyncService.Options

Gives the options that were used to build this DatasyncService instance.

Type:

(readonly) shouldBeConnected :boolean

Returns the current expected connection state to the Webcom back end managed by this DatasyncService instance:

  • true means it should be connected, however it may not be the case if the device network connectivity is down. The actual connection state is given by the connection.connected property of the DatasyncService#currentState member.
  • false means it should be disconnected. The value of this property is driven by calls to the DatasyncService#connect and DatasyncService#disconnect methods.
Type:
  • boolean

Methods

cleanOfflineData()

Removes from the local cache all data that don't result from a currently ongoing subscription. This means that all data preserved until now following calls to the Query#offPreservingOfflineData method are lost and will no longer be available offline.

connect()

Forces the establishment of the real-time connection to the Webcom back end managed by this DatasyncService instance and enables the retry connection feature.

If the device has network connectivity, calling this method should end in switching the connection.connected property of DatasyncService#currentState to true. However, this property will remain false as long as the network or the Webcom back end is unavailable.

disconnect()

Forces the interruption of the real-time connection to the Webcom back end managed by this DatasyncService instance and disables the retry connection feature. The connection will not be reestablished until DatasyncService#connect is called.

persist() → {boolean}

Persists the content of the local cache. It actually stores the value returned by DatasyncService#offlineData into the local storage.

Note: if the persist option of this DatasyncService instance is not set to true or the running client is not a regular browser, this method has no effect.

Returns:

true if the local cache could be persisted, or false otherwise.

Type
boolean

Type Definitions

Options

Type:
  • Object
Properties:
Name Type Attributes Default Description
persist boolean <optional>
false

Indicates whether the local cache content can be persisted using the DatasyncService#persist method. When true, the local cache content is also restored from the client local storage at startup.
Cannot be true for non-browser clients.

connect boolean <optional>
true

Indicates whether the real-time connection to the Webcom back end should be established at startup. If false, then the application starts working offline.

completeSubscriptionOnCancelation boolean <optional>
false

(Since 2.14.1)
Indicates whether the completeCallback of callback subscriptions must be called (with null) when they are canceled by the app (typically by calling Query#off or Query#offPreservingOfflineData methods).

websocket Object <optional>

Specifies the options that control the establishment of the real-time connection to the Webcom back end (advanced use only):

Properties
Name Type Attributes Default Description
protocol number <optional>
5

Version of the protocol to use. Available versions are 5 or 6.

keepAliveDelayMs number <optional>
45000

Maximum delay (expressed in milliseconds) between issuing of 2 consecutive messages to the back end. The range of allowed values is between 30 seconds and 5 minutes.

pongDelayMs number <optional>
5000

Maximum delay (expressed in milliseconds) to receive acknowledgement of ping messages from the back end.

Since:
  • 2.11

State

Represents the current state of a DatasyncService instance. It can be retrieved by either getting the DatasyncService#currentState property or watching the ".info" virtual data node (using the Webcom#on method).

Type:
  • Object
Properties:
Name Type Attributes Description
reachable boolean <optional>

Indicates whether the hosting device has network connectivity, independently of the establishment of the real-time connection to the Webcom back end.

connected boolean

Deprecated: use the connection.connected property instead.

serverTimeOffset number <optional>

Deprecated: use the connection.serverTimeOffsetMs property instead.

connection Object

Gives some information about the real-time connection to the Webcom back end:

Properties
Name Type Attributes Description
connected boolean

Indicates whether the connection is successfully established and available. Typically, this property switches to false when going offline.

serverTimeOffsetMs number <optional>

As soon as the real-time connection is established, indicates the number of milliseconds between the Webcom back end time and the device time (not including the network delay between them) such that: serverTime = deviceTime + offset.
The number may be positive (device time is earlier than back end time) or negative (device time is later than back end time).

authenticated boolean

true if and only if authentication reports an authenticated state (as stated by the AuthenticationService.State#isAuthenticated method).
Deprecated: use the authentication property instead.

authentication AuthenticationService.State

Reports the authentication state validated on the real-time connection to the Webcom back end. This property may be slightly delayed wrt. AuthenticationService#currentState when authenticating or slightly early when the authentication token is revoked by the back end.

Since:
  • 2.11
show
deprecated