- Since:
- 2.11 (moved from
DatasyncServicesince 3.0)
- 2.11 (moved from
Extends
- WebcomService
- ServerlessDb.LongTermSubscriptionService
Classes
Interfaces
Members
(static, constant) FORGET :number
Cache-control policy that removes (forgets) the data watched by a canceled subscription from the local cache.
It may be passed to Webcom.Callback or returned by a ServerlessDb.CancelationCallback.
It is available through the FORGET property of the Webcom.ServerlessDb property.
Type:
- number
(static, constant) KEEP :number
Cache-control policy that keeps a copy of the data watched by a canceled subscription within the local cache.
It may be passed to Webcom.Callback or returned by a ServerlessDb.CancelationCallback.
It is available through the KEEP property of the Webcom.ServerlessDb property.
Type:
- number
(static, constant) KEEP_UPDATING :number
Cache-control policy that keeps the data watched by a canceled subscription within the local cache and keeps updating them, even if the corresponding data node is no longer explicitly watched.
It may be passed to Webcom.Callback or returned by a ServerlessDb.CancelationCallback.
It is available through the KEEP_UPDATING property of the Webcom.ServerlessDb property.
Type:
- number
(static, constant) NEXT_DISCONNECTION :number
Write policy consisting in deferring writing data until the next disconnection (intentional or accidental) from the
ServerlessDb when invoked by ServerlessDb.ServerlessDbNode#clear, ServerlessDb.ServerlessDbNode#set or
ServerlessDb.ServerlessDbNode#merge methods.
It is available through the NEXT_DISCONNECTION property of the Webcom.ServerlessDb property.
Type:
- number
(static, constant) NOW :number
Write policy consisting in writing data immediately when invoked by ServerlessDb.ServerlessDbNode#clear,
ServerlessDb.ServerlessDbNode#set or ServerlessDb.ServerlessDbNode#merge methods.
It is available through the NOW property of the Webcom.ServerlessDb property.
Type:
- number
(static, constant) ON_DISCONNECTION :number
Write policy consisting in writing data recurrently at each disconnection (intentional or accidental) from the
ServerlessDb when invoked by ServerlessDb.ServerlessDbNode#clear, ServerlessDb.ServerlessDbNode#set or
ServerlessDb.ServerlessDbNode#merge methods.
By difference with NEXT_DISCONNECTION the request(s) executed with ON_DISCONNECTION policy will be replayed at each disconnection.
Unlike NEXT_DISCONNECTION, the ON_DISCONNECTION policy will replay the requests at each disconnection.
The only way to stop such scheduled operations is to explicitly invoke the ServerlessDb.ServerlessDbNode#cancelNextDisconnectionOps method.
Type:
- number
- Since:
- 3.3
(readonly) currentState :ServerlessDb.State
The current state of the real-time connection to the Webcom back end managed by this instance of
ServerlessDb. This property returns the same value as the virtual data node at the special
".info" path.
Type:
(readonly) offlineData :string
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 ServerlessDb.Configuration passed to the WebcomApp
constructor.
Type:
- string
rootNode :ServerlessDb.ServerlessDbNode
Get the root data node managed by this ServerlessDb.
Type:
- Since:
- 3.0
(readonly) shouldBeConnected :boolean
Returns the current expected connection state to the Webcom back end managed by this
ServerlessDb instance:
truemeans 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 theconnection.connectedproperty of theServerlessDb#currentStatemember.falsemeans it should be disconnected. The value of this property is driven by calls to theServerlessDb#connectandServerlessDb#disconnectmethods.
Type:
- boolean
Methods
cleanLongTermSubscriptions()
Clears all the ongoing long term subscriptions associated with the current authenticated user from the client local storage.
This method requires a user to be authenticated.
WARNING: this method doesn't cancel the subscriptions!
It only removes them from the local storage, so that the ServerlessDb#getLongTermSubscriptions method can
no longer retrieve them. Use ServerlessDb.ServerlessDbNode#unsubscribe or
ServerlessDbLite.ServerlessDbLiteNode#unsubscribe to actually cancel them (otherwise they may still persist
in the Webcom back end).
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, which results from past subscriptions with a
ServerlessDb.KEEP or ServerlessDb.ServerlessDbNode#KEEP_UPDATING policy, 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
ServerlessDb 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 ServerlessDb#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
ServerlessDb instance and disables the retry connection feature. The connection will not be
reestablished until ServerlessDb#connect is called.
generateUniqueKey() → {string}
Returns a unique key (which can typically be used to get a relativeNode
of a ServerlessDb.ServerlessDbNode).
The generated key is guaranteed to be lexicographically ordered after any previously generated key (even on another client device) and can be used to store sub-nodes from several clients at a time.
The timestamp when the returned key has been generated may be further retrieved using the
ServerlessDb.ServerlessDbNode#timestamp property on a ServerlessDb.ServerlessDbNode with this key.
Returns:
- Type
- string
getLongTermSubscriptions() → {Array.<ServerlessDb.LongTermSubscription>}
Retrieves the list of the ongoing long term subscriptions associated with the current authenticated user, which are stored in the client local storage.
Such subscriptions are stored when invoking the ServerlessDb.ServerlessDbNode#subscribe method with a
ServerlessDb.Webhook or the ServerlessDbLite.ServerlessDbLiteNode#subscribe method.
This method requires a user to be authenticated.
Returns:
- Type
- Array.<ServerlessDb.LongTermSubscription>
persist() → {boolean}
Persists the content of the local cache. It actually stores the value returned by
ServerlessDb#offlineData into the local storage.
Note: if the persist option of this ServerlessDb 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
API
Constants and static methods associated to the ServerlessDb service.
Such an object is available through the Webcom.ServerlessDb property.
Properties:
| Name | Type | Description | ||||||
|---|---|---|---|---|---|---|---|---|
FORGET |
ServerlessDb.FORGET | Cache-control policy that removes (forgets) the data watched by a canceled subscription from the local cache. |
||||||
KEEP |
ServerlessDb.KEEP | Cache-control policy that keeps a copy of the data watched by a canceled subscription within the local cache. |
||||||
KEEP_UPDATING |
ServerlessDb.KEEP_UPDATING | Cache-control policy that keeps the data watched within the local cache and keeps updating them. |
||||||
NOW |
ServerlessDb.NOW | Write policy consisting in writing data immediately. |
||||||
NEXT_DISCONNECTION |
ServerlessDb.NEXT_DISCONNECTION | Write policy consisting in deferring writing data until the next disconnection. |
||||||
ON_DISCONNECTION |
ServerlessDb.ON_DISCONNECTION | Write policy consisting in writing data recurrently at each disconnection. |
||||||
ServerValue |
Object | Dictionary of special objects intended to be replaced by a value computed by the
Webcom back end when written into a Properties
|
||||||
Event |
ServerlessDb.EventDescriptor | Convenient link to the
|
||||||
Callback |
ServerlessDb.Callback.Factory | Function that creates an instance of |
||||||
Constraint |
ServerlessDb.Constraint | Convenient link to the |
- Since:
- 3.5
CancelationCallback(reasonnullable) → {ServerlessDb.FORGET|ServerlessDb.KEEP|ServerlessDb.KEEP_UPDATING}
Callback function called to notify that a subscription (previously started using the
ServerlessDb.ServerlessDbNode#subscribe method) is canceled, that is, either explicitly aborted by the app,
or revoked by the Webcom back end.
Parameters:
| Name | Type | Attributes | Description |
|---|---|---|---|
reason |
Error |
<nullable> |
The reason why the subscription is canceled: either |
Returns:
The cache-control policy to
apply to the data hold by the canceled subscription. If the callback returns nothing (undefined), then the
default cache-control policy setup when the subscription was started is applied.
Configuration
Properties:
| Name | Type | Attributes | Default | Description | ||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
baseUrl |
URL | string |
<optional> |
Since 3.0 |
|||||||||||||||||||||
offlineData |
string | Object |
<optional> |
Initial value of the local cache. If not set, either |
|||||||||||||||||||||
persist |
boolean |
<optional> |
false | Indicates whether the local cache content can be persisted using the
|
||||||||||||||||||||
connect |
boolean |
<optional> |
true | Indicates whether the real-time connection to the Webcom back end should be
established at startup. If |
||||||||||||||||||||
completeSubscriptionOnCancelation |
boolean |
<optional> |
true | Since 2.14.1 |
||||||||||||||||||||
websocket |
Object |
<optional> |
Specifies the options that control the establishment of the real-time connection to the Webcom back end (advanced use only): Properties
|
|||||||||||||||||||||
statPeriodMs |
number |
<optional> |
5*60*1000 | Period (in milliseconds) which usage statistics are sent to the Webcom back end with. |
- Since:
- 2.11
State
Represents the current state of a ServerlessDb instance. It can be retrieved by either getting the
ServerlessDb#currentState property or watching the ".info" virtual data node (using the
ServerlessDb.ServerlessDbNode#subscribe method).
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 |
|||||||||||||
serverTimeOffset |
number |
<optional> |
Deprecated |
||||||||||||
connection |
Object | Gives some information about the real-time connection to the Webcom back end: Properties
|
|||||||||||||
authenticated |
boolean | Deprecated |
|||||||||||||
authentication |
Authentication.State | Reports the authentication state validated on
the real-time connection to the Webcom back end. This property may be slightly delayed wrt.
|
- Since:
- 2.11
SubscriptionCallback(snapshot, precedingChildKeyopt, nullable)
Callback function called to notify that an event, which has been subscribed using the
ServerlessDb.ServerlessDbNode#subscribe method, has just been raised.
Parameters:
| Name | Type | Attributes | Description |
|---|---|---|---|
snapshot |
ServerlessDb.DataSnapshot | The data associated with the raised event. |
|
precedingChildKey |
string |
<optional> <nullable> |
When subscribed to child-related events (see |